php版銀聯(lián)支付接口開發(fā)簡明教程
本文實(shí)例講述了php版銀聯(lián)支付接口開發(fā)的方法。分享給大家供大家參考,具體如下:
支付接口現(xiàn)在有第三方的支付接口也有銀行的支付接口。這里就來介紹php版本銀聯(lián)支付接口開發(fā)的方法。
銀聯(lián)支付,首先要注意二重要的部分:
PHP運(yùn)行環(huán)境是5.4.18以上
開了擴(kuò)展openssl
開發(fā)手冊上面的列子只做參考,因?yàn)榛径际清e(cuò)的。你可以試著去官網(wǎng)下一個(gè)demo。。。注意現(xiàn)在銀聯(lián)開發(fā),沒有測試密鑰提供,只能在正式環(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' => '商戶號',
'MerOrderNo' => '0000001944663232',
'OrderAmt' => '1',
'TranDate' => '20151219',
'TranTime' =>'171248',
'TranType' => '0001',
'BusiType' =>'0001',
'Version' => '20140728',
'CurryNo' => 'CNY',
'AccessType' =>; '0',
'CommodityMsg' => '測試商品1號',
'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";
}
}
}
}
}
銀聯(lián)支付應(yīng)該是算比較簡單的??!
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php常見數(shù)據(jù)庫操作技巧匯總》、《PHP數(shù)組(Array)操作技巧大全》、《php排序算法總結(jié)》、《PHP常用遍歷算法與技巧總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php正則表達(dá)式用法總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》及《php字符串(string)用法總結(jié)》
希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
php基于閉包實(shí)現(xiàn)函數(shù)的自調(diào)用(遞歸)實(shí)例分析
這篇文章主要介紹了php基于閉包實(shí)現(xiàn)函數(shù)的自調(diào)用,結(jié)合實(shí)例形式分析了php閉包實(shí)現(xiàn)遞歸的操作方法,需要的朋友可以參考下2016-11-11
php下獲取http狀態(tài)的實(shí)現(xiàn)代碼
在項(xiàng)目開發(fā)中,有時(shí)我們需要知道遠(yuǎn)程的URL地址是否能訪問正常,判斷其正常與否后進(jìn)行下一步的操作,那么在PHP中如何獲取遠(yuǎn)程HTTP的狀態(tài)呢2014-05-05
php mysql procedure實(shí)現(xiàn)獲取多個(gè)結(jié)果集的方法【基于thinkPHP】
這篇文章主要介紹了php mysql procedure實(shí)現(xiàn)獲取多個(gè)結(jié)果集的方法,基于thinkPHP實(shí)現(xiàn)針對數(shù)據(jù)庫多個(gè)結(jié)果集的相關(guān)操作技巧,需要的朋友可以參考下2016-11-11
php+ajax無刷新上傳圖片的實(shí)現(xiàn)方法
這篇文章主要介紹了php+ajax無刷新上傳圖片的實(shí)現(xiàn)方法,涉及php結(jié)合ajax進(jìn)行文件傳輸操作相關(guān)技巧,需要的朋友可以參考下2016-12-12
php 來訪國內(nèi)外IP判斷代碼并實(shí)現(xiàn)頁面跳轉(zhuǎn)
最近做了公司網(wǎng)站的一個(gè)需求:按來訪人的IP來判斷他是進(jìn)中文網(wǎng)站還是英文網(wǎng)站。2009-12-12
關(guān)于Iframe如何跨域訪問Cookie和Session的解決方法
本篇文章小編將為大家介紹,關(guān)于Iframe如何跨域訪問Cookie和Session的解決方法,有需要的朋友可以參考一下2013-04-04
PHP 返回13位時(shí)間戳的實(shí)現(xiàn)代碼
下面小編就為大家?guī)硪黄狿HP 返回13位時(shí)間戳的實(shí)現(xiàn)代碼。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05
PHP函數(shù)extension_loaded()用法實(shí)例
這篇文章主要介紹了PHP函數(shù)extension_loaded()用法,實(shí)例分析了函數(shù)extension_loaded()檢查一個(gè)擴(kuò)展是否已經(jīng)加載的具體用法,并補(bǔ)充說明了查看本機(jī)已加載php擴(kuò)展的方法,需要的朋友可以參考下2015-01-01

