天气服务

更新时间:2021-04-25 08:35:13下载pdf

本文介绍天气服务相关接口。

API 列表

请求方式 API列表 描述
GET /v1.0/countries/{country_code}/cities 查询城市列表
GET /v1.0/cities/{city_id} 查询城市信息
GET /v1.0/position/city 根据经纬度查询城市列表
GET /v1.0/cities/{city_id}/weather-forecast 查询城市天气预报
GET /v1.0/ip/weather-forecast 根据当前 IP 查询天气预报
GET /v1.0/position/weather 根据经纬度查询天气
GET /v1.0/cities/{cityId}/weathers 查询城市当前天气情况

查询城市列表

功能描述

根据国家码获取该国支持天气数据城市的信息。

接口地址

GET /v1.0/countries/{country_code}/cities

请求参数

参数名 类型 参数类型 必填 说明
countryCode String URI 国家码

请求示例

GET /v1.0/countries/cn/cities

返回信息

参数名 类型 说明
code Integer 参见全局错误码
success Boolean 是否成功:
  • true:成功
  • false:失败
msg String 请求失败的信息,成功为空。
result Object 返回结果。

Result

参数名 类型 说明
area String 地区名称
pinyin String 地区拼音
province String 省份
city String 城市名称
cityId String 城市 ID

返回示例

{ "success": true, "t": 1541399281296, "result": [ { "area": "北京市", "pinyin": "beijingshi", "province": "北京市", "city": "北京市", "cityId": "793409505965772800" }, { "area": "天津市", "pinyin": "tianjinshi", "province": "天津市", "city": "天津市", "cityId": "793409507844820992" } ] }

查询城市信息

功能描述

根据城市 ID来查询城市信息。

接口地址

GET /v1.0/cities/{city_id}

请求参数

参数名 类型 参数类型 必填 说明
city_id String URI 城市 ID

请求示例

GET /v1.0/cities/793409534348627968

返回信息

参数名 类型 说明
code Integer 参见全局错误码
success Boolean 是否成功:
  • true:成功
  • false:失败
msg String 请求失败的信息,成功为空。
result Object 返回结果。

Result

参数名 类型 说明
id String 城市信息
ids String 最近更新时间
dbTable String 城市信息
parentId Integer 城市信息
name String 城市名称
shortName String 城市信息
province String 省份名称
countryName String 国家名称
parentCityName String 城市信息
level Integer 城市信息
lon String 经度
lat String 纬度
cityHash String 城市信息
cityIndexId Integer 城市信息
domesticCity Boolean 城市信息

返回示例

{ "success": true, "t": 1541399281296, "result": { "id": 793409534348627968, "ids": null, "gmtCreate": 1477877317000, "gmtModified": 1477877317000, "dbTable": null, "parentId": 793416838972313600, "name": "杭州市", "shortName": "杭州市", "province": "浙江省", "countryName": "中国", "parentCityName": "杭州市", "level": 3, "lon": "120.1650798", "lat": "30.25258003", "cityHash": "wtmk", "cityIndexId": 62160, "domesticCity": true } }

错误码

以下为该接口常见的业务异常,更多的异常错误,请参见全局错误码

错误码 说明
500 系统错误

根据经纬度查询城市列表

功能描述

根据经纬度查询城市信息

接口地址

GET /v1.0/position/city

请求参数

参数名 类型 参数类型 必填 说明
lon String URL 经度
lat String URL 纬度

请求示例

GET /v1.0/position/city?lon=120.165&lat=30.252

返回信息

参数名 类型 说明
code Integer 参见全局错误码
success Boolean 是否成功:
  • true:成功
  • false:失败
msg String 请求失败的信息,成功为空。
result Object 返回结果。

Result

参数名 类型 说明
area String 地区名称
pinyin String 地区拼音
province String 省份
city String 城市名称
cityId Integer 城市 ID

返回示例

{ "success": true, "t": 1541401512639, "result": { "area": "上城区", "pinyin": "shangshangchengquou", "province": "浙江省", "city": "杭州市", "cityId": 793409589986070528 } }

错误码

以下为该接口常见的业务异常,更多的异常错误,请参见全局错误码

错误码 说明
500 系统错误

查询城市天气预报

功能描述

根据城市 ID查询天气预报。

接口地址

GET /v1.0/cities/{city_id}/weather-forecast

请求参数

参数名 类型 参数类型 必填 说明
city_id String URI 城市 ID

请求示例

GET /v1.0/cities/793409534348627968/weather-forecast

返回信息

参数名 类型 说明
code Integer 参见全局错误码
success Boolean 是否成功:
  • true:成功
  • false:失败
msg String 请求失败的信息,成功为空。
result Object 返回结果。

Result

参数名 类型 说明
year-mouth-day Object 日期对应天气预报

具体天气预报说明

参数名 类型 说明
condTxt String 天气概况
tempRange String 温度区间
updateTime String 更新时间

请求示例

