服務(wù)熱線
15617359779
15617359779
怎么對接銀聯(lián)支付 開始我是按照中國銀聯(lián)開發(fā)平臺的接口文檔對接 后來發(fā)現(xiàn)不是
如圖是中國銀聯(lián)開發(fā)平臺unionpay :
銀聯(lián)接口
chinapay和unionpay 是有區(qū)別的雖然都是銀聯(lián)旗下的 都是接口文檔都是不一樣的.
下面介紹一下對接過程;
第一步,申請好之后他們會發(fā)送一個郵件給你,里面有網(wǎng)關(guān)公鑰,這個文件是需要對接中用到
第二步 需要生成一個商戶的公鑰這個是比較麻煩的 ,不過在郵件附件中有文檔
接口文檔
5.6點是教程 用ie瀏覽器 安裝
控件安裝
安裝控件
安裝證書
選擇你生成的證書(多個就是最新的哪個)
登入 申請證書 導(dǎo)出證書(商戶私鑰,記住導(dǎo)出的密碼要記住后面要用到的)
https://merchant.chinapay.com/BIZSS/admin/loginpage.htm
文檔中有步驟 照著來就可以
登入https://service.chinapay.com/OSIWeb/home/toHome.action
可以下載都demo文件
下面是公共函數(shù)的
public function _initialize() {
header("Content-type:text/html;charset=utf-8");
vendor('Chinapay.util.common',"",".php"); //導(dǎo)入加密核心文件夾
vendor('Chinapay.util.SecssUtil',"",".class.php"); //導(dǎo)入加密核心文件夾
vendor('Chinapay.util.Settings_INI',"",".php"); //導(dǎo)入加密核心文件夾
vendor('Chinapay.util.Settings',"",".php"); //導(dǎo)入加密核心文件夾
define(transResvered, "trans_");
define(cardResvered, "card_");
define(transResveredKey, "TranReserved");
define(signatureField, "Signature");
$this->securityPropFile='.'.."/ThinkPHP/Library/Vendor/Chinapay/config/security.properties"; //這個是放公鑰,私鑰 文件位置信息
//dump($this->securityPropFile);
$this->PaySend = ."/Unionpay/PaySend";
$this->MerBgUrl ="http://www.yyishen.com/index.php/Home/Unionpay/pay_success";
}
代碼塊
sign.file.password=yyshen2020
這個是你導(dǎo)出商戶私鑰的密碼 下面是公鑰的地址
二、發(fā)送參數(shù)信息
$paramArray=array (
'MerId' => '',//商戶id
'MerOrderNo' => $config['MerOrderNo'] ,//訂單號
'OrderAmt' => $config['OrderAmt'],//訂單金額
'TranDate' => date('Ymd'),
'TranTime' => date('His'),
'TimeStamp'=>time(),
'TranType' => '0004',//交易類型
'BusiType' =>'0001',
'Version' => '20140728',//版本號
'CurryNo' => 'CNY',
'AccessType' =>'0',
'CommodityMsg' => $order['goods_name'],//商戶信息
'MerPageUrl' => $this->MerPageUrl,//回跳頁面,
'MerBgUrl' => $this->MerBgUrl,//接受交易狀態(tài)
'MerResv' => 'MerResv',
'RemoteAddr'=>get_client_ip(),//ip
);
if ($paramArray['TranType'] && trim($paramArray['TranType']) != "") {
$dispatchUrl =$this->PaySend;
} else {
$dispatchUrl = $this->PaySend;
}
$transResvedJson = array();
$cardInfoJson = array();
$sendMap = array();
foreach ($paramArray as $key => $value) {
if (isEmpty($value)) {
continue;
}
if (startWith($key, transResvered)) {
$key = substr($key, strlen(transResvered));
$transResvedJson[$key] = $value;
} else
if (startWith($key, cardResvered)) {
$key = substr($key, strlen(cardResvered));
$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 (! is_Empty($transResvedStr)) {
$transResvedStr = $secssUtil->decryptData($transResvedStr);
$sendMap[transResveredKey] = $transResvedStr;
}
if (! is_Empty($cardResvedStr)) {
$cardResvedStr = $secssUtil->decryptData($cardResvedStr);
$sendMap[cardResveredKey] = $cardResvedStr;
}
$securityPropFile =$this->securityPropFile;
$secssUtil->init($securityPropFile);
$secssUtil->sign($sendMap);
//dump($secssUtil->sign($sendMap));
$sendMap[signatureField] = $secssUtil->getSign();
//dump($sendMap);
// dump( $sendMap[signatureField]);
$_SESSION = $sendMap;
header("Location:" . $dispatchUrl);
}
發(fā)送參數(shù)
public function PaySend(){
layout(false);
$settings = new \Settings_INI();
$settings->load($this->securityPropFile);
//dump($settings->load($this->securityPropFile));exit;
$pay_url = "https://payment.chinapay.com/CTITS/service/rest/page/nref/000000000017/0/0/0/0/0";
$html = "
$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 .= "";
}
}
$html .= "";
$html .= ";
";
echo $html;
//dump($html);exit;
// $this->display();
}
整個過程就是Signature 生成簽名時候比較麻煩
代碼塊2
這個文件是完全加密的所以
截
這個文件的公鑰私鑰信息一定要對 如果看到這個頁面就說明已經(jīng)成功了
成功界面