,前段时间我在开发一个自己的微信公众平台,需要实现天气预报功能,在网上度娘了下,实现天气预报的接口API还蛮多的,有:中国气象局、雅虎和新浪等,中国天气预报接口需要全国的编码,雅虎的有时候访问不了,研究了下还是新浪提供的接口比较简单实用。新浪天气预报API的URL是http://PHP.weather.sina.com.cn/xml.php?city=%B1%B1%BE%A9&password=DJOYnieT8234jlsK&day=0。其中,city后的城市转码。Password固定,Day为0表示当天天气,1表示第二天的天气,2表示第三天的天气,以此类推,最大为4。返回的XML,说明如下:
<Profiles>
<Weather>
<city>广州</city>
<status1>晴</status1>
<status2>晴</status2>
<figure1>qing</figure1>
<figure2>qing</figure2>
<direction1>无持续风向</direction1>
<direction2>无持续风向</direction2>
<power1>≤3</power1>
<power2>≤3</power2>
<temperature1>7</temperature1>
<temperature2>-5</temperature2>
<ssd>0</ssd>
<tgd1>7</tgd1>
<tgd2>7</tgd2>
<zwx>2</zwx>
<ktk>7</ktk>
<pollution>3</pollution>
<xcz></xcz>
<zho></zho>
<diy></diy>
<fas></fas>
<chy>6</chy>
<zho_shuoming>暂无</zho_shuoming>
<diy_shuoming>暂无</diy_shuoming>
<fas_shuoming>暂无</fas_shuoming>
<chy_shuoming>棉衣、冬大衣、皮夹克、内着衬衫或羊毛内衣、毛衣、外罩大衣</chy_shuoming>
<pollution_l>一般</pollution_l>
<zwx_l>弱</zwx_l>
<ssd_l>较凉</ssd_l>
<fas_l>暂无</fas_l>
<zho_l>暂无</zho_l>
<chy_l>薄冬衣</chy_l>
<ktk_l>建议开启(制热)</ktk_l>
<xcz_l>暂无</xcz_l>
<diy_l>暂无</diy_l>
<pollution_s>对空气污染物扩散无明显影响</pollution_s>
<zwx_s>紫外线弱</zwx_s>
<ssd_s>老年、幼儿、体弱者外出需要带上薄围巾、薄手套。</ssd_s>
<ktk_s>建议开启空调</ktk_s>
<xcz_s>暂无</xcz_s>
<gm>2</gm>
<gm_l>易发期</gm_l>
<gm_s>天气很凉,季节转换的气候,慎重增加衣服;较易引起感冒;</gm_s>
<yd>5</yd>
<yd_l>不适宜</yd_l>
<yd_s>虽然晴空万里,但是户外运动时会感到很凉;</yd_s>
<savedate_weather>2013-03-01</savedate_weather>
<savedate_life>2013-03-01</savedate_life>
<savedate_zhishu>2013-03-01</savedate_zhishu>
</Weather>
</Profiles>