接口地址

https://www.vxras.com/api/v1/weather

请求方式

GET

接口描述

使用城市名查询天气

请求参数

参数名类型必填位置默认值示例值说明
citystring自动Shanghai-城市
daysstring自动--天数
latstring自动--维度
lonstring自动--经度

请求头

Header名必填说明

返回示例

{
    "code": 200,
    "message": "success",
    "data": {
        "location": {
            "name": "上海",
            "country": "中国",
            "latitude": 31.22222,
            "longitude": 121.45806
        },
        "current": {
            "temperature": 12.4,
            "humidity": 91,
            "weather_code": 1,
            "time": "2025-11-16T01:15"
        },
        "daily": [
            {
                "date": "2025-11-16",
                "temp_max": 22.1,
                "temp_min": 12,
                "weather_code": 3
            },
            {
                "date": "2025-11-17",
                "temp_max": 16.2,
                "temp_min": 6.5,
                "weather_code": 61
            },
            {
                "date": "2025-11-18",
                "temp_max": 8.5,
                "temp_min": 1.9,
                "weather_code": 3
            },
            {
                "date": "2025-11-19",
                "temp_max": 10.4,
                "temp_min": -0.1,
                "weather_code": 0
            },
            {
                "date": "2025-11-20",
                "temp_max": 13,
                "temp_min": 1,
                "weather_code": 2
            }
        ]
    }
}

在线测试

代码示例

curl -X GET "https://www.vxras.com/api/v1/weather"?city=&days=&lat=&lon=
<?php
$url = "https://www.vxras.com/api/v1/weather";
$data = array(
    "city" => "",
    "days" => "",
    "lat" => "",
    "lon" => ""
);
$headers = array(

);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url . "?" . http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
// 使用 Fetch API
const url = "https://www.vxras.com/api/v1/weather";
const data = {
  "city": "",
  "days": "",
  "lat": "",
  "lon": ""
};

const options = {
  method: "GET",
  headers: {

  },
};

fetch(url, options)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error("Error:", error));
# 使用 requests 库
import requests

url = "https://www.vxras.com/api/v1/weather"
data = {
    "city": "",
    "days": "",
    "lat": "",
    "lon": ""
}

headers = {

}

response = requests.get(url, params=data, headers=headers)

print(response.json())

响应码

响应码说明

错误码

错误码说明
500缺少必要参数/服务器错误