Commit 1b0aaec9ab8367a4367d9ff71b17393acf51769c

Authored by YunaiV
1 parent 72438ed5

完成微信支付的支付流程,美滋滋

yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/ShopOrderController.java
... ... @@ -43,7 +43,7 @@ public class ShopOrderController {
43 43 reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis()));
44 44 reqDTO.setSubject("标题:" + shopOrderId);
45 45 reqDTO.setBody("内容:" + shopOrderId);
46   - reqDTO.setAmount(100);
  46 + reqDTO.setAmount(1); // 单位:分
47 47 reqDTO.setExpireTime(DateUtils.addTime(Duration.ofDays(1)));
48 48 Long payOrderId = payOrderCoreService.createPayOrder(reqDTO);
49 49  
... ...
yudao-user-server/src/main/resources/static/MP_verify_DKOvVzFP7vPwwHx2.txt 0 → 100644
  1 +DKOvVzFP7vPwwHx2
0 2 \ No newline at end of file
... ...
yudao-user-server/src/main/resources/static/pay.html
... ... @@ -2,6 +2,7 @@
2 2 <html>
3 3 <head>
4 4 <meta charset="UTF-8">
  5 + <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
5 6 <title>支付测试页</title>
6 7 <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
7 8 <script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
... ... @@ -15,7 +16,8 @@
15 16 <script>
16 17 let shopOrderId = undefined;
17 18 let payOrderId = undefined;
18   - let server = 'http://127.0.0.1:28080';
  19 + // let server = 'http://127.0.0.1:28080';
  20 + let server = 'http://niubi.natapp1.cc';
19 21 $(function() {
20 22 // 获得 JsapiTicket
21 23 // 参考 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html 文档
... ... @@ -56,49 +58,53 @@
56 58 // 微信公众号
57 59 $( "#wx_pub").on( "click", function() {
58 60 if (typeof WeixinJSBridge == "undefined") {
59   - if (document.addEventListener) {
60   - document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
61   - } else if (document.attachEvent) {
62   - document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
63   - document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
64   - }
65   - } else {
66   - onBridgeReady()
  61 + // if (document.addEventListener) {
  62 + // document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
  63 + // } else if (document.attachEvent) {
  64 + // document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
  65 + // document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
  66 + // }
  67 + alert('微信支付,只支持在微信客户端中使用!');
  68 + return;
  69 + }
  70 + if (navigator.userAgent.indexOf('wechatdevtools') >= 0) {
  71 + alert('微信支付,无法在微信开发者工具中使用!请使用微信客户端!');
  72 + return;
67 73 }
68 74  
69   - function onBridgeReady() {
70   - $.ajax({
71   - url: server + "/api/pay/order/submit",
72   - method: 'POST',
73   - dataType: "json",
74   - contentType: "application/json",
75   - data: JSON.stringify({
76   - "id": payOrderId,
77   - "channelCode": 'wx_pub',
78   - }),
79   - success: function( result ) {
80   - if (result.code !== 0) {
81   - alert('提交支付订单失败,原因:' + result.msg)
82   - return;
83   - }
84   - alert('开始调用微信支付');
85   - let data = result.data.invokeResponse;
86   - wx.chooseWXPay({
87   - timestamp: data.timeStamp,
88   - nonceStr: data.nonceStr,
89   - package: data.package,
90   - signType: data.signType,
91   - paySign: data.paySign,
92   - success: function (res) {
93   - alert(JSON.stringify(res));
94   - },
95   - error: function(e) {
96   - alert(JSON.stringify(e));
97   - }
98   - });
  75 + // 提交支付
  76 + $.ajax({
  77 + url: server + "/api/pay/order/submit",
  78 + method: 'POST',
  79 + dataType: "json",
  80 + contentType: "application/json",
  81 + data: JSON.stringify({
  82 + "id": payOrderId,
  83 + "channelCode": 'wx_pub',
  84 + }),
  85 + success: function( result ) {
  86 + if (result.code !== 0) {
  87 + alert('提交支付订单失败,原因:' + result.msg)
  88 + return;
99 89 }
100   - })
101   - }
  90 + alert('点击确定,开始微信支付');
  91 + // 开始调用微信支付
  92 + let data = result.data.invokeResponse;
  93 + wx.chooseWXPay({
  94 + timestamp: data.timeStamp,
  95 + nonceStr: data.nonceStr,
  96 + package: data.packageValue,
  97 + signType: data.signType,
  98 + paySign: data.paySign,
  99 + success: function (res) {
  100 + alert(JSON.stringify(res));
  101 + },
  102 + error: function(e) {
  103 + alert(JSON.stringify(e));
  104 + }
  105 + });
  106 + }
  107 + })
102 108 });
103 109 </script>
104 110 </html>
... ...