From da837b5a0e23b47bc1d038547702cab3cecce577 Mon Sep 17 00:00:00 2001
From: jiangqs <jiangqs>
Date: 星期六, 26 八月 2023 17:51:59 +0800
Subject: [PATCH] Merge branch 'master' of ssh://120.76.84.145:20202/java/HongRuiTang into master

---
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java
index c477d06..d1b2c7b 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java
@@ -88,13 +88,14 @@
                     || WxPayNotifyEventTypeEnum.REFUND_ABNORMAL.getCode().equals(eventType)
                     || WxPayNotifyEventTypeEnum.REFUND_CLOSED.getCode().equals(eventType)) {
 
-                RefundNotifyResult result = wxService.getEcommerceService().parseRefundNotifyResult(notifyData, signatureHeader);
+                RefundNotifyResult result = this.parseRefundNotifyResult(notifyData, signatureHeader);
                 orderService.orderRefundBack(result);
                 resultType = 2;
                 resultMessage = GSON.toJson(result);
             }
 
         }catch (Exception e){
+            e.printStackTrace();
             log.info("微信支付/退款通知异常:  {}", e.getMessage());
         }
         // 保存支付/退款回调信息
@@ -164,6 +165,24 @@
         }
     }
 
+    private RefundNotifyResult parseRefundNotifyResult(String notifyData, SignatureHeader header) throws WxPayException {
+
+        NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class);
+        NotifyResponse.Resource resource = response.getResource();
+        String cipherText = resource.getCiphertext();
+        String associatedData = resource.getAssociatedData();
+        String nonce = resource.getNonce();
+        String apiV3Key = this.wxService.getConfig().getApiV3Key();
+        try {
+            String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key);
+            RefundNotifyResult notifyResult = GSON.fromJson(result, RefundNotifyResult.class);
+            notifyResult.setRawData(response);
+            return notifyResult;
+        } catch (GeneralSecurityException | IOException e) {
+            throw new WxPayException("解析报文异常!", e);
+        }
+    }
+
     private boolean verifyNotifySign(SignatureHeader header, String data) throws WxPayException {
         String beforeSign = String.format("%s\n%s\n%s\n",
                 header.getTimeStamp(),

--
Gitblit v1.7.1