mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-10-13 21:30:25 +00:00
feat 微信分账调试
This commit is contained in:
17
_doc/Task.md
17
_doc/Task.md
@@ -6,15 +6,20 @@
|
||||
## 3.0.0.bate3: 功能完善
|
||||
- 优化:
|
||||
- [ ] 增加首页驾驶舱功能
|
||||
- [ ] 分账功能
|
||||
- [x] 分账界面功能
|
||||
- [x] 分账接收方配置
|
||||
- [ ] 分账单管理
|
||||
- [ ] 分账接口开发
|
||||
- [x] 分账单管理
|
||||
- [x] 接口开发 开启/完结/用不
|
||||
- [ ] 分账接口开发
|
||||
- [x] 支付宝
|
||||
- [ ] 微信
|
||||
- [ ] 分账扩展能力
|
||||
- [ ] 自动分账
|
||||
- [ ] 自动完成
|
||||
- [ ] 自动同步状态
|
||||
- [ ] 网关配套移动端开发
|
||||
- [ ] 同步回调页
|
||||
- [ ] 分账接收方和分账组优化
|
||||
- [ ] 后台管理时, 编号自动生成
|
||||
- [ ] 显示数据
|
||||
- [x] 分账接收方和分账组优化, 后台管理时, 编号自动生成
|
||||
- [x] 微信通道添加单独的认证跳转地址, 处理它的特殊情况
|
||||
- [x] 支付订单新增待支付状态
|
||||
## 3.0.0.beta2 收银台
|
||||
|
@@ -142,7 +142,6 @@ public class AliPayAllocationService {
|
||||
var detail = detailMap.get(receiver.getTransIn());
|
||||
if (Objects.nonNull(detail)) {
|
||||
detail.setResult(this.getDetailResultEnum(receiver.getState()).getCode());
|
||||
detail.setErrorCode(receiver.getErrorCode());
|
||||
detail.setErrorMsg(receiver.getErrorDesc());
|
||||
// 如果是完成, 更新时间
|
||||
if (AllocDetailResultEnum.SUCCESS.getCode().equals(detail.getResult())){
|
||||
|
@@ -2,8 +2,14 @@ package org.dromara.daxpay.channel.wechat.service.allocation;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.daxpay.channel.wechat.entity.config.WechatPayConfig;
|
||||
import org.dromara.daxpay.service.bo.allocation.AllocStartResultBo;
|
||||
import org.dromara.daxpay.service.entity.allocation.transaction.AllocDetail;
|
||||
import org.dromara.daxpay.service.entity.allocation.transaction.AllocOrder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 微信分账V2版本接口
|
||||
* @author xxm
|
||||
@@ -13,4 +19,25 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WeChatPayAllocationV2Service {
|
||||
|
||||
/**
|
||||
* 分账
|
||||
*/
|
||||
public AllocStartResultBo start(AllocOrder order, List<AllocDetail> details, WechatPayConfig config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 完结
|
||||
*/
|
||||
public void finish(AllocOrder order, List<AllocDetail> details, WechatPayConfig config) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步
|
||||
*/
|
||||
public void sync(AllocOrder order, List<AllocDetail> details, WechatPayConfig config) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package org.dromara.daxpay.channel.wechat.service.allocation;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.profitsharing.request.ProfitSharingQueryV3Request;
|
||||
import com.github.binarywang.wxpay.bean.profitsharing.request.ProfitSharingUnfreezeV3Request;
|
||||
import com.github.binarywang.wxpay.bean.profitsharing.request.ProfitSharingV3Request;
|
||||
import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingV3Result;
|
||||
@@ -36,7 +37,7 @@ public class WeChatPayAllocationV3Service {
|
||||
private final WechatPayConfigService wechatPayConfigService;
|
||||
|
||||
/**
|
||||
* 发起分账
|
||||
* 发起分账 使用分账号作为请求号4
|
||||
*/
|
||||
public AllocStartResultBo start(AllocOrder allocOrder, List<AllocDetail> orderDetails, WechatPayConfig config){
|
||||
|
||||
@@ -44,9 +45,10 @@ public class WeChatPayAllocationV3Service {
|
||||
ProfitSharingService sharingService = wxPayService.getProfitSharingService();
|
||||
|
||||
ProfitSharingV3Request request = new ProfitSharingV3Request();
|
||||
request.setAppid(config.getWxAppId());
|
||||
request.setOutOrderNo(allocOrder.getAllocNo());
|
||||
request.setTransactionId(allocOrder.getOutOrderNo());
|
||||
request.setUnfreezeUnsplit(true);
|
||||
request.setUnfreezeUnsplit(false);
|
||||
|
||||
// 分账接收方信息
|
||||
var receivers = orderDetails.stream()
|
||||
@@ -67,7 +69,6 @@ public class WeChatPayAllocationV3Service {
|
||||
request.setReceivers(receivers);
|
||||
try {
|
||||
ProfitSharingV3Result result = sharingService.profitSharingV3(request);
|
||||
|
||||
return new AllocStartResultBo().setOutAllocNo(result.getOrderId());
|
||||
} catch (WxPayException e) {
|
||||
throw new OperationFailException("微信分账V3失败: "+e.getMessage());
|
||||
@@ -75,22 +76,40 @@ public class WeChatPayAllocationV3Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分账完结
|
||||
* 分账完结 使用ID作为请求号
|
||||
*/
|
||||
public void finish(AllocOrder allocOrder, List<AllocDetail> orderDetails, WechatPayConfig config){
|
||||
public void finish(AllocOrder allocOrder, List<AllocDetail> details, WechatPayConfig config){
|
||||
WxPayService wxPayService = wechatPayConfigService.wxJavaSdk(config);
|
||||
ProfitSharingService sharingService = wxPayService.getProfitSharingService();
|
||||
var request = new ProfitSharingUnfreezeV3Request();
|
||||
request.setOutOrderNo(allocOrder.getAllocNo());
|
||||
request.setOutOrderNo(String.valueOf(allocOrder.getId()));
|
||||
request.setTransactionId(allocOrder.getOutOrderNo());
|
||||
request.setDescription("分账完结");
|
||||
try {
|
||||
sharingService.profitSharingUnfreeze(request);
|
||||
var result = sharingService.profitSharingUnfreeze(request);
|
||||
} catch (WxPayException e) {
|
||||
throw new OperationFailException("微信分账V3失败: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步
|
||||
*/
|
||||
public void sync(AllocOrder allocOrder, List<AllocDetail> details, WechatPayConfig config){
|
||||
WxPayService wxPayService = wechatPayConfigService.wxJavaSdk(config);
|
||||
ProfitSharingService sharingService = wxPayService.getProfitSharingService();
|
||||
ProfitSharingQueryV3Request request = new ProfitSharingQueryV3Request();
|
||||
request.setOutOrderNo(allocOrder.getAllocNo());
|
||||
// 根据订单状态判断
|
||||
|
||||
request.setTransactionId(allocOrder.getOutOrderNo());
|
||||
try {
|
||||
var result = sharingService.profitSharingQueryV3(request);
|
||||
} catch (WxPayException e) {
|
||||
throw new OperationFailException("微信分账订单查询V3失败: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分账接收方类型编码
|
||||
*/
|
||||
@@ -103,4 +122,5 @@ public class WeChatPayAllocationV3Service {
|
||||
}
|
||||
throw new ConfigErrorException("分账接收方类型错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,6 +2,11 @@ package org.dromara.daxpay.channel.wechat.strategy;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.daxpay.channel.wechat.code.WechatPayCode;
|
||||
import org.dromara.daxpay.channel.wechat.entity.config.WechatPayConfig;
|
||||
import org.dromara.daxpay.channel.wechat.service.allocation.WeChatPayAllocationV2Service;
|
||||
import org.dromara.daxpay.channel.wechat.service.allocation.WeChatPayAllocationV3Service;
|
||||
import org.dromara.daxpay.channel.wechat.service.config.WechatPayConfigService;
|
||||
import org.dromara.daxpay.core.enums.ChannelEnum;
|
||||
import org.dromara.daxpay.service.bo.allocation.AllocStartResultBo;
|
||||
import org.dromara.daxpay.service.bo.allocation.AllocSyncResultBo;
|
||||
@@ -9,6 +14,8 @@ import org.dromara.daxpay.service.strategy.AbsAllocationStrategy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;
|
||||
|
||||
/**
|
||||
@@ -21,7 +28,11 @@ import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROT
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class WechatAllocationStrategy extends AbsAllocationStrategy {
|
||||
private final WeChatPayAllocationV3Service weChatPayAllocationV3Service;
|
||||
private final WeChatPayAllocationV2Service weChatPayAllocationV2Service;
|
||||
private final WechatPayConfigService wechatPayConfigService;
|
||||
|
||||
private WechatPayConfig config;
|
||||
|
||||
/**
|
||||
* 分账通道
|
||||
@@ -31,20 +42,33 @@ public class WechatAllocationStrategy extends AbsAllocationStrategy {
|
||||
return ChannelEnum.WECHAT.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doBeforeHandler(){
|
||||
this.config = wechatPayConfigService.getAndCheckConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始分账
|
||||
*/
|
||||
@Override
|
||||
public AllocStartResultBo start() {
|
||||
return null;
|
||||
if (Objects.equals(config.getApiVersion(), WechatPayCode.API_V3)){
|
||||
return weChatPayAllocationV3Service.start(getOrder(), getDetails(), this.config);
|
||||
} else {
|
||||
return weChatPayAllocationV2Service.start(getOrder(), getDetails(), this.config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 完结
|
||||
*/
|
||||
@Override
|
||||
public void finish() {
|
||||
|
||||
if (Objects.equals(config.getApiVersion(), WechatPayCode.API_V3)){
|
||||
weChatPayAllocationV3Service.finish(getOrder(), this.getDetails(), this.config);
|
||||
} else {
|
||||
weChatPayAllocationV2Service.finish(getOrder(), this.getDetails(), this.config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,6 +76,13 @@ public class WechatAllocationStrategy extends AbsAllocationStrategy {
|
||||
*/
|
||||
@Override
|
||||
public AllocSyncResultBo doSync() {
|
||||
if (Objects.equals(config.getApiVersion(), WechatPayCode.API_V3)){
|
||||
weChatPayAllocationV3Service.finish(getOrder(), this.getDetails(), this.config);
|
||||
|
||||
weChatPayAllocationV3Service.sync(getOrder(), this.getDetails(), this.config);
|
||||
} else {
|
||||
weChatPayAllocationV2Service.sync(getOrder(), this.getDetails(), this.config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@@ -26,9 +26,15 @@ public class AllocConfig extends MchAppBaseEntity implements ToResult<AllocConfi
|
||||
/** 是否自动分账 */
|
||||
private Boolean autoAlloc;
|
||||
|
||||
/** 自动完结 */
|
||||
private Boolean autoFinish;
|
||||
|
||||
/** 分账起始额 */
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/** 分账延迟时长(分钟) */
|
||||
private Integer delayTime;
|
||||
|
||||
|
||||
/**
|
||||
* 创建对象
|
||||
|
@@ -24,10 +24,19 @@ public class AllocConfigParam {
|
||||
@Schema(description = "是否自动分账")
|
||||
private Boolean autoAlloc;
|
||||
|
||||
/** 自动完结 */
|
||||
@Schema(description = "自动完结")
|
||||
private Boolean autoFinish;
|
||||
|
||||
/** 分账起始额 */
|
||||
@Schema(description = "分账起始额")
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/** 分账延迟时长(分钟) */
|
||||
@Schema(description = "分账延迟时长(分钟)")
|
||||
private Integer delayTime;
|
||||
|
||||
/** 应用AppId */
|
||||
@Schema(description = "应用AppId")
|
||||
private String appId;
|
||||
|
||||
|
@@ -24,4 +24,12 @@ public class AllocConfigResult extends MchAppResult {
|
||||
|
||||
@Schema(description = "分账起始额")
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/** 自动完结 */
|
||||
@Schema(description = "是否自动完结")
|
||||
private Boolean autoFinish;
|
||||
|
||||
/** 分账延迟时长(分钟) */
|
||||
@Schema(description = "分账延迟时长(分钟)")
|
||||
private Integer delayTime;
|
||||
}
|
||||
|
Reference in New Issue
Block a user