

登录用户中心

获取天气
基于城市ID获取实时天气信息,包含当前温度、湿度、空气质量、PM2.5/PM10、感冒指数以及昨天和未来4天的天气预报数据。接口免费使用,每8小时CDN缓存更新一次。
更新时间:2026-05-15 20:41:11
基于公开天气 API 封装的 PHP 代理接口,提供标准 JSON 格式天气数据,支持当前天气、空气质量、未来 5 天预报查询。
GET https://api.xunjinlu.fun/api/weather/index.php?cityId={cityId}
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
cityId |
string | ✅ 是 | 9 位城市 ID,如 101030100(天津) |
format |
string | ❌ 否 | 返回格式,默认 json |
完整城市列表下载: https://api.xunjinlu.fun/api/weather/csid.json
常用城市 ID:
| 城市 | ID |
|---|---|
| 北京 | 101010100 |
| 上海 | 101020100 |
| 天津 | 101030100 |
| 重庆 | 101040100 |
| 广州 | 101280101 |
| 深圳 | 101280601 |
| 字段 | 类型 | 说明 |
|---|---|---|
code |
int | 状态码 |
message |
string | 状态描述 |
time |
string | 响应时间 |
data |
object | 天气数据 |
| 字段 | 类型 | 说明 |
|---|---|---|
update_time |
string | 系统更新时间 |
city_info |
object | 城市基本信息 |
current |
object | 当前实时天气 |
yesterday |
object | 昨日天气回顾 |
forecast |
array | 今天 + 未来 4 天预报 |
| 字段 | 类型 | 说明 |
|---|---|---|
city |
string | 城市名称 |
city_id |
string | 城市 ID |
parent |
string | 上级行政区 |
weather_update_time |
string | 天气更新时间 |
| 字段 | 类型 | 说明 |
|---|---|---|
date |
string | 日期(YYYYMMDD) |
temperature |
string | 当前温度(℃) |
humidity |
string | 相对湿度 |
pm25 |
int | PM2.5 指数 |
pm10 |
int | PM10 指数 |
quality |
string | 空气质量等级 |
cold_index |
string | 感冒指数提示 |
| 字段 | 类型 | 说明 |
|---|---|---|
date |
string | 日期(日) |
ymd |
string | 年月日 |
week |
string | 星期 |
sunrise |
string | 日出时间 |
sunset |
string | 日落时间 |
high |
string | 最高温度 |
low |
string | 最低温度 |
type |
string | 天气类型 |
fx |
string | 风向 |
fl |
string | 风力等级 |
aqi |
int | 空气质量指数 |
notice |
string | 天气提示语 |
| code | 说明 |
|---|---|
| 200 | 请求成功 |
| 400 | 参数错误(缺少 cityId 或格式错误) |
| 500 | 服务器错误或上游 API 故障 |
| 限制项 | 说明 |
|---|---|
| 请求间隔 | ≥ 3 秒 |
| 每分钟阈值 | 300 次(超过封禁 3600 秒) |
| 缓存更新 | 每 8 小时 CDN 缓存更新 |
| 建议 | 自行做本地缓存减少 API 调用 |
curl "https://api.xunjinlu.fun/api/weather/index.php?cityId=101030100"
PHP
<?php
$response = file_get_contents('https://api.xunjinlu.fun/api/weather/index.php?cityId=101030100');
$data = json_decode($response, true);
if ($data['code'] === 200) {
echo "当前温度: " . $data['data']['current']['temperature'] . "℃\n";
echo "空气质量: " . $data['data']['current']['quality'] . "\n";
}
?>
JavaScript
fetch('https://api.xunjinlu.fun/api/weather/index.php?cityId=101030100')
.then(res => res.json())
.then(data => {
if (data.code === 200) {
console.log('当前温度:', data.data.current.temperature);
console.log('空气质量:', data.data.current.quality);
}
});
Query
1
Body
none:不发送任何Body数据,适用于GET请求或不需要Body的API
from-data:使用multipart/form-data格式发送数据,适用于上传文件或包含多种数据类型的请求
x-www-form-urlencoded:使用application/x-www-form-urlencoded格式发送数据,适用于简单的键值对数据
json:使用application/json格式发送数据,适用于复杂数据结构
xml:使用application/xml格式发送数据,适用于XML格式的API
raw:发送原始文本数据,可自定义Content-Type
请根据API要求选择合适的Body类型,并在下方输入对应格式的数据
接口响应
等待发起...
选择编程语言

Node.js

cURL

PHP

Java

Go

Python

Fetch

C#
代码示例
异常情况
联系QQ

