智能定位天气接口介绍

调用说明 调用示例 在线测试
接口地址: https://ping.4759.cn/api/weather_api.php
请求方式: GET
返回格式: JSON
频率限制: 单IP每分钟最多60次请求,额外按APIKey等级限制日调用量
缓存时效: 同一IP+Key数据缓存3小时
授权要求: 需携带有效的key参数
定位方式: 自动获取访问者IPv4 → 自动匹配城市名称查询气象
报错提示: 接口报错时末尾会自动显示

本API无需传入城市、无需adcode,自动获取访问者IP定位城市,返回完整气象信息(实时温湿度、空气质量、5天逐天预报),数据缓存3小时降低请求消耗。
注意:必须携带有效API Key,未授权无法调用。单IP每分钟最高60次请求,超出返回429限流。

调用说明

1. 请求参数

参数名 必选 类型 说明 示例值
key string API授权码 user_xxxx

2. 返回参数

参数名 类型 说明
code int 200成功,400/401/403/404/429/500错误
msg string 接口状态描述
used_api string 接口标识
client_info object 访客定位信息
client_info.user_ip string 访问者IPv4地址
client_info.province string 访客所在省份
client_info.city string 访客所在城市
client_info.adcode string 城市行政编码
weather_source_data object 原始气象数据
weather_source_data.location object 定位城市经纬度、行政编码、地址
weather_source_data.current object 实时天气、温度、风力、空气质量、AQI
weather_source_data.forecast array 未来5天天气预报,包含日出日落、空气质量
call_stats object 当前授权key当日调用统计
call_stats.used_day int 今日已调用次数
call_stats.remaining_day int 今日剩余可用次数

3. 状态码说明

调用示例

1. GET请求(最简调用)

http://ping.4759.cn/api/weather_api.php?key=你的授权码

2. PHP调用示例

<?php // +---------------------------------------------------------------------- // | 自动定位天气 PHP调用示例 // | 复制即可使用,需替换为自己的API Key // +---------------------------------------------------------------------- $key = "你的授权码"; $url = "http://ping.4759.cn/api/weather_api.php?key=" . urlencode($key); $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_SSL_VERIFYPEER => false ]); $response = curl_exec($ch); curl_close($ch); $result = json_decode($response, true); print_r($result); ?>

3. Python调用示例

import requests key = "你的授权码" url = f"http://ping.4759.cn/api/weather_api.php?key={key}" res = requests.get(url, timeout=10) data = res.json() print(data)

4. 成功返回完整真实示例(与线上返回完全一致)

{ "code": 200, "msg": "success", "used_api": "4759.cn 智能IP定位天气接口", "client_info": { "user_ip": "112.96.208.132", "province": "广东省", "city": "广州", "adcode": "440100" }, "weather_source_data": { "location": { "name": "广州市", "province": "广东省", "city": "广州市", "district": "越秀区", "address": "广东省-广州市", "lat": 23.135336, "lng": 113.271431, "adcode": "440104" }, "current": { "update_time": "07:25", "weather": "多云", "weather_code": "d01", "temperature": "30", "wind": "南风", "wind_level": "3级", "humidity": "80%", "pressure": "992百帕", "visibility": "30000", "air_quality": "优", "aqi": "30", "pm25": "19" }, "forecast": [ { "date": "08.13", "day_of_week": "周四", "day_weather": "中雨", "night_weather": "中雨", "high_temp": "34", "low_temp": "25", "wind": "", "wind_level": "<3级", "sunrise": "06:02", "sunset": "19:01", "aqi": "61", "aqi_level": 1, "aqi_desc": "良" }, { "date": "08.14", "day_of_week": "周五", "day_weather": "中雨", "night_weather": "雷阵雨", "high_temp": "32", "low_temp": "25", "wind": "", "wind_level": "<3级", "sunrise": "06:02", "sunset": "19:00", "aqi": "56", "aqi_level": 1, "aqi_desc": "良" }, { "date": "08.15", "day_of_week": "周六", "day_weather": "雷阵雨", "night_weather": "多云", "high_temp": "34", "low_temp": "25", "wind": "", "wind_level": "<3级", "sunrise": "06:02", "sunset": "18:59", "aqi": "53", "aqi_level": 1, "aqi_desc": "良" }, { "date": "08.16", "day_of_week": "周日", "day_weather": "雷阵雨", "night_weather": "雷阵雨", "high_temp": "33", "low_temp": "25", "wind": "", "wind_level": "<3级", "sunrise": "06:03", "sunset": "18:59", "aqi": "45", "aqi_level": 0, "aqi_desc": "优" }, { "date": "08.17", "day_of_week": "周一", "day_weather": "雷阵雨", "night_weather": "雷阵雨", "high_temp": "34", "low_temp": "26", "wind": "", "wind_level": "<3级", "sunrise": "06:03", "sunset": "18:58", "aqi": "", "aqi_level": "", "aqi_desc": "" } ] }, "call_stats": { "used_day": 76, "remaining_day": 424 } }

在线测试

点击按钮获取完整气象JSON。