Code description: php-based api call code instance for public bicycle sites Interface address: http://www.juhe.cn/docs/api/id/41
-
- // + ----------------------------------------------------------------------
-
- //----------------------------------
- // Real-time public bicycle call example code-aggregate data
- // Online interface documentation: http://www.juhe.cn/docs/41
- //----------------------------------
-
- Header ('content-type: text/html; charset = utf-8 ');
-
-
- // Configure the appkey you applied
- $ Appkey = "*********************";
-
-
-
-
- // ************ 1. Suzhou ************
- $ Url = "http://web.juhe.cn: 8080/bike/state/sz ";
- $ Params = array (
- "State" => "", // site name, for example, "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, for example, "North of Yushan Park entrance"
- "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, for example, "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, for example, "North Gate of Experimental Primary School"
- "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, for example, "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, for example, "Longbeishan 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, for example, "micro Garden"
- "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, for example, "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 ";
- }
- //************************************** ************
-
-
-
-
-
- /**
- * Content returned by the request interface
- * @ Param string $ url [requested URL]
- * @ Param string $ params [request parameters]
- * @ Param int $ ipost [whether to use the 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;
- }
|