Commit 0f0e6eb8ba512d6c03af8e0ac033dff74d047514

Authored by jason
1 parent 60f766f3

Pay Client 新增转账接口

Showing 17 changed files with 405 additions and 0 deletions
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClient.java
@@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; @@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
4 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; 4 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
5 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; 5 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
6 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; 6 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
  7 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  8 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
7 9
8 import java.util.Map; 10 import java.util.Map;
9 11
@@ -76,4 +78,12 @@ public interface PayClient { @@ -76,4 +78,12 @@ public interface PayClient {
76 */ 78 */
77 PayRefundRespDTO getRefund(String outTradeNo, String outRefundNo); 79 PayRefundRespDTO getRefund(String outTradeNo, String outRefundNo);
78 80
  81 + /**
  82 + * 调用渠道,进行转账
  83 + *
  84 + * @param reqDTO 统一转账请求信息
  85 + * @return 转账信息
  86 + */
  87 + PayTransferRespDTO unifiedTransfer(PayTransferUnifiedReqDTO reqDTO);
  88 +
79 } 89 }
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferRespDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.pay.core.client.dto.transfer;
  2 +
  3 +import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferStatusRespEnum;
  4 +import lombok.Data;
  5 +
  6 +import java.time.LocalDateTime;
  7 +
  8 +/**
  9 + * 统一转账 Response DTO
  10 + *
  11 + * @author jason
  12 + */
  13 +@Data
  14 +public class PayTransferRespDTO {
  15 +
  16 + private Integer status;
  17 +
  18 + /**
  19 + * 外部转账单号
  20 + *
  21 + */
  22 + private String outTransferNo;
  23 +
  24 + /**
  25 + * 支付渠道编号
  26 + */
  27 + private String channelOrderNo;
  28 +
  29 + /**
  30 + * 支付成功时间
  31 + */
  32 + private LocalDateTime successTime;
  33 +
  34 + /**
  35 + * 原始的返回结果
  36 + */
  37 + private Object rawData;
  38 +
  39 + /**
  40 + * 调用渠道的错误码
  41 + */
  42 + private String channelErrorCode;
  43 + /**
  44 + * 调用渠道报错时,错误信息
  45 + */
  46 + private String channelErrorMsg;
  47 +
  48 + /**
  49 + * 创建【WAITING】状态的转账返回
  50 + */
  51 + public static PayTransferRespDTO waitingOf(String channelOrderNo,
  52 + String outTransferNo, Object rawData) {
  53 + PayTransferRespDTO respDTO = new PayTransferRespDTO();
  54 + respDTO.status = PayTransferStatusRespEnum.WAITING.getStatus();
  55 + respDTO.channelOrderNo = channelOrderNo;
  56 + respDTO.outTransferNo = outTransferNo;
  57 + respDTO.rawData = rawData;
  58 + return respDTO;
  59 + }
  60 +
  61 + /**
  62 + * 创建【FAILURE】状态的转账返回
  63 + */
  64 + public static PayTransferRespDTO failureOf(String channelErrorCode, String channelErrorMsg,
  65 + String outTransferNo, Object rawData) {
  66 + PayTransferRespDTO respDTO = new PayTransferRespDTO();
  67 + respDTO.status = PayTransferStatusRespEnum.FAILURE.getStatus();
  68 + respDTO.channelErrorCode = channelErrorCode;
  69 + respDTO.channelErrorMsg = channelErrorMsg;
  70 + // 相对通用的字段
  71 + respDTO.outTransferNo = outTransferNo;
  72 + respDTO.rawData = rawData;
  73 + return respDTO;
  74 + }
  75 +
  76 + /**
  77 + * 创建【SUCCESS】状态的转账返回
  78 + */
  79 + public static PayTransferRespDTO successOf(String channelTransferNo, LocalDateTime successTime,
  80 + String outTransferNo, Object rawData) {
  81 + PayTransferRespDTO respDTO = new PayTransferRespDTO();
  82 + respDTO.status = PayTransferStatusRespEnum.SUCCESS.getStatus();
  83 + respDTO.channelOrderNo = channelTransferNo;
  84 + respDTO.successTime = successTime;
  85 + // 相对通用的字段
  86 + respDTO.outTransferNo = outTransferNo;
  87 + respDTO.rawData = rawData;
  88 + return respDTO;
  89 + }
  90 +
  91 +}
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferUnifiedReqDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.pay.core.client.dto.transfer;
  2 +
  3 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  4 +import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum;
  5 +import lombok.Data;
  6 +import org.hibernate.validator.constraints.Length;
  7 +
  8 +import javax.validation.constraints.Min;
  9 +import javax.validation.constraints.NotEmpty;
  10 +import javax.validation.constraints.NotNull;
  11 +import java.util.Map;
  12 +
  13 +/**
  14 + * 统一转账 Request DTO
  15 + *
  16 + * @author jason
  17 + */
  18 +@Data
  19 +public class PayTransferUnifiedReqDTO {
  20 +
  21 + /**
  22 + * 转账类型
  23 + *
  24 + * 关联 {@link PayTransferTypeEnum#getType()}
  25 + */
  26 + @NotNull(message = "转账类型不能为空")
  27 + @InEnum(PayTransferTypeEnum.class)
  28 + private Integer type;
  29 +
  30 + /**
  31 + * 用户 IP
  32 + */
  33 + @NotEmpty(message = "用户 IP 不能为空")
  34 + private String userIp;
  35 +
  36 + @NotEmpty(message = "外部转账单编号不能为空")
  37 + private String outTransferNo;
  38 +
  39 + /**
  40 + * 转账金额,单位:分
  41 + */
  42 + @NotNull(message = "转账金额不能为空")
  43 + @Min(value = 1, message = "转账金额必须大于零")
  44 + private Integer price;
  45 +
  46 + /**
  47 + * 转账标题
  48 + */
  49 + @NotEmpty(message = "转账标题不能为空")
  50 + @Length(max = 128, message = "转账标题不能超过 128")
  51 + private String title;
  52 +
  53 + /**
  54 + * 收款方信息,转账类型不同信息不同
  55 + */
  56 + @NotEmpty(message = "收款方信息 不能为空")
  57 + private Map<String, String> payeeInfo;
  58 +
  59 + /**
  60 + * 支付渠道的额外参数
  61 + *
  62 + */
  63 + private Map<String, String> channelExtras;
  64 +
  65 +}
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java
@@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; @@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
8 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; 8 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
9 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; 9 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
10 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; 10 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
  11 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  12 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
