Php-based real estate data interface call code instance

Source: Internet
Author: User
Php-based real estate data interface call code instance
Code description: php-based real estate data interface call code example
Interface address: http://www.juhe.cn/docs/api/id/47

  1. // + ----------------------------------------------------------------------
  2. //----------------------------------
  3. // Sample code for calling real estate data-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 applied
  8. $ Appkey = "*********************";
  9. // ************ 1. real estate search ************
  10. $ Url = "http://v.juhe.cn/estate/query ";
  11. $ Params = array (
  12. "City" => "", // city name, see supported cities list
  13. "Key" => $ appkey, // APPKEY of the application (query on the application details page)
  14. "Q" => "", // real estate name keyword
  15. "Page" => "", // Number of pages. the default value is 1. 10 entries are returned for each page.
  16. "Dtype" => "", // The format of the returned data, xml or json. the default value is 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 real estate ************
  32. $ Url = "http://v.juhe.cn/estate/local ";
  33. $ Params = array (
  34. "Lat" => "", // latitude (Baidu map coordinate system)
  35. "Lng" => "", // longitude
  36. "Radius" => "", // retrieval radius, 5000 meters by default
  37. "Key" => $ appkey, // APPKEY of the application (query on the application details page)
  38. "Page" => "", // Number of pages. the default value is 1. 20 entries are returned for each page.
  39. "Dtype" => "", // The format of the returned data, xml or json. the default value is 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. supported city lists ************
  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. * Content returned by the request interface
  73. * @ Param string $ url [requested URL]
  74. * @ Param string $ params [request parameters]
  75. * @ Param int $ ipost [whether to use the POST form]
  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. }

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.