天气预报
其他 官方文档
根据IP自动判断IP所属地区当日天气信息,可自动获取IP来源,天气信息来源于中国气象局官方数据
基本说明:
接口地址:https://cn.apihz.cn/api/tianqi/tqybip.php
返回格式:json
请求方式:get/post
请求示例:https://cn.apihz.cn/api/tianqi/tqybip.php?id=10004093&key=key&ip=49.234.56.78
请求参数说明:
名称 类型 必填 说明
id int 必填 用户中心的数字ID:10004093
key string 必填 对应平台用户中心通讯秘钥,非本平台 扫码关注公众号
ip string 选填 要查询的ip,如不传则自动获取接口调用IP
返回参数说明:
名称 类型 说明
precipitation int 降水量
temperature string 温度
pressure string 气压
humidity string 湿度
windDirection string 风向
JSON返回示例:
{
	"precipitation": 0,
	"temperature": 34.5,
	"pressure": 1012,
	"humidity": 55,
	"windDirection": "东北风",
	"windDirectionDegree": 61,
	"windSpeed": 1.7,
	"windScale": "微风",
	"feelst": 39.1,
	"code": 200,
	"place": "中国, 上海, 徐家汇",
	"weather1": "多云",
	"weather2": "多云",
	"weather1img": "https://rescdn.apihz.cn/resimg/tianqi/duoyun.png",
	"weather2img": "https://rescdn.apihz.cn/resimg/tianqi/duoyun.png",
	"uptime": "2025/08/18 13:50",
	"jieqi": ""
}
服务级错误码参照
错误码 说明
400 错误信息提示
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2025/4/20 07:11
 */
class freeApi
{
    private $apiUrl;

    public function __construct()
    {
        $this->apiUrl = 'https://cn.apihz.cn/api/tianqi/tqybip.php?id=10004093&key=key&ip=49.234.56.78';
    }

    /**
     * 获取结果
     * @return array
     */
    public function getResult()
    {
        return file_get_contents($this->apiUrl);
    }
}
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

const (
	APIURL   = "https://cn.apihz.cn/api/tianqi/tqybip.php?id=10004093&key=key&ip=49.234.56.78"
)

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