腾讯天气

腾讯天气预报查询,支持全国各省市7天预报

API 文档

  • 接口地址: https://apicx.asia/api/weather
  • 返回格式: JOSN
  • 请求方式: GET
  • 请求示例: https://apicx.asia/api/weather?province=上海&city=上海&county=黄浦区&token=你的token

请求参数说明:

名称 必填 类型 说明
token string 登录获取token
provincestring省份(必填)
citystring城市(必填)
countystring县区(必填)
示例string请求示例:https://apicx.asia/api/weather?province=上海&city=上海&county=黄浦区&token=你的token

返回参数说明:

名称 类型 说明
code integer 返回的状态码
data object 返回的数据/数据对象
msg string 返回的消息
time string 请求时间
data.location.provincestringprovince
data.location.citystringcity
data.current.temperaturestringtemperature
data.current.weatherstringweather
data.current.wind_powerstringwind_power
data.current.wind_directionstringwind_direction
data.current.humiditystringhumidity
data.current.pressurestringpressure
data.forecast[].datestringdate
data.forecast[].day_weatherstringday_weather
data.forecast[].night_weatherstringnight_weather
data.forecast[].min_temperaturestringmin_temperature
data.forecast[].max_temperaturestringmax_temperature
data.forecast[].day_wind_powerstringday_wind_power
data.forecast[].night_wind_powerstringnight_wind_power
data.forecast[].day_wind_directionstringday_wind_direction
data.air_quality.aqinumberaqi
data.air_quality.aqi_namestringaqi_name
data.air_quality.pm2_5nullpm2_5

返回示例:

{
  "status": "success",
  "code": 200,
  "data": {
    "location": {
      "province": "上海",
      "city": "上海"
    },
    "current": {
      "temperature": "18",
      "weather": "阴",
      "wind_power": "1-3",
      "wind_direction": "8",
      "humidity": "89",
      "pressure": "1021"
    },
    "forecast": [
      {
        "date": "2025-11-05",
        "day_weather": "阴",
        "night_weather": "阴",
        "min_temperature": "16",
        "max_temperature": "20",
        "day_wind_power": "1-3",
        "night_wind_power": "1-3",
        "day_wind_direction": "东风"
      },
      {
        "date": "2025-11-06",
        "day_weather": "小雨",
        "night_weather": "小雨",
        "min_temperature": "17",
        "max_temperature": "21",
        "day_wind_power": "1-3",
        "night_wind_power": "1-3",
        "day_wind_direction": "北风"
      },
      {
        "date": "2025-11-07",
        "day_weather": "小雨",
        "night_weather": "小雨",
        "min_temperature": "17",
        "max_temperature": "21",
        "day_wind_power": "1-3",
        "night_wind_power": "1-3",
        "day_wind_direction": "东北风"
      },
      {
        "date": "2025-11-08",
        "day_weather": "小雨",
        "night_weather": "阴",
        "min_temperature": "17",
        "max_temperature": "21",
        "day_wind_power": "1-3",
        "night_wind_power": "1-3",
        "day_wind_direction": "东南风"
      },
      {
        "date": "2025-11-09",
        "day_weather": "阴",
        "night_weather": "阴",
        "min_temperature": "14",
        "max_temperature": "20",
        "day_wind_power": "3-4",
        "night_wind_power": "3-4",
        "day_wind_direction": "北风"
      },
      {
        "date": "2025-11-10",
        "day_weather": "多云",
        "night_weather": "多云",
        "min_temperature": "13",
        "max_temperature": "18",
        "day_wind_power": "3-4",
        "night_wind_power": "1-3",
        "day_wind_direction": "东北风"
      },
      {
        "date": "2025-11-11",
        "day_weather": "多云",
        "night_weather": "阴",
        "min_temperature": "14",
        "max_temperature": "18",
        "day_wind_power": "1-3",
        "night_wind_power": "1-3",
        "day_wind_direction": "东北风"
      }
    ],
    "air_quality": {
      "aqi": 36,
      "aqi_name": "优",
      "pm2_5": null
    }
  },
  "timestamp": "2025-11-06 19:51:06",
  "api_source": "API官网:apicx.asia",
  "cached_time": "2025-11-06 19:51:06"
}

