//有什么问题请联系xemowo@qq.com
//未经授权禁止商业、转载
error_reporting(0);//屏蔽报错
$city=$_GET["city"];
if($city==""){exit("城市为空。");}
$html = file_get_contents("https://restapi.amap.com/v3/weather/weatherInfo?city=".$city."&key=你的高德key");
$arr = json_decode($html, true); // 将获取到的 JSON 数据解析成数组
$province = $arr["lives"][0]["province"];
$city = $arr["lives"][0]["city"];
$adcode = $arr["lives"][0]["adcode"];
$weather = $arr["lives"][0]["weather"];
$temperature = $arr["lives"][0]["temperature"];
$winddirection = $arr["lives"][0]["winddirection"];
$windpower = $arr["lives"][0]["windpower"];
$humidity = $arr["lives"][0]["humidity"];
$reporttime = $arr["lives"][0]["reporttime"];
$temperature_float = $arr["lives"][0]["temperature_float"];
$humidity_float = $arr["lives"][0]["humidity_float"];
$data = array(
'province' => $province,
'city' => $city,
'adcode' => $adcode,
'weather' => $weather,
'temperature' => $temperature,
'winddirection' => $winddirection,
'windpower' => $windpower,
'humidity' => $humidity,
'reporttime' => $reporttime,
'temperature_float' => $temperature_float,
'humidity_float' => $humidity_float,
);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit();
error_reporting(0);//屏蔽报错
$city=$_GET["city"];
if($city==""){exit("城市为空。");}
$html = file_get_contents("https://restapi.amap.com/v3/weather/weatherInfo?city=".$city."&key=你的高德key");
$arr = json_decode($html, true); // 将获取到的 JSON 数据解析成数组
$province = $arr["lives"][0]["province"];
$city = $arr["lives"][0]["city"];
$adcode = $arr["lives"][0]["adcode"];
$weather = $arr["lives"][0]["weather"];
$temperature = $arr["lives"][0]["temperature"];
$winddirection = $arr["lives"][0]["winddirection"];
$windpower = $arr["lives"][0]["windpower"];
$humidity = $arr["lives"][0]["humidity"];
$reporttime = $arr["lives"][0]["reporttime"];
$temperature_float = $arr["lives"][0]["temperature_float"];
$humidity_float = $arr["lives"][0]["humidity_float"];
$data = array(
'province' => $province,
'city' => $city,
'adcode' => $adcode,
'weather' => $weather,
'temperature' => $temperature,
'winddirection' => $winddirection,
'windpower' => $windpower,
'humidity' => $humidity,
'reporttime' => $reporttime,
'temperature_float' => $temperature_float,
'humidity_float' => $humidity_float,
);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
作者: 小恶魔owo, 来源:面包板社区
链接: https://mbb.eet-china.com/blog/uid-me-4067534.html
版权声明:本文为博主原创,未经本人允许,禁止转载!
文章评论(0条评论)
登录后参与讨论