用户可通过行政区划代码查询实时天气信息及未来5天天气预报。
https://api.map.baidu.com/weather_abroad/v1/?district_id=JPN10041030001&data_type=all&ak=你的ak
//GET请求
参数名 | 数据类型 | 必选 | 默认值 | 描述信息 |
---|---|---|---|---|
district_id | string | 否 | 无 | 海外城市行政区划编码海外城市行政区划编码为自定义,只支持海外天气查询服务使用),和location二选一 |
location | double | 否 | 无 | 经纬度,经度在前纬度在后,逗号分隔。支持类型:bd09mc/bd09ll/wgs84/gcj02。开通高级权限后才能使用 |
ak | string | 是 | 无 | 开发者密钥,可在API控制台申请获得 |
data_type | string | 是 | 无 | 请求数据类型。数据类型有:now/fc/index/alert/fc_hour/all,控制返回内容 |
output | string | 否 | json | 返回格式,目前支持json/xml |
language | string | 否 | cn | 语言类型。语言类型有: cn/en,分别表示中文和英文, 默认中文。目前仅支持行政区划显示英文。 |
coordtype | string | 否 | wgs84 | 支持类型:wgs84/bd09ll/bd09mc/gcj02 |
注意:如果district_id和location同时传,默认以district_id为准;
参数名 | 参数类型 | 描述信息 | 返回条件 | 异常值 | 字段类型 |
---|---|---|---|---|---|
address | Object | 地理位置信息 | - | - | 基础字段 |
country | String | 国家名称 | 始终返回 | - | 基础字段 |
province | String | 省份名称 | 始终返回 | - | 基础字段 |
city | String | 城市名称 | 始终返回 | - | 基础字段 |
name | String | 区县名称 | 始终返回 | - | 基础字段 |
id | String | 区县id | 始终返回 | - | 基础字段 |
now | Object | 实况数据 | - | - | 基础字段 |
temp | Int | 温度(℃) | 始终返回 | 999999 | 基础字段 |
feels_like | Int | 体感温度(℃) | data_type=now/all | 999999 | 基础字段 |
rh | Int | 相对湿度(%) | data_type=now/all | 999999 | 基础字段 |
wind_class | String | 风力等级 | data_type=now/all | 暂无 | 基础字段 |
wind_dir | String | 风向描述 | data_type=now/all | 暂无 | 基础字段 |
text | String | 天气现象 | data_type=now/all | 暂无 | 基础字段 |
prec_1h | Double | 1小时累计降水量(mm) | data_type=now/all | 999999 | 高级字段 |
clouds | Int | 云量(%) | data_type=now/all | 999999 | 高级字段 |
vis | Int | 能见度(m) | data_type=now/all | 999999 | 高级字段 |
uptime | String | 数据更新时间,当地时间 | data_type=now/all | - | 基础字段 |
forecasts | ObjectArray | 预报数据 | - | - | 基础字段 |
date | String | 日期,当地时间 | data_type=fc/all | - | 基础字段 |
week | String | 星期,当地时间 | data_type=fc/all | - | 基础字段 |
high | Int | 最高温度(℃) | data_type=fc/all | 999999 | 基础字段 |
low | Int | 最低温度(℃) | data_type=fc/all | 999999 | 基础字段 |
wc_day | String | 白天风力 | data_type=fc/all | "暂无" | 基础字段 |
wc_night | String | 晚上风力 | data_type=fc/all | "暂无" | 基础字段 |
wd_day | String | 白天风向 | data_type=fc/all | "暂无" | 基础字段 |
wd_night | String | 晚上风向 | data_type=fc/all | "暂无" | 基础字段 |
text_day | String | 白天天气现象 | data_type=fc/all | "暂无" | 基础字段 |
text_night | String | 晚上天气现象 | data_type=fc/all | "暂无" | 基础字段 |
未来24小时逐小时预报返回参数
参数名 | 参数类型 | 描述信息 | 返回条件 | 异常值 | 字段类型 |
---|---|---|---|---|---|
forecast_hours | Object Array | 预报数据 | - | - | 高级字段 |
text | String | 天气现象 | data_type=fc_hour/all | "暂无" | 高级字段 |
temp_fc | Int | 温度(℃) | data_type=fc_hour/all | 999999 | 高级字段 |
wind_class | String | 风力等级 | data_type=fc_hour/all | "暂无" | 高级字段 |
wind_dir | String | 风向描述 | data_type=fc_hour/all | "暂无" | 高级字段 |
rh | Int | 相对湿度 | data_type=fc_hour/all | 999999 | 高级字段 |
prec_1h | Double | 1小时累计降水量(mm) | data_type=fc_hour/all | 999999 | 高级字段 |
clouds | Int | 云量(%) | data_type=fc_hour/all | 999999 | 高级字段 |
data_time | String | 数据时间 | data_type=fc_hour/all | 999999 | 高级字段 |
输入AK可生成包含IP/SN校验方式的代码
<?php// 此处填写你在控制台-应用管理-创建应用后获取的AK$ak = '您的AK';// 发起一个http get请求,并返回请求的结果// $url字段为请求的地址// $param字段为请求的参数function request_get($url = '', $param = array()) {if (empty($url) || empty($param)) {return false;}$getUrl = $url . "?" . http_build_query($param);$curl = curl_init(); // 初始化curlcurl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在curl_setopt($curl, CURLOPT_URL, $getUrl); // 抓取指定网页curl_setopt($curl, CURLOPT_TIMEOUT, 1000); // 设置超时时间1秒curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // curl不直接输出到屏幕curl_setopt($curl, CURLOPT_HEADER, 0); // 设置header$data = curl_exec($curl); // 运行curlif (!$data) {print("an error occured in function request_get(): " . curl_error($curl) . "\n");}curl_close($curl);return $data;}// 请求地址$url = 'https://api.map.baidu.com/weather_abroad/v1/';// 构造请求参数$param['district_id'] = 'JPN10041030001';$param['data_type'] = 'all';$param['ak'] = $ak;$res = request_get($url, $param);// 将原始返回的结果打印出来print("请求的原始返回结果为:\n");print($res . "\n");?>
{"status":0,"result":{"location":{"country":"日本","province":"东京都","city":"目黑区","name":"目黑区","id":"JPN10041030001"},"now":{"temp":13,"feels_like":11,"rh":52,"wind_class":"2级","wind_dir":"东风","text":"阴","uptime":"20200220150000"},"forecasts":[{"date":"2020-02-20","week":"星期四","high":12,"low":12,"wc_day":"<3级","wc_night":"<3级","wd_day":"东风","wd_night":"东北风","text_day":"阴","text_night":"多云"},{"date":"2020-02-21","week":"星期五","high":13,"low":13,"wc_day":"<3级","wc_night":"<3级","wd_day":"东南风","wd_night":"东南风","text_day":"多云","text_night":"多云"},{"date":"2020-02-22","week":"星期六","high":16,"low":16,"wc_day":"3~4级","wc_night":"3~4级","wd_day":"西南风","wd_night":"西南风","text_day":"多云","text_night":"多云"},{"date":"2020-02-23","week":"星期日","high":15,"low":15,"wc_day":"<3级","wc_night":"<3级","wd_day":"西北风","wd_night":"北风","text_day":"多云","text_night":"多云"},{"date":"2020-02-24","week":"星期一","high":14,"low":14,"wc_day":"<3级","wc_night":"<3级","wd_day":"南风","wd_night":"南风","text_day":"多云","text_night":"多云"}],"forecast_hours":[{"text":"晴","temp_fc":14,"wind_class":"3~4级","wind_dir":"西南风","rh":15,"prec_1h":0,"clouds":10,"data_time":"2020-04-01 16:00:00"},{"text":"晴","temp_fc":14,"wind_class":"3~4级","wind_dir":"西南风","rh":13,"prec_1h":0,"clouds":10,"data_time":"2020-04-01 17:00:00"},{"text":"晴","temp_fc":13,"wind_class":"<3级","wind_dir":"西南风","rh":14,"prec_1h":0,"clouds":10,"data_time":"2020-04-01 18:00:00"},{"text":"晴","temp_fc":11,"wind_class":"<3级","wind_dir":"西南风","rh":15,"prec_1h":0,"clouds":10,"data_time":"2020-04-01 19:00:00"},{"text":"晴","temp_fc":10,"wind_class":"<3级","wind_dir":"西南风","rh":16,"prec_1h":0,"clouds":10,"data_time":"2020-04-01 20:00:00"},{"text":"晴","temp_fc":9,"wind_class":"<3级","wind_dir":"西风","rh":18,"prec_1h":0,"clouds":6,"data_time":"2020-04-01 21:00:00"},{"text":"晴","temp_fc":9,"wind_class":"<3级","wind_dir":"西风","rh":20,"prec_1h":0,"clouds":3,"data_time":"2020-04-01 22:00:00"},{"text":"晴","temp_fc":8,"wind_class":"<3级","wind_dir":"西风","rh":21,"prec_1h":0,"clouds":0,"data_time":"2020-04-01 23:00:00"},{"text":"晴","temp_fc":7,"wind_class":"<3级","wind_dir":"西北风","rh":26,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 00:00:00"},{"text":"晴","temp_fc":6,"wind_class":"<3级","wind_dir":"西北风","rh":31,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 01:00:00"},{"text":"晴","temp_fc":6,"wind_class":"<3级","wind_dir":"西北风","rh":36,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 02:00:00"},{"text":"晴","temp_fc":5,"wind_class":"<3级","wind_dir":"西北风","rh":39,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 03:00:00"},{"text":"晴","temp_fc":4,"wind_class":"<3级","wind_dir":"西北风","rh":42,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 04:00:00"},{"text":"晴","temp_fc":4,"wind_class":"<3级","wind_dir":"西北风","rh":45,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 05:00:00"},{"text":"晴","temp_fc":5,"wind_class":"<3级","wind_dir":"西北风","rh":40,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 06:00:00"},{"text":"晴","temp_fc":7,"wind_class":"<3级","wind_dir":"西北风","rh":34,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 07:00:00"},{"text":"晴","temp_fc":8,"wind_class":"<3级","wind_dir":"西北风","rh":29,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 08:00:00"},{"text":"晴","temp_fc":11,"wind_class":"<3级","wind_dir":"西北风","rh":29,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 09:00:00"},{"text":"晴","temp_fc":13,"wind_class":"<3级","wind_dir":"西北风","rh":29,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 10:00:00"},{"text":"晴","temp_fc":16,"wind_class":"<3级","wind_dir":"西北风","rh":29,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 11:00:00"},{"text":"晴","temp_fc":17,"wind_class":"3~4级","wind_dir":"西北风","rh":24,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 12:00:00"},{"text":"晴","temp_fc":18,"wind_class":"3~4级","wind_dir":"西北风","rh":19,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 13:00:00"},{"text":"晴","temp_fc":19,"wind_class":"3~4级","wind_dir":"西北风","rh":14,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 14:00:00"},{"text":"晴","temp_fc":19,"wind_class":"<3级","wind_dir":"西风","rh":17,"prec_1h":0,"clouds":0,"data_time":"2020-04-02 15:00:00"}]},"message":"success"}
参数 | 值 | 备注 | 必选 |
---|---|---|---|
district_id | 海外城市行政区划编码海外城市行政区划编码为自定义,只支持海外天气查询服务使用),和location二选一 | 否 | |
data_type | 请求数据类型。数据类型有:now/fc/index/alert/fc_hour/all,控制返回内容 | 是 |
1 | 服务器内部错误 | 具体失败消息会在message提示 |
2 | 高级权限才允许使用location字段 | 用户需开通高级权限功能 |
10 | 缺少必要的请求参数 | 缺少参数的时候会抛出该异常 |
11 | 请求参数格式错误 | 请求参数类型错误时会抛出该异常, 如字符长度、数据类型、数据格式不规范等 |
20 | 身份验证失败 | ak 无效时会抛出该异常 |
21 | timestamp超出有效时间范围 | timestamp 与服务端的当前时间相差超过1分钟 |
40 | 查询的区域编码无效 | 查询的区域编码与约定的编码不符 |
41 | 查询的经纬度值范围无效 | 查询的经纬度超出了正常的经纬度范围 |
42 | 不支持的数据类型 | 查询的数据类型不支持 |
43 | 不支持的语言类型 | 查询的语言类型不支持 |
44 | 经纬度所在地区无数据覆盖 | 输入的经纬度区域无数据覆盖 |
45 | 服务被禁用,请确认是否开通高级权限 | 查询的数据类型与用户类型不匹配,请确认是否开通高级权限 |
50 | 服务繁忙 | 其他类型错误 |
101 | AK参数不存在 | 请求消息没有携带AK参数 |
102 | MCODE参数不存在,mobile类型mcode参数必需 | 对于Mobile类型的应用请求需要携带mcode参数,该错误码代表服务器没有解析到mcode |
200 | APP不存在,AK有误请检查再重试 | 根据请求的AK,找不到对应的APP |
201 | APP被用户自己禁用,请在控制台解禁 | |
202 | APP被管理员删除 | 恶意APP被管理员删除 |
203 | APP类型错误 | 当前API控制台支持Server(类型1), Mobile(类型2, 新版控制台区分为Mobile_Android(类型21)及Mobile_IPhone(类型22))及Browser(类型3),除此之外其他类型认为是APP类型错误 |
210 | APP IP校验失败 | 在申请SERVER类型应用的时候选择IP校验,需要填写IP白名单,如果当前请求的IP地址不在IP白名单或者不是0.0.0.0/0就认为IP校验失败 |
211 | APP SN校验失败 | SERVER类型APP有两种校验方式IP校验和SN校验,当用户请求的SN和服务端计算出来的SN不相等的时候提示SN校验失败 |
220 | APP Referer校验失败 | 浏览器类型的APP会校验referer字段是否存且切在referer白名单里面,否则返回该错误码 |
230 | APP Mcode码校验失败 | 服务器能解析到mcode,但和数据库中不一致,请携带正确的mcode |
240 | APP 服务被禁用 | 用户在API控制台中创建或设置某APP的时候禁用了某项服务,若需开通权限,可进入API控制台为AK勾选对应服务 |
250 | 用户不存在 | 根据请求的user_id, 数据库中找不到该用户的信息,请携带正确的user_id |
251 | 用户被自己删除 | 该用户处于未激活状态 |
252 | 用户被管理员删除 | 恶意用户被加入黑名单 |
260 | 服务不存在 | 服务器解析不到用户请求的服务名称 |
261 | 服务被禁用 | 该服务已下线,请在控制台确认是否有该服务的权限 |
301 | 永久配额超限,限制访问 | 配额超限,可在控制台购买提升配额 |
302 | 天配额超限,限制访问 | 配额超限,可在控制台购买提升配额 |
401 | 当前并发量已经超过约定并发配额,限制访问 | 并发控制超限,可在控制台购买提升并发 |
402 | 当前并发量已经超过约定并发配额,并且服务总并发量也已经超过设定的总并发配额,限制访问 | 并发控制超限,可在控制台购买提升并发 |
上一篇
下一篇
本篇文章对您是否有帮助?