11 import cn.iocoder.yudao.framework.pay.core.client.exception.PayException; 13 import cn.iocoder.yudao.framework.pay.core.client.exception.PayException;
12 import lombok.extern.slf4j.Slf4j; 14 import lombok.extern.slf4j.Slf4j;
13 15
@@ -181,6 +183,26 @@ public abstract class AbstractPayClient&lt;Config extends PayClientConfig&gt; implemen @@ -181,6 +183,26 @@ public abstract class AbstractPayClient&lt;Config extends PayClientConfig&gt; implemen
181 protected abstract PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) 183 protected abstract PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo)
182 throws Throwable; 184 throws Throwable;
183 185
  186 + @Override
  187 + public final PayTransferRespDTO unifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
  188 + ValidationUtils.validate(reqDTO);
  189 + PayTransferRespDTO resp;
  190 + try{
  191 + resp = doUnifiedTransfer(reqDTO);
  192 + }catch (ServiceException ex) { // 业务异常,都是实现类已经翻译,所以直接抛出即可
  193 + throw ex;
  194 + } catch (Throwable ex) {
  195 + // 系统异常,则包装成 PayException 异常抛出
  196 + log.error("[unifiedTransfer][客户端({}) request({}) 发起转账异常]",
  197 + getId(), toJsonString(reqDTO), ex);
  198 + throw buildPayException(ex);
  199 + }
  200 + return resp;
  201 + }
  202 +
  203 + protected abstract PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO)
  204 + throws Throwable;
  205 +
