https://api.cenguigui.cn/api/WeatherInfo/
GET
JSON
正常启用
以下参数为接口所需调用信息
| 参数 | 是否必填 | 类型 | 说明 | 示例 |
|---|---|---|---|---|
| 天气查询接口 | city=城市 | city | 必须加城市才能调用 |
https://api.cenguigui.cn/api/WeatherInfo/?city=北京
https://api.cenguigui.cn/api/WeatherInfo/?city=城市(列如:北京)
搜索比较快的接口(不要加省和县字):
https://api.cenguigui.cn/api/WeatherInfo/api.php?city=北京
经纬度天气:
https://api.cenguigui.cn/api/WeatherInfo/latlon.php?lat=34.442&lon=118.648
{
"code": 200,
"msg": "请求成功",
"data": {
"today": {
"current_temp": "29℃",
"current_cond": "阴",
"night_condition": "多云",
"tomorrow_condition": "阴转多云",
"low": "24℃",
"quality": "良",
"alert": "市气象台2023年6月24日21时00分降级发布高温黄色预警信号:预计,6月25日至27日最高气温较22日至24日有所降低,大部分地区最高气温35~37℃,请注意防范。(预警信息来源:国家预警信息发布中心)",
"update_time": "2023-06-25 09:55:08"
},
"seven_day": [
{
"date": "2023-06-24",
"cond": "晴",
"high": "40℃",
"low": "25℃"
},
{
"date": "2023-06-25",
"cond": "多云",
"high": "35℃",
"low": "24℃"
},
{
"date": "2023-06-26",
"cond": "阴转多云",
"high": "35℃",
"low": "25℃"
},
{
"date": "2023-06-27",
"cond": "多云",
"high": "37℃",
"low": "26℃"
},
{
"date": "2023-06-28",
"cond": "小雨转多云",
"high": "35℃",
"low": "25℃"
},
{
"date": "2023-06-29",
"cond": "多云转晴",
"high": "38℃",
"low": "24℃"
},
{
"date": "2023-06-30",
"cond": "多云",
"high": "38℃",
"low": "23℃"
},
{
"date": "2023-07-01",
"cond": "多云",
"high": "36℃",
"low": "24℃"
},
{
"date": "2023-07-02",
"cond": "阴",
"high": "39℃",
"low": "27℃"
},
{
"date": "2023-07-03",
"cond": "小雨",
"high": "38℃",
"low": "25℃"
},
{
"date": "2023-07-04",
"cond": "小雨转阴",
"high": "35℃",
"low": "22℃"
},
{
"date": "2023-07-05",
"cond": "阴转多云",
"high": "39℃",
"low": "25℃"
},
{
"date": "2023-07-06",
"cond": "阴",
"high": "39℃",
"low": "30℃"
},
{
"date": "2023-07-07",
"cond": "小雨",
"high": "39℃",
"low": "25℃"
},
{
"date": "2023-07-08",
"cond": "小雨",
"high": "39℃",
"low": "22℃"
},
{
"date": "2023-07-09",
"cond": "阴转多云",
"high": "39℃",
"low": "27℃"
}
]
},
"info": {
"request": {
"state": "92dff1b360399bd5a31f985b09063d40",
"request_id": "64979fee0d54e",
"method": "GET",
"api_id": "1",
"api_action": "WeatherInfo",
"api_name": "客户端信息",
"path": "/api/WeatherInfo/?city=%E5%8C%97%E4%BA%AC",
"query": {
"city": "北京"
},
"cdn_node": "当前请求由阿里云CDN加速"
},
"developer": {
"author": "笒鬼鬼",
"home": "https://www.cenguigui.cn",
"mail": "cengugiui@qq.com",
"notice": "交流Q群 695288151",
"time": "2023-06-25 10:01:18"
}
}
}
// JavaScript调用示例
fetch("https://api.cenguigui.cn/api/WeatherInfo/?city=北京", {
method: "GET",
headers: {
"Content-Type": "application/json"
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
# Python调用示例
import requests
url = "https://api.cenguigui.cn/api/WeatherInfo/?city=北京"
response = requests.get(url)
print(response.json())
// Java调用示例
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
public class ApiExample {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.connectTimeout(Duration.ofSeconds(10))
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.cenguigui.cn/api/WeatherInfo/?city=北京"))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
<?php
// PHP调用示例
$url = "https://api.cenguigui.cn/api/WeatherInfo/?city=北京";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
print_r($result);
?>
// C#调用示例
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using var client = new HttpClient();
var url = "https://api.cenguigui.cn/api/WeatherInfo/?city=北京";
var response = await client.GetAsync(url);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
// 响应结果将显示在这里