代碼描述:基於php的地產資料介面調用代碼執行個體 介面地址:http://www.juhe.cn/docs/api/id/47
- // +----------------------------------------------------------------------
-
- //----------------------------------
- // 地產資料調用範例程式碼 - 彙總資料
- // 線上介面文檔:http://www.juhe.cn/docs/47
- //----------------------------------
-
- header('Content-type:text/html;charset=utf-8');
-
-
- //配置您申請的appkey
- $appkey = "*********************";
-
-
-
-
- //************1.地產檢索************
- $url = "http://v.juhe.cn/estate/query";
- $params = array(
- "city" => "",//城市名稱,請參考支援城市列表
- "key" => $appkey,//應用APPKEY(應用詳細頁查詢)
- "q" => "",//地產名關鍵字
- "page" => "",//頁數,預設1,每頁返回10條
- "dtype" => "",//返回資料的格式,xml或json,預設json
- );
- $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.周邊地產************
- $url = "http://v.juhe.cn/estate/local";
- $params = array(
- "lat" => "",//緯度(百度地圖座標系)
- "lng" => "",//經度
- "radius" => "",//檢索半徑,預設5000 單位米
- "key" => $appkey,//應用APPKEY(應用詳細頁查詢)
- "page" => "",//頁數,預設1,每頁返回20條
- "dtype" => "",//返回資料的格式,xml或json,預設json
- );
- $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.支援城市列表************
- $url = "http://v.juhe.cn/estate/citys";
- $params = array(
- );
- $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 "請求失敗";
- }
- //**************************************************
-
-
-
-
-
- /**
- * 請求介面返回內容
- * @param string $url [請求的URL地址]
- * @param string $params [請求的參數]
- * @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;
- }
複製代碼 |