实况天气
其他 官方文档
今日实况天气
基本说明:
接口地址:https://www.tianqiapi.com/free/day
返回格式:json
请求方式:get/post
请求示例:https://www.tianqiapi.com/free/day?appid=23035354&appsecret=8YvlPNrz
请求参数说明:
名称 类型 必填 说明
appid string 必填 账号ID 扫码关注公众号
appsecret string 必填 账号密钥 扫码关注公众号
city string 选填 城市名称
返回参数说明:
名称 类型 说明
- - 见json
JSON返回示例:
{
	"cityid": "101190401",
	"city": "苏州",
	"update_time": "19:59",
	"wea": "晴",
	"wea_img": "qing",
	"tem": "22",
	"tem_day": "28",
	"tem_night": "15",
	"win": "东南风",
	"win_speed": "3级",
	"win_meter": "15km\/h",
	"air": "101"
}
服务级错误码参照
错误码 说明
100 appid或appsecret错误!
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2022/04/08 11:38
 */
class freeApi
{
    private $apiUrl;

    public function __construct()
    {
        $this->apiUrl = 'https://www.tianqiapi.com/free/day?appid=23035354&appsecret=8YvlPNrz';
    }

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

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

const (
	APIURL   = "https://www.tianqiapi.com/free/day?appid=23035354&appsecret=8YvlPNrz"
)

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