织梦cms系统如何code 财付通接口
用織夢做了個旅游網站,網址:http://www.onesheng.cn/ 客戶要求財付通支付,上網找了下 不是要買就是要錢,只有自己寫了。
代碼:
<?php
if(!defined('DEDEINC')) exit('Request Error!');
/**
?*財付通接口類
?*/
class tenpay
{
??? var $dsql;
??? var $mid;
??
??? var $reqURL_onLine = "http://www.tenpay.com";
?? ?
??? var $return_url='/plus/carbuyaction.php?dopost=return'; //返回處理地址
?????? ?
??? /**
??? * 構造函數
??? *
??? * @access? public
??? * @param
??? *
??? * @return void
??? */
??? function tenpay()
??? {
??????? global $dsql;
??????? $this->dsql = $dsql;
??? }
??? function __construct()
??? {
??????? $this->tenpay();
??? }
?? ?
??? /**
???? *? 設定接口會送地址
???? *
???? *? 例如: $this->SetReturnUrl($cfg_basehost."/tuangou/control/index.php?ac=pay&orderid=".$p2_Order)
???? *
???? * @param???? string? $returnurl? 會送地址
???? * @return??? void
???? */
??? function SetReturnUrl($returnurl='')
??? {
??????? if (!empty($returnurl))
??????? {
??????????? $this->return_url = $returnurl;
??????? }
??? }
??? /**
??? * 生成支付代碼
??? * @param?? array?? $order????? 訂單信息
??? * @param?? array?? $payment??? 支付方式信息
??? */
??? function GetCode($order, $payment)
??? {
??????? global $cfg_basehost,$cfg_cmspath;
??????? //對于二級目錄的處理
??????? if(!empty($cfg_cmspath)) $cfg_basehost = $cfg_basehost.'/'.$cfg_cmspath;
????????? $partner????? =? $payment['tenpay_account'];
????????? $out_trade_no = $order['out_trade_no'];
?? ??? ?? $total_fee = floatval($order['price']) * 100;
?????????? $body = $order['out_trade_no'];
?????????? $attach = '';
?? ??? ??? $bank_type = 'DEFAULT';
?? ??? ???? /* 交易類型:2、虛擬交易,1、實物交易 */
???????? $trans_type = 1;
???????? $trade_mode=empty($payment['tenpay_pay_method']) ? '1' : $payment['tenpay_pay_method'];
?????? $parameter = array(
??????????? 'partner'????????????? => $partner,
??????????? 'out_trade_no'???????? => $out_trade_no,?????????????????????????? //訂單號
??????????? 'total_fee'??????????? => $total_fee,????????????????????????????? //總金額
??????????? 'notify_url'?????????? => $cfg_basehost.$this->return_url."&code=".$payment['code'],? //返回地址
??????????? 'return_url'?????????? => $cfg_basehost.$this->return_url."&code=".$payment['code'], //提醒地址
??????????? 'body'???????????????? => $body,??????????????????????????? //交易描述
??????????? 'bank_type'??????????? => $bank_type,?????????????????????? //交易類型? 默認財付通
??????????? //用戶ip
??????????? 'spbill_create_ip'???? => $_SERVER['REMOTE_ADDR'],????????? //交易ip
??????????? 'fee_type'???????????? => '1',??????????????????????? //幣種? 1 人民幣
??????????? 'subject'????????????? => $body,??????????????????????????? //商品名稱
??????????? //系統可選參數
??????????? 'sign_type'??????????? => 'MD5',??????????????????????????? //加密方式
??????????? 'service_version'????? => '1.0',??????????????????????????? //接口版本號 默認1.0
??????????? 'input_charset'??????? => 'UTF-8',???????????????????????? //系統編碼? 'GBK'
??????????? 'sign_key_index'?????? => '1',????????????????????????????? //密鑰序號
??????????? //業務可選參數
??????????? 'attach'?????????????? => $attach,??????????? //附加數據 原樣返回? 默認為空
??????????? 'product_fee'????????? => '',???????????????? //商品費用
??????????? 'transport_fee'??????? => '0',??????????????? //物流費用
??????????? 'time_start'?????????? => date("YmdHis"),???? //訂單生成時間?? date("YmdHis")
??????????? 'time_expire'????????? => '',???????????????? //訂單失效時間
??????????? '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 = '<div style="text-align:center"><a href="https://gw.tenpay.com/gateway/pay.htm?'.$param. '&sign='.$sign.'"><button>立即使用財付通支付</button></a></div>';?
?????? ?
??????? return $button;
??? /* 清空購物車 */
??????? require_once DEDEINC.'/shopcar.class.php';
??????? $cart???? = new MemberShops();
??????? $cart->clearItem();
??????? $cart->MakeOrders();
??????? return $button;
??? }
??? /**
??? * 響應操作
??? */
??? function respond()
??? {
??????? /* 引入配置文件 */
?? ??? ?$code = preg_replace( "#[^0-9a-z-]#i", "", $_GET['code'] );
?? ??? ?require_once DEDEDATA.'/payment/'.$code.'.php';
?????? ?
??????? $attach???????? = $_GET['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)) {
??????????? //檢查支付金額是否相符
??????????? $row = $this->dsql->GetOne("SELECT * FROM #@__shops_orders WHERE oid = '{$order_sn}'");
??????????? if ($row['priceCount'] != $_GET['total_fee'])
??????????? {
??????????????? return $msg = "支付失敗,支付金額與商品總價不相符!";
??????????? }
??????????? $this->mid = $row['userid'];
????
?? ??? ?? /* 檢查數字簽名是否正確 */
??????? ksort($_GET);
??????? reset($_GET);
?? ??? ?
?? ??? $sign = '';
??????? foreach ($_GET AS $key => $val)
??????? {
??????????? if("" != $val && "sign" != $key && $key != 'code') {
??????????????? $sign? .= "$key=$val&";
??????????? }
??????? }
?? ??? ??? $sign .= "key=".$payment['tenpay_key'];
? if(strtolower(md5($sign))==strtolower($_GET['sign']))
{
??????????? if($trade_state==0)
??????????? {?? ? ?
???????????????????? /* 改變訂單狀態 */
?????????????? if($this->success_db($out_trade_no)) ?
?? ??? ??? ??? return $msg = "支付成功!<br> <a href='/'>返回主頁</a> <a href='/member'>會員中心</a>";
?????????????? else? return $msg = "支付失敗!<br> <a href='/'>返回主頁</a> <a href='/member'>會員中心</a>";
??????????? }???
}
else{
?? //return $msg = "支付失敗!<br> <a href='/'>返回主頁</a> <a href='/member'>會員中心</a>";
? }
?? }
? ?
??? /*處理物品交易*/
??? function success_db($order_sn)
??? {
?? ???? $time=time();
?? ??? ?$mid=$this->mid;
??????? //獲取訂單信息,檢查訂單的有效性
??????? $row = $this->dsql->GetOne("SELECT state,priceCount FROM #@__shops_orders WHERE oid='$order_sn' ");
??????? if($row['state'] > 0)
??????? {
??????????? return TRUE;
??????? } ?
?????????????
??????? /* 改變訂單狀態_支付成功 */
?? ????
??????? $sql = "UPDATE `#@__shops_orders` SET `state`='1' WHERE `oid`='$order_sn' AND `userid`='".$this->mid."'";
??????? if($this->dsql->ExecuteNoneQuery($sql))
??????? {
?? ?????
??????????? $this->log_result("verify_success,訂單號:".$order_sn); //將驗證結果存入文件
??????????? return TRUE;
??????? } else {
??????????? $this->log_result ("verify_failed,訂單號:".$order_sn);//將驗證結果存入文件
??????????? return FALSE;
??????? }
??? }
? ?
??? function? log_result($word) {
??????? global $cfg_cmspath;
??????? $fp = fopen(dirname(__FILE__)."/../../data/payment/log.txt","a");
??????? flock($fp, LOCK_EX) ;
??????? fwrite($fp,$word.",執行日期:".strftime("%Y-%m-%d %H:%I:%S",time())."\r\n");
??????? flock($fp, LOCK_UN);
??????? fclose($fp);
??? }
轉載于:https://www.cnblogs.com/phplover2014/p/4188439.html
總結
以上是生活随笔為你收集整理的织梦cms系统如何code 财付通接口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 花呗上征信有什么影响 其实并不一定是坏事
- 下一篇: Android -- setWillNo