From 40f61c07405e4d44c499fa86ae5f8a087a37a1c6 Mon Sep 17 00:00:00 2001 From: bootx Date: Fri, 9 Feb 2024 20:42:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=94=AF=E4=BB=98=E5=AE=9D=E9=80=80?= =?UTF-8?q?=E6=AC=BE=E6=B2=A1=E6=9C=89=E7=BD=91=E5=85=B3=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E5=BE=AE=E4=BF=A1=E5=9B=9E=E8=B0=83=E9=80=80?= =?UTF-8?q?=E6=AC=BE=E7=8A=B6=E6=80=81=E9=83=A8=E5=88=86=E5=9C=BA=E5=90=88?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/controller/DaxPayCashierController.java | 6 +++--- .../demo/service/DaxPayCashierService.java | 6 +++--- .../service/common/context/CallbackLocal.java | 4 ++++ .../service/common/context/PaySyncLocal.java | 3 --- .../alipay/service/AliPayCallbackService.java | 5 ++--- .../alipay/service/AliPaySyncService.java | 3 +-- .../wechat/service/WeChatPayCallbackService.java | 5 +++-- .../sync/service/PayRefundSyncService.java | 3 --- .../daxpay/service/func/AbsCallbackStrategy.java | 16 +++++++--------- 9 files changed, 23 insertions(+), 28 deletions(-) diff --git a/daxpay-single-demo/src/main/java/cn/bootx/platform/daxpay/demo/controller/DaxPayCashierController.java b/daxpay-single-demo/src/main/java/cn/bootx/platform/daxpay/demo/controller/DaxPayCashierController.java index ef0d198a3..b9bba9332 100644 --- a/daxpay-single-demo/src/main/java/cn/bootx/platform/daxpay/demo/controller/DaxPayCashierController.java +++ b/daxpay-single-demo/src/main/java/cn/bootx/platform/daxpay/demo/controller/DaxPayCashierController.java @@ -32,8 +32,8 @@ public class DaxPayCashierController { } @Operation(summary = "查询支付订单") - @GetMapping("/queryPayOrder") - public ResResult queryPayOrder(Long paymentId){ - return Res.ok(cashierService.queryPayOrder(paymentId)); + @GetMapping("/queryPayOrderSuccess") + public ResResult queryPayOrder(String businessNo){ + return Res.ok(cashierService.queryPayOrderSuccess(businessNo)); } } diff --git a/daxpay-single-demo/src/main/java/cn/bootx/platform/daxpay/demo/service/DaxPayCashierService.java b/daxpay-single-demo/src/main/java/cn/bootx/platform/daxpay/demo/service/DaxPayCashierService.java index 56895ae14..82d46a53c 100644 --- a/daxpay-single-demo/src/main/java/cn/bootx/platform/daxpay/demo/service/DaxPayCashierService.java +++ b/daxpay-single-demo/src/main/java/cn/bootx/platform/daxpay/demo/service/DaxPayCashierService.java @@ -105,11 +105,11 @@ public class DaxPayCashierService { } /** - * 订单查询接口 + * 查询订单是否支付成功 */ - public boolean queryPayOrder(Long paymentId){ + public boolean queryPayOrderSuccess(String businessNo){ QueryPayOrderParam queryPayOrderParam = new QueryPayOrderParam(); - queryPayOrderParam.setPaymentId(paymentId); + queryPayOrderParam.setBusinessNo(businessNo); DaxPayResult execute = DaxPayKit.execute(queryPayOrderParam); if (execute.getCode() != 0){ throw new BizException(execute.getMsg()); diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/CallbackLocal.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/CallbackLocal.java index 43b4fce39..0db14f1ab 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/CallbackLocal.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/CallbackLocal.java @@ -3,6 +3,7 @@ package cn.bootx.platform.daxpay.service.common.context; import cn.bootx.platform.daxpay.code.RefundStatusEnum; import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.service.code.PayCallbackStatusEnum; +import cn.bootx.platform.daxpay.service.code.PaymentTypeEnum; import lombok.Data; import lombok.experimental.Accessors; @@ -46,6 +47,9 @@ public class CallbackLocal { /** 修复号 */ private String payRepairNo; + /** 回调类型 */ + private PaymentTypeEnum callbackType; + /** * 回调处理状态 * @see PayCallbackStatusEnum diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/PaySyncLocal.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/PaySyncLocal.java index b1cb924d7..4b0f44144 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/PaySyncLocal.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/PaySyncLocal.java @@ -3,8 +3,6 @@ package cn.bootx.platform.daxpay.service.common.context; import lombok.Data; import lombok.experimental.Accessors; -import java.time.LocalDateTime; - /** * 支付同步信息 * @author xxm @@ -14,5 +12,4 @@ import java.time.LocalDateTime; @Accessors(chain = true) public class PaySyncLocal { - } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCallbackService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCallbackService.java index fcaaef466..caca6964a 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCallbackService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCallbackService.java @@ -110,15 +110,14 @@ public class AliPayCallbackService extends AbsCallbackStrategy { /** * 解析退款回调数据并放到上下文中 + * 注意: 支付宝退款没有网关订单号, 网关订单号是支付单的 */ @Override public void resolveRefundData() { CallbackLocal callback = PaymentContextLocal.get().getCallbackInfo(); Map callbackParam = callback.getCallbackParam(); - // 网关订单号 - callback.setGatewayOrderNo(callbackParam.get(OUT_BIZ_NO)); // 退款订单Id - callback.setOrderId(Long.valueOf(callbackParam.get(OUT_TRADE_NO))); + callback.setOrderId(Long.valueOf(callbackParam.get(OUT_BIZ_NO))); // 退款状态 callback.setGatewayStatus(callbackParam.get(TRADE_STATUS)); // 退款金额 diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPaySyncService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPaySyncService.java index 3703288bb..f96ec54b9 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPaySyncService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPaySyncService.java @@ -94,6 +94,7 @@ public class AliPaySyncService { /** * 退款同步查询 + * 注意: 支付宝退款没有网关订单号, 网关订单号是支付单的 */ public RefundGatewaySyncResult syncRefundStatus(PayRefundOrder refundOrder) { RefundGatewaySyncResult syncResult = new RefundGatewaySyncResult().setSyncStatus(RefundSyncStatusEnum.FAIL); @@ -115,8 +116,6 @@ public class AliPaySyncService { return syncResult; } String tradeStatus = response.getRefundStatus(); - // 设置网关订单号 - syncResult.setGatewayOrderNo(response.getTradeNo()); // 成功 if (Objects.equals(tradeStatus, AliPayCode.REFUND_SUCCESS)){ LocalDateTime localDateTime = LocalDateTimeUtil.of(response.getGmtRefundPay()); diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCallbackService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCallbackService.java index e985c675c..ab03eff6a 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCallbackService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCallbackService.java @@ -51,7 +51,8 @@ public class WeChatPayCallbackService extends AbsCallbackStrategy { */ @Override public boolean verifyNotify() { - Map params = PaymentContextLocal.get().getCallbackInfo().getCallbackParam(); + CallbackLocal callbackInfo = PaymentContextLocal.get().getCallbackInfo(); + Map params = callbackInfo.getCallbackParam(); String callReq = JSONUtil.toJsonStr(params); log.info("微信发起回调 报文: {}", callReq); String appId = params.get(APPID); @@ -62,7 +63,7 @@ public class WeChatPayCallbackService extends AbsCallbackStrategy { } // 退款回调不用进行校验 - PaymentTypeEnum callbackType = this.getCallbackType(); + PaymentTypeEnum callbackType = callbackInfo.getCallbackType(); if (callbackType == PaymentTypeEnum.REFUND){ return true; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/service/PayRefundSyncService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/service/PayRefundSyncService.java index c91949cb4..d451b6224 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/service/PayRefundSyncService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/service/PayRefundSyncService.java @@ -64,12 +64,10 @@ public class PayRefundSyncService { } // 如果不是异步支付, 直接返回返回 if (!refundOrder.isAsyncPay()){ -// return new SyncResult().setSuccess(false).setRepair(false).setErrorMsg("订单没有异步通道的退款,不需要同步"); throw new PayFailureException("订单没有异步通道的退款,不需要同步"); } // 如果订单已经关闭, 直接返回失败 if (Objects.equals(refundOrder.getStatus(), RefundStatusEnum.CLOSE.getCode())){ -// return new SyncResult().setSuccess(false).setRepair(false). setErrorMsg("订单已经关闭,不需要同步"); throw new PayFailureException("订单已经关闭,不需要同步"); } return this.syncRefundOrder(refundOrder); @@ -97,7 +95,6 @@ public class PayRefundSyncService { // 判断是否同步成功 if (Objects.equals(syncResult.getSyncStatus(), RefundSyncStatusEnum.FAIL)) { // 同步失败, 返回失败响应, 同时记录失败的日志 -// return new SyncResult().setErrorMsg(syncResult.getErrorMsg()); this.saveRecord(refundOrder, syncResult, false, null, syncResult.getErrorMsg()); throw new PayFailureException(syncResult.getErrorMsg()); } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsCallbackStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsCallbackStrategy.java index c84de2eb1..807bf2338 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsCallbackStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsCallbackStrategy.java @@ -14,7 +14,6 @@ import lombok.extern.slf4j.Slf4j; import javax.annotation.Resource; import java.util.Map; -import java.util.Optional; /** * 回调处理抽象类, 处理支付回调和退款回调 @@ -40,6 +39,11 @@ public abstract class AbsCallbackStrategy implements PayStrategy { try { // 将参数写入到上下文中 callbackInfo.getCallbackParam().putAll(params); + + // 判断并保存回调类型 + PaymentTypeEnum callbackType = this.getCallbackType(); + callbackInfo.setCallbackType(callbackType); + // 验证消息 if (!this.verifyNotify()) { callbackInfo.setCallbackStatus(PayCallbackStatusEnum.FAIL).setMsg("验证信息格式不通过"); @@ -50,8 +54,7 @@ public abstract class AbsCallbackStrategy implements PayStrategy { // 提前设置订单修复的来源 PaymentContextLocal.get().getRepairInfo().setSource(PayRepairSourceEnum.CALLBACK); - // 判断回调类型 - PaymentTypeEnum callbackType = this.getCallbackType(); + if (callbackType == PaymentTypeEnum.PAY){ // 解析支付数据并放处理 this.resolvePayData(); @@ -103,17 +106,12 @@ public abstract class AbsCallbackStrategy implements PayStrategy { public void saveCallbackRecord() { CallbackLocal callbackInfo = PaymentContextLocal.get().getCallbackInfo(); - // 回调类型 - String callbackType = Optional.ofNullable(this.getCallbackType()) - .map(PaymentTypeEnum::getCode) - .orElse(null); - PayCallbackRecord payNotifyRecord = new PayCallbackRecord() .setChannel(this.getChannel().getCode()) .setNotifyInfo(JSONUtil.toJsonStr(callbackInfo.getCallbackParam())) .setOrderId(callbackInfo.getOrderId()) .setGatewayOrderNo(callbackInfo.getGatewayOrderNo()) - .setCallbackType(callbackType) + .setCallbackType(callbackInfo.getCallbackType().getCode()) .setRepairOrderNo(callbackInfo.getPayRepairNo()) .setStatus(callbackInfo.getCallbackStatus().getCode()) .setMsg(callbackInfo.getMsg());