Example of php-based api call code for public bicycle sites

Source: Internet
Author: User
Example of php-based api call code for public bicycle sites
Code description: php-based api call code instance for public bicycle sites
Interface address: http://www.juhe.cn/docs/api/id/41

  1. // + ----------------------------------------------------------------------
  2. //----------------------------------
  3. // Real-time public bicycle call example code-aggregate data
  4. // Online interface documentation: http://www.juhe.cn/docs/41
  5. //----------------------------------
  6. Header ('content-type: text/html; charset = utf-8 ');
  7. // Configure the appkey you applied
  8. $ Appkey = "*********************";
  9. // ************ 1. Suzhou ************
  10. $ Url = "http://web.juhe.cn: 8080/bike/state/sz ";
  11. $ Params = array (
  12. "State" => "", // site name, for example, "Times Square"
  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 "request failed ";
  26. }
  27. //************************************** ************
  28. // ************ 2. Changshu ************
  29. $ Url = "http://web.juhe.cn: 8080/bike/state/cs ";
  30. $ Params = array (
  31. "State" => "", // site name, for example, "North of Yushan Park entrance"
  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 "request failed ";
  45. }
  46. //************************************** ************
  47. // ************ 3. Kunshan ************
  48. $ Url = "http://web.juhe.cn: 8080/bike/state/ks ";
  49. $ Params = array (
  50. "State" => "", // site name, for example, "Sports Center (North )"
  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 "request failed ";
  64. }
  65. //************************************** ************
  66. // ************ 4. Wujiang ************
  67. $ Url = "http://web.juhe.cn: 8080/bike/state/wj ";
  68. $ Params = array (
  69. "State" => "", // site name, for example, "North Gate of Experimental Primary School"
  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 "request failed ";
  83. }
  84. //************************************** ************
  85. // ************ 5. Nantong ************
  86. $ Url = "http://web.juhe.cn: 8080/bike/state/nt ";
  87. $ Params = array (
  88. "State" => "", // site name, for example, "Ctrip North Tower"
  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 "request failed ";
  102. }
  103. //************************************** ************
  104. // ************ 6. Yixing ************
  105. $ Url = "http://web.juhe.cn: 8080/bike/state/yx ";
  106. $ Params = array (
  107. "State" => "", // site name, for example, "Longbeishan Forest Park"
  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 "request failed ";
  121. }
  122. //************************************** ************
  123. // ************ 7. Xuzhou ************
  124. $ Url = "http://web.juhe.cn: 8080/bike/state/xz ";
  125. $ Params = array (
  126. "State" => "", // site name, for example, "micro Garden"
  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 "request failed ";
  140. }
  141. //************************************** ************
  142. // ************ 8. Zhenjiang ************
  143. $ Url = "http://web.juhe.cn: 8080/bike/state/zj ";
  144. $ Params = array (
  145. "State" => "", // site name, for example, "Jiaoshan Park"
  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 "request failed ";
  159. }
  160. //************************************** ************
  161. /**
  162. * Content returned by the request interface
  163. * @ Param string $ url [requested URL]
  164. * @ Param string $ params [request parameters]
  165. * @ Param int $ ipost [whether to use the POST form]
  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

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.