184 // ========== 各种工具方法 ========== 206 // ========== 各种工具方法 ==========
185 207
186 private PayException buildPayException(Throwable ex) { 208 private PayException buildPayException(Throwable ex) {
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java
@@ -150,6 +150,10 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient&lt;AlipayPa @@ -150,6 +150,10 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient&lt;AlipayPa
150 // 2.1 执行请求 150 // 2.1 执行请求
151 AlipayTradeRefundResponse response = client.execute(request); 151 AlipayTradeRefundResponse response = client.execute(request);
152 if (!response.isSuccess()) { 152 if (!response.isSuccess()) {
  153 + // 当出现 ACQ.SYSTEM_ERROR, 退款可能成功也可能失败。 返回 WAIT 状态. 后续 job 会轮询
  154 + if (Objects.equals(response.getSubCode(), "ACQ.SYSTEM_ERROR")) {
  155 + return PayRefundRespDTO.waitingOf(null, reqDTO.getOutRefundNo(), response);
  156 + }
153 return PayRefundRespDTO.failureOf(response.getSubCode(), response.getSubMsg(), reqDTO.getOutRefundNo(), response); 157 return PayRefundRespDTO.failureOf(response.getSubCode(), response.getSubMsg(), reqDTO.getOutRefundNo(), response);
154 } 158 }
155 // 2.2 创建返回结果 159 // 2.2 创建返回结果
@@ -198,6 +202,8 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient&lt;AlipayPa @@ -198,6 +202,8 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient&lt;AlipayPa
198 return PayRefundRespDTO.waitingOf(null, outRefundNo, response); 202 return PayRefundRespDTO.waitingOf(null, outRefundNo, response);
199 } 203 }
200 204
  205 +
  206 +
201 // ========== 各种工具方法 ========== 207 // ========== 各种工具方法 ==========
202 208
203 protected String formatAmount(Integer amount) { 209 protected String formatAmount(Integer amount) {
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayAppPayClient.java
@@ -2,6 +2,8 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; @@ -2,6 +2,8 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay;
2 2
3 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; 3 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
4 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; 4 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
  5 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  6 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
5 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; 7 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
6 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum; 8 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum;
7 import com.alipay.api.AlipayApiException; 9 import com.alipay.api.AlipayApiException;
@@ -57,4 +59,8 @@ public class AlipayAppPayClient extends AbstractAlipayPayClient { @@ -57,4 +59,8 @@ public class AlipayAppPayClient extends AbstractAlipayPayClient {
57 reqDTO.getOutTradeNo(), response); 59 reqDTO.getOutTradeNo(), response);
58 } 60 }
59 61
  62 + @Override
  63 + protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
  64 + throw new UnsupportedOperationException("支付宝【App 支付】不支持转账操作");
  65 + }
60 } 66 }
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClient.java
@@ -5,6 +5,8 @@ import cn.hutool.core.map.MapUtil; @@ -5,6 +5,8 @@ import cn.hutool.core.map.MapUtil;
5 import cn.hutool.core.util.StrUtil; 5 import cn.hutool.core.util.StrUtil;
6 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; 6 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
7 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; 7 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
  8 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  9 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
8 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; 10 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
9 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum; 11 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum;
10 import com.alipay.api.AlipayApiException; 12 import com.alipay.api.AlipayApiException;
@@ -75,4 +77,8 @@ public class AlipayBarPayClient extends AbstractAlipayPayClient { @@ -75,4 +77,8 @@ public class AlipayBarPayClient extends AbstractAlipayPayClient {
75 reqDTO.getOutTradeNo(), response); 77 reqDTO.getOutTradeNo(), response);
76 } 78 }
77 79
  80 + @Override
  81 + protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
  82 + throw new UnsupportedOperationException("支付宝【条码支付】不支持转账操作");
  83 + }
78 } 84 }
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClient.java
@@ -4,6 +4,8 @@ import cn.hutool.core.util.ObjectUtil; @@ -4,6 +4,8 @@ import cn.hutool.core.util.ObjectUtil;
4 import cn.hutool.http.Method; 4 import cn.hutool.http.Method;
5 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; 5 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
6 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; 6 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
  7 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  8 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
7 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; 9 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
8 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum; 10 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum;
9 import com.alipay.api.AlipayApiException; 11 import com.alipay.api.AlipayApiException;
@@ -67,4 +69,8 @@ public class AlipayPcPayClient extends AbstractAlipayPayClient { @@ -67,4 +69,8 @@ public class AlipayPcPayClient extends AbstractAlipayPayClient {
67 reqDTO.getOutTradeNo(), response); 69 reqDTO.getOutTradeNo(), response);
68 } 70 }
69 71
  72 + @Override
  73 + protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
  74 + throw new UnsupportedOperationException("支付宝【PC 网站】不支持转账操作");
  75 + }
