1. 程式人生 > >中國天氣網API介面[祥注:使用網頁,並設定utf-8編碼,則可以看得見json中的中文,解決亂碼]

中國天氣網API介面[祥注:使用網頁,並設定utf-8編碼,則可以看得見json中的中文,解決亂碼]

這三個已經停用,資料不再更新,即使修改Referer,得到的已經不是正確的資訊。

官網提供的API

一、呼叫規範 規範用於指導三方合作伙伴合理呼叫指數、3天常規預報(24小時)預報服務資料。
請求方式:http get
介面組成:由固定URL加5個不同的引數組成,完整URL需客戶端經過固定方式加密後使用。
資料返回:json
完整URL:http://open.weather.com.cn/data/?areaid=""&type=""&date=""&appid=""&key=".urlencode($key);
固定URL:http://open.weather.com.cn/data/

需要申請ID

返回資料:

{
	"c": {
		"c1": "101010100",
		"c2": "beijing",
		"c3": "北京",
		"c4": "beijing",
		"c5": "北京",
		"c6": "beijing",
		"c7": "北京",
		"c8": "china",
		"c9": "中國",
		"c10": "1",
		"c11": "010",
		"c12": "100000",
		"c13": 116.391000,
		"c14": 39.904000,
		"c15": "33",
		"c16": "AZ9010",
		"c17": "+8"
	},
	"f": {
		"f1": [{
			"fa": "",
			"fb": "01",
			"fc": "",
			"fd": "13",
			"fe": "",
			"ff": "0",
			"fg": "",
			"fh": "0",
			"fi": "05:17|19:05"
		},
		{
			"fa": "01",
			"fb": "00",
			"fc": "28",
			"fd": "15",
			"fe": "0",
			"ff": "0",
			"fg": "0",
			"fh": "0",
			"fi": "05:16|19:06"
		},
		{
			"fa": "00",
			"fb": "01",
			"fc": "31",
			"fd": "15",
			"fe": "0",
			"ff": "0",
			"fg": "0",
			"fh": "0",
			"fi": "05:15|19:07"
		}],
		"f0": "201604281800"
	}
}

================================================================================

中華萬年曆API

抓包中華萬年曆得到的介面(JSON):

http://wthrcdn.etouch.cn/weather_mini?city=北京
通過城市名字獲得天氣資料,json資料
http://wthrcdn.etouch.cn/weather_mini?citykey=101010100
通過城市id獲得天氣資料,json資料

資料和中國天氣網(www.weather.com.cn)一致

資料:

{
	"desc": "OK",
	"status": 1000,
	"data": {
		"wendu": "22",
		"ganmao": "各項氣象條件適宜,無明顯降溫過程,發生感冒機率較低。",
		"forecast": [{
			"fengxiang": "南風",
			"fengli": "3-4級",
			"high": "高溫 26℃",
			"type": "多雲",
			"low": "低溫 13℃",
			"date": "28日星期四"
		},
		{
			"fengxiang": "無持續風向",
			"fengli": "微風級",
			"high": "高溫 28℃",
			"type": "多雲",
			"low": "低溫 15℃",
			"date": "29日星期五"
		},
		{
			"fengxiang": "無持續風向",
			"fengli": "微風級",
			"high": "高溫 31℃",
			"type": "晴",
			"low": "低溫 15℃",
			"date": "30日星期六"
		},
		{
			"fengxiang": "無持續風向",
			"fengli": "微風級",
			"high": "高溫 29℃",
			"type": "多雲",
			"low": "低溫 20℃",
			"date": "1日星期天"
		},
		{
			"fengxiang": "北風",
			"fengli": "4-5級",
			"high": "高溫 26℃",
			"type": "小到中雨",
			"low": "低溫 13℃",
			"date": "2日星期一"
		}],
		"yesterday": {
			"fl": "微風",
			"fx": "無持續風向",
			"high": "高溫 19℃",
			"type": "小雨",
			"low": "低溫 12℃",
			"date": "27日星期三"
		},
		"aqi": "118",
		"city": "北京"
	}
}

XML

http://wthrcdn.etouch.cn/WeatherApi?citykey=101010100

通過城市id獲得天氣資料,xml檔案資料,
當錯誤時會有<error>節點
http://wthrcdn.etouch.cn/WeatherApi?city=北京
通過城市名字獲得天氣資料,xml檔案資料

資料:

<resp>
<city>北京</city>
<updatetime>18:45</updatetime>
<wendu>22</wendu>
<fengli>2級</fengli>
<shidu>33%</shidu>
<fengxiang>東南風</fengxiang>
<sunrise_1>05:19</sunrise_1>
<sunset_1>19:06</sunset_1>
<sunrise_2/>
<sunset_2/>
<environment>
<aqi>118</aqi>
<pm25>61</pm25>
<suggest>兒童、老年人及心臟、呼吸系統疾病患者人群應減少長時間或高強度戶外鍛鍊</suggest>
<quality>輕度汙染</quality>
<MajorPollutants>臭氧8小時</MajorPollutants>
<o3>185</o3>
<co>1</co>
<pm10>101</pm10>
<so2>4</so2>
<no2>24</no2>
<time>18:00:00</time>
</environment>
<yesterday>
<date_1>27日星期三</date_1>
<high_1>高溫 19℃</high_1>
<low_1>低溫 12℃</low_1>
<day_1>
<type_1>小雨</type_1>
<fx_1>無持續風向</fx_1>
<fl_1>微風</fl_1>
</day_1>
<night_1>
<type_1></type_1>
<fx_1>無持續風向</fx_1>
<fl_1>微風</fl_1>
</night_1>
</yesterday>
<forecast>
<weather>
<date>28日星期四</date>
<high>高溫 26℃</high>
<low>低溫 13℃</low>
<day>
<type>多雲</type>
<fengxiang>南風</fengxiang>
<fengli>3-4級</fengli>
</day>
<night>
<type>多雲</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</night>
</weather>
<weather>
<date>29日星期五</date>
<high>高溫 28℃</high>
<low>低溫 15℃</low>
<day>
<type>多雲</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</day>
<night>
<type></type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</night>
</weather>
<weather>
<date>30日星期六</date>
<high>高溫 31℃</high>
<low>低溫 15℃</low>
<day>
<type></type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</day>
<night>
<type>多雲</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</night>
</weather>
<weather>
<date>1日星期天</date>
<high>高溫 29℃</high>
<low>低溫 20℃</low>
<day>
<type>多雲</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</day>
<night>
<type>小雨</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</night>
</weather>
<weather>
<date>2日星期一</date>
<high>高溫 26℃</high>
<low>低溫 13℃</low>
<day>
<type>小到中雨</type>
<fengxiang>北風</fengxiang>
<fengli>4-5級</fengli>
</day>
<night>
<type>多雲</type>
<fengxiang>北風</fengxiang>
<fengli>3-4級</fengli>
</night>
</weather>
</forecast>
<zhishus>
<zhishu>
<name>晨練指數</name>
<value>適宜</value>
<detail>天氣不錯,空氣清新,是您晨練的大好時機,建議不同年齡段的人們積極參加戶外健身活動。</detail>
</zhishu>
<zhishu>
<name>舒適度</name>
<value>較舒適</value>
<detail>白天天氣晴好,您在這種天氣條件下,會感覺早晚涼爽、舒適,午後偏熱。</detail>
</zhishu>
<zhishu>
<name>穿衣指數</name>
<value>舒適</value>
<detail>建議著長袖T恤、襯衫加單褲等服裝。年老體弱者宜著針織長袖襯衫、馬甲和長褲。</detail>
</zhishu>
<zhishu>
<name>感冒指數</name>
<value>少發</value>
<detail>各項氣象條件適宜,無明顯降溫過程,發生感冒機率較低。</detail>
</zhishu>
<zhishu>
<name>晾晒指數</name>
<value>適宜</value>
<detail>天氣不錯,適宜晾晒。趕緊把久未見陽光的衣物搬出來吸收一下太陽的味道吧!</detail>
</zhishu>
<zhishu>
<name>旅遊指數</name>
<value>適宜</value>
<detail>天氣較好,但絲毫不會影響您出行的心情。溫度適宜又有微風相伴,適宜旅遊。</detail>
</zhishu>
<zhishu>
<name>紫外線強度</name>
<value>中等</value>
<detail>屬中等強度紫外線輻射天氣,外出時建議塗擦SPF高於15、PA+的防晒護膚品,戴帽子、太陽鏡。</detail>
</zhishu>
<zhishu>
<name>洗車指數</name>
<value>較適宜</value>
<detail>較適宜洗車,未來一天無雨,風力較小,擦洗一新的汽車至少能保持一天。</detail>
</zhishu>
<zhishu>
<name>運動指數</name>
<value>較適宜</value>
<detail>天氣較好,戶外運動請注意防晒,推薦您在室內進行低強度運動。</detail>
</zhishu>
<zhishu>
<name>約會指數</name>
<value>適宜</value>
<detail>天氣較好,和戀人一起徜徉於熙攘人群中或漫步於柔軟草地上,都是不錯的主意哦。</detail>
</zhishu>
<zhishu>
<name>雨傘指數</name>
<value>不帶傘</value>
<detail>天氣較好,不會降水,因此您可放心出門,無須帶雨傘。</detail>
</zhishu>
</zhishus>
</resp>

一週天氣預報介面

http://mobile.weather.com.cn/data/forecast/101010100.html?_=1461845405

1461845405為Unix的時間戳,貌似該引數沒有什麼用處?

返回資料:

{
	"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"
	}
}

日期始終是201310121100,原因是伺服器限制了Referer

氣象圖示下載

http://openweather.weather.com.cn/Home/Help/icon/iid/10.html

獲取全國所有城市程式碼列表

方法一
XML介面根節點: http://flash.weather.com.cn/wmaps/xml/china.xml
XML介面主要作用是遞迴獲取全國幾千個縣以上單位的城市程式碼,如:
http://flash.weather.com.cn/wmaps/xml/liaocheng.xml
方法二
更新:最新發現可以一次性獲取全國+國外主要城市,8763個城市列表資訊。
URL:http://mobile.weather.com.cn/js/citylist.xml