template design by http://www.20shx.com/
时间:2014-02-26 发布人:SHX 浏览次数:2701 评论:0
一、中国天气网
中国天气网提供了丰富的气象数据接口。下面我们介绍主要的几个:
国家根节点接口:
http://flash.weather.com.cn/wmaps/xml/china.xml
该接口以XML格式列出所有的省(自治区、直辖市)的中文名称(quName)和拼音名称(pyName)及省会城市的天气信息,其中广东的数据如下:
<city quName="广东" pyName="guangdong" cityname="广州" state1="2" state2="7" stateDetailed="阴转小雨" tem1="8" tem2="15" windState="微风"/>
该接口的主要功能是通过它获取省级节点的拼音名称。以广东为例:其pyName是“Guangdong”。
省级节点接口(以广东为例):
http://flash.weather.com.cn/wmaps/xml/Guangdong.xml
该接口以XML格式列出当前省下辖所有市的中文名称(quName)、拼音名称(pyName)、中心坐标、天气信息以及城市编码。其中深圳的数据如下所示:
<city cityX="409" cityY="257" cityname="深圳" centername="深圳" fontColor="FFFFFF" pyName="shenzhen" state1="1" state2="1" stateDetailed="多云" tem1="12" tem2="18" temNow="12" windState="微风" windDir="东北风" windPower="1级" humidity="74%" time="21:15" url="101280601"/>
在这个接口中主要获取城市名称及相应的城市编码。例如,深圳的城市编码为:101280601。可以编写程序将全国城市拓扑结构采集下来。也可以使用方倍工作室已经采集好的,点击这里下载。weather_city.rar
实时天气数据(以深圳为例):
http://www.weather.com.cn/data/sk/101280601.html
该接口以JSON格式列出当前城市的实时天气状况。如下所示:
{ "weatherinfo": { "city": "深圳", "cityid": "101280601", "temp": "12", "WD": "东北风", "WS": "1级", "SD": "75%", "WSE": "1", "time": "21:20", "isRadar": "1", "Radar": "JC_RADAR_AZ9755_JB" } }
实时天气数据参数说明下所示:
六日天气数据(以深圳为例):
http://m.weather.com.cn/data/101280601.html
该接口以JSON格式列出当前城市的六日天气状况。如下所示:
{ "weatherinfo": { "city": "深圳", "city_en": "shenzhen", "date_y": "2014年2月15日", "date": "", "week": "星期六", "fchh": "18", "cityid": "101280601", "temp1": "12℃~18℃", "temp2": "16℃~21℃", "temp3": "17℃~23℃", "temp4": "11℃~18℃", "temp5": "10℃~15℃", "temp6": "12℃~17℃", "tempF1": "53.6℉~64.4℉", "tempF2": "60.8℉~69.8℉", "tempF3": "62.6℉~73.4℉", "tempF4": "51.8℉~64.4℉", "tempF5": "50℉~59℉", "tempF6": "53.6℉~62.6℉", "weather1": "多云", "weather2": "阴", "weather3": "多云", "weather4": "中雨", "weather5": "多云", "weather6": "阴", "img1": "1", "img2": "99", "img3": "2", "img4": "99", "img5": "1", "img6": "99", "img7": "8", "img8": "99", "img9": "1", "img10": "99", "img11": "2", "img12": "99", "img_single": "1", "img_title1": "多云", "img_title2": "多云", "img_title3": "阴", "img_title4": "阴", "img_title5": "多云", "img_title6": "多云", "img_title7": "中雨", "img_title8": "中雨", "img_title9": "多云", "img_title10": "多云", "img_title11": "阴", "img_title12": "阴", "img_title_single": "多云", "wind1": "微风", "wind2": "微风", "wind3": "微风", "wind4": "东北风3-4级", "wind5": "微风", "wind6": "微风", "fx1": "微风", "fx2": "微风", "fl1": "小于3级", "fl2": "小于3级", "fl3": "小于3级", "fl4": "3-4级", "fl5": "小于3级", "fl6": "小于3级", "index": "较舒适", "index_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。", "index48": "较舒适", "index48_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。", "index_uv": "最弱", "index48_uv": "最弱", "index_xc": "适宜", "index_tr": "适宜", "index_co": "舒适", "st1": "19", "st2": "13", "st3": "23", "st4": "16", "st5": "24", "st6": "18", "index_cl": "适宜", "index_ls": "适宜", "index_ag": "不易发" } }
未来六日天气数据主要参数说明如下表所示:
以上接口是我们做天气预报功能将使用到的接口。
四、如何扩展
1. 在数据库加入邮编、区号、拼音等字段,可以扩展成使用区号等方式查询,请参考:http://www.cnblogs.com/txw1958/archive/2013/02/07/weixin-if4-weather-forecast.html
2. 拥有高级接口的用户,可以使用结合语音识别+中文分词技术,实现语音版的智能查询,请参考:http://www.cnblogs.com/txw1958/archive/2013/02/06/weixin-if40-voice-recognition.html
上一篇:三国演义告诉我们的人生60条真理下一篇:程序员的几种分类,你躺枪了吗?