微信公众号天气预报功能实现(1,免费接口介绍)

微信公众号出来也几年了,刚出来没多久的时候博主有关注,也学习了一些基础知识当时还做了一些小功能,比如天气预报,以前用的weather的接口但是现在关闭无法使用了,经过搜索找到了一个免费的接口:

 

新浪天气接口

接口地址:http://php.weather.sina.com.cn/xml.php

http://php.weather.sina.com.cn/xml.php?city=%b1%b1%be%a9&password=DJOYnieT8234jlsK&day=1

city是城市的编码,这里要注意编码正确否则无法查询,这里的编码是 UrlEncode  (gb2321)

password是接口密码不用改

day是查询的时间   0表示今天   1表示明天    经测试最大值是4

获取的参数值如下:

<Profiles>
<Weather>
<city>北京</city>
<status1>多云</status1>
<status2>多云</status2>
<figure1>duoyun</figure1>
<figure2>duoyun</figure2>
<direction1>无持续风向</direction1>
<direction2>无持续风向</direction2>
<power1>≤3</power1>
<power2>≤3</power2>
<temperature1>14</temperature1>
<temperature2>7</temperature2>
<ssd>5</ssd>
<tgd1>16</tgd1>
<tgd2>16</tgd2>
<zwx>2</zwx>
<ktk>7</ktk>
<pollution>3</pollution>
<xcz></xcz>
<zho></zho>
<diy></diy>
<fas></fas>
<chy>5</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>2016-10-22</savedate_weather>
<savedate_life>2016-10-22</savedate_life>
<savedate_zhishu>2016-10-22</savedate_zhishu>
<udatetime>2016-10-21 08:10:00</udatetime>
</Weather>
</Profiles>

 

具体参数值需要的可以查看哦,根据这个接口就可以实现简单的微信公众号天气预报功能了,具体实现后期会更新

About sun 83 Articles
85后青年,自诩为伪文艺青年

Be the first to comment

Leave a Reply

Your email address will not be published.


*