怎么对接银联支付 开始我是按照中国银联开发平台的接口文档对接 后来发现不是
如图是中国银联开发平台unionpay :
chinapay和unionpay 是有区别的虽然都是银联旗下的 都是接口文档都是不一样的.
下面介绍一下对接过程;
第一步,申请好之后他们会发送一个邮件给你,里面有网关公钥,这个文件是需要对接中用到
第二步 需要生成一个商户的公钥这个是比较麻烦的 ,不过在邮件附件中有文档
5.6点是教程 用ie浏览器 安装
安装控件
选择你生成的证书(多个就是最新的哪个)
登入 申请证书 导出证书(商户私钥,记住导出的密码要记住后面要用到的)
https://merchant.chinapay.com/BIZSS/admin/loginpage.htm
文档中有步骤 照着来就可以
登入
https://service.chinapay.com/OSIWeb/home/toHome.action
可以下载都demo文件
下面是公共函数的
public function _initialize() {
header("Content-type:text/html;charset=utf-8");
vendor('Chinapay.util.common',"",".php"); //导入加密核心文件夹
vendor('Chinapay.util.SecssUtil',"",".class.php"); //导入加密核心文件夹
vendor('Chinapay.util.Settings_INI',"",".php"); //导入加密核心文件夹
vendor('Chinapay.util.Settings',"",".php"); //导入加密核心文件夹
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
这个是你导出商户私钥的密码 下面是公钥的地址
二、发送参数信息
$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,//接受交易状态
'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);
}
发送参数
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 = "<form id='payment' 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 .= "<input type='submit' type='hidden' value='提交订单' >";
$html .= "<script>document.forms['payment'].submit();</script>;
</script>";
echo $html;
//dump($html);exit;
// $this->display();
}
整个过程就是Signature 生成签名时候比较麻烦
这个文件是完全加密的所以
这个文件的公钥私钥信息一定要对 如果看到这个页面就说明已经成功了