{ "HeWeather6": [{ "basic": { "cid": "CN101010100", "location": "北京", "parent_city": "北京", "admin_area": "北京", "cnty": "我们", "lat": "39.90498734", "lon": "116.4052887", "tz": "+8.00" }, "update": { "loc": "2020-01-08 16:56", "utc": "2020-01-08 08:56" }, "status": "ok", "daily_forecast": [{ "cond_code_d": "100", "cond_code_n": "100", "cond_txt_d": "晴", "cond_txt_n": "晴", "date": "2020-01-08", "hum": "39", "mr": "14:50", "ms": "04:49", "pcpn": "0.0", "pop": "0", "pres": "1022", "sr": "07:35", "ss": "17:07", "tmp_max": "5", "tmp_min": "-7", "uv_index": "5", "vis": "25", "wind_deg": "358", "wind_dir": "北风", "wind_sc": "1-2", "wind_spd": "2" }, { "cond_code_d": "100", "cond_code_n": "101", "cond_txt_d": "晴", "cond_txt_n": "多云", "date": "2020-01-09", "hum": "43", "mr": "15:37", "ms": "05:54", "pcpn": "0.0", "pop": "0", "pres": "1019", "sr": "07:35", "ss": "17:08", "tmp_max": "4", "tmp_min": "-6", "uv_index": "3", "vis": "25", "wind_deg": "186", "wind_dir": "南风", "wind_sc": "1-2", "wind_spd": "11" }, { "cond_code_d": "101", "cond_code_n": "101", "cond_txt_d": "多云", "cond_txt_n": "多云", "date": "2020-01-10", "hum": "35", "mr": "16:33", "ms": "06:56", "pcpn": "0.0", "pop": "1", "pres": "1020", "sr": "07:35", "ss": "17:09", "tmp_max": "6", "tmp_min": "-4", "uv_index": "2", "vis": "25", "wind_deg": "6", "wind_dir": "北风", "wind_sc": "1-2", "wind_spd": "1" }] }] }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2020/01/06 22:16 */ //---------------------------------- // 3天天气预报 调用类 //---------------------------------- class freeApi{ private $apiUrl; private $appKey; public function __construct($appKey){ $this->appKey = $appKey; $this->apiUrl = 'https://chuanshuoapi.heweather.net/s6/weather/forecast'; } /** * 获取结果 * @return array */ public function getResult(){ $paras = [ 'key' => $this->appKey, 'location' => 'beijing', ]; return $this->freeApiCurl($this->apiUrl,$paras); } /** * 请求接口返回内容 * @param string $url [请求的URL地址] * @param string $params [请求的参数] * @param int $ipost [是否采用POST形式] * @return string */ public function freeApiCurl($url,$params=false){ $headers = array('Content-Type: application/x-www-form-urlencoded'); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params)); // Post提交的数据包 curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环 curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($curl); // 执行操作 if (curl_errno($curl)) { echo 'Errno'.curl_error($curl);//捕抓异常 } curl_close($curl); // 关闭CURL会话 return $result; } }
package main import ( "fmt" "io/ioutil" "log" "net/http" ) const ( APIURL = "https://chuanshuoapi.heweather.net/s6/weather/forecast" APIKEY = "your key" ) func main() { queryUrl := fmt.Sprintf("%s?key=%s&location=beijing",APIURL,APIKEY) 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)) }