PHP に基づく公共自転車ネットワーク API 呼び出しコードの例

WBOY
リリース: 2016-07-25 08:44:00
オリジナル
1362 人が閲覧しました
コードの説明: 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" => ; "",//サイト名、例: "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 "リクエストが失敗しました";
  102. }
  103. //**************************************************
  104. //************6.宜興************
  105. $url = "http://web.juhe.cn:8080/bike /state/yx";
  106. $params = array(
  107. "state" => "",//サイト名、例: "龍北山森林公園"
  108. "key" => $appkey,// APP キー
  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" => "",//サイト名、例: "Micro Park "
  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. * @文字列を返す
  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 $応答;
  200. }
复制代
php、API

ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!