PHP code example of zhangv / union-pay
1. Go to this page and download the library: Download zhangv/union-pay library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zhangv / union-pay example snippets
return ['test', [
'version' => '5.1.0',
'signMethod'=> '01', //RSA
'encoding' => 'UTF-8',
'merId' => '700000000000001',
'returnUrl' => 'http://dev.git.com/union-pay/demo/payreturn.php', //前台网关支付返回
'notifyUrl' => 'http://dev.git.com/union-pay/demo/paynotify.php', //后台通知
'frontFailUrl' => 'http://dev.git.com/union-pay/demo/payfail.php',
'refundnotifyUrl' => 'http://dev.git.com.com/union-pay/demo/refundnotify.php',
'signCertPath' => dirname(__FILE__).'/../cert/acp_test_sign.pfx',
'signCertPwd' => '000000', //签名证书密码
'verifyCertPath' => dirname(__FILE__).'/../cert/acp_test_verify_sign.cer', //v5.0.0
list($mode,$config) = onfig,$mode);
$payOrderNo = date('YmdHis');
$amt = 1;
$html = $unionPay->pay($payOrderNo,$amt);
echo $html;
list($mode,$config) = onfig,$mode);
$postdata = $_REQUEST;
$unionPay->onPayNotify($postdata,function($notifydata){
echo 'SUCCESS';
var_dump($notifydata);
});
list($mode,$config) = config,$mode);
$notifyData = $_POST;
$respCode = $notifyData['respCode'];
if($respCode == '00'){
$unionPay->onNotify($notifyData,'demoCallback');
}elseif(in_array($respCode,['03','04','05'])){
//后续需发起交易状态查询交易确定交易状态
}else{
echo 'fail';
}
function demoCallback($notifyData){//自定义回调
var_dump($notifyData);
print('ok');
}