国内天气预报查询
ALAPI 官方文档
now为查询今日天气预报,grid为查询七日天气
基本说明:
接口地址:https://v2.alapi.cn/api/tianqi/now(grid)
返回格式:json
请求方式:get/post
请求示例:https://v2.alapi.cn/api/tianqi/now?token=token
请求参数说明:
名称 类型 必填 说明
token string 必填 请求token 扫码关注公众号
cityid int 选填 城市的id
city string 选填 城市名称
ip string 选填 根据IP查询天气
返回参数说明:
名称 类型 说明
- - -
JSON返回示例:
{
	"code": 200,
	"msg": "success",
	"data": {
		"cityid": "101010100",
		"date": "2001-09-30",
		"week": "星期一",
		"update_time": "10:15",
		"city": "北京",
		"cityEn": "beijing",
		"country": "我们",
		"countryEn": "China",
		"wea": "晴",
		"wea_img": "qing",
		"tem": "23",
		"tem1": "30",
		"tem2": "19",
		"win": "东风",
		"win_speed": "2级",
		"win_meter": "小于12km/h",
		"humidity": "62%",
		"visibility": "3.4km",
		"pressure": "1011",
		"air": "124",
		"air_pm25": "124",
		"air_level": "轻度污染",
		"air_tips": "儿童、老年人及心脏病、呼吸系统疾病患者应尽量减少体力消耗大的户外活动。",
		"alarm": {
			"alarm_type": "",
			"alarm_level": "",
			"alarm_content": ""
		}
	},
	"Author": {
		"name": "Alone88",
		"desc": "由Alone88提供的免费API 服务,官方文档:www.alapi.cn"
	}
}
服务级错误码参照
错误码 说明
500 处理异常
完整教学代码示例
<?php

/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2020/02/01 00:16
 */
class freeApi
{
    private $apiUrl;

    public function __construct()
    {
        $this->apiUrl = 'https://v1.alapi.cn/api/tianqi/now';
    }

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

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

const (
	APIURL   = "https://v1.alapi.cn/api/tianqi/now"
)

func main() {
	queryUrl := fmt.Sprintf("%s?city=北京市",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))
}