适应手机端的天气预报页面
http://m.weather.com.cn
奇怪的是 在微信浏览器里面 必须要带上经纬度http://m.weather.com.cn/d/town/index?lat=$lat&lon=$lon
更多关于天气的接口
https://blog.csdn.net/x_iya/article/details/52189750
https://blog.csdn.net/weixin_41830601/article/details/81661611
原文 链接 https://zhidao.baidu.com/question/1989073542429544307.html
http://flash.weather.com.cn/wmaps/xml/china.xml
http://flash.weather.com.cn/wmaps/xml/hubei.xml
感觉也不是所有的省份名都行 广东的就没有
http://flash.weather.com.cn/wmaps/xml/城市拼音.xml
根据 拼音来的
得到的数据是xml格式的
数据有两种结果
http://flash.weather.com.cn/wmaps/xml/shenzhen.xml
shenzhen.png
http://flash.weather.com.cn/wmaps/xml/weihai.xml
weihai.png
处理方式: (很草率啊.. 赶得紧,就先这样。)$pinyin = new \Pin\Pinyin\pinyin(); $result = $pinyin->pinyin(substr(I('post.city'), 0, -1)); // 将接收的城市名称转换为拼音 $url = 'http://flash.weather.com.cn/wmaps/xml/'.$result.'.xml'; $xml = $this->curl_get($url); // 获取xml $xml = (array)simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA); $jsonArray = json_decode(json_encode($xml),true); // 将xml 解析为普通数组 // 如果接口返回的值有两个以上 if ($jsonArray['city'][0] == null) { $list['stateDetailed'] = $jsonArray['city']['@attributes']['stateDetailed']; $list['windPower'] = $jsonArray['city']['@attributes']['windPower']; } else { $list['stateDetailed'] = $jsonArray['city'][0]['@attributes']['stateDetailed']; $list['windPower'] = $jsonArray['city'][0]['@attributes']['windPower']; } /** * curl get method */ function curl_get($url){ if(function_exists('file_get_contents')){ $file_contents = file_get_contents($url); } else{ $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); } return $file_contents; }
2018-09-26 天气预报
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 1. 国家气象局 实时接口:实时天气1:http://www.weather.com.cn/data/sk/101...