您好,登錄后才能下訂單哦!
小編給大家分享一下php版如何開發(fā)銀聯(lián)支付接口,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
銀聯(lián)支付,首先要注意二重要的部分:
PHP運(yùn)行環(huán)境是5.4.18以上
開了擴(kuò)展openssl
開發(fā)手冊(cè)上面的列子只做參考,因?yàn)榛径际清e(cuò)的。你可以試著去官網(wǎng)下一個(gè)demo。。。注意現(xiàn)在銀聯(lián)開發(fā),沒有測(cè)試密鑰提供,只能在正式環(huán)境開發(fā)
下面是我用ThinkPHP編寫的一個(gè)支付類
/** * 銀聯(lián)支付 v0.1 * @auther:Summer<dengwz7788@gmail.com>; * @date:20151202 * **/ class NetPayAction extends BaseAction{ //在類初始化方法中,引入相關(guān)類庫 public function _initialize() { header("Content-type:text/html;charset=utf-8"); vendor('Netpay.util.common',"",".php"); //導(dǎo)入加密核心文件夾 vendor('Netpay.util.SecssUtil',"",".class.php"); //導(dǎo)入加密核心文件夾 vendor('Netpay.util.Settings_INI',"",".php"); //導(dǎo)入加密核心文件夾 vendor('Netpay.util.Settings',"",".php"); //導(dǎo)入加密核心文件夾 $this->securityPropFile= $_SERVER['DOCUMENT_ROOT'] . "/ThinkPHP/Extend/Vendor/Netpay/config/security.properties"; //誰知道這是啥,反正他們要我加的 $this->b2cPaySend = __APP__."/Index/NetPay/b2cPaySend"; $this->b2cRefundSend = __APP__."/Index/NetPay/b2cRefundSend"; $this->b2cQuerySend = __APP__."/Index/NetPay/b2cQuerySend"; $this->;MerBgUrl = __APP__."/Index/NetPay/MerBgUrl"; $this->MerPageUrl = __APP__."/Index/NetPay/MerPageUrl"; } public function index() { $paramArray=array ( 'MerId' => '商戶號(hào)', 'MerOrderNo' => '0000001944663232', 'OrderAmt' => '1', 'TranDate' => '20151219', 'TranTime' =>'171248', 'TranType' => '0001', 'BusiType' =>'0001', 'Version' => '20140728', 'CurryNo' => 'CNY', 'AccessType' =>; '0', 'CommodityMsg' => '測(cè)試商品1號(hào)', 'MerPageUrl' => $this->MerBgUrl, 'MerBgUrl' =>$this->MerPageUrl, 'MerResv' => 'MerResv', ); if (count($paramArray) >0) { $dispatchUrl = $this->b2cPaySend; $transResvedJson = array(); $cardInfoJson = array(); $sendMap = array(); foreach ($paramArray as $key => $value) { if (isEmpty($value)) { continue; } if (startWith($key, "trans_")) { $key = substr($key, strlen("trans_")); $transResvedJson[$key] = $value; } else if (startWith($key, "card_")) { $key = substr($key, strlen("card_")); $cardInfoJson[$key] = $value; } else { $sendMap[$key] = $value; } } $transResvedStr = null; $cardResvedStr = null; if (count($transResvedJson) >0) { $transResvedStr = json_encode($transResvedJson); } if (count($cardInfoJson) > 0) { $cardResvedStr = json_encode($cardInfoJson); } $secssUtil = new SecssUtil(); if (! isEmpty($transResvedStr)) { $transResvedStr = $secssUtil->decryptData($transResvedStr); $sendMap["TranReserved"] = $transResvedStr; } if (! isEmpty($cardResvedStr)) { $cardResvedStr = $secssUtil->decryptData($cardResvedStr); $sendMap["card_"] = $cardResvedStr; } $securityPropFile = $this>securityPropFile; $secssUtil->init($securityPropFile); $secssUtil->sign($sendMap); $sendMap["Signature"] = $secssUtil->getSign(); $_SESSION = $sendMap; header("Location:" . $dispatchUrl); } } public function b2cPaySend(){ layout(false); $settings = new Settings_INI(); $settings->oad($this->securityPropFile); $pay_url = "https://payment.chinapay.com/CTITS/service/rest/page/nref/000000000017/0/0/0/0/0"; $html = "<form name='payment' action='{$pay_url}' method='POST' target='_blank'>;"; $params = "TranReserved;MerId;MerOrderNo;OrderAmt;CurryNo;TranDate;SplitMethod;BusiType;MerPageUrl;MerBgUrl;SplitType;MerSplitMsg;PayTimeOut;MerResv;Version;BankInstNo;CommodityMsg;Signature;AccessType;AcqCode;OrderExpiryTime;TranType;RemoteAddr;Referred;TranTime;TimeStamp;CardTranData"; foreach ($_SESSION as $k =>$v) { if (strstr($params, $k)) { $html .= "<input type='hidden' name = '" . $k . "' value ='" . $v . "'/>"; } } $html .= "<nput type='button' type='hidden' value='提交訂單' >"; $html .= "<;/from>"; $this->html = $html; $this->display(); } public function pgReturn(){ if ($_POST) { if (count($_POST) > 0) { $secssUtil = new SecssUtil(); $securityPropFile = $this>securityPropFile; $secssUtil->init($securityPropFile); $text = array(); foreach($_POST as $key=>$value){ $text[$key] = urldecode($value); } if ($secssUtil->verify($text)) { //支付成功 $_SESSION["VERIFY_KEY"] = "success"; } else { //支付失敗 $_SESSION["VERIFY_KEY"] = "fail"; } } } } }
以上是“php版如何開發(fā)銀聯(lián)支付接口”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。