未来天气
ROLL 官方文档
全国天气信息查询,定时更新未来天气
基本说明:
接口地址:https://www.mxnzp.com/api/weather/forecast/{city}
返回格式:json
请求方式:get
请求示例:https://www.mxnzp.com/api/weather/forecast/深圳市?app_id=your&app_secret=your
请求参数说明:
名称 类型 必填 说明
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 此次天气发布时间
JSON返回示例:
{
	"code": 1,
	"msg": "数据返回成功!",
	"data": {
		"address": "广东省 深圳市",
		"cityCode": "440300",
		"reportTime": "2022-09-19 13:30:19",
		"forecasts": [{
			"date": "2022-09-19",
			"dayOfWeek": "1",
			"dayWeather": "多云",
			"nightWeather": "多云",
			"dayTemp": "34℃",
			"nightTemp": "27℃",
			"dayWindDirection": "北",
			"nightWindDirection": "北",
			"dayWindPower": "≤3级",
			"nightWindPower": "≤3级"
		}, {
			"date": "2022-09-20",
			"dayOfWeek": "2",
			"dayWeather": "多云",
			"nightWeather": "多云",
			"dayTemp": "32℃",
			"nightTemp": "24℃",
			"dayWindDirection": "东",
			"nightWindDirection": "东",
			"dayWindPower": "4级",
			"nightWindPower": "4级"
		}, {
			"date": "2022-09-21",
			"dayOfWeek": "3",
			"dayWeather": "多云",
			"nightWeather": "多云",
			"dayTemp": "30℃",
			"nightTemp": "25℃",
			"dayWindDirection": "北",
			"nightWindDirection": "北",
			"dayWindPower": "≤3级",
			"nightWindPower": "≤3级"
		}, {
			"date": "2022-09-22",
			"dayOfWeek": "4",
			"dayWeather": "晴",
			"nightWeather": "多云",
			"dayTemp": "32℃",
			"nightTemp": "25℃",
			"dayWindDirection": "北",
			"nightWindDirection": "北",
			"dayWindPower": "≤3级",
			"nightWindPower": "≤3级"
		}]
	}
}
服务级错误码参照
错误码 说明
0 app_id或者app_secret不合法
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2022/09/19 14:56
 */
class freeApi
{
    private $apiUrl;

    public function __construct()
    {
        $this->apiUrl = 'https://www.mxnzp.com/api/weather/forecast/深圳市?app_id=your&app_secret=your';
    }

    /**
     * 获取结果
     * @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/forecast/深圳市?app_id=your&app_secret=your"
)

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))
}