Code description: php-based real estate data interface call code example Interface address: http://www.juhe.cn/docs/api/id/47
-
- // + ----------------------------------------------------------------------
-
- //----------------------------------
- // Sample code for calling real estate data-aggregate data
- // Online interface documentation: http://www.juhe.cn/docs/47
- //----------------------------------
-
- Header ('content-type: text/html; charset = utf-8 ');
-
-
- // Configure the appkey you applied
- $ Appkey = "*********************";
-
-
-
-
- // ************ 1. real estate search ************
- $ Url = "http://v.juhe.cn/estate/query ";
- $ Params = array (
- "City" => "", // city name, see supported cities list
- "Key" => $ appkey, // APPKEY of the application (query on the application details page)
- "Q" => "", // real estate name keyword
- "Page" => "", // Number of pages. the default value is 1. 10 entries are returned for each page.
- "Dtype" => "", // The format of the returned data, xml or json. the default value is 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 "request failed ";
- }
- //************************************** ************
-
-
-
-
- // ************ 2. surrounding real estate ************
- $ Url = "http://v.juhe.cn/estate/local ";
- $ Params = array (
- "Lat" => "", // latitude (Baidu map coordinate system)
- "Lng" => "", // longitude
- "Radius" => "", // retrieval radius, 5000 meters by default
- "Key" => $ appkey, // APPKEY of the application (query on the application details page)
- "Page" => "", // Number of pages. the default value is 1. 20 entries are returned for each page.
- "Dtype" => "", // The format of the returned data, xml or json. the default value is 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 "request failed ";
- }
- //************************************** ************
-
-
-
-
- // ************ 3. supported city lists ************
- $ 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 "request failed ";
- }
- //************************************** ************
-
-
-
-
-
- /**
- * Content returned by the request interface
- * @ Param string $ url [requested URL]
- * @ Param string $ params [request parameters]
- * @ Param int $ ipost [whether to use the POST form]
- * @ 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;
- }
|