天气查询
多平台天气查询
接口信息
GET / POST
api.vsaa.cn/api/weather/index.php
Method
GET / POST
分类
天气
Calls
3
KEY
无需 KEY
计费
免费
QPM
127/MIN
鉴权方式
无需密钥
作者
请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| city | string | 是 | 城市名 | 渠县 |
| days | string | 否 | 预报天数 | 7 |
| type | string | 否 | 平台:墨迹天气(moji)、百度天气(baidu)、中国天气(zgtq)、中央气象台(zytq)、彩云天气(cytq) | cytq |
[
{
"name": "city",
"type": "string",
"required": true,
"description": "城市名",
"example": "渠县"
},
{
"name": "days",
"type": "string",
"required": false,
"description": "预报天数",
"example": "7"
},
{
"name": "type",
"type": "string",
"required": false,
"description": "平台:墨迹天气(moji)、百度天气(baidu)、中国天气(zgtq)、中央气象台(zytq)、彩云天气(cytq)",
"example": "cytq"
}
]
返回示例
{
"code": 200,
"success": true,
"city": "渠县",
"location": {
"name": "中国 四川省 达州市 渠县",
"longitude": 106.970746,
"latitude": 30.836348
},
"current": {
"temperature": 35.21,
"feels_like": 36.6,
"humidity": 34,
"pressure": 97713.44,
"visibility": 30.08,
"wind_direction": 51.15,
"wind_speed": 6.66,
"weather": "CLEAR_DAY",
"air_quality": {
"aqi": 45,
"pm25": 19,
"description": "优"
},
"life_index": {
"ultraviolet": "强",
"comfort": "很热"
}
},
"forecast": [
{
"date": "2026-09-03T00:00+08:00",
"weather": "CLEAR_DAY",
"max_temp": 35.21,
"min_temp": 21.69,
"wind_direction": 26.89,
"wind_speed": 6.57,
"humidity": 0.51,
"precipitation": 0
},
{
"date": "2026-09-04T00:00+08:00",
"weather": "CLEAR_DAY",
"max_temp": 36.07,
"min_temp": 23.46,
"wind_direction": 324.96,
"wind_speed": 6.03,
"humidity": 0.59,
"precipitation": 0
},
{
"date": "2026-09-05T00:00+08:00",
"weather": "PARTLY_CLOUDY_DAY",
"max_temp": 36.98,
"min_temp": 25.27,
"wind_direction": 106.88,
"wind_speed": 5.77,
"humidity": 0.61,
"precipitation": 0
},
{
"date": "2026-09-06T00:00+08:00",
"weather": "PARTLY_CLOUDY_DAY",
"max_temp": 36.67,
"min_temp": 26.44,
"wind_direction": 89.3,
"wind_speed": 6.94,
"humidity": 0.62,
"precipitation": 0
},
{
"date": "2026-09-07T00:00+08:00",
"weather": "CLOUDY",
"max_temp": 36.86,
"min_temp": 25.35,
"wind_direction": 87.31,
"wind_speed": 7.02,
"humidity": 0.57,
"precipitation": 0
},
{
"date": "2026-09-08T00:00+08:00",
"weather": "CLOUDY",
"max_temp": 36.77,
"min_temp": 25.44,
"wind_direction": 359.13,
"wind_speed": 7.17,
"humidity": 0.59,
"precipitation": 0
},
{
"date": "2026-09-09T00:00+08:00",
"weather": "HEAVY_RAIN",
"max_temp": 31.11,
"min_temp": 25.15,
"wind_direction": 0.13,
"wind_speed": 8.15,
"humidity": 0.76,
"precipitation": 1.5457
}
],
"summary": {
"key_point": "未来两小时不会下雨,放心出门吧",
"hourly_description": "晴,今天夜里24点钟后转多云,其后晴"
}
}
详细文档
天气查询
接口说明
本接口提供多平台天气数据聚合查询服务,支持墨迹天气、百度天气、中国天气网、中央气象台及彩云天气等多种数据源。面向需要快速获取城市实时天气及未来预报的开发者开放,无需鉴权即可调用。接口返回当前天气、空气质量、生活指数及逐日预报等结构化数据,便于快速集成至各类应用。
调用地址
/api/weather/index.php
请求方式
支持 GET 和 POST 两种请求方式。
鉴权说明
本接口无需密钥即可调用。
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| city | string | 是 | 目标城市名称,如 渠县 |
| days | string | 否 | 预报天数,默认 7 天 |
| type | string | 否 | 数据来源平台,可选值:moji(墨迹天气)、baidu(百度天气)、zgtq(中国天气)、zytq(中央气象台)、cytq(彩云天气) |
成功响应示例
{
"code": 200,
"success": true,
"city": "渠县",
"location": {
"name": "中国 四川省 达州市 渠县",
"longitude": 106.970746,
"latitude": 30.836348
},
"current": {
"temperature": 35.21,
"feels_like": 36.6,
"humidity": 34,
"pressure": 97713.44,
"visibility": 30.08,
"wind_direction": 51.15,
"wind_speed": 6.66,
"weather": "CLEAR_DAY",
"air_quality": {
"aqi": 45,
"pm25": 19,
"description": "优"
},
"life_index": {
"ultraviolet": "强",
"comfort": "很热"
}
},
"forecast": [
{
"date": "2026-09-03T00:00+08:00",
"weather": "CLEAR_DAY",
"max_temp": 35.21,
"min_temp": 21.69,
"wind_direction": 26.89,
"wind_speed": 6.57,
"humidity": 0.51,
"precipitation": 0
},
{
"date": "2026-09-04T00:00+08:00",
"weather": "CLEAR_DAY",
"max_temp": 36.07,
"min_temp": 23.46,
"wind_direction": 324.96,
"wind_speed": 6.03,
"humidity": 0.59,
"precipitation": 0
},
{
"date": "2026-09-05T00:00+08:00",
"weather": "PARTLY_CLOUDY_DAY",
"max_temp": 36.98,
"min_temp": 25.27,
"wind_direction": 106.88,
"wind_speed": 5.77,
"humidity": 0.61,
"precipitation": 0
}
],
"summary": {
"key_point": "未来两小时不会下雨,放心出门吧",
"hourly_description": "晴,今天夜里24点钟后转多云,其后晴"
}
}
响应字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| code | number | 状态码,200 表示请求成功 |
| success | boolean | 请求是否成功 |
| city | string | 查询的城市名称 |
| location | object | 地理位置信息 |
| location.name | string | 完整地理位置描述 |
| location.longitude | number | 经度 |
| location.latitude | number | 纬度 |
| current | object | 当前天气数据 |
| current.temperature | number | 当前温度(℃) |
| current.feels_like | number | 体感温度(℃) |
| current.humidity | number | 相对湿度(%) |
| current.pressure | number | 大气压强(Pa) |
| current.visibility | number | 能见度(km) |
| current.wind_direction | number | 风向(角度,0°-360°) |
| current.wind_speed | number | 风速(m/s) |
| current.weather |
错误响应示例
{
"code": 0,
"msg": "未提供调用密钥",
"errcode": 11001
}
业务错误码说明
| errcode | 含义 |
|---|---|
| 11001 | 未提供调用密钥 |
| 11002 | 密钥错误 |
| 11003 | 密钥已禁用 |
| 11004 | 积分余额不足 |
| 11005 | 请求过于频繁(QPM 限制) |
| 11006 | 接口维护中 |
| 11007 | 接口已禁用 |
| 11008 | 接口不可用 |
| 11009 | 密钥校验暂不可用 |
| 11010 | 积分系统暂不可用 |
| 11011 | 收费接口须提供有效密钥 |
| 11012 | 鉴权方式错误 |
| 11013 | 接口不存在 |
| 11014 | ***地址无效 |
| 11015 | ***地址不允许 |
| 11016 | ***请求失败 |
| 11017 | 服务暂不可用 |
| 11018 | 请求方式不允许 |
| 11019 | 当前IP不在白名单内 |
| 11020 | 启用出口代理须提供有效密钥 |
| 11021 | 未配置可用出口代理 |
| 11022 | 出口代理不可用 |
调用示例
终端 curl(bash)
curl "https://your-domain.com/api/weather/index.php?city=渠县&days=7&type=cytq"
PHP
// PHP
$city = '渠县';
$days = 7;
$type = 'cytq';
$url = 'https://your-domain.com/api/weather/index.php?city=' . urlencode($city)
. '&days=' . $days
. '&type=' . urlencode($type);
$response = file_get_contents($url);
$data = json_decode($response, true);
echo '城市:' . $data['city'] . PHP_EOL;
echo '当前温度:' . $data['current']['temperature'] . '°C' . PHP_EOL;
echo '预报天数:' . count($data['forecast']) . '天' . PHP_EOL;
注意事项
- 本接口无需鉴权密钥,直接调用即可,但仍建议通过 HTTPS 协议访问以保护请求参数安全。
- 频率限制为每分钟约 127 次,高频调用请做好本地缓存,避免触发限流。
city参数支持中文城市名,建议传入标准名称(如「渠县」「北京」),模糊或错误地名可能导致查询失败或返回误差较大数据。days为可选参数,默认为 7 天预报,可指定其他天数,建议不超过 15 天以保证数据准确性。type参数控制数据来源平台,可选值为:moji(墨迹天气)、baidu(百度天气)、zgtq(中国天气)、zytq(中央气象台)、cytq(彩云天气),各平台数据更新频率和覆盖范围略有差异,可依据实际需求切换。- 返回的温度单位为摄氏度,湿度为百分比数值,气压单位为 Pa,风速单位为 m/s,风向单位为角度(0°–360°,正北为 0°/360°)。
weather字段为枚举值(如CLEAR_DAY、PARTLY_CLOUDY_DAY、CLOUDY、HEAVY_RAIN等),前端可据此映射为对应天气图标。- 空气质量指数
aqi与pm25数据部分平台可能缺失,读取时建议做空值兼容处理。 - 接口返回时间均使用北京时间(+08:00)时区,解析日期时请注意时区对齐。
快速上手
curl "http://localhost/api/weather/index.php?city=渠县&days=7&type=cytq"
在线测试
请求地址
api.vsaa.cn/api/weather/index.php
Method
参数
Response
等待中
// 结果将在此处显示