Code description: PHP-based real estate data interface calling code example Interface address: http://www.juhe.cn/docs/api/id/47
- // +------------- -------------------------------------------------- --------
-
- //----------------------------------
- // Real Estate Data calling sample code - aggregated data
- // Online interface documentation: http://www.juhe.cn/docs/47
- //-------------------------- ---------------
-
- header('Content-type:text/html;charset=utf-8');
-
-
- //Configure the appkey you applied for
- $appkey = " *********************";
-
-
-
-
- //************1. Real estate search************
- $url = "http://v.juhe.cn/estate/query";
- $params = array(
- "city" => "",//City name, please refer to the list of supported cities
- "key" => $appkey,//Application APPKEY (application details page query)
- "q" => " ",//Real estate name keyword
- "page" => "",//Number of pages, default 1, 10 items returned per page
- "dtype" => "",//Format of returned data, xml or json, default 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, default 5000 units meters
- "key" => $appkey,//Application APPKEY (application details page query)
- "page" => "",//Number of pages, default 1, return 20 items per page
- "dtype" => "",//Format of returned data, xml or json, default 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 list************
- $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";
- }
- //************************ *********************************
-
-
-
-
-
- /**
- * Request interface return content
- * @param string $url [requested URL address]
- * @param string $params [requested parameters]
- * @param int $ipost [whether to use 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;
- }
复制代码
|