Home  >  Article  >  Backend Development  >  Real estate data interface calling code example based on PHP

Real estate data interface calling code example based on PHP

WBOY
WBOYOriginal
2016-07-25 08:43:56921browse
Code description: PHP-based real estate data interface calling code example
Interface address: http://www.juhe.cn/docs/api/id/47
  1. // +------------- -------------------------------------------------- --------
  2. //----------------------------------
  3. // Real Estate Data calling sample code - aggregated 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 for
  8. $appkey = " *********************";
  9. //************1. Real estate search************
  10. $url = "http://v.juhe.cn/estate/query";
  11. $params = array(
  12. "city" => "",//City name, please refer to the list of supported cities
  13. "key" => $appkey,//Application APPKEY (application details page query)
  14. "q" => " ",//Real estate name keyword
  15. "page" => "",//Number of pages, default 1, 10 items returned per page
  16. "dtype" => "",//Format of 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 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, default 5000 units meters
  37. "key" => $appkey,//Application APPKEY (application details page query)
  38. "page" => "",//Number of pages, default 1, return 20 items per page
  39. "dtype" => "",//Format of 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. Supported 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 return content
  73. * @param string $url [requested URL address]
  74. * @param string $params [requested parameters]
  75. * @param int $ipost [whether to use 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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:self-increasing counterNext article:self-increasing counter