1、手机端则利用下面的代码
第一步:利用百度的api获取当前城市
$getIp=$_SERVER["REMOTE_ADDR"];
$content =file_get_contents("http://api.map.baidu.com/location/ip?ak=6tNCG8mTxXruj6Cmek7heNS5099eDw0F&ip={$getIp}&coor=bd09ll");
$json = json_decode($content);
$address['city']=$json->{'content'}->{'address_detail'}->{'city'};第二步:利用下面代码获取相关天气信息
$data =file_get_contents('http://www.sojson.com/open/api/weather/json.shtml?city=哈尔滨市');
$obj=json_decode($data);
$city= $obj->city;//北京 1
$a=$obj->data->forecast;
$quality=$obj->data->quality; //空气质量 4
$a1=trim(mb_substr($a[1]->high,2,-1,'utf-8'));//最高气温 3
$b1=trim(mb_substr($a[1]->low,2,-1,'utf-8'));//最低气温
$wendu=$a1."℃"."~".$b1."℃";
$type=$a[1]->type;//天气 2
dump($obj);
die;以上就是获取天气的api的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号