Skip to content

和风天气查询接口文档 检测中...

接口地址: https://api.chyt.top/get_weather_info

请求方式: GET

返回格式: JSON

请求示例: https://api.chyt.top/get_weather_info?city=北京

接口说明: 本接口用于查询指定城市或省份的当前天气信息。

请求参数

参数名必选类型说明
citystring要查询天气的城市或省份名称

返回参数

参数名类型说明
codeint请求状态码,200 表示成功,其他值表示失败
msgstring错误信息,仅当 code 非 200 时返回
city_infoobject城市信息,包括 Location_ID 等详情
current_weatherobject当前天气信息,包含气温、湿度、风速等

city_info 对象字段

参数名类型说明
Location_IDstring城市的唯一 Location ID
Location_Name_ZHstring城市名称
Adm1_Name_ZHstring省份名称
Latitudestring城市纬度
Longitudestring城市经度

current_weather 对象字段

参数名类型说明
obsTimestring观测时间(标准格式)
tempstring当前温度(摄氏度)
feelsLikestring体感温度
iconstring天气图标代码
textstring天气描述
wind360string风向(角度)
windDirstring风向描述
windScalestring风力等级
windSpeedstring风速(km/h)
humiditystring湿度(%)
precipstring降水量(mm)
pressurestring气压(百帕)
visstring能见度(公里)
cloudstring云量(%)
dewstring露点温度(摄氏度)

返回示例

成功响应:

json
{
  "code": 200,
  "city_info": {
    "Location_ID": "101010100",
    "Location_Name_ZH": "北京",
    "Adm1_Name_ZH": "北京市",
    "Latitude": "39.9042",
    "Longitude": "116.4074"
  },
  "current_weather": {
    "obsTime": "2024-11-09 02:09:00",
    "temp": "16",
    "feelsLike": "15",
    "icon": "104",
    "text": "阴",
    "wind360": "90",
    "windDir": "东风",
    "windScale": "1",
    "windSpeed": "5",
    "humidity": "67",
    "precip": "0.0",
    "pressure": "1019",
    "vis": "15",
    "cloud": "100",
    "dew": "9"
  }
}

代码示例

php
<?php
$url = 'https://api.chyt.top/get_weather_info?city=北京';

$response = file_get_contents($url);
echo $response;
?>
python
import requests

url = 'https://api.chyt.top/get_weather_info'
params = {'city': '北京'}

response = requests.get(url, params=params)
print(response.json())
JavaScript
const https = require('https');

const url = 'https://api.chyt.top/get_weather_info?city=北京';

https.get(url, (res) => {
    res.on('data', (d) => process.stdout.write(d));
});
java
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static void main(String[] args) throws IOException {
        URL url = new URL("https://api.chyt.top/get_weather_info?city=北京");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");

        try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
            String response;
            while ((response = br.readLine()) != null) {
                System.out.println(response);
            }
        }
    }
}
C
#include <stdio.h>
#include <curl/curl.h>

int main() {
    CURL *curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://api.chyt.top/get_weather_info?city=北京");

        CURLcode res = curl_easy_perform(curl);
        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));

        curl_easy_cleanup(curl);
    }
    return 0;
}