用户可通过行政区划代码查询实时天气信息及未来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 | 是 | 无 | 开发者密钥,可在申请获得 |
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字段为请求的参数functionrequest_get($url ='', $param =array()){if(empty($url)||empty($param)){returnfalse;}$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 | 当前并发量已经超过约定并发配额,并且服务总并发量也已经超过设定的总并发配额,限制访问 | 并发控制超限,可在控制台 |
上一篇
下一篇
本篇文章对您是否有帮助?