加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php使用百度天气接口示例

发布时间:2020-12-12 20:09:23 所属栏目:PHP教程 来源:网络整理
导读:注意地区要转码的 百度ak申请地址:http://lbsyun.baidu.com/apiconsole/key 代码如下: $city="嘉兴"; $content = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=%E5%98%89%E5%85%B4ak=5slgyqGDENN7Sy7pw29IUvrZ"); print_r(

注意地区要转码的
百度ak申请地址:http://lbsyun.baidu.com/apiconsole/key

代码如下:

$city="嘉兴";
$content = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=%E5%98%89%E5%85%B4&output=json&ak=5slgyqGDENN7Sy7pw29IUvrZ");
print_r(json_decode($content));

代码如下:
{
error: 0,
status: "success",
date: "2014-04-18",
results: [
{
currentCity: "嘉兴",
weather_data: [
{
date: "今天(周三)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多云",
wind: "微风",
temperature: "23℃"
},
{
date: "明天(周四)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/leizhenyu.png",
nightPictureUrl: "http://api.map.baidu.com/images/weather/night/zhongyu.png",
weather: "雷阵雨转中雨",
temperature: "29~22℃"
},
{
date: "后天(周五)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/yin.png",
weather: "阴转多云",
temperature: "31~23℃"
},
{
date: "大后天(周六)",
temperature: "31~24℃"
}
]
},
{
currentCity: "合肥市",
wind: "东风3-4级",
temperature: "27℃"
},
wind: "东北风3-4级",
temperature: "35~27℃"
},
wind: "南风",
wind: "东风",
temperature: "34~27℃"
}
]
}
]
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读