接口大厅/天气预报
返回接口大厅
41 API Endpoint GET

天气预报

正常

可查询今日以及未来几日的天气

Status
正常
Total Calls
1,619
Created
2025-08-02
Updated
2026-06-20
Response
JSON
01

Request Info

请求信息
Endpoint GET http://cyapi.top/API/weather.php
Example http://cyapi.top/API/weather.php?city=贵阳&n=1&type=text
02

Parameters

3 params
Name Type Required Description
apikey string 填入你的 API Key
city string 城市名
n string 不传则返回城市列表,传入序号选择对应城市
type string 支持json和text
03

Status Codes

状态码
Code Meaning
200请求成功
403无权限或密钥无效
404接口不存在或参数错误
429请求过于频繁,已达限额
500服务器内部错误
04

Online Test

在线测试
请求参数
Response Format: JSON
响应结果
output
点击「立即测试」查看接口返回结果
05

Code Examples

调用示例
<?php
$url = 'http://cyapi.top/API/weather.php?apikey=' . urlencode($params['apikey']) . '&city=' . urlencode($params['city']) . '&n=' . urlencode($params['n']) . '&type=' . urlencode($params['type'])';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>
import requests

url = 'http://cyapi.top/API/weather.php'
params = {
    'apikey': 'YOUR_API_KEY',
    'city': 'YOUR_VALUE',
    'n': 'YOUR_VALUE',
    'type': 'YOUR_VALUE'
}

response = requests.get(url, params=params)
print(response.text)
const url = new URL('http://cyapi.top/API/weather.php');
const params = new URLSearchParams();
params.append('apikey', 'YOUR_API_KEY');
params.append('city', 'YOUR_VALUE');
params.append('n', 'YOUR_VALUE');
params.append('type', 'YOUR_VALUE');
url.search = params.toString();

fetch(url)
  .then(res => res.text())
  .then(data => console.log(data));