天气
天气,我们致力于为用户提供专业的免费 API 数据接口服务
天气
v1.0最后更新:
天气
以和风天气(QWeather)为主数据源的实时天气与预报接口,纯文本输出,覆盖全国 3200+ 城市区县及全球任意经纬度,支持城市名、拼音、区县名、LocationID、经纬度多种定位方式。一次返回实时天气、1-10 天每日预报(含日出日落、月相)与逐小时预报,排版为可直接展示的中文天气报告;和风异常时自动回落 Open-Meteo 备用源。
接口地址
https://api.qsxfr.top/API/tq.php
请求地址
https://api.qsxfr.top/API/tq.php?city=北京
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| city | string | 可选 | 城市名称,支持中文/拼音/英文,也可填区县名(如 思明区),默认北京 |
| lat | string | 可选 | 纬度(十进制),需与 lon 同时传,如 39.92 |
| lon | string | 可选 | 经度(十进制),如 116.41 |
| id | string | 可选 | 和风天气 LocationID,如 101010100(内置 3200+ 城市区县,离线反查) |
| type | string | 可选 | 返回类型:all(默认,实时+预报+小时) / now / daily / hourly |
| days | string | 可选 | 每日预报天数,1-10,默认 7 |
| hours | string | 可选 | 逐小时预报条数,1-24,默认 24 |
| lang | string | 可选 | 语言:zh(默认) / en |
| source | string | 可选 | 强制数据源:qweather / openmeteo,默认自动选择 |
city
string城市名称,支持中文/拼音/英文,也可填区县名(如 思明区),默认北京
lat
string纬度(十进制),需与 lon 同时传,如 39.92
lon
string经度(十进制),如 116.41
id
string和风天气 LocationID,如 101010100(内置 3200+ 城市区县,离线反查)
type
string返回类型:all(默认,实时+预报+小时) / now / daily / hourly
days
string每日预报天数,1-10,默认 7
hours
string逐小时预报条数,1-24,默认 24
lang
string语言:zh(默认) / en
source
string强制数据源:qweather / openmeteo,默认自动选择
在线测试
返回结果
点击「发送请求」按钮,查看接口返回结果
返回码说明
| 返回码 | 说明 |
|---|---|
| 正常 | 成功,直接返回中文天气报告文本 |
| -1 | 参数错误 |
| -2 | 城市或 LocationID 未找到 |
| -3 | 上游天气服务异常,请稍后重试 |
| -4 | 无数据 |
正常
成功,直接返回中文天气报告文本
-1
参数错误
-2
城市或 LocationID 未找到
-3
上游天气服务异常,请稍后重试
-4
无数据
多语言调用示例
curl -X GET "https://api.qsxfr.top/API/tq.php?city=北京&city=your_city&lat=your_lat&lon=your_lon&id=your_id&type=your_type&days=your_days&hours=your_hours&lang=your_lang&source=your_source"
import requests
url = "https://api.qsxfr.top/API/tq.php?city=北京"
params = {
'city': 'your_city',
'lat': 'your_lat',
'lon': 'your_lon',
'id': 'your_id',
'type': 'your_type',
'days': 'your_days',
'hours': 'your_hours',
'lang': 'your_lang',
'source': 'your_source'
}
response = requests.get(url, params=params)
print(response.text)
<?php
$url = "https://api.qsxfr.top/API/tq.php?city=北京";
$params = [
'city' => 'your_city',
'lat' => 'your_lat',
'lon' => 'your_lon',
'id' => 'your_id',
'type' => 'your_type',
'days' => 'your_days',
'hours' => 'your_hours',
'lang' => 'your_lang',
'source' => 'your_source'
];
$full_url = $url . (strpos($url, '?') === false ? '?' : '&') . http_build_query($params);
$result = file_get_contents($full_url);
echo $result;
?>
// 使用 fetch 发送GET请求
const url = new URL('https://api.qsxfr.top/API/tq.php?city=北京');
url.searchParams.append('city', 'your_city');
url.searchParams.append('lat', 'your_lat');
url.searchParams.append('lon', 'your_lon');
url.searchParams.append('id', 'your_id');
url.searchParams.append('type', 'your_type');
url.searchParams.append('days', 'your_days');
url.searchParams.append('hours', 'your_hours');
url.searchParams.append('lang', 'your_lang');
url.searchParams.append('source', 'your_source');
fetch(url)
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error('请求失败:', err));
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ApiRequest {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newHttpClient();
String url = "https://api.qsxfr.top/API/tq.php?city=北京";
// 拼接请求参数
url += "?" + "city=your_city&lat=your_lat&lon=your_lon&id=your_id&type=your_type&days=your_days&hours=your_hours&lang=your_lang&source=your_source";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.GET()
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
package main
import (
"fmt"
"net/http"
"net/url"
"io/ioutil"
)
func main() {
baseUrl := "https://api.qsxfr.top/API/tq.php?city=北京"
parsedUrl, _ := url.Parse(baseUrl)
q := parsedUrl.Query()
q.Set("city", "your_city");
q.Set("lat", "your_lat");
q.Set("lon", "your_lon");
q.Set("id", "your_id");
q.Set("type", "your_type");
q.Set("days", "your_days");
q.Set("hours", "your_hours");
q.Set("lang", "your_lang");
q.Set("source", "your_source");
parsedUrl.RawQuery = q.Encode()
resp, err := http.Get(parsedUrl.String())
if err != nil {
fmt.Println("请求失败:", err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using var client = new HttpClient();
var url = new Uri("https://api.qsxfr.top/API/tq.php?city=北京");
var queryParams = new Dictionary<string, string>();
queryParams.Add("city", "your_city");
queryParams.Add("lat", "your_lat");
queryParams.Add("lon", "your_lon");
queryParams.Add("id", "your_id");
queryParams.Add("type", "your_type");
queryParams.Add("days", "your_days");
queryParams.Add("hours", "your_hours");
queryParams.Add("lang", "your_lang");
queryParams.Add("source", "your_source");
var uriBuilder = new UriBuilder(url);
uriBuilder.Query = new FormUrlEncodedContent(queryParams).ReadAsStringAsync().Result;
url = uriBuilder.Uri;
var response = await client.GetAsync(url);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
# 使用curl发送GET请求
curl -X GET "https://api.qsxfr.top/API/tq.php?city=北京&city=your_city&lat=your_lat&lon=your_lon&id=your_id&type=your_type&days=your_days&hours=your_hours&lang=your_lang&source=your_source"
=== API Key 使用说明 ===
1. 在本站注册账号并登录
2. 进入用户中心 → API密钥 → 申请API Key
3. 管理员审核通过后获得 apikey
4. 调用接口时在URL参数中添加 apikey 参数
示例:
https://api.qsxfr.top/API/tq.php?city=北京&apikey=你的apikey
注意事项:
- 请勿将 apikey 泄露给他人
- 如发现 apikey 泄露,请及时在用户中心申请删除
- 每个 apikey 有调用频率限制,请合理使用
# Secluded/QRspeed/ClousX6
A:$访问 https://api.qsxfr.top/API/tq.php?city=北京&city=your_city&lat=your_lat&lon=your_lon&id=your_id&type=your_type&days=your_days&hours=your_hours&lang=your_lang&source=your_source$
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
fun main() {
val client = OkHttpClient()
val url = "https://api.qsxfr.top/API/tq.php?city=北京"
// GET 请求拼接参数
val requestBuilder = Request.Builder().url(url + "?" + "city=your_city&lat=your_lat&lon=your_lon&id=your_id&type=your_type&days=your_days&hours=your_hours&lang=your_lang&source=your_source")
val request = requestBuilder.get().build()
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw RuntimeException("请求失败: ${response.code}")
println(response.body?.string())
}
}