Skip to content

城市天气预报获取

获取指定城市当日天气信息,来源于中国气象局官方数据。

接口地址

https://api.nxvav.cn/api/weather/

请求示例

https://api.nxvav.cn/api/weather/?city=北京

https://api.nxvav.cn/api/weather/?city=香港

shell
curl https://api.nxvav.cn/api/weather -X POST -d 'city=香港'
php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
   CURLOPT_URL => 'https://api.nxvav.cn/api/weather/?city=北京',
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_ENCODING => '',
   CURLOPT_MAXREDIRS => 10,
   CURLOPT_TIMEOUT => 0,
   CURLOPT_FOLLOWLOCATION => true,
   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
   CURLOPT_CUSTOMREQUEST => 'GET',
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
?>

请求参数

参数名类型必填说明
citystring城市名字,可使用拼音

返回参数

返回参数类型说明
codestring状态码
locationstring城市位置数据
location > namestring城市
location > countrystring国家
location > pathstring位置
nowstring天气信息数据
now > textstring天气现象文字
now > codestring天气现象代码
now > temperaturestring温度,单位为c摄氏度

返回示例

json
{
    "code": 200,
    "location": {
        "name": "北京",
        "country": "CN",
        "path": "北京,北京,中国"
    },
    "now": {
        "text": "晴",
        "code": "0",
        "temperature": "13"
    },
    "last_update": "2024-11-16T12:27:40+08:00"
}
json
{
    "code": 200,
    "msg": "错误"
}