国家气象局官方发布网站 中国天气网接口:
接口1: http://m.weather.com.cn/data/citycode.html ,返回的数据相对最全面,包含未来6天的天气情况;
接口2: http://weather.com.cn/data/cityinfo/citycode.html ,返回当天的天气数据;
接口3: http://www.weather.com.cn/data/sk/citycode.html ,返回实时天气数据;
网址中 citycode 为城市代码,百度就可查询到。如:http://m.weather.com.cn/data/101010100.html为北京天气数据;
PHP端可以直接用函数 file_get_contents 抓取接口数据,再进行json 转码即可。
接口1返回数据格式:
{ "weatherinfo":{ ["city"]=> string(6) "北京" //城市名 ["city_en"]=> string(7) "beijing" //城市英文名 ["date_y"]=> string(15) "2014年1月8日" //发布日期 ["date"]=> string(0) "" ["week"]=> string(9) "星期三" //星期几发布的 ["fchh"]=> string(2) "08" ["cityid"]=> string(9) "101010100" //城市代码 ["temp1"]=> string(10) "0℃~-9℃" //今天至未来六天气温(摄氏度) ["temp2"]=> string(10) "1℃~-9℃" ["temp3"]=> string(10) "3℃~-7℃" ["temp4"]=> string(10) "4℃~-6℃" ["temp5"]=> string(10) "2℃~-7℃" ["tem