Home Backend Development PHP Tutorial Public bicycle network API calling code example based on PHP

Public bicycle network API calling code example based on PHP

Jul 25, 2016 am 08:44 AM

Code description: PHP-based public bicycle network API calling code example
Interface address: http://www.juhe.cn/docs/api/id/41
  1. <!--?php
  2. // +---------------------------------- ----------------------------------
  3. // | JuhePHP [ NO ZUO NO DIE ]
  4. // + -------------------------------------------------- --------------------
  5. // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
  6. // +---- -------------------------------------------------- ----------------
  7. // | Author: Juhedata <info@juhe.cn-->
  8. // +------------- -------------------------------------------------- --------
  9. //----------------------------------
  10. // Real time Public bicycle calling sample code - aggregated data
  11. // Online interface documentation: http://www.juhe.cn/docs/41
  12. //------------------- ---------------
  13. header('Content-type:text/html;charset=utf-8');
  14. //Configure the appkey you applied for
  15. $appkey = "**********************";
  16. //************1.Suzhou**** ********
  17. $url = "http://web.juhe.cn:8080/bike/state/sz";
  18. $params = array(
  19. "state" => "",// Site name, such as: "Times Square"
  20. "key" => $appkey,// APP Key
  21. );
  22. $paramstring = http_build_query($params);
  23. $content = juhecurl($url,$paramstring);
  24. $result = json_decode($content,true);
  25. if($result){
  26. if($result['error_code']=='0'){
  27. print_r($result);
  28. }else{
  29. echo $result ['error_code'].":".$result['reason'];
  30. }
  31. }else{
  32. echo "Request failed";
  33. }
  34. //************** ************************************
  35. //******* *****2.Changshu************
  36. $url = "http://web.juhe.cn:8080/bike/state/cs";
  37. $params = array(
  38. "state" => "",//Site name, such as: "Yushan Park Entrance North"
  39. "key" => $appkey,// APP Key
  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.Kunshan************
  55. $url = "http://web.juhe.cn: 8080/bike/state/ks";
  56. $params = array(
  57. "state" => "",//Site name, such as: "Sports Center (North)"
  58. "key" => $appkey,/ / APP Key
  59. );
  60. $paramstring = http_build_query($params);
  61. $content = juhecurl($url,$paramstring);
  62. $result = json_decode($content,true);
  63. if($result){
  64. if ($result['error_code']=='0'){
  65. print_r($result);
  66. }else{
  67. echo $result['error_code'].":".$result['reason'];
  68. }
  69. }else{
  70. echo "Request failed";
  71. }
  72. //************************************ ****************
  73. //************4.Wujiang************
  74. $url = "http://web.juhe.cn:8080/bike/state/wj";
  75. $params = array(
  76. "state" => "",//Site name, such as: "Experimental Primary School North Gate"
  77. "key" => $appkey,// APP Key
  78. );
  79. $paramstring = http_build_query($params);
  80. $content = juhecurl($url,$paramstring);
  81. $result = json_decode($ content,true);
  82. if($result){
  83. if($result['error_code']=='0'){
  84. print_r($result);
  85. }else{
  86. echo $result['error_code']. ":".$result['reason'];
  87. }
  88. }else{
  89. echo "Request failed";
  90. }
  91. //******************** ******************************
  92. //************5 .Nantong************
  93. $url = "http://web.juhe.cn:8080/bike/state/nt";
  94. $params = array(
  95. "state" =&gt ; "",//Site name, such as: "Ctrip North Tower"
  96. "key" => $appkey,// APP Key
  97. );
  98. $paramstring = http_build_query($params);
  99. $content = juhecurl($ url,$paramstring);
  100. $result = json_decode($content,true);
  101. if($result){
  102. if($result['error_code']=='0'){
  103. print_r($result);
  104. }else{
  105. echo $result['error_code'].":".$result['reason'];
  106. }
  107. }else{
  108. echo "Request failed";
  109. }
  110. //**************************************************
  111. //************6.Yixing************
  112. $url = "http://web.juhe.cn:8080/bike /state/yx";
  113. $params = array(
  114. "state" => "",//Site name, such as: "Longbei Mountain Forest Park"
  115. "key" => $appkey,// APP Key
  116. );
  117. $paramstring = http_build_query($params);
  118. $content = juhecurl($url,$paramstring);
  119. $result = json_decode($content,true);
  120. if($result){
  121. if($result[ 'error_code']=='0'){
  122. print_r($result);
  123. }else{
  124. echo $result['error_code'].":".$result['reason'];
  125. }
  126. }else{
  127. echo "Request failed";
  128. }
  129. //**************************************** ************
  130. //************7.Xuzhou************
  131. $url = "http://web.juhe.cn:8080/bike/state/xz";
  132. $params = array(
  133. "state" => "",//Site name, such as: "Micro Park"
  134. "key " => $appkey,// APP Key
  135. );
  136. $paramstring = http_build_query($params);
  137. $content = juhecurl($url,$paramstring);
  138. $result = json_decode($content,true);
  139. if($result){
  140. if($result['error_code']=='0'){
  141. print_r($result);
  142. }else{
  143. echo $result['error_code'].":".$result ['reason'];
  144. }
  145. }else{
  146. echo "Request failed";
  147. }
  148. //************************** ************************
  149. //************8.Zhenjiang**** ********
  150. $url = "http://web.juhe.cn:8080/bike/state/zj";
  151. $params = array(
  152. "state" => "",// Site name, such as: "Jiaoshan Park"
  153. "key" => $appkey,// APP Key
  154. );
  155. $paramstring = http_build_query($params);
  156. $content = juhecurl($url,$paramstring);
  157. $result = json_decode($content,true);
  158. if($result){
  159. if($result['error_code']=='0'){
  160. print_r($result);
  161. }else{
  162. echo $ result['error_code'].":".$result['reason'];
  163. }
  164. }else{
  165. echo "Request failed";
  166. }
  167. //****************** *************************************
  168. /**
  169. * Request interface Return content
  170. * @param string $url [requested URL address]
  171. * @param string $params [requested parameters]
  172. * @param int $ipost [whether to use POST form]
  173. * @return string
  174. */
  175. function juhecurl($url,$params=false,$ispost=0){
  176. $httpInfo = array();
  177. $ch = curl_init();
  178. curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
  179. curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
  180. curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
  181. curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
  182. curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
  183. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  184. if( $ispost )
  185. {
  186. curl_setopt( $ch , CURLOPT_POST , true );
  187. curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
  188. curl_setopt( $ch , CURLOPT_URL , $url );
  189. }
  190. else
  191. {
  192. if($params){
  193. curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
  194. }else{
  195. curl_setopt( $ch , CURLOPT_URL , $url);
  196. }
  197. }
  198. $response = curl_exec( $ch );
  199. if ($response === FALSE) {
  200. //echo "cURL Error: " . curl_error($ch);
  201. return false;
  202. }
  203. $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
  204. $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
  205. curl_close( $ch );
  206. return $response;
  207. }
复制代码
php, api


Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Introduction to the Instagram API

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles