程式碼描述:基於php的公共自行車網點api呼叫程式碼實例 介面位址:http://www.juhe.cn/docs/api/id/41
- // ----------------------------------------------- -----------------------
-
- //------------------- ---------------
- // 即時公共自行車呼叫範例程式碼- 聚合資料
- // 線上介面文件:http://www.juhe.cn/docs/ 41
- //----------------------------------
-
- header('Content -type:text/html;charset=utf-8');
-
-
- //設定您申請的appkey
- $appkey = "************ *********";
-
-
-
-
- //************1.蘇州******* *****
- $url = "http://web.juhe.cn:8080/bike/state/sz";
- $params = array(
- "state" => "", //網站名稱,如:"時代廣場"
- "key" => $appkey,// APP Key
- );
- $paramstring = http_build_query($params);
- $content = juhecurl ($url,$paramstring);
- $result = json_decode($content,true);
- if($result){
- if($result['error_code']=='0'){
- print_r($result);
- }else{
- echo $result['error_code'].":".$result['reason'];
- }
- }else{
- echo "請求失敗";
- }
- //********************************* *****************
-
-
-
-
- //************2.常熟* ***********
- $url = "http://web.juhe.cn:8080/bike/state/cs";
- $params = array(
- "state " => "",//站點名稱,如:"虞山公園入口北"
- "key" => $appkey,// APP Key
- );
- $paramstring = http_build_query($params );
- $content = juhecurl($url,$paramstring);
- $result = json_decode($content,true);
- if($result){
- if($result['error_code ']=='0'){
- print_r($result);
- }else{
- echo $result['error_code'].":".$result['reason'];
- }
- }else{
- echo "請求失敗";
- }
- //************************ **************************
-
-
-
-
- //******* *****3.崑山************
- $url = "http://web.juhe.cn:8080/bike/state/ks";
- $ params = array(
- "state" => "",//站點名稱,如:"體育中心(北)"
- "key" => $appkey,// APP Key
- );
- $paramstring = http_build_query($params);
- $content = juhecurl($url,$paramstring);
- $result = json_decode($content,true);
- if($result){ if($result['error_code']=='0'){
- print_r($result);
- }else{
- echo $result['error_code'].":".$ result['reason'];
- }
- }else{
- echo "請求失敗";
- }
- //*************** ***********************************
-
-
-
-
- //************4.吳江************
- $url = "http://web.juhe.cn:8080/bike/ state/wj";
- $params = array(
- "state" => "",//站點名稱,如:"實驗小學北門"
- "key" => $appkey,// APP Key
- );
- $paramstring = http_build_query($params);
- $content = juhecurl($url,$paramstring);
- $result = json_decode($content,true);if($result){
- if($result['error_code']=='0'){
- print_r($result);
- }else{
- echo $result['error_code '].":".$result['reason'];
- }
- }else{
- echo "請求失敗";
- }
- //******* *******************************************
-
-
-
-
- //************5.南通************
- $url = "http://web. juhe.cn:8080/bike/state/nt";
- $params = array(
- "state" => "",//站點名稱,如:"攜程北樓"
- "key" => $appkey,// APP Key
- );
- $paramstring = http_build_query($params);
- $content = juhecurl($url,$paramstring);
- $result = json_decode($ content,true);
- if($result){
- if($result['error_code']=='0'){
- print_r($result);
- }else{
- echo $result['error_code'].":".$result['reason'];
- }
- }else{
- echo "請求失敗";
- }
- //**************************************************
-
-
-
-
- //************6.宜興************
- $url = "http ://web.juhe.cn:8080/bike/state/yx";
- $params = array(
- "state" => "",//站點名稱,如:"龍背山森林公園"
- "key" => $appkey,// APP Key
- );
- $paramstring = http_build_query($params);
- $content = juhecurl($url,$paramstring);
- $result = json_decode($content,true);
- if($result){
- if($result['error_code']=='0'){
- print_r($result);
- }else{
- echo $result['error_code'].":".$result['reason'];
- }
- }else{
- echo "請求失敗";
- }
- //******************************************** ******
-
-
-
-
- //************7.徐州************
- $url = "http://web.juhe.cn:8080/bike/state/xz";
- $params = array(
- "state" => "",//網站名稱,如:"微園"
- "key" => $appkey,// APP Key
- );
- $paramstring = http_build_query($params);
- $content = juhecurl($url,$ paramstring);
- $result = json_decode($content,true);
- if($result){
- if($result['error_code']=='0'){
- print_r( $result);
- }else{
- echo $result['error_code'].":".$result['reason'];
- }
- }else{
- echo "請求失敗";
- }
- //************************************** ************
-
-
-
-
- //************8.鎮江****** ******
- $url = "http://web.juhe.cn:8080/bike/state/zj";
- $params = array(
- "state" => "" ,//站點名稱,如:"焦山公園"
- "key" => $appkey,// APP Key
- );
- $paramstring = http_build_query($params);
- $content = juhecurl($url,$paramstring);
- $result = json_decode($content,true);
- if($result){
- if($result['error_code']=='0' ){
- print_r($result);
- }else{
- echo $result['error_code'].":".$result['reason'];
- }
- }else {
- echo "請求失敗";
- }
- //******************************* *******************
-
-
-
-
-
- /**
- * 要求介面回傳內容
- * @param string $url [請求的URL位址]
- * @param string $params [請求的參數]
- * @param int $ipost [是否採用POST形式]
- * @return string
- */
- function juhecurl($url,$params=false,$ispost=0){
- $httpInfo = array();
- $ch = curl_init( );
-
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
- curl_setopt( $ch, CURLOPT_USERAGENT , '], ); );
- 捲曲_設定選項( $ch, CURLOPT_TIMEOUT , 60);
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
- curl_setopt($ch, CURLOPT_FOLLOW );
- curl_setopt($ch, CURLOPT_FOLLOWLOCLO);
- curl_setopt( $ch , CURLOPT_POST , true );
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
- curl_setopt( $ch , CURLOPT_URL 🎜> {
- if($params){
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
- }else{
- curl_setopt( $URch , CURPT_ $URch , CURPT_ $UR網址);
- }
- }
- $response = curl_exec( $ch );
- if ($response === FALSE) {
- //echo "cURL Error: " . curl_error($ch);
- return false;
- }
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
- $httpInfo = array_merge( $httpInfo , curl_ info(> $httpInfo = array_merge( $httpInfo , curl_info); >curl_close( $ch );
- return $response;
- }
-
-
- 複製程式碼
-
-
-
php、api
|