调用示例
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
}
}