百度提供天氣預報查詢接口API,可以根據經緯度/城市名查詢天氣情況,我們可以在微信公眾平台開發中調用這一接口。
接口說明
根據經緯度/城市名查詢天氣的結果
接口示例
http://api.map.baidu.com/telematics/v3/weather?location=北京&output=json&ak=yourkey
百度ak申請地址:http://lbsyun.baidu.com/apiconsole/key
接口參數說明
參數類型 | 參數名稱 | 是否必須 | 具體描述 |
---|---|---|---|
String | ak | true | 開發者密鑰 |
String | sn | false | 若用戶所用ak的校驗方式為sn校驗時該參數必須。 |
String | location | true | 輸入城市名或經緯度,城市名稱如:北京,經緯度格式為lng,lat坐標如: location=116.305145,39.982368;城市天氣預報中間"|"分隔,location=116.305145,39.982368| 122.305145,36.982368|…. |
String | output | false | 輸出的數據格式,默認為xml格式,當output設置為’json’時,輸出的為json格式的數據; |
String | coord_type | false | 請求參數坐標類型,默認為gcj02經緯度坐標。允許的值為bd09ll、bd09mc、gcj02、wgs84。bd09ll表示百度經緯度坐標,bd09mc表示百度墨卡托坐標,gcj02表示經過國測局加密的坐標。wgs84表示gps獲取的坐標。 |
返回結果
參數名稱 | 含義 | 說明 | |
---|---|---|---|
currentCity | 當前城市 | 返回城市名 | |
status | 返回結果狀態信息 | ||
date | 當前時間 | 年-月-日 | |
results | 天氣預報信息 | 白天可返回近期3天的天氣情況(今天、明天、后天)、晚上可返回近期4天的天氣情況(今天、明天、后天、大后天) | |
results.currentCity | 當前城市 | ||
results.weather_data | weather_data.date | 天氣預報時間 | |
weather_data.dayPictureUrl | 白天的天氣預報圖片url | ||
weather_data.nightPictureUrl | 晚上的天氣預報圖片url | ||
weather_data.weather | 天氣狀況 | 所有天氣情況(”|”分隔符):晴|多雲|陰|陣雨|雷陣雨|雷陣雨伴有冰雹|雨夾雪|小雨|中雨|大雨|暴雨|大暴雨|特大暴雨|陣雪|小雪|中雪|大雪|暴雪|霧|凍雨|沙塵暴|小雨轉中雨|中雨轉大雨|大雨轉暴雨|暴雨轉大暴雨|大暴雨轉特大暴雨|小雪轉中雪|中雪轉大雪|大雪轉暴雪|浮塵|揚沙|強沙塵暴|霾 | |
weather_data.wind | 風力 | ||
weather_data.temperature | 溫度 |
返回xml格式的數據
<?xml version="1.0" encoding="utf-8" ?> <CityWeatherResponse> <status>success</status> <date>2014-05-03</date> <results> <currentCity>北京</currentCity> <weather_data> <date>周六(今天, 實時:22℃)</date> <dayPictureUrl>http://api.map.baidu.com/images/weather/day/leizhenyu.png</dayPictureUrl> <nightPictureUrl>http://api.map.baidu.com/images/weather/night/duoyun.png</nightPictureUrl> <weather>雷陣雨轉多雲</weather> <wind>北風5-6級</wind> <temperature>24 ~ 11℃</temperature> <date>周日</date> <dayPictureUrl>http://api.map.baidu.com/images/weather/day/duoyun.png</dayPictureUrl> <nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl> <weather>多雲轉晴</weather> <wind>北風4-5級</wind> <temperature>19 ~ 8℃</temperature> <date>周一</date> <dayPictureUrl>http://api.map.baidu.com/images/weather/day/qing.png</dayPictureUrl> <nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl> <weather>晴</weather> <wind>微風</wind> <temperature>21 ~ 9℃</temperature> <date>周二</date> <dayPictureUrl>http://api.map.baidu.com/images/weather/day/duoyun.png</dayPictureUrl> <nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl> <weather>多雲轉晴</weather> <wind>微風</wind> <temperature>21 ~ 10℃</temperature> </weather_data> </results> </CityWeatherResponse>
返回json格式的數據
{ "error": 0, "status": "success", "date": "2014-05-03", "results": [ { "currentCity": "北京", "weather_data": [ { "date": "周六(今天, 實時:22℃)", "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/leizhenyu.png", "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/duoyun.png", "weather": "雷陣雨轉多雲", "wind": "北風5-6級", "temperature": "24 ~ 11℃" }, { "date": "周日", "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png", "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png", "weather": "多雲轉晴", "wind": "北風4-5級", "temperature": "19 ~ 8℃" }, { "date": "周一", "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/qing.png", "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png", "weather": "晴", "wind": "微風", "temperature": "21 ~ 9℃" }, { "date": "周二", "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png", "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png", "weather": "多雲轉晴", "wind": "微風", "temperature": "21 ~ 10℃" } ] } ] }
效果如下:
★購買天氣預報功能源碼
微信掃描二維碼關注后返回購買圖文鏈接,然后進入購買:
