Code Description: PHP-based fuel card recharge interface Call Code instance Related data: Refueling 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
- // +----------------------------------------------------------------------
- //----------------------------------
- Refueling Card Recharge Call sample code-aggregate data
- Online interface Documentation: HTTP://WWW.JUHE.CN/DOCS/87
- //----------------------------------
- Header (' Content-type:text/html;charset=utf-8 ');
- Configure the Appkey you requested
- $appkey = "*********************";
- 1. Order Status Inquiry ************
- $url = "Http://op.juhe.cn/ofpay/sinopec/ordersta";
- $params = Array (
- "OrderID" and ","//Merchant order number, 8-32-digit alphanumeric combination
- "Key" = $appkey,//Application Appkey (Application Detail page query)
- );
- $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. Account Balance Enquiry ************
- $url = "Http://op.juhe.cn/ofpay/sinopec/yue";
- $params = Array (
- "Timestamp" = "" ",//current timestamp, e.g.: 1432788379
- "Key" = $appkey,//Application Appkey (Application Detail page query)
- "Sign" = "" ",//checksum value, MD5 (OPENID+KEY+TIMESTAMP), OpenID in the Personal center query
- );
- $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. Refueling Card Recharge ************
- $url = "Http://op.juhe.cn/ofpay/sinopec/onlineorder";
- $params = Array (
- "Proid" and "" ",//Product id:10000 (Sinopec 50 Yuan Refueling card), 10001 (Sinopec 100 Yuan Refueling card), 10003 (Sinopec 500 Yuan Refueling card), 10004 (Sinopec 1000 Yuan Refueling card), 10007 (Sinopec any amount of recharge) , 10008 (any amount of PetroChina)
- "Cardnum" and "" ",//recharge the amount of any charge (integer (yuan)), the remaining face value is fixed at 1
- "OrderID" and ","//Merchant order number, 8-32-digit alphanumeric combination
- "Game_userid" and "" ",//refueling card number, Sinopec: Starting with 100011 card number, PetroChina: 9 card number
- "Gascardtel" and "" ",//Cardholder's mobile number
- "Gascardname" and "" ",//Cardholder's name
- "Chargetype" and "" ",//Fuel card type (1: Sinopec, 2: PetroChina; default = 1)
- "Key" = $appkey,//Application Appkey (Application Detail page query)
- "Sign" = "" ",//checksum value, MD5 (Openid+key+proid+cardnum+game_userid+orderid), OpenID in the Personal center query
- );
- $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 to return content
- * @param string $url [requested URL address]
- * @param string $params [parameter requested]
- * @param int $ipost [if post is used]
- * @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;
- }
Copy Code |