From 6d38269cb3edbd183b5529186a84977f05b8cb96 Mon Sep 17 00:00:00 2001 From: nws <3239709711@qq.com> Date: Thu, 4 Jan 2024 00:22:49 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E8=81=94=E8=B0=83,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alipay/service/AliPayCloseService.java | 2 +- .../alipay/service/AliPayOrderService.java | 1 + .../wechat/entity/WeChatPayConfig.java | 42 +------------------ .../channel/wechat/entity/WeChatPayOrder.java | 2 +- .../wechat/service/WeChatPayCloseService.java | 2 +- .../service/WeChatPayConfigService.java | 4 +- .../pay/strategy/WeChatPayStrategy.java | 21 +++++----- .../strategy/WeChatPayRefundStrategy.java | 1 - .../repair/service/PayRepairService.java | 1 + .../channel/wechat/WeChatPayConfigDto.java | 18 +------- .../channel/wechat/WeChatPayConfigParam.java | 27 +----------- 11 files changed, 20 insertions(+), 101 deletions(-) diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCloseService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCloseService.java index 6eaf8900a..c3bd8e5ee 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCloseService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCloseService.java @@ -31,7 +31,7 @@ public class AliPayCloseService { * 交易关闭: 只有订单在未支付的状态下才可以进行关闭, 商户不需要额外申请就有此接口的权限 * 交易撤销: 如果用户支付成功,会将此订单资金退还给用户. 限制时间为1天,过了24小时,该接口无法再使用。可以视为一个特殊的接口, 需要专门签约这个接口的权限 * - * TODO 如果返回已经关闭, 也视为关闭成功 + * TODO 如果返回已经关闭, 也视为关闭成功, 考虑如果关闭识别, 查询一下网关的状态进行对比 */ @Retryable(value = RetryableException.class) public void close(PayOrder payOrder) { diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayOrderService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayOrderService.java index 62e64f7a7..8e98db3ca 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayOrderService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayOrderService.java @@ -81,6 +81,7 @@ public class AliPayOrderService { .setRefundableBalance(amount) .setBusinessNo(payOrder.getBusinessNo()) .setStatus(PayStatusEnum.SUCCESS.getCode()) + // 读取回调中的支付时间 .setPayTime(LocalDateTime.now()); aliPayOrderManager.save(aliPayOrder); } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/entity/WeChatPayConfig.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/entity/WeChatPayConfig.java index 05f70c890..ec2adc068 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/entity/WeChatPayConfig.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/entity/WeChatPayConfig.java @@ -5,14 +5,11 @@ import cn.bootx.platform.common.core.annotation.EncryptionField; import cn.bootx.platform.common.core.function.EntityBaseFunction; import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity; import cn.bootx.platform.common.mybatisplus.handler.StringListTypeHandler; -import cn.bootx.platform.daxpay.service.code.WeChatPayCode; import cn.bootx.platform.daxpay.service.core.channel.wechat.convert.WeChatConvert; import cn.bootx.platform.daxpay.service.dto.channel.wechat.WeChatPayConfigDto; -import cn.bootx.platform.daxpay.service.param.channel.wechat.WeChatPayConfigParam; import cn.bootx.table.modify.annotation.DbColumn; import cn.bootx.table.modify.annotation.DbTable; import cn.bootx.table.modify.mysql.annotation.DbMySqlFieldType; -import cn.bootx.table.modify.mysql.annotation.DbMySqlIndex; import cn.bootx.table.modify.mysql.constants.MySqlFieldTypeEnum; import com.baomidou.mybatisplus.annotation.FieldStrategy; import com.baomidou.mybatisplus.annotation.TableField; @@ -36,21 +33,6 @@ import java.util.List; @TableName(value = "pay_wechat_pay_config",autoResultMap = true) public class WeChatPayConfig extends MpBaseEntity implements EntityBaseFunction { - /** 名称 */ - @DbColumn(comment = "名称") - private String name; - - /** 商户编码 */ - @TableField(updateStrategy = FieldStrategy.NEVER) - @DbColumn(comment = "商户编码") - private String mchCode; - - /** 商户应用编码 */ - @TableField(updateStrategy = FieldStrategy.NEVER) - @DbMySqlIndex(comment = "商户应用编码唯一索引") - @DbColumn(comment = "商户应用编码") - private String mchAppCode; - /** 微信商户Id */ @DbColumn(comment = "微信商户号") private String wxMchId; @@ -59,13 +41,6 @@ public class WeChatPayConfig extends MpBaseEntity implements EntityBaseFunction< @DbColumn(comment = "微信应用appId") private String wxAppId; - /** - * api版本 - * @see WeChatPayCode#API_V2 - */ - @DbColumn(comment = "api版本") - private String apiVersion; - /** 商户平台「API安全」中的 APIv2 密钥 */ @TableField(updateStrategy = FieldStrategy.ALWAYS) @BigField @@ -94,22 +69,14 @@ public class WeChatPayConfig extends MpBaseEntity implements EntityBaseFunction< @DbColumn(comment = "API证书中p12证书Base64") private String p12; - /** 服务器异步通知页面路径 通知url必须为直接可访问的url,不能携带参数。公网域名必须为https */ - @DbColumn(comment = "异步通知页面") + /** 这个是跳转到当前网关服务上的, 不是通知到客户系统的 */ + @DbColumn(comment = "异步通知路径") private String notifyUrl; - /** 页面跳转同步通知页面路径 */ - @DbColumn(comment = "同步通知页面") - private String returnUrl; - /** 是否沙箱环境 */ @DbColumn(comment = "是否沙箱环境") private boolean sandbox; - /** 超时时间(分钟) */ - @DbColumn(comment = "超时时间(分钟)") - private Integer expireTime; - /** 可用支付方式 */ @DbColumn(comment = "可用支付方式") @DbMySqlFieldType(MySqlFieldTypeEnum.LONGTEXT) @@ -124,9 +91,4 @@ public class WeChatPayConfig extends MpBaseEntity implements EntityBaseFunction< public WeChatPayConfigDto toDto() { return WeChatConvert.CONVERT.convert(this); } - - public static WeChatPayConfig init(WeChatPayConfigParam in) { - return WeChatConvert.CONVERT.convert(in); - } - } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/entity/WeChatPayOrder.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/entity/WeChatPayOrder.java index d8471feaa..92945eacf 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/entity/WeChatPayOrder.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/entity/WeChatPayOrder.java @@ -18,7 +18,7 @@ import lombok.experimental.Accessors; @Data @DbTable(comment = "微信支付记录") @Accessors(chain = true) -@TableName("pay_wechat_payment") +@TableName("pay_wechat_pay_order") public class WeChatPayOrder extends BasePayOrder implements EntityBaseFunction { /** diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCloseService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCloseService.java index 2236975dd..bb894e42b 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCloseService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCloseService.java @@ -32,7 +32,7 @@ import java.util.Optional; public class WeChatPayCloseService { /** - * 关闭支付 + * 关闭支付, 微信对已经关闭的支付单也可以重复关闭 */ @Retryable(value = RetryableException.class) public void close(PayOrder payOrder, WeChatPayConfig weChatPayConfig) { diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayConfigService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayConfigService.java index 6988f7225..9eea83297 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayConfigService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayConfigService.java @@ -36,9 +36,7 @@ public class WeChatPayConfigService { */ @Transactional(rollbackFor = Exception.class) public void update(WeChatPayConfigParam param) { - WeChatPayConfig weChatPayConfig = weChatPayConfigManager.findById(ID) - .orElseThrow(() -> new PayFailureException("微信支付配置不存在")); - param.setActivity(null); + WeChatPayConfig weChatPayConfig = weChatPayConfigManager.findById(ID).orElseThrow(() -> new PayFailureException("微信支付配置不存在")); BeanUtil.copyProperties(param, weChatPayConfig, CopyOptions.create().ignoreNullValue()); weChatPayConfigManager.updateById(weChatPayConfig); } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WeChatPayStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WeChatPayStrategy.java index 82d6e34d2..a39b61c63 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WeChatPayStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WeChatPayStrategy.java @@ -1,18 +1,17 @@ package cn.bootx.platform.daxpay.service.core.payment.pay.strategy; import cn.bootx.platform.daxpay.code.PayChannelEnum; -import cn.bootx.platform.daxpay.service.common.exception.ExceptionInfo; -import cn.bootx.platform.daxpay.service.core.channel.wechat.dao.WeChatPayConfigManager; -import cn.bootx.platform.daxpay.service.core.channel.wechat.entity.WeChatPayConfig; -import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayCloseService; -import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayOrderService; -import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayService; -import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPaySyncService; import cn.bootx.platform.daxpay.exception.pay.PayAmountAbnormalException; import cn.bootx.platform.daxpay.exception.pay.PayFailureException; +import cn.bootx.platform.daxpay.param.pay.PayWayParam; +import cn.bootx.platform.daxpay.service.common.exception.ExceptionInfo; +import cn.bootx.platform.daxpay.service.core.channel.wechat.entity.WeChatPayConfig; +import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayCloseService; +import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayConfigService; +import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayOrderService; +import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayService; import cn.bootx.platform.daxpay.service.func.AbsPayStrategy; import cn.bootx.platform.daxpay.service.param.channel.wechat.WeChatPayParam; -import cn.bootx.platform.daxpay.param.pay.PayWayParam; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONException; import cn.hutool.json.JSONUtil; @@ -33,7 +32,7 @@ import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROT @RequiredArgsConstructor public class WeChatPayStrategy extends AbsPayStrategy { - private final WeChatPayConfigManager weChatPayConfigManager; + private final WeChatPayConfigService weChatPayConfigService; private final WeChatPayService weChatPayService; @@ -41,8 +40,6 @@ public class WeChatPayStrategy extends AbsPayStrategy { private final WeChatPayCloseService weChatPayCloseService; - private final WeChatPaySyncService weChatPaySyncService; - private WeChatPayConfig weChatPayConfig; private WeChatPayParam weChatPayParam; @@ -60,6 +57,7 @@ public class WeChatPayStrategy extends AbsPayStrategy { */ @Override public void doBeforePayHandler() { + this.initWeChatPayConfig(); try { // 微信参数验证 String extraParamsJson = this.getPayWayParam().getChannelExtra(); @@ -122,6 +120,7 @@ public class WeChatPayStrategy extends AbsPayStrategy { * 初始化微信支付 */ private void initWeChatPayConfig() { + this.weChatPayConfig = weChatPayConfigService.getConfig(); } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WeChatPayRefundStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WeChatPayRefundStrategy.java index eee2646fa..bf416d480 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WeChatPayRefundStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WeChatPayRefundStrategy.java @@ -57,7 +57,6 @@ public class WeChatPayRefundStrategy extends AbsPayRefundStrategy { wechatRefundService.refund(this.getOrder(), this.getChannelParam().getAmount(), this.weChatPayConfig); weChatPayOrderService.updateRefund(this.getOrder().getId(), this.getChannelParam().getAmount()); payOrderService.updateRefundSuccess(this.getOrder(), this.getChannelParam().getAmount(), PayChannelEnum.WECHAT); - } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/PayRepairService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/PayRepairService.java index c46f9a3e1..1ab0a0b31 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/PayRepairService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/PayRepairService.java @@ -72,6 +72,7 @@ public class PayRepairService { // 修改订单支付状态为成功 payment.setStatus(PayStatusEnum.SUCCESS.getCode()); + // TODO 读取支付网关中的时间 payment.setPayTime(LocalDateTime.now()); payOrderService.updateById(payment); } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/channel/wechat/WeChatPayConfigDto.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/channel/wechat/WeChatPayConfigDto.java index fd17e5b81..cea3f85a6 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/channel/wechat/WeChatPayConfigDto.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/channel/wechat/WeChatPayConfigDto.java @@ -1,7 +1,6 @@ package cn.bootx.platform.daxpay.service.dto.channel.wechat; import cn.bootx.platform.common.core.rest.dto.BaseDto; -import cn.bootx.platform.daxpay.service.code.WeChatPayCode; import cn.bootx.platform.starter.data.perm.sensitive.SensitiveInfo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -21,9 +20,6 @@ import java.util.List; @Schema(title = "微信支付配置") public class WeChatPayConfigDto extends BaseDto implements Serializable { - @Schema(description = "名称") - private String name; - @Schema(description = "微信商户号") @SensitiveInfo private String wxMchId; @@ -32,12 +28,6 @@ public class WeChatPayConfigDto extends BaseDto implements Serializable { @SensitiveInfo private String wxAppId; - /** - * @see WeChatPayCode#API_V2 - */ - @Schema(description = "api版本") - private String apiVersion; - @Schema(description = "商户平台「API安全」中的 APIv2 密钥") @SensitiveInfo private String apiKeyV2; @@ -57,17 +47,11 @@ public class WeChatPayConfigDto extends BaseDto implements Serializable { @Schema(description = "服务器异步通知页面路径 通知url必须为直接可访问的url,不能携带参数。公网域名必须为https ") private String notifyUrl; - @Schema(description = "页面跳转同步通知页面路径") - private String returnUrl; - @Schema(description = "是否沙箱环境") private boolean sandbox; - @Schema(description = "超时时间(分钟)") - private Integer expireTime; - @Schema(description = "可用支付方式") - private List payWayList; + private List payWays; @Schema(description = "是否启用") private Boolean activity; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/param/channel/wechat/WeChatPayConfigParam.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/param/channel/wechat/WeChatPayConfigParam.java index c1ecf5e1a..0908430ba 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/param/channel/wechat/WeChatPayConfigParam.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/param/channel/wechat/WeChatPayConfigParam.java @@ -1,7 +1,6 @@ package cn.bootx.platform.daxpay.service.param.channel.wechat; import cn.bootx.platform.common.core.annotation.QueryParam; -import cn.bootx.platform.daxpay.service.code.WeChatPayCode; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.experimental.Accessors; @@ -20,27 +19,12 @@ import java.util.List; @Schema(title = "微信支付配置参数") public class WeChatPayConfigParam { - @Schema(description = "名称") - private String name; - - @Schema(description = "商户编码") - private String mchCode; - - @Schema(description = "商户应用编码") - private String mchAppCode; - @Schema(description = "微信商户号") private String wxMchId; @Schema(description = "微信应用appId") private String wxAppId; - /** - * @see WeChatPayCode#API_V2 - */ - @Schema(description = "api版本") - private String apiVersion; - @Schema(description = "商户平台「API安全」中的 APIv2 密钥") private String apiKeyV2; @@ -56,20 +40,11 @@ public class WeChatPayConfigParam { @Schema(description = "服务器异步通知页面路径 通知url必须为直接可访问的url,不能携带参数。公网域名必须为https ") private String notifyUrl; - @Schema(description = "页面跳转同步通知页面路径") - private String returnUrl; - @Schema(description = "是否沙箱环境") private boolean sandbox; - @Schema(description = "超时时间(分钟)") - private Integer expireTime; - @Schema(description = "可用支付方式") - private List payWayList; - - @Schema(description = "是否启用") - private Boolean activity; + private List payWays; @Schema(description = "状态") private String state;