接口地址:https://www.mxnzp.com/api/weather/current/{city} |
---|
返回格式:json |
请求方式:get |
请求示例:hhttps://www.mxnzp.com/api/weather/current/昆山市?app_id=&app_secret= |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
app_id | string | 必填 | app_id 扫码关注公众号 |
app_secret | string | 必填 | app_secret 扫码关注公众号 |
city | string | 必填 | 查询的城市 |
名称 | 类型 | 说明 |
---|---|---|
address | string | 城市具体信息,比如 “广东省 深圳市” |
cityCode | string | 城市code |
temp | string | 温度值 |
weather | string | 天气描述 |
windDirection | string | 风向描述 |
windPower | string | 风力描述 |
humidity | string | 湿度值 |
reportTime | string | 此次天气发布时间 |
{
"code": 1,
"msg": "数据返回成功!",
"data": {
"address": "江苏省 苏州市 昆山市",
"cityCode": "320583",
"temp": "36℃",
"weather": "晴",
"windDirection": "东南",
"windPower": "4级",
"humidity": "49%",
"reportTime": "2022-08-04 15:01:44"
}
}
错误码 | 说明 |
---|---|
0 | app_id或者app_secret不合法 |
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2022/08/04 14:56
*/
class freeApi
{
private $apiUrl;
public function __construct()
{
$this->apiUrl = 'https://www.mxnzp.com/api/weather/current/昆山市?app_id=&app_secret=';
}
/**
* 获取结果
* @return array
*/
public function getResult()
{
return file_get_contents($this->apiUrl);
}
}
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
const (
APIURL = "https://www.mxnzp.com/api/weather/current/昆山市?app_id=&app_secret="
)
func main() {
queryUrl := fmt.Sprintf("%s",APIURL)
resp, err := http.Get(queryUrl)
if err != nil {
log.Println(err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}