实用工具类
weather & v1

2024-09-17 04:12:32

Start Me
Pasta

累计调用:1801

头像
客源
未开源

专注于企业级API开发与架构设计,5年以上开发经验

天气查询

GET

国气象干旱综合监测 土壤水分监测 热带气旋监测公报. 官方权威发布天气预报,逐三小时天气预报

接口地址: https://api.qster.top/API/v1/weather
接口示例: https://api.qster.top/API/v1/weather/?city=深圳

请求参数

参数名 类型 必填 说明
type string 默认json 可选json/text
city string 城市
qskey string 申请临时密钥

响应参数

参数 说明
msg 响应说明
living 建议
data.city 中文地区名
data.cityEnglish 英文地区名
data.temp 温度
data.tempn 最高温度
data.weather 天气
data.wind 风向
data.windSpeed 风速
data.time 更新时间
data.warning 预警
data.current.city 中文地区名
data.current.cityEnglish 英文地区名
data.current.humidity 湿度
data.current.wind 风向
data.current.windSpeed 风速
data.current.visibility 能见度
data.current.weather 当前天气
data.current.weatherEnglish 当前天气英文
data.current.temp 当前温度
data.current.fahrenheit 华氏度
data.current.air 当前空气指数
data.current.air_pm25 pm2.5
data.current.date 日期
data.current.time 更新时间
data.current.tempn 最高温度
code 200正常400失败 查看更多

代码示例

<?php
// 要调用的 URL
$url = "https://api.qster.top/API/v1/weather";

// 参数数组
$params = [
"type" => "默认json 可选json/text",
"city" => "城市",
"qskey" => "0",
];

// 使用 http_build_query 将参数转换为查询字符串
$queryString = http_build_query($params);

// 在 URL 中添加查询字符串
$finalUrl = $url . '?' . $queryString;

// 使用 file_get_contents 获取内容
$response = file_get_contents($finalUrl);

// 输出响应
echo $response;
?>

import requests

url = "https://api.qster.top/API/v1/weather";
params = {
"type" : "默认json 可选json/text",
"city" : "城市",
"qskey" => "0"
}
response = requests.get(url, params=params)
print(response.text)

function fetchData(url, params) {

const queryString = Object.keys(params)
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
.join('&');
const fullUrl = `${url}?${queryString}`;

fetch(fullUrl)
.then(response => response.text())
.then(data => {
const resultElement = document.createElement('pre');
resultElement.textContent = data;
document.body.appendChild(resultElement);
})
.catch(error => console.error('Error fetching data:', error));
}

// 示例用法
const url = "https://api.qster.top/API/v1/weather";
const params = {
"type" : "默认json 可选json/text",
"city" : "城市",
"qskey" => "0"
};
fetchData(url, params);

在线调试