1. 國家氣象局
實時接口:
實時天氣1:http://www.weather.com.cn/data/sk/101190408.html
實時天氣2:http://www.weather.com.cn/data/cityinfo/101190408.html
實時天氣3(帶時間戳):http://mobile.weather.com.cn/data/sk/101010100.html?_=1381891661455
一周天氣預報接口
7天預報數(shù)據(jù) URL:http://mobile.weather.com.cn/data/forecast/101010100.html?_=1381891660081
該接口來源氣象局移動版網(wǎng)站整袁,json數(shù)據(jù)格式如下:
{"c": {"c1":"101010100","c2":"beijing","c3":"北京","c4":"beijing","c5":"北京","c6":"beijing","c7":"北京","c8":"china","c9":"中國","c10":"1","c11":"010","c12":"100000","c13":"116.391","c14":"39.904","c15":"33","c16":"AZ9010","c17":"+8"},"f": {"f1": [? ? ? ? ? ? {"fa":"01","fb":"03","fc":"10","fd":"5","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:21|17:40"},? ? ? ? ? ? {"fa":"07","fb":"07","fc":"19","fd":"12","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:22|17:38"},? ? ? ? ? ? {"fa":"02","fb":"00","fc":"15","fd":"5","fe":"8","ff":"8","fg":"3","fh":"1","fi":"06:23|17:37"},? ? ? ? ? ? {"fa":"00","fb":"00","fc":"16","fd":"4","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:24|17:35"},? ? ? ? ? ? {"fa":"00","fb":"00","fc":"18","fd":"7","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:25|17:34"},? ? ? ? ? ? {"fa":"00","fb":"01","fc":"18","fd":"8","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:26|17:32"},? ? ? ? ? ? {"fa":"01","fb":"01","fc":"16","fd":"6","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:27|17:31"}? ? ? ? ],"f0":"201310121100"}}
詳細接口分析如下:
//格式說明 var format={"fa":圖片1,"fb":圖片2,"fc":溫度1,fd:溫度2,fe:風向1,ff:風向2,fg:風力1,fh:風力2,fi:日出日落}; //定義天氣類型var weatherArr={"10":"暴雨","11":"大暴雨","12":"特大暴雨","13":"陣雪","14":"小雪","15":"中雪","16":"大雪","17":"暴雪","18":"霧","19":"凍雨","20":"沙塵暴","21":"小到中雨","22":"中到大雨","23":"大到暴雨","24":"暴雨到大暴雨","25":"大暴雨到特大暴雨","26":"小到中雪","27":"中到大雪","28":"大到暴雪","29":"浮塵","30":"揚沙","31":"強沙塵暴","53":"霾","99":"","00":"晴","01":"多云","02":"陰","03":"陣雨","04":"雷陣雨","05":"雷陣雨伴有冰雹","06":"雨夾雪","07":"小雨","08":"中雨","09":"大雨"}; //定義風向數(shù)組 var fxArr={"0":"無持續(xù)風向","1":"東北風","2":"東風","3":"東南風","4":"南風","5":"西南風","6":"西風","7":"西北風","8":"北風","9":"旋轉風"};//定義風力數(shù)組 var flArr={"0":"微風","1":"3-4級","2":"4-5級","3":"5-6級","4":"6-7級","5":"7-8級","6":"8-9級","7":"9-10級","8":"10-11級","9":"11-12級"};
獲取全國所有城市代碼列表
方法一:XML接口根節(jié)點:http://flash.weather.com.cn/wmaps/xml/china.xmlXML接口主要作用是遞歸獲取全國幾千個縣以上單位的城市代碼,如:江蘇的XML地址為:http://flash.weather.com.cn/wmaps/xml/shanghai.xml蘇州的XML地址為:http://flash.weather.com.cn/wmaps/xml/jiangsu.xml上面頁面獲得太倉city code:101190408合成太倉天氣信息地址:http://m.weather.com.cn/data/101190408.html
下面貼一段PHP代碼實現(xiàn)的磺樱,通過XML接口根節(jié)點遞歸獲得全國幾千個縣以上城市cide code的代碼砰蠢,供參考(可直接在終端下運行):
方法二:一次性獲取全國+國外主要城市辨泳,8763個城市列表信息虱岂。URL:http://mobile.weather.com.cn/js/citylist.xml
2. 中國天氣SmartWeatherAPI(http://smart.weather.com.cn/wzfw/smart/weatherapi.shtml)
SmartWeatherAPI接口(簡稱”SWA”接口)是中國氣象局面向網(wǎng)絡媒體、手機廠商漠吻、第三方氣象服務機構等用戶量瓜,通過web方式提供數(shù)據(jù)氣象服務的官方載體司恳。該數(shù)據(jù)主要包括預警途乃、實況、指數(shù)扔傅、常規(guī)預報(24小時)等數(shù)據(jù)內容耍共。
接口文檔:http://download.weather.com.cn/creative/SmartWeatherAPI_Lite_WebAPI_3.0.1.rar
使用須申請,詳見官網(wǎng)http://smart.weather.com.cn/wzfw/smart/weatherapi.shtml
3. 和風天氣
數(shù)據(jù)主要包含:實時天氣猎塞,3天內天氣預報试读,生活指數(shù),空氣質量荠耽。
訪問流量:4000次/天钩骇。
訪問頻率:200次/分鐘。
URL:https://free-api.heweather.com/v5/forecast?city=yourcity&key=yourkey
city:城市名稱,city可通過城市中英文名稱倘屹、ID银亲、IP和經(jīng)緯度進行查詢,經(jīng)緯度查詢格式為:經(jīng)度,緯度纽匙。例:city=北京务蝠,city=beijing,city=CN101010100烛缔,city= 60.194.130.1
key:用戶認證key
注冊頁面:https://www.heweather.com/products
接口文檔:https://www.heweather.com/documents/api/v5
4. 心知天氣(免費版只提供地級市數(shù)據(jù))
包含數(shù)據(jù):中國地級城市馏段、天氣實況、天氣預報(3天)践瓷、生活指數(shù)(基礎)院喜。
訪問頻率限制:400次/小時
api詳述:https://www.seniverse.com/doc
使用需注冊。
注冊地址:https://www.seniverse.com/signup
5. 彩云天氣
數(shù)據(jù)包含:實時天氣數(shù)據(jù)(天氣当窗、溫度够坐、濕度、風向崖面、網(wǎng)速元咙、云量、降雨量巫员、PM2.5庶香、空氣質量指數(shù))。
API詳述:http://wiki.swarma.net/index.php/%E5%BD%A9%E4%BA%91%E5%A4%A9%E6%B0%94API/v2
url示例:https://api.caiyunapp.com/v2/TAkhjf8d1nlSlspN/121.6544,25.1552/realtime.json
https://api.caiyunapp.com/v2/TAkhjf8d1nlSlspN/121.6544,25.1552/realtime.jsonp?callback=MYCALLBACK
使用需注冊
產(chǎn)品詳單:http://labs.swarma.net/api/caiyun_api_service_price.pdf
注冊頁面:https://www.caiyunapp.com/dev_center/regist.html
6. 中央天氣預報
url:http://tj.nineton.cn/Heart/index/all
參數(shù)如下:
city:城市碼
language:固定值 zh-chs
unit:溫度單位固定值 c简识「弦矗可不填。也可省略該參數(shù)
aqi:固定值 city七扰∩萋福可不填。也可省略該參數(shù)
alarm:固定值 1颈走∩旁睿可不填。也可省略該參數(shù)
key:秘鑰立由,固定值 78928e706123c1a8f1766f062bc8676b轧钓。可不填锐膜。也可省略該參數(shù)
url 示例:http://tj.nineton.cn/Heart/index/all?city=CHSH000000&language=zh-chs&unit=c&aqi=city&alarm=1&key=78928e706123c1a8f1766f062bc8676b或http://tj.nineton.cn/Heart/index/all?city=CHSH000000&language=&unit=&aqi=&alarm=&key=或http://tj.nineton.cn/Heart/index/all?city=CHSH000000
json 示例:
{"status":"OK","weather": [? ? {"city_name":"佛山","city_id":"CHGD070000","last_update":"2017-02-19T12:15:00+08:00","now": {"text":"陰","code":"9","temperature":"21","feels_like":"21","wind_direction":"南","wind_speed":"10.44","wind_scale":"2","humidity":"58","visibility":"13.8","pressure":"1014","pressure_rising":"未知","air_quality": {"city": {"aqi":"64","pm25":"46","pm10":"74","so2":"9","no2":"28","co":"0.575","o3":"108","last_update":"2017-02-19T12:00:00+08:00","quality":"良"},"stations":null}? ? ? },"today": {"sunrise":"06:58 AM","sunset":"6:27 PM","suggestion": {"dressing": {"brief":"單衣類","details":"建議著長袖T恤毕箍、襯衫加單褲等服裝。年老體弱者宜著針織長袖襯衫道盏、馬甲和長褲而柑。"},"uv": {"brief":"最弱","details":"屬弱紫外線輻射天氣文捶,無需特別防護。若長期在戶外媒咳,建議涂擦SPF在8-12之間的防曬護膚品拄轻。"},"car_washing": {"brief":"不適宜","details":"不宜洗車,未來24小時內有雨伟葫,如果在此期間洗車恨搓,雨水和路上的泥水可能會再次弄臟您的愛車。"},"travel": {"brief":"適宜","details":"天氣較好筏养,溫度適宜斧抱,總體來說還是好天氣哦,這樣的天氣適宜旅游渐溶,您可以盡情地享受大自然的風光辉浦。"},"flu": {"brief":"易發(fā)期","details":"相對今天出現(xiàn)了較大幅度降溫,較易發(fā)生感冒茎辐,體質較弱的朋友請注意適當防護宪郊。"},"sport": {"brief":"比較適宜","details":"陰天,較適宜進行各種戶內外運動拖陆。"}? ? ? ? }? ? ? },"future": [? ? ? ? {"date":"2017-02-19","day":"周日","text":"陰/小雨","code1":"9","code2":"13","high":"24","low":"18","cop":"","wind":"微風3級"},? ? ? ? {"date":"2017-02-20","day":"周一","text":"陰","code1":"9","code2":"9","high":"23","low":"18","cop":"","wind":"微風3級"},? ? ? ? {"date":"2017-02-21","day":"周二","text":"陣雨","code1":"10","code2":"10","high":"22","low":"18","cop":"","wind":"微風3級"},? ? ? ? {"date":"2017-02-22","day":"周三","text":"小雨","code1":"13","code2":"13","high":"23","low":"13","cop":"","wind":"微風3級"},? ? ? ? {"date":"2017-02-23","day":"周四","text":"小雨","code1":"13","code2":"13","high":"20","low":"10","cop":"","wind":"北風4級"},? ? ? ? {"date":"2017-02-24","day":"周五","text":"小雨","code1":"13","code2":"13","high":"14","low":"10","cop":"","wind":"北風4級"},? ? ? ? {"date":"2017-02-25","day":"周六","text":"小雨","code1":"13","code2":"13","high":"15","low":"10","cop":"","wind":"微風3級"},? ? ? ? {"date":"2017-02-26","day":"周日","text":"小雨","code1":"13","code2":"13","high":"15","low":"10","cop":"","wind":"北風3級"},? ? ? ? {"date":"2017-02-27","day":"周一","text":"小雨/多云","code1":"13","code2":"4","high":"21","low":"11","cop":"","wind":"北風3級"},? ? ? ? {"date":"2017-02-28","day":"周二","text":"多云","code1":"4","code2":"4","high":"24","low":"14","cop":"","wind":"北風3級"}? ? ? ]? ? }? ]}
解析:
status:成功時返回 OK? ? weather:天氣信息? ? city_name:城市名? ? city_id:城市idlast_update:上次更新時間? ? now:現(xiàn)在天氣狀況? ? ? ? text:天氣狀況? ? ? ? code:???? ? ? ? temperature:溫度? ? ? ? feels_like:體感溫度? ? ? ? wind_direction:風向? ? ? ? wind_speed:風速? ? ? ? wind_scale:風力大小? ? ? ? humidity:空氣濕度? ? ? ? visibility:能見度弛槐,單位為 km? ? ? ? pressure:氣壓,單位為 hPa? ? ? ? air_quality:具體空氣質量指數(shù)? ? ? ? ? ? aqi:空氣質量指數(shù)? ? ? ? ? ? pm25:pm2.5指數(shù)? ? ? ? ? ? pm10:pm10指數(shù)? ? ? ? ? ? so2:二氧化硫指數(shù)? ? ? ? ? ? no2:二氧化氮指數(shù)? ? ? ? ? ? co:一氧化碳指數(shù)? ? ? ? ? ? o3:臭氧指數(shù)? ? ? ? ? ? last_update:上次更新時間? ? ? ? ? ? quality:空氣質量? ? today:今日天氣狀況? ? ? ? sunrise:日出時間? ? ? ? sunset:日落時間? ? ? ? suggestion:建議列表? ? ? ? ? ? dressing:穿衣信息? ? ? ? ? ? uv:紫外線建議? ? ? ? ? ? car_washing:洗車信息? ? ? ? ? ? travel:旅游信息? ? ? ? ? ? flu:流感信息? ? ? ? ? ? sport:運動信息? ? ? ? ? ? ? ? brief:建議依啰、說明? ? ? ? ? ? ? ? details:具體信息? ? future:未來天氣狀況列表? ? ? ? date:日期? ? ? ? day:周幾? ? ? ? text:天氣狀況? ? ? ? code1:???? ? ? ? code2:???? ? ? ? high:當日最高氣溫? ? ? ? low:當日最低氣溫? ? ? ? cop:???? ? ? ? wind:風力信息
24小時天氣預報
url:http://tj.nineton.cn/Heart/index/future24h/
拼接參數(shù):
city:城市
language:語言
key:秘鑰乎串,固定值 78928e706123c1a8f1766f062bc8676b∷倬可不填叹誉。也可省略該參數(shù)
或http://tj.nineton.cn/Heart/index/future24h/?city=CHSH000000&language=&key=
或http://tj.nineton.cn/Heart/index/future24h/?city=CHSH000000
json示例
{"status":"OK","hourly": [? ? {"text":"多云","code":"4","temperature":"16","time":"2017-02-19T13:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"18","time":"2017-02-19T14:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"17","time":"2017-02-19T15:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"16","time":"2017-02-19T16:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"16","time":"2017-02-19T17:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"16","time":"2017-02-19T18:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"15","time":"2017-02-19T19:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"15","time":"2017-02-19T20:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"15","time":"2017-02-19T21:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"14","time":"2017-02-19T22:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"14","time":"2017-02-19T23:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"14","time":"2017-02-20T00:00:00+08:00"},? ? {"text":"多云","code":"4","temperature":"15","time":"2017-02-20T01:00:00+08:00"},? ? {"text":"小雨","code":"13","temperature":"15","time":"2017-02-20T02:00:00+08:00"},? ? {"text":"小雨","code":"13","temperature":"15","time":"2017-02-20T03:00:00+08:00"},? ? {"text":"小雨","code":"13","temperature":"15","time":"2017-02-20T04:00:00+08:00"},? ? {"text":"中雨","code":"14","temperature":"15","time":"2017-02-20T05:00:00+08:00"},? ? {"text":"中雨","code":"14","temperature":"13","time":"2017-02-20T06:00:00+08:00"},? ? {"text":"中雨","code":"14","temperature":"10","time":"2017-02-20T07:00:00+08:00"},? ? {"text":"小雨","code":"13","temperature":"8","time":"2017-02-20T08:00:00+08:00"},? ? {"text":"小雨","code":"13","temperature":"6","time":"2017-02-20T09:00:00+08:00"},? ? {"text":"小雨","code":"13","temperature":"5","time":"2017-02-20T10:00:00+08:00"},? ? {"text":"小雨","code":"13","temperature":"5","time":"2017-02-20T11:00:00+08:00"},? ? {"text":"小雨","code":"13","temperature":"6","time":"2017-02-20T12:00:00+08:00"}? ]}
解析
status:成功時返回OKhourly:具體小時天氣信息列表text:天氣狀況code:請參考[code 細節(jié)]temperature:溫度time:時間
另 ,code細節(jié)
/// 晴casesunny =0/// 晴caseclear =1/// 晴casefair1 =2/// 晴casefair2 =3/// 多云casecloudy =4/// 晴間多云casepartlyCloudy1 =5/// 晴間多云casepartlyCloudy2 =6/// 大部多云casemostlyCloudy1 =7/// 大部多云casemostlyCloudy2 =8/// 陰caseovercast =9/// 陣雨caseshower =10/// 雷陣雨casethundershower =11/// 雷陣雨伴有冰雹casethundershowerWithHail =12/// 小雨caselightRain =13/// 中雨casemoderateRain =14/// 大雨caseheavyRain =15/// 暴雨casestorm =16/// 大暴雨caseheavyStorm =17/// 特大暴雨casesevereStorm =18/// 凍雨caseiceRain =19/// 雨夾雪casesleet =20/// 陣雪casesnowFlurry =21/// 小雪caselightSnow =22/// 中雪casemoderateSnow =23/// 大雪caseheavySnow =24/// 暴雪casesnowstorm =25/// 浮塵casedust =26/// 揚沙casesand =27/// 沙塵暴caseduststorm =28/// 強沙塵暴casesandstorm =29/// 霧casefoggy =30/// 霾casehaze =31/// 風casewindy =32/// 大風caseblustery =33/// 颶風casehurricane =34/// 熱帶風暴casetropicalStorm =35/// 龍卷風casetornado =36/// 冷casecold =37/// 熱casehot =38/// 未知caseunknown =99
簡書著作權歸作者所有闷旧,任何形式的轉載都請聯(lián)系作者獲得授權并注明出處长豁。