微信公众号支付
1.需要配置调起支付的路径
2.预支付时返回的签名有特殊字符 + ,需要 encode , 否则+会变成空格 ,导致调起支付 报签名错误 。
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>支付</title>
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no">
<link rel="stylesheet" href="css/payment.css">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
var appId = '${appId}';
var timeStamp = '${timeStamp}';
var nonceStr = '${nonceStr}';
var pg = '${pg}';
var signType = '${signType}';
var paySign = '${paySign}';
function onBridgeReady() {
WeixinJSBridge.invoke('getBrandWCPayRequest', {
"appId" : appId, //公众号名称,由商户传入
"timeStamp" : timeStamp, //时间戳,自1970年以来的秒数
"nonceStr" : nonceStr, //随机串
"package" : pg,
"signType" : signType, //微信签名方式:
"paySign" : paySign
}, function(res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
} // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回 ok,但并不保证它绝对可靠。
else {
alert(JSON.stringify(res));
alert('支付失败:' + res.err_msg);
}
WeixinJSBridge.call('closeWindow');
});
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady,
false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
} else {
onBridgeReady();
}
</script>
</head>
<body style="background-color: #f8f8f8;"
οnlοad="javascript:onBridgeReady()">
</body>
</html>