免費、穩定的天氣預報API
一. 國家氣象局
-
實時介面:
實時天氣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天預報資料 URL: http://mobile.weather.com.cn/data/forecast/101010100.html?_=1381891660081
該介面來源氣象局移動版網站,json資料格式如下:{
“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": "大雨" }; //定義風向陣列 var fxArr={ "0": "無持續風向", "1": "東北風", "2": "東風", "3": "東南風", "4": "南風", "5": "西南風", "6": "西風", "7": "西北風", "8": "北風", "9": "旋轉風" }; //定義風力陣列 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介面根節點: 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程式碼實現的,通過XML介面根節點遞迴獲得全國幾千個縣以上城市cide code的程式碼,供參考(可直接在終端下執行):
方法二:一次性獲取全國+國外主要城市,8763個城市列表資訊。URL:http://mobile.weather.com.cn/js/citylist.xml
二. 中國天氣
SmartWeatherAPI(http://smart.weather.com.cn/wzfw/smart/weatherapi.shtml) -
SmartWeatherAPI介面(簡稱”SWA”介面)是中國氣象局面向網路媒體、手機廠商、第三方氣象服務機構等使用者,通過web方式提供資料氣象服務的官方載體。該資料主要包括預警、實況、指數、常規預報(24小時)等資料內容。
介面文件:http://download.weather.com.cn/creative/SmartWeatherAPI_Lite_WebAPI_3.0.1.rar
使用須申請,詳見官網http://smart.weather.com.cn/wzfw/smart/weatherapi.shtml
三. 和風天氣
資料主要包含:實時天氣,3天內天氣預報,生活指數,空氣質量。
訪問流量:4000次/天。
訪問頻率:200次/分鐘。
URL:https://free-api.heweather.com/v5/forecast?city=yourcity&key=yourkey
city:城市名稱,city可通過城市中英文名稱、ID、IP和經緯度進行查詢,經緯度查詢格式為:經度,緯度。例:city=北京,city=beijing,city=CN101010100,city= 60.194.130.1
key:使用者認證key
註冊頁面:https://www.heweather.com/products
介面文件:https://www.heweather.com/documents/api/v5
四. 心知天氣(免費版只提供地級市資料)
包含資料:中國地級城市、天氣實況、天氣預報(3天)、生活指數(基礎)。
訪問頻率限制:400次/小時
api詳述:https://www.seniverse.com/doc
使用需註冊。
註冊地址:https://www.seniverse.com/signup
五. 彩雲天氣
資料包含:實時天氣資料(天氣、溫度、溼度、風向、網速、雲量、降雨量、PM2.5、空氣質量指數)。
API詳述:http://wiki.swarma.net/index.php/彩雲天氣API/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
使用需註冊
產品詳單:http://labs.swarma.net/api/caiyun_api_service_price.pdf
註冊頁面:https://www.caiyunapp.com/dev_center/regist.html
六. 中央天氣預報
url:http://tj.nineton.cn/Heart/index/all
引數如下:
city:城市碼
language:固定值 zh-chs
unit:溫度單位固定值 c。可不填。也可省略該引數
aqi:固定值 city。可不填。也可省略該引數
alarm:固定值 1。可不填。也可省略該引數
key:祕鑰,固定值 78928e706123c1a8f1766f062bc8676b。可不填。也可省略該引數
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”: “易發期”,
“details”: “相對今天出現了較大幅度降溫,較易發生感冒,體質較弱的朋友請注意適當防護。”
},
“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:城市 id
last_update:上次更新時間
now:現在天氣狀況
text:天氣狀況
code:???
temperature:溫度
feels_like:體感溫度
wind_direction:風向
wind_speed:風速
wind_scale:風力大小
humidity:空氣溼度
visibility:能見度,單位為 km
pressure:氣壓,單位為 hPa
air_quality:具體空氣質量指數
aqi:空氣質量指數
pm25:pm2.5指數
pm10:pm10指數
so2:二氧化硫指數
no2:二氧化氮指數
co:一氧化碳指數
o3:臭氧指數
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/
拼接引數:
city:城市
language:語言
key:祕鑰,固定值 78928e706123c1a8f1766f062bc8676b。可不填。也可省略該引數
url 示例:http://tj.nineton.cn/Heart/index/future24h/?city=CHSH000000&language=zh-chs&key=36bdd59658111bc23ff2bf9aaf6e345c
或 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:成功時返回 OK
hourly:具體小時天氣資訊列表
text:天氣狀況
code:請參考 [code 細節]
temperature:溫度
time:時間
另 ,code細節
/// 晴
case sunny = 0
/// 晴
case clear = 1
/// 晴
case fair1 = 2
/// 晴
case fair2 = 3
/// 多雲
case cloudy = 4
/// 晴間多雲
case partlyCloudy1 = 5
/// 晴間多雲
case partlyCloudy2 = 6
/// 大部多雲
case mostlyCloudy1 = 7
/// 大部多雲
case mostlyCloudy2 = 8
/// 陰
case overcast = 9
/// 陣雨
case shower = 10
/// 雷陣雨
case thundershower = 11
/// 雷陣雨伴有冰雹
case thundershowerWithHail = 12
/// 小雨
case lightRain = 13
/// 中雨
case moderateRain = 14
/// 大雨
case heavyRain = 15
/// 暴雨
case storm = 16
/// 大暴雨
case heavyStorm = 17
/// 特大暴雨
case severeStorm = 18
/// 凍雨
case iceRain = 19
/// 雨夾雪
case sleet = 20
/// 陣雪
case snowFlurry = 21
/// 小雪
case lightSnow = 22
/// 中雪
case moderateSnow = 23
/// 大雪
case heavySnow = 24
/// 暴雪
case snowstorm = 25
/// 浮塵
case dust = 26
/// 揚沙
case sand = 27
/// 沙塵暴
case duststorm = 28
/// 強沙塵暴
case sandstorm = 29
/// 霧
case foggy = 30
/// 霾
case haze = 31
/// 風
case windy = 32
/// 大風
case blustery = 33
/// 颶風
case hurricane = 34
/// 熱帶風暴
case tropicalStorm = 35
/// 龍捲風
case tornado = 36
/// 冷
case cold = 37
/// 熱
case hot = 38
/// 未知
case unknown = 99