Code description: PHP-based public bicycle network API calling code example Interface address: http://www.juhe.cn/docs/api/id/41
- // +------------- -------------------------------------------------- --------
-
- //----------------------------------
- // Real time Public bicycle calling sample code - aggregated data
- // Online interface documentation: http://www.juhe.cn/docs/41
- //------------------- ---------------
-
- header('Content-type:text/html;charset=utf-8');
-
-
- //Configure the appkey you applied for
- $appkey = "**********************";
-
-
-
-
- //************1.Suzhou**** ********
- $url = "http://web.juhe.cn:8080/bike/state/sz";
- $params = array(
- "state" => "",// Site name, such as: "Times Square"
- "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 "Request failed";
- }
- //************** ************************************
-
-
-
-
- //******* *****2.Changshu************
- $url = "http://web.juhe.cn:8080/bike/state/cs";
- $params = array(
- "state" => "",//Site name, such as: "Yushan Park Entrance North"
- "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 "Request failed";
- }
- / /************************************************ *
-
-
-
-
- //************3.Kunshan************
- $url = "http://web.juhe.cn: 8080/bike/state/ks";
- $params = array(
- "state" => "",//Site name, such as: "Sports Center (North)"
- "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 "Request failed";
- }
- //************************************ ****************
-
-
-
-
- //************4.Wujiang************
- $url = "http://web.juhe.cn:8080/bike/state/wj";
- $params = array(
- "state" => "",//Site name, such as: "Experimental Primary School North Gate"
- "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 "Request failed";
- }
- //******************** ******************************
-
-
-
-
- //************5 .Nantong************
- $url = "http://web.juhe.cn:8080/bike/state/nt";
- $params = array(
- "state" => ; "",//Site name, such as: "Ctrip North Tower"
- "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 "Request failed";
- }
- //**************************************************
-
-
-
-
- //************6.Yixing************
- $url = "http://web.juhe.cn:8080/bike /state/yx";
- $params = array(
- "state" => "",//Site name, such as: "Longbei Mountain Forest Park"
- "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 "Request failed";
- }
- //**************************************** ************
-
-
-
-
- //************7.Xuzhou************
- $url = "http://web.juhe.cn:8080/bike/state/xz";
- $params = array(
- "state" => "",//Site name, such as: "Micro Park"
- "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 "Request failed";
- }
- //************************** ************************
-
-
-
-
- //************8.Zhenjiang**** ********
- $url = "http://web.juhe.cn:8080/bike/state/zj";
- $params = array(
- "state" => "",// Site name, such as: "Jiaoshan Park"
- "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 "Request failed";
- }
- //****************** *************************************
-
-
-
-
-
- /**
- * Request interface Return content
- * @param string $url [requested URL address]
- * @param string $params [requested parameters]
- * @param int $ipost [whether to use POST form]
- * @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 , 'JuheData' );
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- if( $ispost )
- {
- curl_setopt( $ch , CURLOPT_POST , true );
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
- curl_setopt( $ch , CURLOPT_URL , $url );
- }
- else
- {
- if($params){
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
- }else{
- curl_setopt( $ch , CURLOPT_URL , $url);
- }
- }
- $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_getinfo( $ch ) );
- curl_close( $ch );
- return $response;
- }
复制代码
|