1.平台下单接口
参考地址
注意:若是微信公众号支付 请使用 qmf.webPay 并在 微信公众号的环境中测试
$mdKey = 'fcAmtnx7MwismjWNhNKdHC44mNXtnEQeJkRrhKJwyrW2ysRR';
$mid = '898340149000005';
$tid = '88880001';
$merOrderId = '3194' . 'SH20191120093138668264';
$msgSrc = 'WWW.TEST.COM';
$time = time();
$notifyUrl = $_W['siteroot'] . './addons/xt_agent/payment/yinlian/notify.php';
$requestTimestamp = date('Y-m-d H:i:s',$time);
$msgType = 'qmf.webPay';//微信支付:WXPay.jsPay,支付宝支付:trade.jsPay,银联支付:qmf.jspay(qmf.webPay)
//根据实际情况,回调时携带的参数
$attachedData = [
'money' => $money,
'module' => $module,
'number' => $number,
'number2' => $number2,
'uniacid' => $_W['uniacid'],
'acid' => $_W['acid'],
];
$attachedData = json_encode($attachedData);///转为json类型
$data = [
'instMid' => 'YUEDANDEFAULT',//业务类型
'merOrderId' => $merOrderId,//订单号
'mid' => $mid,//商户号
'msgSrc' => $msgSrc,//消息来源
'msgType' => $msgType,//消息类型
'orderDesc' => '测试',//订单描述
'requestTimestamp' => $requestTimestamp,//报文请求时间
'tid' => $tid,//终端号
'totalAmount' => '1',//支付金额
'notifyUrl' => $notifyUrl,//支付结果通知地址,结果页面会将返回参数通过post传过来。通过status值来判断是否支付成功
'returnUrl' => $notifyUrl,//网页跳转地址,结果页面会将返回参数通过get传过来。通过status值来判断是否支付成功
'attachedData' => $attachedData, //携带的参数
];
ksort($data, SORT_STRING);
reset($data);
$options = '';
$options2 = '';
foreach ($data as $key => $value) {
$options .= $key . '=' . $value .'&';
///注意 参数还要用urlencode函数处理一下
$options2 .= $key . '=' . urlencode($value) . '&';
}
$options = rtrim($options, '&');
//存在转义字符,那么去掉转义
if(get_magic_quotes_gpc()){
$options = stripslashes($options);
}
$sign = md5($options . $mdKey);
$options2 .= 'sign=' . urlencode($sign);///注意 参数还要用urlencode函数处理一下
$url = 'https://qr-test2.chinaums.com/netpay-portal/webpay/pay.do?'.$options2;
exit('<script>top.window.location.href=\'' . $url . '\'</script>');
2.支付结果查询接口
$msgType = empty($msgType) ? 'query' : $msgType;
$mdKey = 'fcAmtnx7MwismjWNhNKdHC44mNXtnEQeJkRrhKJwyrW2ysRR';
$mid = '898340149000005';
$tid = '88880001';
$merOrderId = '3194' . 'SH20191120093138668264';
$msgSrc = 'WWW.TEST.COM';
$time = time();
$notifyUrl = $_W['siteroot'] . '/addons/sz_yi/payment/yinlian/notify.php';
$requestTimestamp = date('Y-m-d H:i:s',$time);
$data = [
'instMid' => 'YUEDANDEFAULT',//业务类型
'merOrderId' => $merOrderId,//订单号
'mid' => $mid,//商户号
// 'msgSrc' => 'WWW.HANGZPXWH.COM',//消息来源
'msgSrc' => $msgSrc,//消息来源
'msgType' => $msgType,//消息类型
'requestTimestamp' => $requestTimestamp,//报文请求时间
'tid' => $tid,//终端号
];
ksort($data, SORT_STRING);
reset($data);
$options = '';
$options2 = '';
foreach ($data as $key => $value) {
$options .= $key . '=' . $value .'&';
}
$options = rtrim($options, '&');
//存在转义字符,那么去掉转义
if(get_magic_quotes_gpc()){
$options = stripslashes($options);
}
$sign = md5($options . $mdKey);
$data['sign'] = $sign;
$ch = curl_init();
///json 格式 请求
$data = json_encode($data);
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, 'https://qr-test2.chinaums.com/netpay-route-server/api/');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// dump(123);die;
curl_setopt($ch, CURLOPT_POSTFIELDS, ($data));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//设置header信息application/x-www-form-urlencoded;charset=utf-8 application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output);
3.订单退款接口
$msgType = empty($msgType) ? 'refund' : $msgType;
$instMid = 'YUEDANDEFAULT';//业务类型
$mdKey = 'fcAmtnx7MwismjWNhNKdHC44mNXtnEQeJkRrhKJwyrW2ysRR';
$mid = '898340149000005';
$tid = '88880001';
$merOrderId = '3194SH2030erererere6666699';//订单号
$msgSrc = 'WWW.TEST.COM';
$time = time();
$notifyUrl = $_W['siteroot'] . '/addons/sz_yi/payment/yinlian/notify.php';
$requestTimestamp = date('Y-m-d H:i:s',$time);
$data = [
'instMid' => $instMid,//业务类型
'merOrderId' => $merOrderId,//订单号
'mid' => $mid,//商户号
'msgSrc' => $msgSrc,//消息来源
'msgType' => $msgType,//消息类型
'requestTimestamp' => $requestTimestamp,//报文请求时间
'tid' => $tid,//终端号
'refundAmount' => 1,//退款金额
'refundDesc' => '测试',//退款说明
];
ksort($data, SORT_STRING);
reset($data);
$options = '';
$options2 = '';
foreach ($data as $key => $value) {
$options .= $key . '=' . $value .'&';
}
$options = rtrim($options, '&');
//存在转义字符,那么去掉转义
if(get_magic_quotes_gpc()){
$options = stripslashes($options);
}
$sign = md5($options . $mdKey);
$data['sign'] = $sign;
$ch = curl_init();
///json 格式 请求
$data = json_encode($data);
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, 'https://qr-test2.chinaums.com/netpay-route-server/api/');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($data));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//设置header信息application/x-www-form-urlencoded;charset=utf-8 application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output);
- 调试
若不知道支付结果通知地址返回的参数,可以通过写文件的方式来观看返回的参数结果
$myfile = fopen("./notify.txt", "w") or die("Unable to open file!"); //创建或打开文件
$post2 = json_encode($post);//根据通知地址返回的是get还是post方式
fwrite($myfile, $post2);
fclose($myfile); // 关闭文件
(1)当notify.php 文件代码,不执行时,可以将returnUrl的路径=notifyUrl的路径,观看是否为路径错误,或是否为notify.php因代码错误而无法执行。
(2)若因notify.php代码错误而无法执行。可以通过浏览器访问notifyUrl路径来观看notify.php是否是代码错误,而无法执行