基於php的公共自行車網點api呼叫程式碼實例

WBOY
發布: 2016-07-25 08:44:00
原創
1379 人瀏覽過
程式碼描述:基於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){ if($result['error_code']=='0'){
  57. print_r($result);
  58. }else{
  59. echo $result['error_code'].":".$ result['reason'];
  60. }
  61. }else{
  62. echo "請求失敗";
  63. }
  64. //*************** ***********************************
  65. //************4.吳江************
  66. $url = "http://web.juhe.cn:8080/bike/ state/wj";
  67. $params = array(
  68. "state" => "",//站點名稱,如:"實驗小學北門"
  69. "key" => $appkey,// APP Key
  70. );
  71. $paramstring = http_build_query($params);
  72. $content = juhecurl($url,$paramstring);
  73. $result = json_decode($content,true);if($result){
  74. if($result['error_code']=='0'){
  75. print_r($result);
  76. }else{
  77. echo $result['error_code '].":".$result['reason'];
  78. }
  79. }else{
  80. echo "請求失敗";
  81. }
  82. //******* *******************************************
  83. //************5.南通************
  84. $url = "http://web. juhe.cn:8080/bike/state/nt";
  85. $params = array(
  86. "state" => "",//站點名稱,如:"攜程北樓"
  87. "key" => $appkey,// APP Key
  88. );
  89. $paramstring = http_build_query($params);
  90. $content = juhecurl($url,$paramstring);
  91. $result = json_decode($ content,true);
  92. if($result){
  93. if($result['error_code']=='0'){
  94. print_r($result);
  95. }else{
  96. echo $result['error_code'].":".$result['reason'];
  97. }
  98. }else{
  99. echo "請求失敗";
  100. }
  101. //**************************************************
  102. //************6.宜興************
  103. $url = "http ://web.juhe.cn:8080/bike/state/yx";
  104. $params = array(
  105. "state" => "",//站點名稱,如:"龍背山森林公園"
  106. "key" => $appkey,// APP Key
  107. );
  108. $paramstring = http_build_query($params);
  109. $content = juhecurl($url,$paramstring);
  110. $result = json_decode($content,true);
  111. if($result){
  112. if($result['error_code']=='0'){
  113. print_r($result);
  114. }else{
  115. echo $result['error_code'].":".$result['reason'];
  116. }
  117. }else{
  118. echo "請求失敗";
  119. }
  120. //******************************************** ******
  121. //************7.徐州************
  122. $url = "http://web.juhe.cn:8080/bike/state/xz";
  123. $params = array(
  124. "state" => "",//網站名稱,如:"微園"
  125. "key" => $appkey,// APP Key
  126. );
  127. $paramstring = http_build_query($params);
  128. $content = juhecurl($url,$ paramstring);
  129. $result = json_decode($content,true);
  130. if($result){
  131. if($result['error_code']=='0'){
  132. print_r( $result);
  133. }else{
  134. echo $result['error_code'].":".$result['reason'];
  135. }
  136. }else{
  137. echo "請求失敗";
  138. }
  139. //************************************** ************
  140. //************8.鎮江****** ******
  141. $url = "http://web.juhe.cn:8080/bike/state/zj";
  142. $params = array(
  143. "state" => "" ,//站點名稱,如:"焦山公園"
  144. "key" => $appkey,// APP Key
  145. );
  146. $paramstring = http_build_query($params);
  147. $content = juhecurl($url,$paramstring);
  148. $result = json_decode($content,true);
  149. if($result){
  150. if($result['error_code']=='0' ){
  151. print_r($result);
  152. }else{
  153. echo $result['error_code'].":".$result['reason'];
  154. }
  155. }else {
  156. echo "請求失敗";
  157. }
  158. //******************************* *******************
  159. /**
  160. * 要求介面回傳內容
  161. * @param string $url [請求的URL位址]
  162. * @param string $params [請求的參數]
  163. * @param int $ipost [是否採用POST形式]
  164. * @return string
  165. */
  166. function juhecurl($url,$params=false,$ispost=0){
  167. $httpInfo = array();
  168. $ch = curl_init( );
  169. curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
  170. curl_setopt( $ch, CURLOPT_USERAGENT , '], ); );
  171. 捲曲_設定選項( $ch, CURLOPT_TIMEOUT , 60);
  172. curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
  173. curl_setopt($ch, CURLOPT_FOLLOW );
  174. curl_setopt($ch, CURLOPT_FOLLOWLOCLO);
  175. curl_setopt( $ch , CURLOPT_POST , true );
  176. curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
  177. curl_setopt( $ch , CURLOPT_URL 🎜> {
  178. if($params){
  179. curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
  180. }else{
  181. curl_setopt( $URch , CURPT_ $URch , CURPT_ $UR網址);
  182. }
  183. }
  184. $response = curl_exec( $ch );
  185. if ($response === FALSE) {
  186. //echo "cURL Error: " . curl_error($ch);
  187. return false;
  188. }
  189. $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
  190. $httpInfo = array_merge( $httpInfo , curl_ info(> $httpInfo = array_merge( $httpInfo , curl_info); >curl_close( $ch );
  191. return $response;
  192. }
  193. 複製程式碼
php、api
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!