欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          php如何查詢城市空氣質(zhì)量

          php查詢城市空氣質(zhì)量的方法:1、開通空氣質(zhì)量API接口;2、創(chuàng)建php示例文件;3、設(shè)置文件編碼為“utf-8”;4、配置申請的appkey;5、請求接口URL;6、通過“$params = ['city' => '…', 'key' => '…'];”方式請求城市空氣質(zhì)量相關(guān)參數(shù)信息即可。

          php如何查詢城市空氣質(zhì)量

          php入門到就業(yè)線上直播課:進入學習
          Apipost = Postman + Swagger + Mock + Jmeter 超好用的API調(diào)試工具:點擊使用

          本教程操作環(huán)境:windows7系統(tǒng)、PHP8.1版、Dell G3電腦。

          php如何查詢城市空氣質(zhì)量?

          1、開通空氣質(zhì)量API接口:

          • 通過https://www.juhe.cn/docs/api/id/33?s=cpphpcn注冊及開通

          接口說明:

          • 支持全國大部分城市空氣質(zhì)量查詢,可實時查詢空氣質(zhì)量,小時粒度,實時給出空氣質(zhì)量AQI指數(shù),并給出空氣質(zhì)量級別和首要污染物。

          • 有的城市可能沒有監(jiān)測點實時監(jiān)測的數(shù)據(jù),每1小時更新一次。

          2、基于php的空氣質(zhì)量接口調(diào)用示例

          php代碼如下:

          // 空氣質(zhì)量調(diào)用示例代碼   header('Content-type:text/html;charset=utf-8');  //配置您申請的appkey  $appkey = "*********************";  //************1.城市空氣質(zhì)量************  $url = "http://web.juhe.cn:8080/environment/air/cityair";  $params = array(  "city" => "",//城市名稱的中文名稱或拼音,如:上海 或 shanghai  "key" => $appkey,//APP Key  );  $paramstring = http_build_query($params);  $content = juhecurl($url,$paramstring);  $result = json_decode($content,true);  if($result){  if($result['error_code']=='0'){  print_r($result);  }else{  echo $result['error_code'].":".$result['reason'];  }  }else{  echo "請求失敗";  }  //**************************************************  //************2.城市空氣PM2.5指數(shù)************  $url = "http://web.juhe.cn:8080/environment/air/pm";  $params = array(  "city" => "",//城市名稱的中文名稱或拼音,如:上海 或 shanghai  "key" => $appkey,//APP Key  );  $paramstring = http_build_query($params);  $content = juhecurl($url,$paramstring);  $result = json_decode($content,true);  if($result){  if($result['error_code']=='0'){  print_r($result);  }else{  echo $result['error_code'].":".$result['reason'];  }  }else{  echo "請求失敗";  }  //**************************************************  //************3.城市空氣質(zhì)量-城市列表************  $url = "http://web.juhe.cn:8080/environment/air/airCities";  $params = array(  "key" => $appkey,//APP Key  );  $paramstring = http_build_query($params);  $content = juhecurl($url,$paramstring);  $result = json_decode($content,true);  if($result){  if($result['error_code']=='0'){  print_r($result);  }else{  echo $result['error_code'].":".$result['reason'];  }  }else{  echo "請求失敗";  }  //**************************************************  //************4.城市空氣PM2.5指數(shù)-城市列表************  $url = "http://web.juhe.cn:8080/environment/air/pmCities";  $params = array(  "key" => $appkey,//APP Key  );  $paramstring = http_build_query($params);  $content = juhecurl($url,$paramstring);  $result = json_decode($content,true);  if($result){  if($result['error_code']=='0'){  print_r($result);  }else{  echo $result['error_code'].":".$result['reason'];  }  }else{  echo "請求失敗";  }  //**************************************************  //************5.城市輻射指數(shù)************  $url = "http://web.juhe.cn:8080/environment/air/radia";  $params = array(  "city" => "",//城市名稱的中文拼音,查詢城市為“上?!?,則輸入:上海  "num" => "",//查詢頁碼數(shù),不寫默認為第一頁。  "key" => $appkey,//APP Key  );  $paramstring = http_build_query($params);  $content = juhecurl($url,$paramstring);  $result = json_decode($content,true);  if($result){  if($result['error_code']=='0'){  print_r($result);  }else{  echo $result['error_code'].":".$result['reason'];  }  }else{  echo "請求失敗";  }  //**************************************************  /**  * 請求接口返回內(nèi)容  * @param string $url [請求的URL地址]  * @param string $params [請求的參數(shù)]  * @param int $ipost [是否采用POST形式]  * @return string  */  function juhecurl($url,$params=false,$ispost=0){  $httpInfo = array();  $ch = curl_init();  curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );  curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );  curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );  curl_setopt( $ch, CURLOPT_TIMEOUT , 60);  curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);  if( $ispost )  {  curl_setopt( $ch , CURLOPT_POST , true );  curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );  curl_setopt( $ch , CURLOPT_URL , $url );  }  else  {  if($params){  curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );  }else{  curl_setopt( $ch , CURLOPT_URL , $url);  }  }  $response = curl_exec( $ch );  if ($response === FALSE) {  //echo "cURL Error: " . curl_error($ch);  return false;  }  $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );  $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );  curl_close( $ch );  return $response;  }
          登錄后復制

          推薦學習:《PHP視頻教程》

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號