基於php的公用單車網點api調用代碼執行個體

來源:互聯網
上載者:User
代碼描述:基於php的公用單車網點api調用代碼執行個體
介面地址:http://www.juhe.cn/docs/api/id/41
  1. // +----------------------------------------------------------------------
  2. //----------------------------------
  3. // 即時公用單車調用範例程式碼 - 彙總資料
  4. // 線上介面文檔:http://www.juhe.cn/docs/41
  5. //----------------------------------
  6. header('Content-type:text/html;charset=utf-8');
  7. //配置您申請的appkey
  8. $appkey = "*********************";
  9. //************1.蘇州************
  10. $url = "http://web.juhe.cn:8080/bike/state/sz";
  11. $params = array(
  12. "state" => "",//網站名稱,如:"時代廣場"
  13. "key" => $appkey,// APP Key
  14. );
  15. $paramstring = http_build_query($params);
  16. $content = juhecurl($url,$paramstring);
  17. $result = json_decode($content,true);
  18. if($result){
  19. if($result['error_code']=='0'){
  20. print_r($result);
  21. }else{
  22. echo $result['error_code'].":".$result['reason'];
  23. }
  24. }else{
  25. echo "請求失敗";
  26. }
  27. //**************************************************
  28. //************2.常熟************
  29. $url = "http://web.juhe.cn:8080/bike/state/cs";
  30. $params = array(
  31. "state" => "",//網站名稱,如:"虞山公園入口北"
  32. "key" => $appkey,// APP Key
  33. );
  34. $paramstring = http_build_query($params);
  35. $content = juhecurl($url,$paramstring);
  36. $result = json_decode($content,true);
  37. if($result){
  38. if($result['error_code']=='0'){
  39. print_r($result);
  40. }else{
  41. echo $result['error_code'].":".$result['reason'];
  42. }
  43. }else{
  44. echo "請求失敗";
  45. }
  46. //**************************************************
  47. //************3.崑山************
  48. $url = "http://web.juhe.cn:8080/bike/state/ks";
  49. $params = array(
  50. "state" => "",//網站名稱,如:"體育中心(北)"
  51. "key" => $appkey,// APP Key
  52. );
  53. $paramstring = http_build_query($params);
  54. $content = juhecurl($url,$paramstring);
  55. $result = json_decode($content,true);
  56. if($result){
  57. if($result['error_code']=='0'){
  58. print_r($result);
  59. }else{
  60. echo $result['error_code'].":".$result['reason'];
  61. }
  62. }else{
  63. echo "請求失敗";
  64. }
  65. //**************************************************
  66. //************4.吳江************
  67. $url = "http://web.juhe.cn:8080/bike/state/wj";
  68. $params = array(
  69. "state" => "",//網站名稱,如:"實驗小學北門"
  70. "key" => $appkey,// APP Key
  71. );
  72. $paramstring = http_build_query($params);
  73. $content = juhecurl($url,$paramstring);
  74. $result = json_decode($content,true);
  75. if($result){
  76. if($result['error_code']=='0'){
  77. print_r($result);
  78. }else{
  79. echo $result['error_code'].":".$result['reason'];
  80. }
  81. }else{
  82. echo "請求失敗";
  83. }
  84. //**************************************************
  85. //************5.南通************
  86. $url = "http://web.juhe.cn:8080/bike/state/nt";
  87. $params = array(
  88. "state" => "",//網站名稱,如:"攜程北樓"
  89. "key" => $appkey,// APP Key
  90. );
  91. $paramstring = http_build_query($params);
  92. $content = juhecurl($url,$paramstring);
  93. $result = json_decode($content,true);
  94. if($result){
  95. if($result['error_code']=='0'){
  96. print_r($result);
  97. }else{
  98. echo $result['error_code'].":".$result['reason'];
  99. }
  100. }else{
  101. echo "請求失敗";
  102. }
  103. //**************************************************
  104. //************6.宜興************
  105. $url = "http://web.juhe.cn:8080/bike/state/yx";
  106. $params = array(
  107. "state" => "",//網站名稱,如:"龍背山森林公園"
  108. "key" => $appkey,// APP Key
  109. );
  110. $paramstring = http_build_query($params);
  111. $content = juhecurl($url,$paramstring);
  112. $result = json_decode($content,true);
  113. if($result){
  114. if($result['error_code']=='0'){
  115. print_r($result);
  116. }else{
  117. echo $result['error_code'].":".$result['reason'];
  118. }
  119. }else{
  120. echo "請求失敗";
  121. }
  122. //**************************************************
  123. //************7.徐州************
  124. $url = "http://web.juhe.cn:8080/bike/state/xz";
  125. $params = array(
  126. "state" => "",//網站名稱,如:"微園"
  127. "key" => $appkey,// APP Key
  128. );
  129. $paramstring = http_build_query($params);
  130. $content = juhecurl($url,$paramstring);
  131. $result = json_decode($content,true);
  132. if($result){
  133. if($result['error_code']=='0'){
  134. print_r($result);
  135. }else{
  136. echo $result['error_code'].":".$result['reason'];
  137. }
  138. }else{
  139. echo "請求失敗";
  140. }
  141. //**************************************************
  142. //************8.鎮江************
  143. $url = "http://web.juhe.cn:8080/bike/state/zj";
  144. $params = array(
  145. "state" => "",//網站名稱,如:"焦山公園"
  146. "key" => $appkey,// APP Key
  147. );
  148. $paramstring = http_build_query($params);
  149. $content = juhecurl($url,$paramstring);
  150. $result = json_decode($content,true);
  151. if($result){
  152. if($result['error_code']=='0'){
  153. print_r($result);
  154. }else{
  155. echo $result['error_code'].":".$result['reason'];
  156. }
  157. }else{
  158. echo "請求失敗";
  159. }
  160. //**************************************************
  161. /**
  162. * 請求介面返回內容
  163. * @param string $url [請求的URL地址]
  164. * @param string $params [請求的參數]
  165. * @param int $ipost [是否採用POST形式]
  166. * @return string
  167. */
  168. function juhecurl($url,$params=false,$ispost=0){
  169. $httpInfo = array();
  170. $ch = curl_init();
  171. curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
  172. curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
  173. curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
  174. curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
  175. curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
  176. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  177. if( $ispost )
  178. {
  179. curl_setopt( $ch , CURLOPT_POST , true );
  180. curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
  181. curl_setopt( $ch , CURLOPT_URL , $url );
  182. }
  183. else
  184. {
  185. if($params){
  186. curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
  187. }else{
  188. curl_setopt( $ch , CURLOPT_URL , $url);
  189. }
  190. }
  191. $response = curl_exec( $ch );
  192. if ($response === FALSE) {
  193. //echo "cURL Error: " . curl_error($ch);
  194. return false;
  195. }
  196. $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
  197. $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
  198. curl_close( $ch );
  199. return $response;
  200. }
複製代碼
php, api
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.