70 } 76 }
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayQrPayClient.java
@@ -2,6 +2,8 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; @@ -2,6 +2,8 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay;
2 2
3 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; 3 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
4 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; 4 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
  5 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  6 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
5 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; 7 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
6 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum; 8 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum;
7 import com.alipay.api.AlipayApiException; 9 import com.alipay.api.AlipayApiException;
@@ -54,4 +56,8 @@ public class AlipayQrPayClient extends AbstractAlipayPayClient { @@ -54,4 +56,8 @@ public class AlipayQrPayClient extends AbstractAlipayPayClient {
54 reqDTO.getOutTradeNo(), response); 56 reqDTO.getOutTradeNo(), response);
55 } 57 }
56 58
  59 + @Override
  60 + protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
  61 + throw new UnsupportedOperationException("支付宝【扫码支付】不支持转账操作");
  62 + }
57 } 63 }
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayTransferClient.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.pay.core.client.impl.alipay;
  2 +
  3 +import cn.hutool.core.map.MapUtil;
  4 +import cn.hutool.core.util.StrUtil;
  5 +import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
  6 +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
  7 +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
  8 +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
  9 +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
  10 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  11 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
  12 +import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
  13 +import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum;
  14 +import com.alipay.api.AlipayApiException;
  15 +import com.alipay.api.domain.AlipayFundTransUniTransferModel;
  16 +import com.alipay.api.domain.Participant;
  17 +import com.alipay.api.request.AlipayFundTransUniTransferRequest;
  18 +import com.alipay.api.response.AlipayFundTransUniTransferResponse;
  19 +import lombok.extern.slf4j.Slf4j;
  20 +
  21 +import java.util.Objects;
  22 +
  23 +import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST;
  24 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
  25 +
  26 +/**
  27 + * 支付宝转账的 PayClient 实现类
  28 + *
  29 + * @author jason
  30 + */
  31 +@Slf4j
  32 +public class AlipayTransferClient extends AbstractAlipayPayClient {
  33 + public AlipayTransferClient(Long channelId, AlipayPayClientConfig config) {
  34 + super(channelId, PayChannelEnum.ALIPAY_TRANSFER.getCode(), config);
  35 + }
  36 + @Override
  37 + protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) {
  38 + throw new UnsupportedOperationException("支付宝转账不支持统一下单请求");
  39 + }
  40 + @Override
  41 + protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) {
  42 + throw new UnsupportedOperationException("支付宝转账不支持统一退款请求");
  43 + }
  44 + @Override
  45 + protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) throws AlipayApiException {
  46 + // 1.1 构建 AlipayFundTransUniTransferModel
  47 + AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();
  48 + // ① 通用的参数
  49 + model.setTransAmount(formatAmount(reqDTO.getPrice())); // 转账金额
  50 + model.setOrderTitle(reqDTO.getTitle()); // 转账业务的标题,用于在支付宝用户的账单里显示。
  51 + model.setOutBizNo(reqDTO.getOutTransferNo());
  52 + model.setProductCode("TRANS_ACCOUNT_NO_PWD"); // 销售产品码。单笔无密转账固定为 TRANS_ACCOUNT_NO_PWD
  53 + model.setBizScene("DIRECT_TRANSFER"); // 业务场景 单笔无密转账固定为 DIRECT_TRANSFER。
  54 + model.setBusinessParams(JsonUtils.toJsonString(reqDTO.getChannelExtras()));
  55 + PayTransferTypeEnum transferType = PayTransferTypeEnum.valueOf(reqDTO.getType());
  56 + switch(transferType){
  57 + case WX_BALANCE :
  58 + case WALLET_BALANCE : {
  59 + log.error("[doUnifiedTransfer],支付宝转账不支持的转账类型{}", transferType);
  60 + throw new UnsupportedOperationException(String.format("支付宝转账不支持转账类型: %s",transferType.getName()));
  61 + }
  62 + case ALIPAY_BALANCE : {
  63 + // ② 个性化的参数
  64 + Participant payeeInfo = new Participant();
  65 + payeeInfo.setIdentityType("ALIPAY_LOGON_ID");
  66 + String logonId = MapUtil.getStr(reqDTO.getPayeeInfo(), "ALIPAY_LOGON_ID");
  67 + if (StrUtil.isEmpty(logonId)) {
  68 + throw exception0(BAD_REQUEST.getCode(), "支付包登录 ID 不能为空");
  69 + }
  70 + String accountName = MapUtil.getStr(reqDTO.getPayeeInfo(), "ALIPAY_ACCOUNT_NAME");
  71 + if (StrUtil.isEmpty(accountName)) {
  72 + throw exception0(BAD_REQUEST.getCode(), "支付包账户名称不能为空");
  73 + }
  74 + payeeInfo.setIdentity(logonId); // 支付宝登录号
  75 + payeeInfo.setName(accountName); // 支付宝账号姓名
  76 + model.setPayeeInfo(payeeInfo);
  77 + // 1.2 构建 AlipayFundTransUniTransferRequest
  78 + AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
  79 + request.setBizModel(model);
  80 + // 执行请求
  81 + AlipayFundTransUniTransferResponse response = client.certificateExecute(request);
  82 + // 处理结果
  83 + if (!response.isSuccess()) {
  84 + // 当出现 SYSTEM_ERROR, 转账可能成功也可能失败。 返回 WAIT 状态. 后续 job 会轮询
  85 + if (Objects.equals(response.getSubCode(), "SYSTEM_ERROR")) {
  86 + return PayTransferRespDTO.waitingOf(null, reqDTO.getOutTransferNo(), response);
  87 + }
  88 + return PayTransferRespDTO.failureOf(response.getSubCode(), response.getSubMsg(),
  89 + reqDTO.getOutTransferNo(), response);
  90 +
  91 + }
  92 + return PayTransferRespDTO.successOf(response.getOrderId(), parseTime(response.getTransDate()),
  93 + response.getOutBizNo(), response);
  94 + }
  95 + case BANK_CARD : {
  96 + Participant payeeInfo = new Participant();
  97 + payeeInfo.setIdentityType("BANKCARD_ACCOUNT");
  98 + throw new UnsupportedOperationException("待实现");
  99 + }
  100 + default: {
  101 + throw new IllegalStateException("不正确的转账类型: " + transferType);
  102 + }
  103 + }
  104 + }
  105 +}
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayWapPayClient.java
@@ -3,6 +3,8 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; @@ -3,6 +3,8 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay;
3 import cn.hutool.http.Method; 3 import cn.hutool.http.Method;
4 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; 4 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
5 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; 5 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
  6 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  7 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
