feat 分账组和分账接收者配置联调, 平台配置优化

This commit is contained in:
DaxPay
2024-10-08 17:44:13 +08:00
parent 5c1587eb3f
commit bfb082bc8b
18 changed files with 89 additions and 119 deletions

View File

@@ -1,13 +1,12 @@
package org.dromara.daxpay.channel.alipay.controller;
import cn.bootx.platform.core.annotation.IgnoreAuth;
import org.dromara.daxpay.channel.alipay.service.callback.AliPayCallbackService;
import org.dromara.daxpay.channel.alipay.service.extra.AliPayAuthService;
import org.dromara.daxpay.service.service.assist.PaymentAssistService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.dromara.daxpay.channel.alipay.service.callback.AliPayCallbackService;
import org.dromara.daxpay.service.service.assist.PaymentAssistService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -28,7 +27,6 @@ public class AliPayCallbackController {
private final PaymentAssistService paymentAssistService;
private final AliPayCallbackService payCallbackService;
private final AliPayAuthService aliPayAuthService;
@Operation(summary = "支付宝回调")
@PostMapping("/alipay")

View File

@@ -56,7 +56,6 @@ public class AliPayAllocReceiverService {
public void bind(AllocReceiver allocReceiver){
AlipayClient alipayClient = aliPayConfigService.getAlipayClient();
AlipayTradeRoyaltyRelationBindModel model = new AlipayTradeRoyaltyRelationBindModel();
model.setOutRequestNo(String.valueOf(allocReceiver.getId()));
RoyaltyEntity entity = new RoyaltyEntity();
AllocReceiverTypeEnum receiverTypeEnum = AllocReceiverTypeEnum.findByCode(allocReceiver.getReceiverType());
@@ -68,6 +67,7 @@ public class AliPayAllocReceiverService {
// 不报错视为同步成功
model.setReceiverList(Collections.singletonList(entity));
AlipayTradeRoyaltyRelationBindRequest request = new AlipayTradeRoyaltyRelationBindRequest();
model.setOutRequestNo(String.valueOf(allocReceiver.getId()));
request.setBizModel(model);
AlipayTradeRoyaltyRelationBindResponse response = alipayClient.execute(request);
this.verifyErrorMsg(response);
@@ -118,13 +118,13 @@ public class AliPayAllocReceiverService {
*/
private String getReceiverType(AllocReceiverTypeEnum receiverTypeEnum){
if (receiverTypeEnum == USER_ID){
return "ali_user_id";
return "userId";
}
if (receiverTypeEnum == OPEN_ID){
return "ali_open_id";
return "openId";
}
if (receiverTypeEnum == LOGIN_NAME){
return "ali_login_name";
return "loginName";
}
throw new ConfigErrorException("分账接收方类型错误");
}

View File

@@ -1,13 +1,6 @@
package org.dromara.daxpay.channel.alipay.service.extra;
import cn.bootx.platform.core.exception.BizException;
import org.dromara.daxpay.channel.alipay.entity.config.AliPayConfig;
import org.dromara.daxpay.channel.alipay.service.config.AliPayConfigService;
import org.dromara.daxpay.core.param.assist.GenerateAuthUrlParam;
import org.dromara.daxpay.core.result.assist.AuthResult;
import org.dromara.daxpay.core.result.assist.AuthUrlResult;
import org.dromara.daxpay.service.entity.config.PlatformConfig;
import org.dromara.daxpay.service.service.config.PlatformConfigService;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.alipay.api.AlipayClient;
@@ -16,7 +9,13 @@ import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.dromara.daxpay.channel.alipay.entity.config.AliPayConfig;
import org.dromara.daxpay.channel.alipay.service.config.AliPayConfigService;
import org.dromara.daxpay.core.param.assist.GenerateAuthUrlParam;
import org.dromara.daxpay.core.result.assist.AuthResult;
import org.dromara.daxpay.core.result.assist.AuthUrlResult;
import org.dromara.daxpay.service.entity.config.PlatformConfig;
import org.dromara.daxpay.service.service.config.PlatformConfigService;
import org.springframework.stereotype.Service;
/**
@@ -33,8 +32,6 @@ public class AliPayAuthService {
private final PlatformConfigService platformsConfigService;
private final RedisTemplate<String, AuthResult> redisTemplate;
/**
* 生成一个用于授权页面的链接
* 1. 如果手动传输授权回调地址, 不进行处理
@@ -49,19 +46,10 @@ public class AliPayAuthService {
AliPayConfig aliPayConfig = aliPayConfigService.getAliPayConfig();
String queryCode = RandomUtil.randomString(10);
// 判断是否独立部署前端
String authUrl;
if (platformConfig.isMobileEmbedded()){
// 嵌入式
// 授权地址
String serverUrl = platformConfig.getGatewayMobileUrl();
authUrl = StrUtil.format("{}/h5/alipay/auth/{}/{}/{}/{}",
String authUrl = StrUtil.format("{}/alipay/auth/{}/{}/{}/{}",
serverUrl, param.getAppId(),param.getChannel(),queryCode,aliPayConfig.getAliAppId());
} else {
// 独立部署
String serverUrl = platformConfig.getGatewayMobileUrl();
authUrl = StrUtil.format("{}/alipay/auth/{}/{}/{}/{}",
serverUrl, param.getAppId(),param.getChannel(),queryCode,aliPayConfig.getAliAppId());
}
return new AuthUrlResult().setAuthUrl(authUrl).setQueryCode(queryCode);
}

View File

@@ -49,17 +49,8 @@ public class AliPayRedirectUrlService {
return StrUtil.format("{}?biz_trade_no={}&trade_no={}", order.getReturnUrl(),order.getBizOrderNo(),order.getOrderNo() );
} else {
PlatformConfig platformConfig = platformConfigService.getConfig();
if (platformConfig.isMobileEmbedded()){
// 嵌入式
String serverUrl = platformConfig.getGatewayMobileUrl();
return StrUtil.format("{}/h5/alipay/pay/finish", serverUrl);
} else {
// 独立部署
String serverUrl = platformConfig.getGatewayMobileUrl();
return StrUtil.format("{}/alipay/pay/finish", serverUrl);
}
String serverUrl = platformConfig.getGatewayMobileUrl();
return StrUtil.format("{}/alipay/pay/finish", serverUrl);
}
}
}

View File

@@ -18,6 +18,8 @@ import org.dromara.daxpay.service.entity.allocation.receiver.AllocReceiver;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import static org.dromara.daxpay.core.enums.AllocReceiverTypeEnum.MERCHANT_NO;
import static org.dromara.daxpay.core.enums.AllocReceiverTypeEnum.OPEN_ID;
@@ -47,7 +49,7 @@ public class WechatPayAllocReceiverV2Service {
ProfitSharingService sharingService = wxPayService.getProfitSharingService();
ProfitSharingReceiverRequest request = new ProfitSharingReceiverRequest();
Receiver receiver = new Receiver(receiverType,allocReceiver.getReceiverAccount(),allocReceiver.getReceiverName(),allocReceiver.getRelationType(),allocReceiver.getRelationName());
Receiver receiver = new Receiver(receiverType,allocReceiver.getReceiverAccount(),allocReceiver.getReceiverName(),getRelationType(allocReceiver.getRelationType()),allocReceiver.getRelationName());
List<Receiver> receivers = List.of(receiver);
request.setReceiver(GSON.toJson(receivers));
@@ -92,4 +94,14 @@ public class WechatPayAllocReceiverV2Service {
}
throw new ConfigErrorException("分账接收方类型错误");
}
/**
* 获取分账关系类型编码
*/
private String getRelationType(String relationType){
if (Objects.isNull(relationType)){
return null;
}
return relationType.toUpperCase(Locale.ROOT);
}
}

View File

@@ -14,8 +14,8 @@ import org.dromara.daxpay.core.exception.OperationFailException;
import org.dromara.daxpay.service.entity.allocation.receiver.AllocReceiver;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import static org.dromara.daxpay.core.enums.AllocReceiverTypeEnum.MERCHANT_NO;
import static org.dromara.daxpay.core.enums.AllocReceiverTypeEnum.OPEN_ID;
@@ -31,15 +31,6 @@ import static org.dromara.daxpay.core.enums.AllocReceiverTypeEnum.OPEN_ID;
public class WechatPayAllocReceiverV3Service {
private final WechatPayConfigService wechatPayConfigService;
/**
* 校验参数是否合法
*/
public boolean validation(AllocReceiver allocReceiver){
List<String> list = Arrays.asList(AllocReceiverTypeEnum.OPEN_ID.getCode(), AllocReceiverTypeEnum.MERCHANT_NO.getCode());
String receiverType = allocReceiver.getReceiverType();
return list.contains(receiverType);
}
/**
* 绑定
*/
@@ -54,7 +45,7 @@ public class WechatPayAllocReceiverV3Service {
request.setType(receiverType);
request.setAccount(allocReceiver.getReceiverAccount());
request.setName(allocReceiver.getReceiverName());
request.setRelationType(allocReceiver.getRelationType());
request.setRelationType(getRelationType(allocReceiver.getRelationType()));
request.setCustomRelation(allocReceiver.getRelationName());
try {
sharingService.addReceiverV3(request);
@@ -77,7 +68,7 @@ public class WechatPayAllocReceiverV3Service {
request.setType(receiverType);
request.setAccount(allocReceiver.getReceiverAccount());
request.setName(allocReceiver.getReceiverName());
request.setRelationType(allocReceiver.getRelationType());
request.setRelationType(getRelationType(allocReceiver.getRelationType()));
request.setCustomRelation(allocReceiver.getRelationName());
try {
sharingService.removeReceiverV3(request);
@@ -98,4 +89,13 @@ public class WechatPayAllocReceiverV3Service {
}
throw new ConfigErrorException("分账接收方类型错误");
}
/**
* 获取分账关系类型编码
*/
private String getRelationType(String relationType){
if (Objects.isNull(relationType)){
return null;
}
return relationType.toUpperCase(Locale.ROOT);
}
}

View File

@@ -46,20 +46,9 @@ public class WechatAuthService {
} else {
PlatformConfig platformConfig = platformsConfigService.getConfig();
String queryCode = RandomUtil.randomString(10);
// 判断是否独立部署前端
String authUrl;
if (platformConfig.isMobileEmbedded()){
// 嵌入式
String serverUrl = platformConfig.getGatewayMobileUrl();
String redirectUrl = StrUtil.format("{}/h5/wechat/auth/{}/{}/{}", serverUrl, param.getAppId(), param.getChannel(),queryCode);
authUrl = wxMpService.getOAuth2Service().buildAuthorizationUrl(redirectUrl, WxConsts.OAuth2Scope.SNSAPI_BASE, "");
} else {
// 独立部署
String serverUrl = platformConfig.getGatewayMobileUrl();
String redirectUrl = StrUtil.format("{}/wechat/auth/{}/{}/{}", serverUrl, param.getAppId(), param.getChannel(),queryCode);
authUrl = wxMpService.getOAuth2Service().buildAuthorizationUrl(redirectUrl, WxConsts.OAuth2Scope.SNSAPI_BASE, "");
}
String serverUrl = platformConfig.getGatewayMobileUrl();
String redirectUrl = StrUtil.format("{}/wechat/auth/{}/{}/{}", serverUrl, param.getAppId(), param.getChannel(),queryCode);
String authUrl = wxMpService.getOAuth2Service().buildAuthorizationUrl(redirectUrl, WxConsts.OAuth2Scope.SNSAPI_BASE, "");
return new AuthUrlResult().setAuthUrl(authUrl).setQueryCode(queryCode);
}
}

View File

@@ -42,18 +42,9 @@ public class WechatPayCashierService {
public String generateAuthUrl(CashierAuthUrlParam param) {
WxMpService wxMpService = this.getWxMpService();
PlatformConfig platformConfig = platformConfigService.getConfig();
// 判断是否独立部署前端
if (platformConfig.isMobileEmbedded()){
// 嵌入式
String serverUrl = platformConfig.getGatewayMobileUrl();
String redirectUrl = StrUtil.format("{}/h5/wechat/cashier/{}/{}", serverUrl, param.getAppId());
return wxMpService.getOAuth2Service().buildAuthorizationUrl(redirectUrl, WxConsts.OAuth2Scope.SNSAPI_BASE, "");
} else {
// 独立部署
String serverUrl = platformConfig.getGatewayMobileUrl();
String redirectUrl = StrUtil.format("{}/wechat/cashier/{}/{}", serverUrl, param.getAppId());
return wxMpService.getOAuth2Service().buildAuthorizationUrl(redirectUrl, WxConsts.OAuth2Scope.SNSAPI_BASE, "");
}
String serverUrl = platformConfig.getGatewayMobileUrl();
String redirectUrl = StrUtil.format("{}/wechat/cashier/{}/{}", serverUrl, param.getAppId());
return wxMpService.getOAuth2Service().buildAuthorizationUrl(redirectUrl, WxConsts.OAuth2Scope.SNSAPI_BASE, "");
}
/**