PHP调用百度天气接口API
程序员文章站
2023-09-05 19:49:51
```php
//百度天气接口API
$location = "北京"; //地区
$ak = "5slgyqGDENN7Sy7pw29IUvrZ"; //秘钥,需要申请,百度为了防止频繁请求
$weatherURL = "http://api.map.baidu.com/telematics/v3... ......
//百度天气接口api $location = "北京"; //地区 $ak = "5slgyqgdenn7sy7pw29iuvrz"; //秘钥,需要申请,百度为了防止频繁请求 $weatherurl = "http://api.map.baidu.com/telematics/v3/weather?location=$location&output=json&ak=$ak"; $ch = curl_init($weatherurl) ; curl_setopt($ch, curlopt_returntransfer, true); // 获取数据返回 curl_setopt($ch, curlopt_binarytransfer, true); // 在启用 curlopt_returntransfer 时候将获取数据返回 $result = curl_exec($ch); echo $result;
上一篇: PHP调用百度地图API