天气查询API文档
注意: 来源:高德地图,提供全国城市,地区等实时天气信息
基础信息
- 接口地址: https://apiv1.yrain.top/tq.php
- 请求方式: GET
- 返回格式: JSON
- 编码: UTF-8
请求参数
| 参数名 |
类型 |
必填 |
说明 |
| city |
string |
是 |
城市,地区的名称或区号 |
请求示例
GET https://apiv1.yrain.top/tq.php?city=天津
响应示例
成功响应
{
"status": 1,
"city": "天津市",
"province": "天津",
"weather": "多云",
"temperature": "14°C",
"wind": "东南风 ≤3级",
"humidity": "28%",
"report_time": "2025-11-15 17:06:54",
"adcode": "120000"
}
错误响应
{
"status": 0,
"message": "请提供参数"
}
{
"status": 0,
"message": "获取天气信息失败",
"error_code": "10001"
}
数据结构说明
响应根对象
| 字段 |
类型 |
说明 |
| status |
integer |
状态码(1=成功,0=失败) |
| city |
string |
城市名称 |
| province |
string |
省份名称 |
| weather |
string |
天气状况 |
| temperature |
string |
温度(包含单位) |
| wind |
string |
风向和风力 |
| humidity |
string |
湿度(包含单位) |
| report_time |
string |
数据报告时间 |
| adcode |
string |
城市行政区划代码 |
| message |
string |
错误信息(仅status=0时存在) |
| error_code |
string |
错误代码(仅status=0时存在) |
使用示例
JavaScript 调用示例
fetch('https://apiv1.yrain.top/tq.php?city=天津')
.then(response => response.json())
.then(data => {
if (data.status === 1) {
console.log(`城市: ${data.city}`);
console.log(`天气: ${data.weather}`);
console.log(`温度: ${data.temperature}`);
console.log(`风力: ${data.wind}`);
console.log(`湿度: ${data.humidity}`);
} else {
console.error('获取失败:', data.message);
}
})
.catch(error => {
console.error('请求失败:', error);
});
使用限制
注意事项
- 请确保城市名称正确,只支持中国
- 如遇查询失败,请检查城市名称格式
- 天气数据仅供参考
- 不得用于违法用途
技术支持
如有问题请联系: [email protected]
版本信息
- 当前版本: v1.0
- 更新日期: 2025.11.15