天气查询API文档

注意: 来源:高德地图,提供全国城市,地区等实时天气信息

基础信息

请求参数

参数名 类型 必填 说明
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]

版本信息