From 7e2eb8af7459da7a03a23606651dfbfb5a5f2cee Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期一, 29 十二月 2025 16:12:31 +0800
Subject: [PATCH] 文档调整

---
 ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/WxPayController.java |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 103 insertions(+), 0 deletions(-)

diff --git a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/WxPayController.java b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/WxPayController.java
index d8f3d6f..b3ca4a9 100644
--- a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/WxPayController.java
+++ b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/WxPayController.java
@@ -7,7 +7,10 @@
 import com.ruoyi.common.utils.CodeGenerateUtils;
 import com.ruoyi.framework.web.service.TokenService;
 import com.ruoyi.system.model.TCourseOrder;
+import com.ruoyi.system.model.TInsurance;
+import com.ruoyi.system.model.TInsuranceOrder;
 import com.ruoyi.system.service.TCourseOrderService;
+import com.ruoyi.system.service.TInsuranceOrderService;
 import com.ruoyi.system.wxPay.enums.RefundEnum;
 import com.ruoyi.system.wxPay.enums.TradeStateEnum;
 import com.ruoyi.system.wxPay.model.WeixinPayProperties;
@@ -28,6 +31,8 @@
 import java.io.PrintWriter;
 import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
+import java.time.LocalDateTime;
+import java.util.Date;
 import java.util.Map;
 import java.util.Objects;
 
@@ -49,6 +54,9 @@
 
     @Autowired
     private TCourseOrderService courseOrderService;
+
+    @Autowired
+    private TInsuranceOrderService tInsuranceOrderService;
 
 
 
@@ -90,6 +98,55 @@
                 order.setPayTime(WxTimeUtils.dateToLocalDateTime(WxTimeUtils.toRfc3339Date(success_time)));
                 order.setTransactionId(transaction_id);
                 courseOrderService.updateById(order);
+
+                PrintWriter out = response.getWriter();
+                out.print("SUCCESS");
+                out.flush();
+                out.close();
+            }
+        } catch (Exception e) {
+            log.error("支付回调异常:{}", e, e);
+            wxV3Pay.ack(false, e.getMessage());
+        }
+    }
+    /**
+     * 支付回调
+     */
+    @PostMapping("pay/notifyInsurance")
+    @ApiOperation("保险订单回调")
+    public void notifyInsurance(HttpServletRequest request, HttpServletResponse response) throws Exception {
+        try {
+            System.err.println("微信回调");
+            BufferedReader reader = request.getReader();
+            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(weixinPayProperties.getV3().getApiKey().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.parse(decryptedData);
+            String out_trade_no = jsonInfo.getString("out_trade_no");
+            String transaction_id = jsonInfo.getString("transaction_id");
+            String trade_state = jsonInfo.getString("trade_state");
+            String success_time = jsonInfo.getString("success_time");
+            // 查询订单
+
+            TInsuranceOrder order = tInsuranceOrderService.getOne(Wrappers.lambdaQuery(TInsuranceOrder.class)
+                    .eq(TInsuranceOrder::getPayNo, out_trade_no).last("LIMIT 1"));
+            if (trade_state.equals(TradeStateEnum.SUCCESS.name())) {
+                log.info("回调成功");
+                // 订单号查询订单
+                order.setStatus(2);
+                order.setPayTime(LocalDateTime.now());
+                order.setTransactionId(transaction_id);
+                tInsuranceOrderService.updateById(order);
 
                 PrintWriter out = response.getWriter();
                 out.print("SUCCESS");
@@ -168,4 +225,50 @@
             wxV3Pay.ack(false, "不是成功的退款状态");
         }
     }
+
+
+    @PostMapping("refund/notifyInsurance")
+    public void notifyInsurance(HttpServletRequest request) throws IOException {
+        try {
+
+            System.err.println("微信退款回调");
+            BufferedReader reader = request.getReader();
+            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(weixinPayProperties.getV3().getApiKey().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 params = JSONObject.parseObject(decryptedData);
+
+            // 商户订单号
+            String out_trade_no = params.get("out_trade_no").toString();
+            // 商户退款单号
+            String out_refund_no = params.get("out_refund_no").toString();
+            // 退款状态
+            String tradeState = params.get("refund_status").toString();
+            // 微信支付订单号
+            String transaction_id = params.get("transaction_id").toString();
+            if (tradeState.equals(RefundEnum.SUCCESS.name())) {
+                TInsuranceOrder order = tInsuranceOrderService.getOne(Wrappers.lambdaQuery(TInsuranceOrder.class)
+                        .eq(TInsuranceOrder::getRefundNumber, out_refund_no).last("LIMIT 1"));
+                order.setStatus(1);
+                order.setRefundStatus(2);
+                order.setRefundTransactionId(transaction_id);
+                tInsuranceOrderService.updateById(order);
+
+                wxV3Pay.ack();
+            }
+        }catch (Exception e){
+            wxV3Pay.ack(false, "不是成功的退款状态");
+        }
+    }
 }

--
Gitblit v1.7.1