PHP获取城市天气API接口源码
php获取城市天气API接口源码,接口调用的是微鲤的接口,2020年9月1日 10:11:07测试接口还可以正常使用。
API查询接口代码
<?php function tian(){ $city=$_GET['city']; $url="https://wthrcdn.etouch.cn/weather_mini?city=".$city; $str = file_get_contents($url); $result= gzdecode($str); //end echo $result; } tian(); ?>
接口返回数据
{"data":{"yesterday":{"date":"31日星期一","high":"高温 34℃","fx":"北风","low":"低温 24℃","fl":"<![CDATA[2级]]>","type":"晴"},"city":"武汉","forecast":[{"date":"1日星期二","high":"高温 34℃","fengli":"<![CDATA[3级]]>","low":"低温 23℃","fengxiang":"北风","type":"晴"},{"date":"2日星期三","high":"高温 32℃","fengli":"<![CDATA[2级]]>","low":"低温 20℃","fengxiang":"北风","type":"晴"},{"date":"3日星期四","high":"高温 33℃","fengli":"<![CDATA[2级]]>","low":"低温 19℃","fengxiang":"西风","type":"晴"},{"date":"4日星期五","high":"高温 33℃","fengli":"<![CDATA[2级]]>","low":"低温 21℃","fengxiang":"南风","type":"晴"},{"date":"5日星期六","high":"高温 31℃","fengli":"<![CDATA[2级]]>","low":"低温 21℃","fengxiang":"东风","type":"多云"}],"ganmao":"感冒易发期,外出请适当调整衣物,注意补充水分。","wendu":"28"},"status":1000,"desc":"OK"}
本文结束