错误码格式说明:

名称 类型 说明
200 string 返回状态码(成功)
500 string 返回的状态码(失败)

代码示例:


<?php
// 初始化cURL会话
$ch = curl_init();
// 设置请求URL,用户中心获取token,自行替换其他参数
curl_setopt($ch, CURLOPT_URL, "https://apicx.asia/api/weather?province=上海&city=上海&county=黄浦区&token=你的token");
// 设置请求头
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: YOUR_TOKEN'
));
// 返回响应而不是直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 执行请求并获取响应
$response = curl_exec($ch);
// 关闭cURL会话
curl_close($ch);
// 将响应解析为JSON格式
$data = json_decode($response, true);
// 输出JSON数据
print_r($data);
?>
            

import requests

# 设置请求URL和头部,用户中心获取token,自行替换其他参数
url = "https://apicx.asia/api/weather?province=上海&city=上海&county=黄浦区&token=你的token"
headers = {
    'Authorization': 'YOUR_TOKEN'
}

# 发送GET请求
response = requests.get(url, headers=headers)
# 将响应解析为JSON格式
data = response.json()
# 输出JSON数据
print(data)
            

// 发送GET请求,用户中心获取token,自行替换其他参数
fetch("https://apicx.asia/api/weather?province=上海&city=上海&county=黄浦区&token=你的token", {
    method: "GET",
    headers: {
        "Authorization": "YOUR_TOKEN"
    }
})
.then(response => response.json()) // 将响应解析为JSON格式
.then(data => console.log(data)) // 输出JSON数据
.catch(error => console.error('Error:', error));
            

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static void main(String[] args) throws Exception {
        // 创建URL对象,用户中心获取token,自行替换其他参数
        URL url = new URL("https://apicx.asia/api/weather?province=上海&city=上海&county=黄浦区&token=你的token");
        // 打开连接
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        // 设置请求方法
        conn.setRequestMethod("GET");
        // 设置请求头
        conn.setRequestProperty("Authorization", "YOUR_TOKEN");

        // 读取响应
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String inputLine;
        StringBuffer content = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            content.append(inputLine);
        }
        in.close();
        // 输出JSON数据
        System.out.println(content.toString());
    }
}
            

using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program {
    static async Task Main() {
        using (HttpClient client = new HttpClient()) {
            // 设置请求头
            client.DefaultRequestHeaders.Add("Authorization", "YOUR_TOKEN");
            // 发送GET请求,用户中心获取token,自行替换其他参数
            HttpResponseMessage response = await client.GetAsync("https://apicx.asia/api/weather?province=上海&city=上海&county=黄浦区&token=你的token");
            // 将响应解析为字符串
            string responseBody = await response.Content.ReadAsStringAsync();
            // 输出JSON数据
            Console.WriteLine(responseBody);
        }
    }
}
            

require 'net/http'
require 'uri'

# 创建URI对象,用户中心获取token,自行替换其他参数
uri = URI.parse("https://apicx.asia/api/weather?province=上海&city=上海&county=黄浦区&token=你的token")
# 创建GET请求
request = Net::HTTP::Get.new(uri)
# 设置请求头
request["Authorization"] = "YOUR_TOKEN"

# 发送请求并获取响应
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end

# 输出JSON数据
puts response.body
            

package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
)

func main() {
    client := &http.Client{}
    // 创建GET请求,用户中心获取token,自行替换其他参数
    req, err := http.NewRequest("GET", "https://apicx.asia/api/weather?province=上海&city=上海&county=黄浦区&token=你的token", nil)
    if err != nil {
        panic(err)
    }
    // 设置请求头
    req.Header.Add("Authorization", "YOUR_TOKEN")

    // 发送请求并获取响应
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    // 读取响应体
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }
    // 输出JSON数据
    fmt.Println(string(body))
}