feat:【PAY 支付】增加 channelPackageInfo 字段,对接微信新的转账 API(太难了!!!!!!!!!!!!!!!!!!!!)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.api.transfer;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferRespDTO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@@ -16,9 +16,9 @@ public interface PayTransferApi {
|
||||
* 创建转账单
|
||||
*
|
||||
* @param reqDTO 创建请求
|
||||
* @return 转账单编号
|
||||
* @return 创建结果
|
||||
*/
|
||||
Long createTransfer(@Valid PayTransferCreateReqDTO reqDTO);
|
||||
PayTransferCreateRespDTO createTransfer(@Valid PayTransferCreateReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 获得转账单
|
||||
|
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.pay.api.transfer.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 转账单创建 Response DTO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class PayTransferCreateRespDTO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
// ========== 其它字段 ==========
|
||||
|
||||
/**
|
||||
* 渠道 package 信息
|
||||
*
|
||||
* 特殊:目前只有微信转账有这个东西!!!
|
||||
* @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4012716430">JSAPI 调起用户确认收款</a>
|
||||
*/
|
||||
private String channelPackageInfo;
|
||||
|
||||
}
|
@@ -63,4 +63,12 @@ public class PayTransferRespDTO {
|
||||
*/
|
||||
private String channelErrorMsg;
|
||||
|
||||
/**
|
||||
* 渠道 package 信息
|
||||
*
|
||||
* 特殊:目前只有微信转账有这个东西!!!
|
||||
* @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4012716430">JSAPI 调起用户确认收款</a>
|
||||
*/
|
||||
private String channelPackageInfo;
|
||||
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.pay.api.transfer;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
||||
import cn.iocoder.yudao.module.pay.service.transfer.PayTransferService;
|
||||
@@ -22,7 +23,7 @@ public class PayTransferApiImpl implements PayTransferApi {
|
||||
private PayTransferService payTransferService;
|
||||
|
||||
@Override
|
||||
public Long createTransfer(PayTransferCreateReqDTO reqDTO) {
|
||||
public PayTransferCreateRespDTO createTransfer(PayTransferCreateReqDTO reqDTO) {
|
||||
return payTransferService.createTransfer(reqDTO);
|
||||
}
|
||||
|
||||
|
@@ -80,5 +80,12 @@ public class PayDemoWithdrawDO extends BaseDO {
|
||||
* 转账错误提示
|
||||
*/
|
||||
private String transferErrorMsg;
|
||||
/**
|
||||
* 渠道 package 信息
|
||||
*
|
||||
* 特殊:目前只有微信转账有这个东西!!!
|
||||
* @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4012716430">JSAPI 调起用户确认收款</a>
|
||||
*/
|
||||
private String transferChannelPackageInfo;
|
||||
|
||||
}
|
@@ -135,4 +135,12 @@ public class PayTransferDO extends BaseDO {
|
||||
*/
|
||||
private String channelNotifyData;
|
||||
|
||||
/**
|
||||
* 渠道 package 信息
|
||||
*
|
||||
* 特殊:目前只有微信转账有这个东西!!!
|
||||
* @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4012716430">JSAPI 调起用户确认收款</a>
|
||||
*/
|
||||
private String channelPackageInfo;
|
||||
|
||||
}
|
@@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.PayTransferApi;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.withdraw.PayDemoWithdrawCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoWithdrawDO;
|
||||
@@ -83,12 +84,13 @@ public class PayDemoTransferServiceImpl implements PayDemoWithdrawService {
|
||||
transferReqDTO.setChannelExtras(PayTransferCreateReqDTO.buildWeiXinChannelExtra1000(
|
||||
"测试活动", "测试奖励"));
|
||||
}
|
||||
Long payTransferId = payTransferApi.createTransfer(transferReqDTO);
|
||||
PayTransferCreateRespDTO transferRespDTO = payTransferApi.createTransfer(transferReqDTO);
|
||||
|
||||
// 2.2 更新转账单到 demo 示例提现单,并将状态更新为转账中
|
||||
demoTransferMapper.updateByIdAndStatus(withdraw.getId(), withdraw.getStatus(),
|
||||
new PayDemoWithdrawDO().setPayTransferId(payTransferId));
|
||||
return payTransferId;
|
||||
new PayDemoWithdrawDO().setPayTransferId(transferRespDTO.getId())
|
||||
.setTransferChannelPackageInfo(transferRespDTO.getChannelPackageInfo()));
|
||||
return transferRespDTO.getId();
|
||||
}
|
||||
|
||||
private PayDemoWithdrawDO validateDemoWithdrawCanTransfer(Long id) {
|
||||
|
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pay.service.transfer;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -20,7 +21,7 @@ public interface PayTransferService {
|
||||
* @param reqDTO 创建请求
|
||||
* @return 转账单编号
|
||||
*/
|
||||
Long createTransfer(@Valid PayTransferCreateReqDTO reqDTO);
|
||||
PayTransferCreateRespDTO createTransfer(@Valid PayTransferCreateReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 获取转账单
|
||||
|
@@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifie
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferStatusRespEnum;
|
||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
|
||||
@@ -62,7 +63,7 @@ public class PayTransferServiceImpl implements PayTransferService {
|
||||
private PayNoRedisDAO noRedisDAO;
|
||||
|
||||
@Override
|
||||
public Long createTransfer(PayTransferCreateReqDTO reqDTO) {
|
||||
public PayTransferCreateRespDTO createTransfer(PayTransferCreateReqDTO reqDTO) {
|
||||
// 1.1 校验 App
|
||||
PayAppDO payApp = appService.validPayApp(reqDTO.getAppKey());
|
||||
// 1.2 校验支付渠道是否有效
|
||||
@@ -88,12 +89,13 @@ public class PayTransferServiceImpl implements PayTransferService {
|
||||
transferMapper.updateByIdAndStatus(transfer.getId(), transfer.getStatus(),
|
||||
new PayTransferDO().setStatus(PayTransferStatusEnum.WAITING.getStatus()));
|
||||
}
|
||||
PayTransferRespDTO unifiedTransferResp = null;
|
||||
try {
|
||||
// 3. 调用三方渠道发起转账
|
||||
PayTransferUnifiedReqDTO transferUnifiedReq = BeanUtils.toBean(reqDTO, PayTransferUnifiedReqDTO.class)
|
||||
.setOutTransferNo(transfer.getNo())
|
||||
.setNotifyUrl(genChannelTransferNotifyUrl(channel));
|
||||
PayTransferRespDTO unifiedTransferResp = client.unifiedTransfer(transferUnifiedReq);
|
||||
unifiedTransferResp = client.unifiedTransfer(transferUnifiedReq);
|
||||
// 4. 通知转账结果
|
||||
getSelf().notifyTransfer(channel, unifiedTransferResp);
|
||||
} catch (Throwable e) {
|
||||
@@ -102,7 +104,8 @@ public class PayTransferServiceImpl implements PayTransferService {
|
||||
// 或者,使用相同 no 再次发起转账请求
|
||||
log.error("[createTransfer][转账编号({}) requestDTO({}) 发生异常]", transfer.getId(), reqDTO, e);
|
||||
}
|
||||
return transfer.getId();
|
||||
return new PayTransferCreateRespDTO().setId(transfer.getId())
|
||||
.setChannelPackageInfo(unifiedTransferResp != null ? unifiedTransferResp.getChannelPackageInfo() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +157,7 @@ public class PayTransferServiceImpl implements PayTransferService {
|
||||
}
|
||||
|
||||
private void notifyTransferProgressing(PayChannelDO channel, PayTransferRespDTO notify) {
|
||||
// 1.校验
|
||||
// 1. 校验
|
||||
PayTransferDO transfer = transferMapper.selectByAppIdAndNo(channel.getAppId(), notify.getOutTransferNo());
|
||||
if (transfer == null) {
|
||||
throw exception(PAY_TRANSFER_NOT_FOUND);
|
||||
@@ -170,7 +173,8 @@ public class PayTransferServiceImpl implements PayTransferService {
|
||||
// 2. 更新状态
|
||||
int updateCounts = transferMapper.updateByIdAndStatus(transfer.getId(),
|
||||
PayTransferStatusEnum.WAITING.getStatus(),
|
||||
new PayTransferDO().setStatus(PayTransferStatusEnum.PROCESSING.getStatus()));
|
||||
new PayTransferDO().setStatus(PayTransferStatusEnum.PROCESSING.getStatus())
|
||||
.setChannelPackageInfo(transfer.getChannelPackageInfo()));
|
||||
if (updateCounts == 0) {
|
||||
throw exception(PAY_TRANSFER_NOTIFY_FAIL_STATUS_IS_NOT_WAITING);
|
||||
}
|
||||
@@ -261,6 +265,9 @@ public class PayTransferServiceImpl implements PayTransferService {
|
||||
}
|
||||
int count = 0;
|
||||
for (PayTransferDO transfer : list) {
|
||||
if (!transfer.getId().equals(54L)) {
|
||||
continue;
|
||||
}
|
||||
count += syncTransfer(transfer) ? 1 : 0;
|
||||
}
|
||||
return count;
|
||||
|
@@ -22,7 +22,6 @@ public class PayTransferRespDTO {
|
||||
|
||||
/**
|
||||
* 外部转账单号
|
||||
*
|
||||
*/
|
||||
private String outTransferNo;
|
||||
|
||||
@@ -50,11 +49,19 @@ public class PayTransferRespDTO {
|
||||
*/
|
||||
private String channelErrorMsg;
|
||||
|
||||
/**
|
||||
* 渠道 package 信息
|
||||
*
|
||||
* 特殊:目前只有微信转账有这个东西!!!
|
||||
* @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4012716430">JSAPI 调起用户确认收款</a>
|
||||
*/
|
||||
private String channelPackageInfo;
|
||||
|
||||
/**
|
||||
* 创建【WAITING】状态的转账返回
|
||||
*/
|
||||
public static PayTransferRespDTO waitingOf(String channelTransferNo,
|
||||
String outTransferNo, Object rawData) {
|
||||
String outTransferNo, Object rawData) {
|
||||
PayTransferRespDTO respDTO = new PayTransferRespDTO();
|
||||
respDTO.status = PayTransferStatusRespEnum.WAITING.getStatus();
|
||||
respDTO.channelTransferNo = channelTransferNo;
|
||||
|
@@ -482,11 +482,19 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
|
||||
// 2.1 执行请求
|
||||
try {
|
||||
TransferBillsResult response = client.getTransferService().transferBills(request);
|
||||
System.out.println(response);
|
||||
|
||||
// 2.2 创建返回结果
|
||||
// TODO @芋艿:这里要解析下;
|
||||
return PayTransferRespDTO.processingOf(response.getTransferBillNo(), reqDTO.getOutTransferNo(), response);
|
||||
String state = response.getState();
|
||||
if (ObjectUtils.equalsAny(state, "ACCEPTED", "PROCESSING", "WAIT_USER_CONFIRM", "TRANSFERING")) {
|
||||
return PayTransferRespDTO.processingOf(response.getTransferBillNo(), response.getOutBillNo(), response)
|
||||
.setChannelPackageInfo(response.getPackageInfo()); // 一般情况下,只有 WAIT_USER_CONFIRM 会有!
|
||||
}
|
||||
if (Objects.equals("SUCCESS", state)) {
|
||||
return PayTransferRespDTO.successOf(response.getTransferBillNo(), parseDateV3(response.getCreateTime()),
|
||||
response.getOutBillNo(), response);
|
||||
}
|
||||
return PayTransferRespDTO.closedOf(state, response.getFailReason(),
|
||||
response.getOutBillNo(), response);
|
||||
} catch (WxPayException e) {
|
||||
log.error("[doUnifiedTransfer][转账({}) 发起微信支付异常", reqDTO, e);
|
||||
String errorCode = getErrorCode(e);
|
||||
@@ -499,7 +507,7 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
|
||||
@Override
|
||||
protected PayTransferRespDTO doGetTransfer(String outTradeNo) throws WxPayException {
|
||||
// 1. 执行请求
|
||||
TransferBillsGetResult response = client.getTransferService().getBillsByTransferBillNo(outTradeNo);
|
||||
TransferBillsGetResult response = client.getTransferService().getBillsByOutBillNo(outTradeNo);
|
||||
|
||||
// 2. 创建返回结果
|
||||
String state = response.getState();
|
||||
|
Reference in New Issue
Block a user