6 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; 8 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
7 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum; 9 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum;
8 import com.alipay.api.AlipayApiException; 10 import com.alipay.api.AlipayApiException;
@@ -56,4 +58,8 @@ public class AlipayWapPayClient extends AbstractAlipayPayClient { @@ -56,4 +58,8 @@ public class AlipayWapPayClient extends AbstractAlipayPayClient {
56 reqDTO.getOutTradeNo(), response); 58 reqDTO.getOutTradeNo(), response);
57 } 59 }
58 60
  61 + @Override
  62 + public PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
  63 + throw new UnsupportedOperationException("支付宝【Wap 网站】不支持转账操作");
  64 + }
59 } 65 }
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/mock/MockPayClient.java
@@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; @@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
4 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; 4 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
5 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; 5 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
6 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; 6 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
  7 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  8 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
7 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; 9 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
8 import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig; 10 import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig;
9 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; 11 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
@@ -64,4 +66,8 @@ public class MockPayClient extends AbstractPayClient&lt;NonePayClientConfig&gt; { @@ -64,4 +66,8 @@ public class MockPayClient extends AbstractPayClient&lt;NonePayClientConfig&gt; {
64 throw new UnsupportedOperationException("模拟支付无支付回调"); 66 throw new UnsupportedOperationException("模拟支付无支付回调");
65 } 67 }
66 68
  69 + @Override
  70 + protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
  71 + throw new UnsupportedOperationException("待实现");
  72 + }
67 } 73 }
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/AbstractWxPayClient.java
@@ -12,6 +12,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; @@ -12,6 +12,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
12 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; 12 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
13 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; 13 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
14 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; 14 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
  15 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  16 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
