站長(zhǎng)資訊網(wǎng)
        最全最豐富的資訊網(wǎng)站

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

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

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

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

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

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

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

        • 通過(guò)https://www.juhe.cn/docs/api/id/33?s=cpphpcn注冊(cè)及開(kāi)通

        接口說(shuō)明:

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

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

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

        php代碼如下:

        // 空氣質(zhì)量調(diào)用示例代碼   header('Content-type:text/html;charset=utf-8');  //配置您申請(qǐng)的appkey  $appkey = "*********************";  //************1.城市空氣質(zhì)量************  $url = "http://web.juhe.cn:8080/environment/air/cityair";  $params = array(  "city" => "",//城市名稱(chēng)的中文名稱(chēng)或拼音,如:上海 或 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 "請(qǐng)求失敗";  }  //**************************************************  //************2.城市空氣PM2.5指數(shù)************  $url = "http://web.juhe.cn:8080/environment/air/pm";  $params = array(  "city" => "",//城市名稱(chēng)的中文名稱(chēng)或拼音,如:上海 或 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 "請(qǐng)求失敗";  }  //**************************************************  //************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 "請(qǐng)求失敗";  }  //**************************************************  //************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 "請(qǐng)求失敗";  }  //**************************************************  //************5.城市輻射指數(shù)************  $url = "http://web.juhe.cn:8080/environment/air/radia";  $params = array(  "city" => "",//城市名稱(chēng)的中文拼音,查詢(xún)城市為“上海”,則輸入:上海  "num" => "",//查詢(xún)頁(yè)碼數(shù),不寫(xiě)默認(rèn)為第一頁(yè)。  "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 "請(qǐng)求失敗";  }  //**************************************************  /**  * 請(qǐng)求接口返回內(nèi)容  * @param string $url [請(qǐng)求的URL地址]  * @param string $params [請(qǐng)求的參數(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;  }
        登錄后復(fù)制

        推薦學(xué)習(xí):《PHP視頻教程》

        贊(0)
        分享到: 更多 (0)
        網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)
        主站蜘蛛池模板: 四库影院永久四虎精品国产| 国产高清在线精品一本大道国产 | 国产高清在线精品一本大道国产 | 九九热这里只有在线精品视 | 久久精品国产半推半就| 中文字幕在线亚洲精品| 国产欧美日本精品| 精品免费tv久久久久久久| 久久久久人妻精品一区| 最新国产成人精品2024| 久久91精品综合国产首页| 91精品国产91久久久久久青草 | 亚洲国产精品自在在线观看| 国内精品久久九九国产精品| 无码精品人妻一区二区三区人妻斩| 国产三级精品三级在专区| 中文字幕亚洲综合精品一区| 91麻豆精品视频| 精品国偷自产在线| 乱码精品一区二区三区| 亚洲精品线路一在线观看| 久久精品亚洲乱码伦伦中文| 国产精品秘入口福利姬网站| 亚洲第一精品福利| 久久成人国产精品二三区| .精品久久久麻豆国产精品| 久久99久久99精品免视看动漫| 最新精品国偷自产在线| 亚洲国产精品成人| 日韩午夜高清福利片在线观看欧美亚洲精品suv | 亚洲AV永久无码精品水牛影视| 亚洲欧美日韩国产一区二区三区精品| 久久精品国产第一区二区| 国产精品无码一区二区在线| 97久人人做人人妻人人玩精品| 91国内揄拍国内精品对白不卡| 56prom精品视频在放免费| Xx性欧美肥妇精品久久久久久| 99久久夜色精品国产网站| 国产精品天干天干在线综合| 精品欧美一区二区在线观看|