Code description: PHP-based gas card recharge interface calling code example Associated data: Gas 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
- // +------------------ -------------------------------------------------- --
-
- //----------------------------------
- // Gas card recharge call sample code- Aggregated data
- // Online interface documentation: http://www.juhe.cn/docs/87
- //------------------------- ---------
-
- header('Content-type:text/html;charset=utf-8');
-
-
- //Configure the appkey you applied for
- $appkey = "***** ****************";
-
-
-
-
- //************1. Order status query************ ****
- $url = "http://op.juhe.cn/ofpay/sinopec/ordersta";
- $params = array(
- "orderid" => "",//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 inquiry************
- $url = "http://op.juhe.cn/ofpay/sinopec/yue";
- $params = array(
- "timestamp" => "",//Current timestamp, such as: 1432788379
- "key" => $appkey,//Application APPKEY (application detail page query)
- "sign" => "" ,//Check value, md5 (OpenID+key+timestamp), OpenID is queried 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";
- }
- //****************** ************************************
-
-
-
-
- //******** ***3. Gas card recharge************
- $url = "http://op.juhe.cn/ofpay/sinopec/onlineorder";
- $params = array(
- " proid" => "",//Product id: 10000 (Sinopec 50 yuan gas card), 10001 (Sinopec 100 yuan gas card), 10003 (Sinopec 500 yuan gas card), 10004 (Sinopec 1,000 yuan gas card), 10007 (Recharge any amount of Sinopec), 10008 (Recharge any amount of PetroChina)
- "cardnum" => "", //Recharge any amount (integer (yuan)), the remaining face values are fixed at 1
- "orderid" => "",//Merchant order number, 8-32 digit alphanumeric combination
- "game_userid" => "",//Gas card number, Sinopec: card number starting with 100011, PetroChina: card number starting with 9
- "gasCardTel " => "",//Cardholder's mobile phone number
- "gasCardName" => "",//Cardholder's name
- "chargeType" => "",//Gas card type (1: Sinopec, 2: PetroChina; the default is 1)
- "key" => $appkey,//Application APPKEY (application details page query)
- "sign" => "",//check value, md5 (OpenID+key+ proid+cardnum+game_userid+orderid), OpenID is queried 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 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;
- }
复制代码
|