Code Description: PHP-based real estate data interface Call code instance
Interface Address: HTTP://WWW.JUHE.CN/DOCS/API/ID/47
- // +----------------------------------------------------------------------
- //----------------------------------
- Real Estate data Call sample code-aggregate data
- Online interface Documentation: HTTP://WWW.JUHE.CN/DOCS/47
- //----------------------------------
- Header (' Content-type:text/html;charset=utf-8 ');
- Configure the Appkey you requested
- $appkey = "*********************";
- 1. Real Estate Search ************
- $url = "Http://v.juhe.cn/estate/query";
- $params = Array (
- "City" and "" ",//town name, please refer to the list of supported cities
- "Key" = $appkey,//Application Appkey (Application Detail page query)
- "Q" + "" ",//Real estate name Keywords
- "Page" = "" ",//number of pages, default 1, return 10 per page
- "Dtype" + "",//format of the 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 Property ************
- $url = "Http://v.juhe.cn/estate/local";
- $params = Array (
- "Lat" = "",//latitude (Baidu Map coordinate system)
- "LNG" = ","//Longitude
- "Radius" = "",//Search radius, default 5000 units m
- "Key" = $appkey,//Application Appkey (Application Detail page query)
- "Page" = "" ",//number of pages, default 1, return 20 per page
- "Dtype" + "",//format of the 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. Support 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 to return content
- * @param string $url [requested URL address]
- * @param string $params [parameter requested]
- * @param int $ipost [if post is used]
- * @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;
- }
Copy Code |