15 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; 17 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
16 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum; 18 import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum;
17 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; 19 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
@@ -425,6 +427,10 @@ public abstract class AbstractWxPayClient extends AbstractPayClient&lt;WxPayClientC @@ -425,6 +427,10 @@ public abstract class AbstractWxPayClient extends AbstractPayClient&lt;WxPayClientC
425 } 427 }
426 } 428 }
427 429
  430 + @Override
  431 + protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
  432 + throw new UnsupportedOperationException("待实现");
  433 + }
428 // ========== 各种工具方法 ========== 434 // ========== 各种工具方法 ==========
429 435
430 static String formatDateV2(LocalDateTime time) { 436 static String formatDateV2(LocalDateTime time) {
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/channel/PayChannelEnum.java
@@ -28,6 +28,7 @@ public enum PayChannelEnum { @@ -28,6 +28,7 @@ public enum PayChannelEnum {
28 ALIPAY_APP("alipay_app", "支付宝App 支付", AlipayPayClientConfig.class), 28 ALIPAY_APP("alipay_app", "支付宝App 支付", AlipayPayClientConfig.class),
29 ALIPAY_QR("alipay_qr", "支付宝扫码支付", AlipayPayClientConfig.class), 29 ALIPAY_QR("alipay_qr", "支付宝扫码支付", AlipayPayClientConfig.class),
30 ALIPAY_BAR("alipay_bar", "支付宝条码支付", AlipayPayClientConfig.class), 30 ALIPAY_BAR("alipay_bar", "支付宝条码支付", AlipayPayClientConfig.class),
  31 + ALIPAY_TRANSFER("alipay_transfer", "支付宝转账", AlipayPayClientConfig.class),
31 32
32 MOCK("mock", "模拟支付", NonePayClientConfig.class), 33 MOCK("mock", "模拟支付", NonePayClientConfig.class),
33 34
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/transfer/PayTransferStatusRespEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.pay.core.enums.transfer;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Getter;
  5 +
  6 +/**
  7 + * 渠道的转账状态枚举
  8 + *
  9 + * @author jason
  10 + */
  11 +@Getter
  12 +@AllArgsConstructor
  13 +public enum PayTransferStatusRespEnum {
  14 +
  15 + WAITING(0, "等待转账"),
  16 + SUCCESS(10, "转账成功"),
  17 + FAILURE(20, "转账失败");
  18 +
  19 + private final Integer status;
  20 + private final String name;
  21 +}
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/transfer/PayTransferTypeEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.pay.core.enums.transfer;
  2 +
  3 +import cn.hutool.core.util.ArrayUtil;
  4 +import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
  5 +import lombok.AllArgsConstructor;
  6 +import lombok.Getter;
  7 +
  8 +import java.util.Arrays;
  9 +
  10 +/**
  11 + * 转账类型枚举
  12 + *
  13 + * @author jason
  14 + */
  15 +@AllArgsConstructor
  16 +@Getter
  17 +public enum PayTransferTypeEnum implements IntArrayValuable {
  18 + ALIPAY_BALANCE(1, "支付宝余额"),
  19 + WX_BALANCE(2, "微信余额"),
  20 + BANK_CARD(3, "银行卡"),
  21 + WALLET_BALANCE(4, "钱包余额");
  22 +
  23 + private final Integer type;
  24 + private final String name;
  25 +
  26 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PayTransferTypeEnum::getType).toArray();
  27 +
  28 + @Override
  29 + public int[] array() {
  30 + return ARRAYS;
  31 + }
  32 +
  33 + public static PayTransferTypeEnum valueOf(Integer type) {
  34 + return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
  35 + }
  36 +}
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java
@@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; @@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
8 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; 8 import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
9 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; 9 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
10 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; 10 import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
  11 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
  12 +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
11 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; 13 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
12 import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig; 14 import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig;
13 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; 15 import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
@@ -174,4 +176,8 @@ public class WalletPayClient extends AbstractPayClient&lt;NonePayClientConfig&gt; { @@ -174,4 +176,8 @@ public class WalletPayClient extends AbstractPayClient&lt;NonePayClientConfig&gt; {
174 throw new IllegalStateException(String.format("支付退款单[%s] 状态不正确", outRefundNo)); 176 throw new IllegalStateException(String.format("支付退款单[%s] 状态不正确", outRefundNo));
175 } 177 }
176 178
  179 + @Override
  180 + public PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
  181 + throw new UnsupportedOperationException("待实现");
  182 + }
177 } 183 }