Home  >  Article  >  Backend Development  >  dedecms Tenpay interface

dedecms Tenpay interface

WBOY
WBOYOriginal
2016-08-08 09:32:01888browse

I used Redtourism to create a travel website, the URL is: http://www.redtourism.cn/ The customer asked for payment via Tenpay, so I looked online and found that I either wanted to buy it or ask for money, so I had to write it myself.

Code:

if(!defined('DEDEINC')) exit('Request Error!');
/**
*Yibao interface class
*/
class tenpay
{
var $dsql;
var $mid;

var $reqURL_onLine = "http://www.tenpay.com";

var $return_url='/plus/carbuyaction.php?dopost=return'; //Return processing address

/**
     * Constructor
     *
    * @access public
    * @param
     *
                          * /
function tenpay()
{
global $dsql;
$this->dsql = $dsql;
}
function __construct()
{
$this->tenpay();
}

/**
          *       * The address will be sent when setting the interface
             *
                * For example: $this->SetReturnUrl($cfg_basehost."/tuangou/control/index.php?ac=pay&orderid=".$p2_Order)
             *
                 * @param      string $returnurl will send the address
* @return void
*/
        function SetReturnUrl($returnurl='')
                                                                                                                   
/** '/ '.$cfg_cmspath;        $body = $order['out_trade_no'];
          $attach = '';
                 $bank_type = 'DEFAULT'; 
                                                                                                                                        ​$trade_mode= empty($payment['tenpay_pay_method']) ? '1' : $payment['tenpay_pay_method'];
                                                                               => $out_trade_no,                                          /Order number
          'total_fee'                                                                                                                                                                                      . $this->return_url."&code=".$payment['code'], //return Address
'return_url' => $cfg_basehost.$this->return_url."&code=".$payment['code'], //Reminder address
"body" => $body, //Transaction description
                                                        " //Transaction IP
                                                                                                                                                                                        //Currency 1 RMB
                                                                                                                                       => 'MD5', 'service_version' => ' 1.0 ', // The interface version number default 1.0
' input_charset '= & gt;' utf-8 ', // system encoding' gbk'
'sign_index' = & gt; '1', // key serial number
business Optional parameter
'Attach' = & GT; $ Attach, // The original data is originally returned to the default
'Product_fee' = & GT; ', // Commodity costs
' transport_fee '= & gt;' 0 ', // logistics Cost
                                                                                                                                                      using Order expiration time
            'buyer_id'             => '',                 //买方财付通帐号
            'goods_tag'            => '',                 //商品标记
            'trade_mode'           => $trade_mode,        //交易模式(1.即时到帐模式,2.中介担保模式,3.后台选择(卖家进入支付中心列表选择))
            'transport_desc'       => '',                 //物流说明
            'trans_type'           => $trans_type,        //交易类型
            'agentid'              => '',                 //平台ID
            'agent_type'           => '',                 //代理模式(0.无代理,1.表示卡易售模式,2.表示网店模式)
            'seller_id'            => ''                  //卖家商户号
        );
        ksort($parameter);
        reset($parameter);
        $param = '';
        $sign  = '';
        foreach ($parameter AS $key => $val)
        {
            $param .= "$key=" .urlencode($val). "&";
            if("" != $val && "sign" != $key) {
                $sign  .= "$key=$val&";
            }
        }
        $param = substr($param, 0, -1);
        $sign .= "key=".$payment['tenpay_key'];
        $sign = strtolower(md5($sign));  
        
        $button = '

$cart->MakeOrders();
                                                                                                       return $button; 0-9a-z-]#i", "", $_GET['code'] );
                                                                                                            . attach'];
$trade_state = $_GET['trade_state'];
$total_fee = $_GET['total_fee'];

$out_trade_no = trim($_GET['out_trade_no']);

if(preg_match ("/S-P[0-9]+RN[0-9]/",$order_sn)) {
                                                   ("SELECT * FROM #@__shops_orders WHERE oid = '{$order_sn}'");
                 if ($row['priceCount'] != $_GET['total_fee'])
                                                                                                                                                                                                             , The payment amount does not match the total price of the product! ";
}
$ this- & gt; mid = $ row ['userid'];
| val)
                                          if("" != $val && "sign" != $key && $key != 'code') {
                                                                                                                                                            =".$payment['tenpay_key'];

if(strtolower(md5($sign))==strtolower($_GET['sign']))
({
if ($ Trade_State == 0) {
/* Change the order status* /
if ($ this-& gt; success_db ($ out_trade_no))

Return $ msg = "Payment success!" & lt; a href='/'>Return to the homepage Member Center";

                                                                                                                                                                                                                                              . ;a href='/'>Return to homepage Member Center";
                                                                                    
}

else{

//return $msg = "Payment failed!
Return to homepage Member Center ";

}
}

/*Process item transactions*/
function success_db($order_sn)
{
$time=time();
$mid=$this->mid;
//Get order information, check Order Validity
          $row = $this->dsql->GetOne("SELECT state,priceCount FROM #@__shops_orders WHERE oid='$order_sn' ");
                                                                                               )
                                                                   . s_orders` SET `state`='1' WHERE `oid`='$order_sn' AND `userid`='".$this->mid."'"; success , Order number: "$ order_sn); // Stock the verification results into the files
Return true;}} else {
$ This- & GT; log_result (" Verify_faird, Order number: ". $ Order_sn)) Results Save the files t Return False;
}}
Function log_result ($ word) {
Global $ CFG_CMSPATH;
$ fp = FOPEN (__file __). t/log .txt", "a");
               flock($fp, LOCK_EX); 
                                                                                                                           ; ;
The above introduces the dedecms Tenpay interface, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn