From 5dc40fcd64b0513150f1d8335ab849e6d8cdc28e Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 04 七月 2025 19:42:49 +0800
Subject: [PATCH] 支付版本更新 根据资金流向使用V2或V3服务商版本支付

---
 cloud-server-account/src/main/java/com/dsh/account/controller/UseBenefitsController.java |  119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 108 insertions(+), 11 deletions(-)

diff --git a/cloud-server-account/src/main/java/com/dsh/account/controller/UseBenefitsController.java b/cloud-server-account/src/main/java/com/dsh/account/controller/UseBenefitsController.java
index 1467f9c..b868a95 100644
--- a/cloud-server-account/src/main/java/com/dsh/account/controller/UseBenefitsController.java
+++ b/cloud-server-account/src/main/java/com/dsh/account/controller/UseBenefitsController.java
@@ -1,6 +1,7 @@
 package com.dsh.account.controller;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.dsh.account.entity.TAppUser;
 import com.dsh.account.feignclient.activity.model.IntegralCommodity;
 import com.dsh.account.feignclient.other.SysLogClient;
@@ -8,9 +9,12 @@
 import com.dsh.account.service.RechargeRecordsService;
 import com.dsh.account.service.TAppUserService;
 import com.dsh.account.service.UserIntegralChangesService;
+import com.dsh.account.util.PayMoneyUtil;
 import com.dsh.account.util.ResultUtil;
 import com.dsh.account.util.TokenUtil;
 import com.dsh.account.util.ToolUtil;
+import com.dsh.account.util.wx.WxV3PayConfig;
+import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
@@ -20,8 +24,13 @@
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
+import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 使用福利 控制器
@@ -49,10 +58,13 @@
 
     private final SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
 
+    @Autowired
+    private PayMoneyUtil payMoneyUtil;
+
 
     @ResponseBody
     @PostMapping("/api/useBenefit/indexOfAppUser")
-    @ApiOperation(value = "福利主页", tags = {"APP-使用福利"})
+    @ApiOperation(value = "福利主页【2.0】", tags = {"APP-使用福利"})
     @ApiImplicitParams({
             @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
             @ApiImplicitParam(name = "lat", value = "经度", dataType = "string"),
@@ -307,12 +319,7 @@
             @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
     })
     public ResultUtil<List<Goods>> pointsMallList(MallRequest request) {
-//        try {
-        System.out.println("======request========" + request);
         return ResultUtil.success(tauService.queryAppUserIntegral(request));
-//        }catch (Exception e){
-//            return ResultUtil.runErr();
-//        }
     }
 
 
@@ -407,7 +414,7 @@
     @ApiImplicitParams({
             @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
     })
-    public synchronized ResultUtil productRedemptionOperation(GoodsExchangeVo exchangeType) {
+    public ResultUtil productRedemptionOperation(GoodsExchangeVo exchangeType) {
         try {
             Integer userIdFormRedis = tokenUtil.getUserIdFormRedis();
             if (null == userIdFormRedis) {
@@ -418,6 +425,100 @@
             return ResultUtil.runErr();
         }
     }
+
+
+    /**
+     * V3版本回调
+     * @param request
+     * @param response
+     */
+    @ResponseBody
+    @PostMapping("/base/coupon/weChatPaymentCouponCallback1")
+    public void weChatPaymentCouponCallback1(HttpServletRequest request, HttpServletResponse response){
+        try {
+            System.err.println("微信回调");
+            System.err.println("请求" + request);
+            BufferedReader reader = request.getReader();
+            String string1 = reader.toString();
+            System.err.println("请求reader" + string1);
+            StringBuilder requestBody = new StringBuilder();
+            String line;
+            while ((line = reader.readLine()) != null) {
+                requestBody.append(line);
+            }
+            System.err.println("全部请求体" + requestBody);
+            JSONObject jsonObject = JSONObject.parseObject(requestBody.toString());
+            JSONObject resource = jsonObject.getJSONObject("resource");
+
+            AesUtil aesUtil = new AesUtil(WxV3PayConfig.apiV3Key.getBytes(StandardCharsets.UTF_8));
+            String decryptedData = aesUtil.decryptToString(resource.getString("associated_data").getBytes(StandardCharsets.UTF_8), resource.getString("nonce").getBytes(StandardCharsets.UTF_8),
+                    resource.getString("ciphertext"));
+            System.err.println("微信解密的字符串信息" + decryptedData);
+            JSONObject jsonInfo = (JSONObject) JSONObject.parse(decryptedData);
+            String code = jsonInfo.getString("out_trade_no");
+            String trade_no = jsonInfo.getString("transaction_id");
+            String trade_state = jsonInfo.getString("trade_state");
+            if (trade_state.equals("SUCCESS")) {
+                ResultUtil resultUtil = tauService.paymentCouponCallback(code, trade_no);
+                if(resultUtil.getCode() == 200){
+                    PrintWriter out = response.getWriter();
+                    out.print("SUCCESS");
+                    out.flush();
+                    out.close();
+                }
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    @ResponseBody
+    @PostMapping("/base/coupon/weChatPaymentCouponCallback")
+    public void weChatPaymentCouponCallback(HttpServletRequest request, HttpServletResponse response){
+        try {
+            Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
+            if(null != map){
+                String code = map.get("out_trade_no");
+                String trade_no = map.get("transaction_id");
+                String result = map.get("result");
+                ResultUtil resultUtil = tauService.paymentCouponCallback(code, trade_no);
+                if(resultUtil.getCode() == 200){
+                    PrintWriter out = response.getWriter();
+                    out.print(result);
+                    out.flush();
+                    out.close();
+                }
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    @ResponseBody
+    @PostMapping("/base/coupon/aliPaymentCouponCallback")
+    public void aliPaymentCouponCallback(HttpServletRequest request, HttpServletResponse response){
+        try {
+            Map<String, String> map = payMoneyUtil.alipayCallback(request);
+            if(null != map){
+                String code = map.get("out_trade_no");
+                String trade_no = map.get("trade_no");
+                ResultUtil resultUtil = tauService.paymentCouponCallback(code, trade_no);
+                if(resultUtil.getCode() == 200){
+                    PrintWriter out = response.getWriter();
+                    out.print("success");
+                    out.flush();
+                    out.close();
+                }
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+
+
+
+
 
 
     /**
@@ -485,13 +586,9 @@
             @ApiImplicitParam(value = "记录id", name = "detailsId", required = true, dataType = "string"),
     })
     public ResultUtil<PointDetailsVo> redemptionDetails(Long detailsId) {
-//        try {
         PointDetailsVo pointDetailsVo = uicService.queryRedemptionDetails(detailsId);
         pointDetailsVo.getPics().remove(0);
         return ResultUtil.success(pointDetailsVo);
-//        }catch (Exception e){
-//            return ResultUtil.runErr();
-//        }
     }
 
 

--
Gitblit v1.7.1