最近在做微信公眾平臺測試時,想在里面子菜單上添加查詢未來幾天(包括今天)天氣的功能,就查找了下好用的天氣預報查詢接口API,使用比較多的有:國家氣象局天氣接口、新浪天氣預報接口、百度天氣預報接口、google天氣接口、Yahoo天氣接口等等,我使用的是百度提供的免費天氣查詢接口API,下面與大家分享下...
創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都做網(wǎng)站、成都網(wǎng)站設計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的玉龍網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!
1、查詢方式:
百度提供的是根據(jù)緯度和城市名查詢天氣情況
2、接口事例:
3、接口參數(shù)說明:
4、返回結(jié)果說明:
5、
//城市名
$city?=?'上海';
//對json格式的字符串進行編碼
$arr?=json_decode($str,TRUE);
print_r($atr);
//城市名
$city = '上海';
//獲取json格式的數(shù)據(jù)
$str =file_get_contents("".$city."output=jsonak=5slgyqGDENN7Sy7pw29IUvrZ");
//對json格式的字符串進行編碼
$arr =json_decode($str,TRUE); ? ? ?
print_r($atr);
6、返回頁面的是json編碼后的數(shù)據(jù):
[plain] view plain copy print?
meta?charset="UTF-8"
Array
(
[error]?=?0
[status]?=?success
[date]?=?2014-03-17
[results]?=?Array
(
[0]?=?Array
(
[currentCity]=?上海
[weather_data]=?Array
(
[0]=?Array
(
[date]?=?周一(今天,?實時:19℃)
[dayPictureUrl]?=
[nightPictureUrl]?=
[weather]?=?晴
[wind]?=?西南風3-4級
[temperature]?=?13℃
)
[1]?=?Array
(
[date]=?周二
[dayPictureUrl]?=
[nightPictureUrl]?=?
[weather]=?多云轉(zhuǎn)陰
[wind]=?東北風3-4級
[temperature]?=?24?~?9℃
)
[2]?=?Array
(
[date]=?周三
[dayPictureUrl]?=
[nightPictureUrl]?=?
[weather]=?中雨轉(zhuǎn)小雨
[wind]=?東北風3-4級
[temperature]?=?15?~?8℃
)
[3]?=?Array
(
[date]=?周四
[dayPictureUrl]?=
[nightPictureUrl]?=
[weather]=?多云轉(zhuǎn)晴
[wind]=?北風3-4級
[temperature]?=?14?~?6℃
)
)
)
)
)
meta charset="UTF-8"
Array
(
[error] = 0
[status] = success
[date] = 2014-03-17
[results] = Array
?(
? ? ?[0] = Array
? ? ? ? ?(
? ? ? ? ? ? ?[currentCity]= 上海
? ? ? ? ? ? ?[weather_data]= Array
? ? ? ? ? ? ? ? ?(
? ? ? ? ? ? ? ? ? ? ?[0]= Array
? ? ? ? ? ? ? ? ? ? ? ? ?(
? ? ? ? ? ? ? ? ? ? ? ? ? ? [date] = 周一(今天, 實時:19℃)
? ? ? ? ? ? ? ? ? ? ? ? ? ? [dayPictureUrl] =
? ? ? ? ? ? ? ? ? ? ? ? ? ? [nightPictureUrl] =
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[weather] = 晴
? ? ? ? ? ? ? ? ? ? ? ? ? ? [wind] = 西南風3-4級
? ? ? ? ? ? ? ? ? ? ? ? ? ? [temperature] = 13℃
? ? ? ? ? ? ? ? ? ? ? ? ?)
? ? ? ? ? ? ? ? ? ? ?[1] = Array
? ? ? ? ? ? ? ? ? ? ? ? ?(
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[date]= 周二
? ? ? ? ? ? ? ? ? ? ? ? ? ? [dayPictureUrl] =
? ? ? ? ? ? ? ? ? ? ? ? ? ? [nightPictureUrl] =
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[weather]= 多云轉(zhuǎn)陰
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[wind]= 東北風3-4級
? ? ? ? ? ? ? ? ? ? ? ? ? ? [temperature] = 24 ~ 9℃
? ? ? ? ? ? ? ? ? ? ? ? ?)
? ? ? ? ? ? ? ? ? ? ?[2] = Array
? ? ? ? ? ? ? ? ? ? ? ? ?(
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[date]= 周三
? ? ? ? ? ? ? ? ? ? ? ? ? ? [dayPictureUrl] =
? ? ? ? ? ? ? ? ? ? ? ? ? ? [nightPictureUrl] =
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[weather]= 中雨轉(zhuǎn)小雨
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[wind]= 東北風3-4級
? ? ? ? ? ? ? ? ? ? ? ? ? ? [temperature] = 15 ~ 8℃
? ? ? ? ? ? ? ? ? ? ? ? ?)
? ? ? ? ? ? ? ? ? ? ?[3] = Array
? ? ? ? ? ? ? ? ? ? ? ? ?(
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[date]= 周四
? ? ? ? ? ? ? ? ? ? ? ? ? ? [dayPictureUrl] =
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[nightPictureUrl] =
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[weather]= 多云轉(zhuǎn)晴
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[wind]= 北風3-4級
? ? ? ? ? ? ? ? ? ? ? ? ? ? [temperature] = 14 ~ 6℃
? ? ? ? ? ? ? ? ? ? ? ? ?)
? ? ? ? ? ? ? ? ?)
? ? ? ? ?)
?)
)
7、PHP中自帶了處理json格式字符串的內(nèi)置函數(shù),下面做一個事例,并給出完整代碼:
[php] view plain copy print?
metacharset="UTF-8"
?php
//城市名
$city?=?'上海';
//獲取json格式的數(shù)據(jù)
$str?=?file_get_contents("".$city."output=jsonak=5slgyqGDENN7Sy7pw29IUvrZ");
//對json格式的字符串進行編碼
$arr?=?json_decode($str,TRUE);
echo?"城市:".$arr['results'][0]['currentCity']."?日期:".$arr['date']."br?/br?/";
foreach($arr['results'][0]['weather_data']as?$val)
{
echo?$val['date']."br/";
echo?"天氣:{$val['weather']}br/";
echo?"風向:{$val['wind']}br/";
echo?"溫度:{$val['temperature']}br/br?/";
}
?
metacharset="UTF-8"
?php
//城市名
$city = '上海';
//獲取json格式的數(shù)據(jù)
$str = file_get_contents("".$city."output=jsonak=5slgyqGDENN7Sy7pw29IUvrZ");
//對json格式的字符串進行編碼
$arr = json_decode($str,TRUE); ? ? ?
echo "城市:".$arr['results'][0]['currentCity']." 日期:".$arr['date']."br /br /";
foreach($arr['results'][0]['weather_data']as $val)
{
?echo $val['date']."br/";
?echo "天氣:{$val['weather']}br/";
?echo "風向:{$val['wind']}br/";
?echo "溫度:{$val['temperature']}br/br /";
}
?
8、返回的內(nèi)容如下:
1.修改PHP配置文件,保證能夠連接到數(shù)據(jù)庫。
2.修改數(shù)據(jù)庫配置,授予192.168.1.253以訪問權限。這里只需授予這個IP就行了。如果不授予,PHP將不能訪問數(shù)據(jù)庫;如果授予范圍過廣,將會給你的系統(tǒng)帶來潛在的安全風險。
標準控件可以用CreateWindow函數(shù)生成,其中的lpClassName參數(shù)使用系統(tǒng)預定義的了名字,如BUTTON EDIT LISTBOX等,具體查看這個函數(shù)的說明
用ajax···數(shù)據(jù)庫查詢好數(shù)據(jù)后以json的格式和js通信··然后顯示在頁面上··PHP百度地圖API怎么讀取數(shù)據(jù)庫里的坐標點顯示在地
新聞名稱:數(shù)據(jù)庫php查詢api php查詢數(shù)據(jù)庫內(nèi)容表格
文章網(wǎng)址:http://chinadenli.net/article12/ddeijgc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)站營銷、、App設計、營銷型網(wǎng)站建設、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)