程式碼描述:基於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);
- $resultult = juhecurl($url,$paramstring);
- $resultult = 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_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( $churl_setopt( $ ( $ch , CURLOPT_URL , $url );
- }
- else
- {
- if($params){
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$m. );
- }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 ); >}
-
-
複製程式碼
|
php