张延森 vor 3 Jahren
Ursprung
Commit
4c19864d57

+ 5
- 3
src/main/java/com/yunzhi/nanyang/common/WxPayUtils.java Datei anzeigen

@@ -32,7 +32,7 @@ public class WxPayUtils {
32 32
      * @return
33 33
      * @throws Exception
34 34
      */
35
-    public WxPayUnifiedOrderV3Result.JsapiResult createOrder(WxPayUnifiedOrderV3Request request, String client) throws WxPayException {
35
+    public WxPayUnifiedOrderV3Result createOrder(WxPayUnifiedOrderV3Request request, String client) throws WxPayException {
36 36
         // 北京时间
37 37
         LocalDateTime now = LocalDateTime.now(ZoneOffset.ofHours(8));
38 38
         WxPayService payService = wxUtils.getPayService();
@@ -44,8 +44,10 @@ public class WxPayUtils {
44 44
             tradeType = TradeTypeEnum.APP;
45 45
         }
46 46
 
47
-        WxPayUnifiedOrderV3Result wxPayUnifiedOrderV3Result = payService.unifiedOrderV3(tradeType, request);
48
-        return wxPayUnifiedOrderV3Result.getPayInfo(tradeType, request.getAppid(), request.getMchid(), payService.getConfig().getPrivateKey());
47
+        return payService.unifiedOrderV3(tradeType, request);
48
+
49
+//        WxPayUnifiedOrderV3Result wxPayUnifiedOrderV3Result =
50
+//        return wxPayUnifiedOrderV3Result.getPayInfo(tradeType, request.getAppid(), request.getMchid(), payService.getConfig().getPrivateKey());
49 51
     }
50 52
 
51 53
     /**

+ 18
- 6
src/main/java/com/yunzhi/nanyang/controller/TaPayController.java Datei anzeigen

@@ -1,10 +1,10 @@
1 1
 package com.yunzhi.nanyang.controller;
2 2
 
3 3
 import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
4
-import com.yunzhi.nanyang.common.BaseController;
5
-import com.yunzhi.nanyang.common.Constants;
6
-import com.yunzhi.nanyang.common.ResponseBean;
7
-import com.yunzhi.nanyang.common.StringUtils;
4
+import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum;
5
+import com.github.binarywang.wxpay.config.WxPayConfig;
6
+import com.github.binarywang.wxpay.service.WxPayService;
7
+import com.yunzhi.nanyang.common.*;
8 8
 import com.yunzhi.nanyang.entity.TaOrder;
9 9
 import com.yunzhi.nanyang.service.ITaOrderService;
10 10
 import com.yunzhi.nanyang.service.ITaPayService;
@@ -22,6 +22,9 @@ import java.util.Map;
22 22
 @RequestMapping("/")
23 23
 public class TaPayController extends BaseController {
24 24
 
25
+    @Autowired
26
+    WxUtils wxUtils;
27
+
25 28
     @Autowired
26 29
     ITaPayService iTaPayService;
27 30
 
@@ -50,8 +53,17 @@ public class TaPayController extends BaseController {
50 53
             return ResponseBean.error("订单已支付");
51 54
         }
52 55
 
53
-        WxPayUnifiedOrderV3Result.JsapiResult result = iTaPayService.createPay(client, clientId, taOrder);
54
-        return ResponseBean.success(result);
56
+        WxPayUnifiedOrderV3Result payResult = iTaPayService.createPay(client, clientId, taOrder);
57
+
58
+        WxPayConfig payConfig = wxUtils.getPayService().getConfig();
59
+
60
+        if ("wx".equals(client)) {
61
+            WxPayUnifiedOrderV3Result.JsapiResult result = payResult.getPayInfo(TradeTypeEnum.JSAPI, payConfig.getAppId(), payConfig.getMchId(), payConfig.getPrivateKey());
62
+            return ResponseBean.success(result);
63
+        } else {
64
+            WxPayUnifiedOrderV3Result.AppResult result = payResult.getPayInfo(TradeTypeEnum.APP, payConfig.getAppId(), payConfig.getMchId(), payConfig.getPrivateKey());
65
+            return ResponseBean.success(result);
66
+        }
55 67
     }
56 68
 
57 69
 

+ 2
- 2
src/main/java/com/yunzhi/nanyang/service/ITaPayService.java Datei anzeigen

@@ -8,9 +8,9 @@ import com.yunzhi.nanyang.entity.TaPay;
8 8
 
9 9
 public interface ITaPayService extends IBaseService<TaPay> {
10 10
 
11
-    WxPayUnifiedOrderV3Result.JsapiResult createPay(String client, String clientId, TaOrder taOrder) throws Exception;
11
+    WxPayUnifiedOrderV3Result createPay(String client, String clientId, TaOrder taOrder) throws Exception;
12 12
 
13
-    WxPayUnifiedOrderV3Result.JsapiResult prePay(TaPay taPay, String client) throws Exception;
13
+    WxPayUnifiedOrderV3Result prePay(TaPay taPay, String client) throws Exception;
14 14
 
15 15
     TaPay getByOrderNo(String orderNo);
16 16
 

+ 8
- 5
src/main/java/com/yunzhi/nanyang/service/impl/TaPayServiceImpl.java Datei anzeigen

@@ -50,7 +50,7 @@ public class TaPayServiceImpl extends BaseServiceImpl<TaPayMapper, TaPay> implem
50 50
     TaAccountMapper taAccountMapper;
51 51
 
52 52
     @Override
53
-    public WxPayUnifiedOrderV3Result.JsapiResult createPay(String client, String clientId, TaOrder taOrder) throws Exception {
53
+    public WxPayUnifiedOrderV3Result createPay(String client, String clientId, TaOrder taOrder) throws Exception {
54 54
         TaPay taPay = getByOrderNo(taOrder.getOrderNo());
55 55
         if (null == taPay) {
56 56
             taPay = new TaPay();
@@ -70,14 +70,14 @@ public class TaPayServiceImpl extends BaseServiceImpl<TaPayMapper, TaPay> implem
70 70
         }
71 71
 
72 72
         try {
73
-            WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = prePay(taPay, client);
73
+            WxPayUnifiedOrderV3Result payResult = prePay(taPay, client);
74 74
             if (StringUtils.isEmpty(taPay.getPayId())) {
75 75
                 taPay.setPayId(StringUtils.uuid());
76 76
                 if (!save(taPay)) {
77 77
                     throw new Exception("系统出错请重试");
78 78
                 }
79 79
             }
80
-            return jsapiResult;
80
+            return payResult;
81 81
         } catch (WxPayException e) {
82 82
             e.printStackTrace();
83 83
 
@@ -104,7 +104,7 @@ public class TaPayServiceImpl extends BaseServiceImpl<TaPayMapper, TaPay> implem
104 104
     }
105 105
 
106 106
     @Override
107
-    public WxPayUnifiedOrderV3Result.JsapiResult prePay(TaPay taPay, String client) throws WxPayException {
107
+    public WxPayUnifiedOrderV3Result prePay(TaPay taPay, String client) throws WxPayException {
108 108
         // 生成订单
109 109
         if ("wx".equals(taPay.getPayType())) {
110 110
             WxPayUnifiedOrderV3Request.Amount amount = new  WxPayUnifiedOrderV3Request.Amount();
@@ -117,7 +117,10 @@ public class TaPayServiceImpl extends BaseServiceImpl<TaPayMapper, TaPay> implem
117 117
             req.setDescription(taPay.getDescription());
118 118
             req.setOutTradeNo(taPay.getOrderNo());
119 119
             req.setAmount(amount);
120
-            req.setPayer(payer);
120
+
121
+            if ("wx".equals(client)) {
122
+                req.setPayer(payer);
123
+            }
121 124
 
122 125
             return wxPayUtils.createOrder(req, client);
123 126
         }