From 8444084e6aa11efa23287e7f82474ac22378a5c4 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期二, 01 四月 2025 16:03:19 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java | 30 +++++++++++++++++++++++------- 1 files changed, 23 insertions(+), 7 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 6e3df59..6574ab5 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 @@ -14,6 +14,9 @@ import com.google.gson.GsonBuilder; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.redis.service.RedisService; +import com.ruoyi.order.domain.dto.WechatPaymentRefundDto; +import com.ruoyi.order.domain.dto.WeixinPaymentNotifyDto; import com.ruoyi.order.domain.pojo.account.OrderRefund; import com.ruoyi.order.domain.vo.ProfitSharingNotifyNewResult; import com.ruoyi.order.domain.vo.WeixinPaymentNotifyVo; @@ -36,12 +39,14 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; +import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.util.Collection; import java.util.Enumeration; import java.util.Map; import java.util.Objects; +import java.util.concurrent.TimeUnit; /** * @program: ruoyi @@ -73,6 +78,9 @@ @Resource private OrderRefundService orderRefundService; + @Resource + private RedisService redisService; + @PostMapping(value = "/payNotify") @ApiOperation(value = "微信支付/退款通知") public String payNotify(@RequestBody String notifyData, HttpServletRequest request, HttpServletResponse response) throws WxPayException { @@ -94,7 +102,7 @@ PartnerTransactionsResult result = notifyResult.getResult(); // 支付通知回调 if ("SUCCESS".equals(result.getTradeState())) { - orderService.payBack(result); + orderService.payBack(result, BigDecimal.ONE); } resultMessage = GSON.toJson(notifyResult); } else if (WxPayNotifyEventTypeEnum.REFUND_SUCCESS.getCode().equals(eventType) @@ -229,16 +237,24 @@ @RequestMapping(value = "/wechatPaymentCallback", method = RequestMethod.POST) @ApiOperation(value = "微信支付通知(汇付天下)") - public void wechatPaymentCallback(@RequestBody JSONObject jsonObject, HttpServletResponse response){ - R<WeixinPaymentNotifyVo> r = HuiFuTianXiaUtil.weixinPaymentNotify(jsonObject); + public void wechatPaymentCallback(WeixinPaymentNotifyDto dto, HttpServletResponse response){ + R<WeixinPaymentNotifyVo> r = HuiFuTianXiaUtil.weixinPaymentNotify(dto); if(r.getCode() == 200){ WeixinPaymentNotifyVo data = r.getData(); String transStat = data.getTransStat(); if("S".equals(transStat)){ PartnerTransactionsResult transaction = new PartnerTransactionsResult(); transaction.setOutTradeNo(data.getReqSeqId()); + + //防止回调频繁导致时间处理异常 + Object cacheObject = redisService.getCacheObject(data.getReqSeqId()); + if(null == cacheObject){ + redisService.setCacheObject(data.getReqSeqId(), "", 10L, TimeUnit.SECONDS); + }else{ + return; + } //开始处理业务数据 - orderService.payBack(transaction); + orderService.payBack(transaction, data.getFeeFlag() == 1 ? BigDecimal.ZERO : new BigDecimal(data.getFeeAmount())); response.setStatus(200); PrintWriter out = null; @@ -260,8 +276,8 @@ @RequestMapping(value = "/wechatPaymentRefundCallback", method = RequestMethod.POST) @ApiOperation(value = "微信支付退款通知(汇付天下)") - public void wechatPaymentRefundCallback(@RequestBody JSONObject jsonObject, HttpServletResponse response){ - R<WeixinPaymentRefundVo> r = HuiFuTianXiaUtil.weixinPaymentRefundNotify(jsonObject); + public void wechatPaymentRefundCallback(WechatPaymentRefundDto dto, HttpServletResponse response){ + R<WeixinPaymentRefundVo> r = HuiFuTianXiaUtil.weixinPaymentRefundNotify(dto); if(r.getCode() == 200){ WeixinPaymentRefundVo data = r.getData(); String transStat = data.getTransStat(); @@ -269,7 +285,7 @@ //开始处理业务数据 String reqSeqId = data.getReqSeqId(); OrderRefund orderRefund = orderRefundService.getById(reqSeqId); - if(null != orderRefund){ + if(null != orderRefund && orderRefund.getRefundStatus() != 2){ orderRefund.setWxRefundId(data.getPartyOrderId()); orderRefund.setBackTime(data.getTransDate() + data.getTransTime()); orderRefund.setRefundStatus(2); -- Gitblit v1.7.1