完成微信支付的支付流程,美滋滋
parent
72438ed5f6
commit
1b0aaec9ab
|
@ -43,7 +43,7 @@ public class ShopOrderController {
|
||||||
reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis()));
|
reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis()));
|
||||||
reqDTO.setSubject("标题:" + shopOrderId);
|
reqDTO.setSubject("标题:" + shopOrderId);
|
||||||
reqDTO.setBody("内容:" + shopOrderId);
|
reqDTO.setBody("内容:" + shopOrderId);
|
||||||
reqDTO.setAmount(100);
|
reqDTO.setAmount(1); // 单位:分
|
||||||
reqDTO.setExpireTime(DateUtils.addTime(Duration.ofDays(1)));
|
reqDTO.setExpireTime(DateUtils.addTime(Duration.ofDays(1)));
|
||||||
Long payOrderId = payOrderCoreService.createPayOrder(reqDTO);
|
Long payOrderId = payOrderCoreService.createPayOrder(reqDTO);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
DKOvVzFP7vPwwHx2
|
|
@ -2,6 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
|
||||||
<title>支付测试页</title>
|
<title>支付测试页</title>
|
||||||
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
|
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
|
||||||
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
|
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
|
||||||
|
@ -15,7 +16,8 @@
|
||||||
<script>
|
<script>
|
||||||
let shopOrderId = undefined;
|
let shopOrderId = undefined;
|
||||||
let payOrderId = undefined;
|
let payOrderId = undefined;
|
||||||
let server = 'http://127.0.0.1:28080';
|
// let server = 'http://127.0.0.1:28080';
|
||||||
|
let server = 'http://niubi.natapp1.cc';
|
||||||
$(function() {
|
$(function() {
|
||||||
// 获得 JsapiTicket
|
// 获得 JsapiTicket
|
||||||
// 参考 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html 文档
|
// 参考 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html 文档
|
||||||
|
@ -56,17 +58,21 @@
|
||||||
// 微信公众号
|
// 微信公众号
|
||||||
$( "#wx_pub").on( "click", function() {
|
$( "#wx_pub").on( "click", function() {
|
||||||
if (typeof WeixinJSBridge == "undefined") {
|
if (typeof WeixinJSBridge == "undefined") {
|
||||||
if (document.addEventListener) {
|
// if (document.addEventListener) {
|
||||||
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
|
// document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
|
||||||
} else if (document.attachEvent) {
|
// } else if (document.attachEvent) {
|
||||||
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
|
// document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
|
||||||
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
|
// document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
|
||||||
|
// }
|
||||||
|
alert('微信支付,只支持在微信客户端中使用!');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
if (navigator.userAgent.indexOf('wechatdevtools') >= 0) {
|
||||||
onBridgeReady()
|
alert('微信支付,无法在微信开发者工具中使用!请使用微信客户端!');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onBridgeReady() {
|
// 提交支付
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: server + "/api/pay/order/submit",
|
url: server + "/api/pay/order/submit",
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -81,12 +87,13 @@
|
||||||
alert('提交支付订单失败,原因:' + result.msg)
|
alert('提交支付订单失败,原因:' + result.msg)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
alert('开始调用微信支付');
|
alert('点击确定,开始微信支付');
|
||||||
|
// 开始调用微信支付
|
||||||
let data = result.data.invokeResponse;
|
let data = result.data.invokeResponse;
|
||||||
wx.chooseWXPay({
|
wx.chooseWXPay({
|
||||||
timestamp: data.timeStamp,
|
timestamp: data.timeStamp,
|
||||||
nonceStr: data.nonceStr,
|
nonceStr: data.nonceStr,
|
||||||
package: data.package,
|
package: data.packageValue,
|
||||||
signType: data.signType,
|
signType: data.signType,
|
||||||
paySign: data.paySign,
|
paySign: data.paySign,
|
||||||
success: function (res) {
|
success: function (res) {
|
||||||
|
@ -98,7 +105,6 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue