Code description: php-based oil card recharge interface call code example Associated Data: fuel card recharge Interface address: http://www.juhe.cn/docs/api/id/87
- // + ----------------------------------------------------------------------
- // | JuhePHP [no zuo no die]
- // + ----------------------------------------------------------------------
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
- // + ----------------------------------------------------------------------
- // | Author: Juhedata
- // + ----------------------------------------------------------------------
-
- //----------------------------------
- // Example code of the recharge call of the fuel card-aggregate data
- // Online interface documentation: http://www.juhe.cn/docs/87
- //----------------------------------
-
- Header ('content-type: text/html; charset = utf-8 ');
-
-
- // Configure the appkey you applied
- $ Appkey = "*********************";
-
-
-
-
- // ************ 1. query the order status ************
- $ Url = "http://op.juhe.cn/ofpay/sinopec/ordersta ";
- $ Params = array (
- "Orderid" => "", // merchant order number, 8-32-bit combination of letters and numbers
- "Key" => $ appkey, // APPKEY of the application (query on the application details page)
- );
- $ 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. query the account balance ************
- $ Url = "http://op.juhe.cn/ofpay/sinopec/yue ";
- $ Params = array (
- "Timestamp" => "", // Current timestamp, for example, 1432788379
- "Key" => $ appkey, // APPKEY of the application (query on the application details page)
- "Sign" => "", // Check value, md5 (OpenID + key + timestamp), OpenID query in Personal Center
- );
- $ 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. recharge the oil card ************
- $ Url = "http://op.juhe.cn/ofpay/sinopec/onlineorder ";
- $ Params = array (
- "Proid" => "", // product id: 10000 (Sinopec 50 yuan oil card), 10001 (Sinopec 100 yuan oil card), 10003 (Sinopec 500 yuan oil card), 10004 (Sinopec 1000 yuan refueling card), 10007 (Sinopec any amount of recharge), 10008 (PetroChina any amount of recharge)
- "Cardnum" => "", // any charge (integer (RMB) for the number of top-up items, and the fixed value for other denominations is 1
- "Orderid" => "", // merchant order number, 8-32-bit combination of letters and numbers
- "Game_userid" => "", // oil card number, Sinopec: Card number starting with 100011, and PetroChina: Card number starting with 9
- "GasCardTel" => "", // the cardholder's mobile phone number
- "GasCardName" => "", // cardholder name
- "ChargeType" => "", // card type (1: Sinopec, 2: CNPC; default value: 1)
- "Key" => $ appkey, // APPKEY of the application (query on the application details page)
- "Sign" => "", // Check value, md5 (OpenID + key + proid + cardnum + game_userid + orderid), OpenID query in the Personal Center
- );
- $ 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;
- }
|