名称 | 必填 | 类型 | 描述 | 示例 |
---|---|---|---|---|
token | true | string | 请求token,用户中心获取。 | 用户中心获取token |
city | false | string | 根据城市名称 | 南昌 |
city_id | string | 根据城市ID | ||
ip | string | 根据ip查询 | ||
lon | string | 经纬度查询 | ||
lat | string | 经纬度查询 | ||
province | string | 省份,如:广东;和city配合使用。传入该参数则会查询该省份下面的城市 |
上面参数任选一个进行查询就可以,默认不填根据请求的ip查询对应的城市天气
名称 | 描述 |
---|---|
city_id | 城市ID |
city | 城市名称 |
province | 省份 |
leader | 上级城市 |
date | 日期 |
temp_day | 白天温度 |
temp_night | 夜晚温度 |
wea_day | 白天天气 |
wea_day_code | 白天天气代码 |
wea_night | 夜晚天气 |
wea_night_code | 夜晚天气代码 |
wind_day | 白天风向 |
wind_night | 夜晚风向 |
wind_day_level | 白天风力等级 |
wind_night_level | 夜晚风力等级 |
air | 空气质量指数 |
air_level | 空气质量级别 |
precipitation | 降水量 |
sunrise | 日出时间 |
sunset | 日落时间 |
curl -X POST \
https://v2.alapi.cn/api/tianqi/forty \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'token=用户中心获取token&city=南昌&city_id=&ip=&lon=&lat=&province='
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://v2.alapi.cn/api/tianqi/forty",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "token=用户中心获取token&city=南昌&city_id=&ip=&lon=&lat=&province=",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "token=用户中心获取token&city=南昌&city_id=&ip=&lon=&lat=&province=");
Request request = new Request.Builder()
.url("https://v2.alapi.cn/api/tianqi/forty")
.post(body)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
import requests
url = "https://v2.alapi.cn/api/tianqi/forty"
payload = "token=用户中心获取token&city=南昌&city_id=&ip=&lon=&lat=&province="
headers = {'Content-Type': "application/x-www-form-urlencoded"}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "token=用户中心获取token&city=南昌&city_id=&ip=&lon=&lat=&province=");
Request request = new Request.Builder()
.url("https://v2.alapi.cn/api/tianqi/forty")
.post(body)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://v2.alapi.cn/api/tianqi/forty"
payload := strings.NewReader("token=用户中心获取token&city=南昌&city_id=&ip=&lon=&lat=&province=")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
返回状态码 code
描述参照
错误码 | 说明 |
---|---|
200 | 返回200表示接口正常 |
404 | 接口地址不存在 |
422 | 接口请求失败 |
400 | 接口请求失败 |
405 | 请求方法不被允许 |
100 | token 错误 |
101 | 账号过期 |
102 | 接口请求次数超过限制 |
104 | 来源或者ip不在白名单 |
406 | 没有更多数据了 |
429 | 请求 QPS 超过限制 |
内容 | 详情 |
---|---|
客服QQ | 1830934534 |
交流群 |