接入教程
https://devapi.qweather.com/v7/weather/now?location=101010100&key=你的KEY1. 访问和风天气开发者服务官网注册账号。
2. 登录控制台,创建一个项目和API Key。
3. 用Key请求实时天气接口,例如:
4. 其中location支持城市ID或经纬度,返回JSON包含实时温度、天气现象等。
5. 免费订阅额度为每天1000次,超出后可按量计费继续使用。
Python 获取实时天气
python
import requests
url = "https://devapi.qweather.com/v7/weather/now"
params = {
"location": "101010100",
"key": "你的KEY"
}
r = requests.get(url, params=params)
data = r.json()
print(data["now"]["temp"], data["now"]["text"])
PHP 获取实时天气
php
<?php
$url = 'https://devapi.qweather.com/v7/weather/now?location=101010100&key=你的KEY';
$res = file_get_contents($url);
$data = json_decode($res, true);
echo $data['now']['temp'] . ' ' . $data['now']['text'];
JavaScript 获取实时天气
javascript
fetch('https://devapi.qweather.com/v7/weather/now?location=101010100&key=你的KEY')
.then(r => r.json())
.then(d => console.log(d.now.temp, d.now.text));
常见问题
免费额度是多少?
免费订阅每天提供1000次请求额度,超出后自动按量计费。
需要付费才能使用吗?
不需要,注册后创建项目和Key即可免费调用,适合个人开发与项目原型。
Aitishiku.com