PHP-based real estate data interface Invocation code instance

Source: Internet
Author: User
Code Description: PHP-based real estate data interface Call code instance
Interface Address: HTTP://WWW.JUHE.CN/DOCS/API/ID/47
  1. // +----------------------------------------------------------------------
  2. //----------------------------------
  3. Real Estate data Call sample code-aggregate data
  4. Online interface Documentation: HTTP://WWW.JUHE.CN/DOCS/47
  5. //----------------------------------
  6. Header (' Content-type:text/html;charset=utf-8 ');
  7. Configure the Appkey you requested
  8. $appkey = "*********************";
  9. 1. Real Estate Search ************
  10. $url = "Http://v.juhe.cn/estate/query";
  11. $params = Array (
  12. "City" and "" ",//town name, please refer to the list of supported cities
  13. "Key" = $appkey,//Application Appkey (Application Detail page query)
  14. "Q" + "" ",//Real estate name Keywords
  15. "Page" = "" ",//number of pages, default 1, return 10 per page
  16. "Dtype" + "",//format of the returned data, XML or JSON, default JSON
  17. );
  18. $paramstring = Http_build_query ($params);
  19. $content = Juhecurl ($url, $paramstring);
  20. $result = Json_decode ($content, true);
  21. if ($result) {
  22. if ($result [' error_code ']== ' 0 ') {
  23. Print_r ($result);
  24. }else{
  25. echo $result [' Error_code ']. ":". $result [' reason '];
  26. }
  27. }else{
  28. echo "Request Failed";
  29. }
  30. //**************************************************
  31. 2. Surrounding Property ************
  32. $url = "Http://v.juhe.cn/estate/local";
  33. $params = Array (
  34. "Lat" = "",//latitude (Baidu Map coordinate system)
  35. "LNG" = ","//Longitude
  36. "Radius" = "",//Search radius, default 5000 units m
  37. "Key" = $appkey,//Application Appkey (Application Detail page query)
  38. "Page" = "" ",//number of pages, default 1, return 20 per page
  39. "Dtype" + "",//format of the returned data, XML or JSON, default JSON
  40. );
  41. $paramstring = Http_build_query ($params);
  42. $content = Juhecurl ($url, $paramstring);
  43. $result = Json_decode ($content, true);
  44. if ($result) {
  45. if ($result [' error_code ']== ' 0 ') {
  46. Print_r ($result);
  47. }else{
  48. echo $result [' Error_code ']. ":". $result [' reason '];
  49. }
  50. }else{
  51. echo "Request Failed";
  52. }
  53. //**************************************************
  54. 3. Support City List ************
  55. $url = "Http://v.juhe.cn/estate/citys";
  56. $params = Array (
  57. );
  58. $paramstring = Http_build_query ($params);
  59. $content = Juhecurl ($url, $paramstring);
  60. $result = Json_decode ($content, true);
  61. if ($result) {
  62. if ($result [' error_code ']== ' 0 ') {
  63. Print_r ($result);
  64. }else{
  65. echo $result [' Error_code ']. ":". $result [' reason '];
  66. }
  67. }else{
  68. echo "Request Failed";
  69. }
  70. //**************************************************
  71. /**
  72. * Request interface to return content
  73. * @param string $url [requested URL address]
  74. * @param string $params [parameter requested]
  75. * @param int $ipost [if post is used]
  76. * @return String
  77. */
  78. function Juhecurl ($url, $params =false, $ispost =0) {
  79. $httpInfo = Array ();
  80. $ch = Curl_init ();
  81. curl_setopt ($ch, curlopt_http_version, curl_http_version_1_1);
  82. curl_setopt ($ch, curlopt_useragent, ' juhedata ');
  83. curl_setopt ($ch, curlopt_connecttimeout, 60);
  84. curl_setopt ($ch, curlopt_timeout, 60);
  85. curl_setopt ($ch, Curlopt_returntransfer, true);
  86. curl_setopt ($ch, curlopt_followlocation, true);
  87. if ($ispost)
  88. {
  89. curl_setopt ($ch, Curlopt_post, true);
  90. curl_setopt ($ch, Curlopt_postfields, $params);
  91. curl_setopt ($ch, Curlopt_url, $url);
  92. }
  93. Else
  94. {
  95. if ($params) {
  96. curl_setopt ($ch, Curlopt_url, $url. '? '. $params);
  97. }else{
  98. curl_setopt ($ch, Curlopt_url, $url);
  99. }
  100. }
  101. $response = curl_exec ($ch);
  102. if ($response = = = FALSE) {
  103. echo "CURL Error:". Curl_error ($ch);
  104. return false;
  105. }
  106. $httpCode = Curl_getinfo ($ch, Curlinfo_http_code);
  107. $httpInfo = Array_merge ($httpInfo, Curl_getinfo ($ch));
  108. Curl_close ($ch);
  109. return $response;
  110. }
Copy Code
Php
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.