{ "success": true, "t": 1541402025275, "result": { "2018-11-07": { "condTxt": "小雨", "tempRange": "16-20", "updateTime": null }, "2018-11-08": { "condTxt": "小雨", "tempRange": "10-18", "updateTime": null } } }

错误码

以下为该接口常见的业务异常,更多的异常错误,请参见全局错误码

错误码 说明
500 系统错误

根据 IP 查询天气预报

功能描述

根据城市 IP 查询天气预报。

接口地址

GET /v1.0/ip/weather-forecast

请求参数

参数名 类型 参数类型 必填 说明
ip String URL IP

请求示例

GET /v1.0/ip/weather-forecast?ip=xxx.xxx.xxx.xxx

返回信息

参数名 类型 说明
code Integer 参见全局错误码
success Boolean 是否成功:
  • true:成功
  • false:失败
msg String 请求失败的信息,成功为空。
result Object 返回结果。

Result

参数名 类型 说明
year-mouth-day Object 日期对应天气预报

具体天气预报说明

参数名 类型 说明
condTxt String
tempRange String 温度区间
updateTime String 更新时间

请求示例

{ "success": true, "t": 1541402025275, "result": { "2018-11-07": { "condTxt": "小雨", "tempRange": "16-20", "updateTime": null }, "2018-11-08": { "condTxt": "小雨", "tempRange": "10-18", "updateTime": null } } }

错误码

以下为该接口常见的业务异常,更多的异常错误,请参见全局错误码

错误码 说明
500 系统错误

根据经纬度查询天气

功能描述

根据城市经纬度来查询城市的天气信息。

接口地址

GET /v1.0/position/weather

请求参数

参数名 类型 参数类型 说明 必填
lon String URL 经度
lat String URL 纬度

请求示例

GET /v1.0/position/weather?lon=120.1650798&lat=30.25258003

返回信息

参数名 类型 说明
code Integer 参见全局错误码
success Boolean 是否成功:
  • true:成功
  • false:失败
msg String 请求失败的信息,成功为空。
result Object 返回结果。

Result

参数名 类型 说明
data Object 城市信息
lastUpdateTime String 最近更新时间

Data

参数名 类型 说明
temp String 温度
o3 String O3 指数
windLevel String 风等级
pm10 String PM10 指数
uvi String 紫外线指数
pressure String 气压
windDir String 风向
co String CO 指数
tips String 天气贴士
realFeel String 温度实感
no2 String NO2 指数
condition String 天气情况,阴晴雨雪
pm25 String PM2.5 指数
so2 String 二氧化硫指数
aqi String 空气质量指数
humidity String 湿度
rank String 空气评分
windSpeed String 风速

返回示例

{ "success": true, "t": 1541403147707, "result": { "data": { "temp": "21", "o3": "13", "windLevel": "2", "pm10": "53", "uvi": "4", "pressure": "1020", "windDir": "东风", "co": "8", "tips": "今天有雨,冷热适宜,感觉很舒适。", "realFeel": "21", "no2": "21", "condition": "阴", "pm25": "46", "so2": "4", "aqi": "53", "humidity": "78", "rank": "393/577", "windSpeed": "2.45" }, "lastUpdateTime": 1541390400000 } }

错误码

以下为该接口常见的业务异常,更多的异常错误,请参见全局错误码

错误码 说明
500 系统错误

查询城市当前天气情况

功能描述

根据城市 ID查询城市当前天气情况。

接口地址

GET /v1.0/cities/{city_id}/weathers

请求参数

参数名 类型 参数类型 填说明
city_id String URI 城市 ID

请求示例

GET /v1.0/cities/793409505965772800/weathers

返回信息

参数名 类型 说明
code Integer 参见全局错误码
success Boolean 是否成功:
  • true:成功
  • false:失败
msg String 请求失败的信息,成功为空。
result Object 返回结果。

Result

参数名 类型 说明
temp String 温度
o3 String O3 指数
windLevel String 风等级
pm10 String PM10 指数
uvi String 紫外线指数
pressure String 气压
windDir String 风向
co String CO 指数
tips String 天气贴士
realFeel String 温度实感
no2 String NO2 指数
condition String 天气情况,阴晴雨雪
pm25 String PM2.5 指数
so2 String 二氧化硫指数
aqi String 空气质量指数
humidity String 湿度
rank String 空气评分
windSpeed String 风速

返回示例

{ "result": { "data": { "aqi": "26", "co": "3", "condition": "晴", "humidity": "22", "no2": "7", "o3": "19", "pm10": "26", "pm25": "11", "pressure": "1020", "realFeel": "19", "so2": "1", "temp": "19", "tips": "略微偏凉,还是蛮舒适的。", "uvi": "6", "windDir": "北风", "windLevel": "3", "windSpeed": "3.6" }, "lastUpdateTime": 1585882508000 }, "success": true, "t": 1585884424027 }

错误码

以下为该接口常见的业务异常,更多的异常错误,请参见全局错误码

错误码 说明
500 系统错误