php使用百度天气接口示例
程序员文章站
2023-11-24 16:58:10
注意地区要转码的百度ak申请地址:http://lbsyun.baidu.com/apiconsole/key
复制代码 代码如下:
<?php
{
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: "雷阵雨转中雨",
wind: "微风",
temperature: "29~22℃"
},
{
date: "后天(周五)",
daypictureurl: "http://api.map.baidu.com/images/weather/day/yin.png",
nightpictureurl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "阴转多云",
wind: "微风",
temperature: "31~23℃"
},
{
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: "31~24℃"
}
]
},
{
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: "东风3-4级",
temperature: "27℃"
},
{
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: "东北风3-4级",
temperature: "35~27℃"
},
{
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: "35~27℃"
},
{
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: "34~27℃"
}
]
}
]
}
注意地区要转码的
百度ak申请地址:http://lbsyun.baidu.com/apiconsole/key
复制代码 代码如下:
<?php
$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: "雷阵雨转中雨",
wind: "微风",
temperature: "29~22℃"
},
{
date: "后天(周五)",
daypictureurl: "http://api.map.baidu.com/images/weather/day/yin.png",
nightpictureurl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "阴转多云",
wind: "微风",
temperature: "31~23℃"
},
{
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: "31~24℃"
}
]
},
{
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: "东风3-4级",
temperature: "27℃"
},
{
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: "东北风3-4级",
temperature: "35~27℃"
},
{
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: "35~27℃"
},
{
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: "34~27℃"
}
]
}
]
}
上一篇: 我也谈谈百度K站以及百度k站原因?