基於php的地產資料介面調用代碼執行個體

來源:互聯網
上載者:User
代碼描述:基於php的地產資料介面調用代碼執行個體
介面地址:http://www.juhe.cn/docs/api/id/47
  1. // +----------------------------------------------------------------------
  2. //----------------------------------
  3. // 地產資料調用範例程式碼 - 彙總資料
  4. // 線上介面文檔:http://www.juhe.cn/docs/47
  5. //----------------------------------
  6. header('Content-type:text/html;charset=utf-8');
  7. //配置您申請的appkey
  8. $appkey = "*********************";
  9. //************1.地產檢索************
  10. $url = "http://v.juhe.cn/estate/query";
  11. $params = array(
  12. "city" => "",//城市名稱,請參考支援城市列表
  13. "key" => $appkey,//應用APPKEY(應用詳細頁查詢)
  14. "q" => "",//地產名關鍵字
  15. "page" => "",//頁數,預設1,每頁返回10條
  16. "dtype" => "",//返回資料的格式,xml或json,預設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 "請求失敗";
  29. }
  30. //**************************************************
  31. //************2.周邊地產************
  32. $url = "http://v.juhe.cn/estate/local";
  33. $params = array(
  34. "lat" => "",//緯度(百度地圖座標系)
  35. "lng" => "",//經度
  36. "radius" => "",//檢索半徑,預設5000 單位米
  37. "key" => $appkey,//應用APPKEY(應用詳細頁查詢)
  38. "page" => "",//頁數,預設1,每頁返回20條
  39. "dtype" => "",//返回資料的格式,xml或json,預設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 "請求失敗";
  52. }
  53. //**************************************************
  54. //************3.支援城市列表************
  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 "請求失敗";
  69. }
  70. //**************************************************
  71. /**
  72. * 請求介面返回內容
  73. * @param string $url [請求的URL地址]
  74. * @param string $params [請求的參數]
  75. * @param int $ipost [是否採用POST形式]
  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
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.