和风天气查询接口文档 检测中...
接口地址: https://api.chyt.top/get_weather_info
请求方式: GET
返回格式: JSON
请求示例: https://api.chyt.top/get_weather_info?city=北京
接口说明: 本接口用于查询指定城市或省份的当前天气信息。
请求参数
参数名 | 必选 | 类型 | 说明 |
---|---|---|---|
city | 是 | string | 要查询天气的城市或省份名称 |
返回参数
参数名 | 类型 | 说明 |
---|---|---|
code | int | 请求状态码,200 表示成功,其他值表示失败 |
msg | string | 错误信息,仅当 code 非 200 时返回 |
city_info | object | 城市信息,包括 Location_ID 等详情 |
current_weather | object | 当前天气信息,包含气温、湿度、风速等 |
city_info 对象字段
参数名 | 类型 | 说明 |
---|---|---|
Location_ID | string | 城市的唯一 Location ID |
Location_Name_ZH | string | 城市名称 |
Adm1_Name_ZH | string | 省份名称 |
Latitude | string | 城市纬度 |
Longitude | string | 城市经度 |
current_weather 对象字段
参数名 | 类型 | 说明 |
---|---|---|
obsTime | string | 观测时间(标准格式) |
temp | string | 当前温度(摄氏度) |
feelsLike | string | 体感温度 |
icon | string | 天气图标代码 |
text | string | 天气描述 |
wind360 | string | 风向(角度) |
windDir | string | 风向描述 |
windScale | string | 风力等级 |
windSpeed | string | 风速(km/h) |
humidity | string | 湿度(%) |
precip | string | 降水量(mm) |
pressure | string | 气压(百帕) |
vis | string | 能见度(公里) |
cloud | string | 云量(%) |
dew | string | 露点温度(摄氏度) |
返回示例
成功响应:
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;
}