From 4e124926ee6ee682084466067ae37550fca475fa Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期二, 05 八月 2025 11:39:48 +0800
Subject: [PATCH] 代码提交 世界杯修改支付宝资金结算功能

---
 cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/controller/WorldCupController.java |  118 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 106 insertions(+), 12 deletions(-)

diff --git a/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/controller/WorldCupController.java b/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/controller/WorldCupController.java
index ccec4d5..cae4036 100644
--- a/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/controller/WorldCupController.java
+++ b/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/controller/WorldCupController.java
@@ -23,6 +23,8 @@
 import com.dsh.communityWorldCup.util.PayMoneyUtil;
 import com.dsh.communityWorldCup.util.ResultUtil;
 import com.dsh.communityWorldCup.util.TokenUtil;
+import com.dsh.communityWorldCup.util.wx.WxV3PayConfig;
+import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
 import groovy.util.logging.Log4j;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -37,8 +39,10 @@
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -102,7 +106,6 @@
 
     /**
      * 查询社区世界杯收入--管理后台
-     * @param storeId
      * @return
      */
     @ResponseBody
@@ -448,23 +451,66 @@
         }
     }
 
-
+    @ResponseBody
+    @PostMapping("/base/worldCup/wxPayWorldCupCallback")
+    public void wxPayWorldCupCallback(HttpServletRequest request, HttpServletResponse response){
+            System.err.println("微信回调");
+            try {
+                Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
+                if (null != map) {
+                    String code = map.get("out_trade_no");
+                    String transaction_id = map.get("transaction_id");
+                    String result = map.get("result");
+                    ResultUtil resultUtil = worldCupService.paymentWorldCupCallback(code, transaction_id);
+                    if (resultUtil.getCode() == 200) {
+                        PrintWriter out = response.getWriter();
+                        out.println(result);
+                        out.flush();
+                        out.close();
+                    } else {
+                        log.error("社区世界杯报名微信支付回业务处理异常:" + resultUtil.getMsg());
+                    }
+                } else {
+                    log.error("社区世界杯报名微信支付回调解析异常");
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+    }
     /**
      * 微信支付回调
      */
     @ResponseBody
-    @PostMapping("/base/worldCup/wxPayWorldCupCallback")
-    public void wxPayWorldCupCallback(HttpServletRequest request, HttpServletResponse response){
+    @PostMapping("/base/worldCup/wxPayWorldCupCallback1")
+    public void wxPayWorldCupCallback1(HttpServletRequest request, HttpServletResponse response){
         try {
-            Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
-            if(null != map){
-                String code = map.get("out_trade_no");
-                String transaction_id = map.get("transaction_id");
-                String result = map.get("result");
+            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 transaction_id = jsonInfo.getString("transaction_id");
+            String trade_state = jsonInfo.getString("trade_state");
+            if (trade_state.equals("SUCCESS")) {
                 ResultUtil resultUtil = worldCupService.paymentWorldCupCallback(code, transaction_id);
                 if(resultUtil.getCode() == 200){
                     PrintWriter out = response.getWriter();
-                    out.println(result);
+                    out.println("SUCCESS");
                     out.flush();
                     out.close();
                 }else{
@@ -607,7 +653,7 @@
             @ApiImplicitParam(name = "id", value = "列表中的id", required = true, dataType = "Long"),
             @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
     })
-    public ResultUtil cancelMyWorldCup(Long id){
+    public ResultUtil cancelMyWorldCup(Long id) throws Exception {
         return worldCupPaymentService.cancelMyWorldCup(id);
     }
 
@@ -895,7 +941,7 @@
      */
     @ResponseBody
     @PostMapping("/worldCup/cancelWorldCupRefund")
-    public void cancelWorldCupRefund(@RequestBody Integer id){
+    public void cancelWorldCupRefund(@RequestBody Integer id) throws Exception {
         worldCupService.cancelWorldCupRefund(id);
     }
 
@@ -941,6 +987,54 @@
             out.close();
         }
     }
+    /**
+     * 取消赛事后微信退款回调微信V3回调
+     * @param request
+     * @param response
+     */
+    @ResponseBody
+    @PostMapping("/base/worldCup/wxRefundWorldCupCallback1")
+    public void wxRefundWorldCupCallback1(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 transaction_id = jsonInfo.getString("transaction_id");
+            String refund_status = jsonInfo.getString("refund_status");
+            String out_refund_no = jsonInfo.getString("out_refund_no");
+            if (refund_status.equals("SUCCESS")) {
+                WorldCupPayment worldCupPayment = worldCupPaymentService.getOne(new QueryWrapper<WorldCupPayment>().eq("code", out_refund_no));
+                worldCupPayment.setRefundOrderNo(code);
+                worldCupPayment.setRefundTime(new Date());
+                worldCupPayment.setPayStatus(3);
+                worldCupPayment.setWorldCupId(null);
+                worldCupPaymentService.updateById(worldCupPayment);
+                PrintWriter out = response.getWriter();
+                out.write("SUCCESS");
+                out.flush();
+                out.close();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
 
     /**

--
Gitblit v1.7.1