{ "HeWeather6": [{ "basic": { "cid": "CN101010100", "location": "北京", "parent_city": "北京", "admin_area": "北京", "cnty": "中国", "lat": "39.90498734", "lon": "116.4052887", "tz": "+8.00" }, "update": { "loc": "2020-01-06 16:55", "utc": "2020-01-06 08:55" }, "status": "ok", "lifestyle": [{ "type": "comf", "brf": "较不舒适", "txt": "白天天气晴好,但仍会使您感觉偏冷,不很舒适,请注意适时添加衣物,以防感冒。" }, { "type": "drsg", "brf": "冷", "txt": "天气冷,建议着棉服、羽绒服、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣、冬大衣或厚羽绒服。" }, { "type": "flu", "brf": "易发", "txt": "昼夜温差很大,易发生感冒,请注意适当增减衣服,加强自我防护避免感冒。" }, { "type": "sport", "brf": "较不宜", "txt": "天气较好,但考虑天气寒冷,推荐您进行室内运动,户外运动时请注意保暖并做好准备活动。" }, { "type": "trav", "brf": "适宜", "txt": "天气较好,气温稍低,会感觉稍微有点凉,不过也是个好天气哦。适宜旅游,可不要错过机会呦!" }, { "type": "uv", "brf": "中等", "txt": "属中等强度紫外线辐射天气,外出时建议涂擦SPF高于15、PA+的防晒护肤品,戴帽子、太阳镜。" }, { "type": "cw", "brf": "适宜", "txt": "适宜洗车,未来持续两天无雨天气较好,适合擦洗汽车,蓝天白云、风和日丽将伴您的车子连日洁净。" }, { "type": "air", "brf": "中", "txt": "气象条件对空气污染物稀释、扩散和清除无明显影响。" }] }] }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2020/01/06 22:16 */ //---------------------------------- // 生活指数 调用类 //---------------------------------- class freeApi{ private $apiUrl; private $appKey; public function __construct($appKey){ $this->appKey = $appKey; $this->apiUrl = 'https://free-api.heweather.net/s6/weather/lifestyle'; } /** * 获取结果 * @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://free-api.heweather.net/s6/weather/lifestyle" 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)) }