refactor(cashier): 重构收银台模块

- 将 ChannelCashierController 重命名为 CashierCodeController
- 更新了 CashierCodeService 和 CashierCodeConfigService 的实现
- 新增了 CashierCodeAuthCodeParam 和 CashierCodeAuthUrlParam 类
- 调整了 WechatPayConfig 和 WechatAuthService 的实现- 更新了相关文档和注释
This commit is contained in:
DaxPay
2024-11-25 20:28:02 +08:00
parent 8901fb7463
commit e63fb5e335
15 changed files with 237 additions and 170 deletions

View File

@@ -2,6 +2,7 @@ package org.dromara.daxpay.channel.wechat.entity.config;
import cn.bootx.platform.common.mybatisplus.function.ToResult;
import cn.bootx.platform.core.util.JsonUtil;
import cn.hutool.core.util.StrUtil;
import org.dromara.daxpay.channel.wechat.code.WechatPayCode;
import org.dromara.daxpay.channel.wechat.convert.config.WechatPayConfigConvert;
import org.dromara.daxpay.channel.wechat.result.config.WechatPayConfigResult;
@@ -109,6 +110,10 @@ public class WechatPayConfig implements ToResult<WechatPayConfigResult> {
return config;
}
public String getAuthUrl() {
return StrUtil.removeSuffix(authUrl, "/");
}
@Override
public WechatPayConfigResult toResult() {
return WechatPayConfigConvert.CONVERT.toResult(this);

View File

@@ -31,7 +31,7 @@ public class WechatAuthService {
private final WechatPayConfigService wechatPayConfigService;
private final PlatformConfigService platformsConfigService;
private final PlatformConfigService platformConfigService;
/**
* 构建微信oauth2授权的url连接
@@ -45,10 +45,10 @@ public class WechatAuthService {
.buildAuthorizationUrl(param.getAuthRedirectUrl(), WxConsts.OAuth2Scope.SNSAPI_BASE, "");
return new AuthUrlResult().setAuthUrl(url);
} else {
String serverUrl = platformsConfigService.getConfig().getGatewayMobileUrl();
// 如果配置中有地址配置则使用, 没有的话使用平台地址进行拼接
if (StrUtil.isNotBlank(config.getAuthUrl())){
PlatformConfig platformConfig = platformsConfigService.getConfig();
String serverUrl = config.getAuthUrl();
if (StrUtil.isBlank(serverUrl)){
PlatformConfig platformConfig = platformConfigService.getConfig();
serverUrl = platformConfig.getGatewayMobileUrl();
}
String queryCode = RandomUtil.randomString(10);

View File

@@ -40,10 +40,16 @@ public class WechatPayCashierService {
* 生成授权链接, 主要是微信类通道使用, 用于获取OpenId
*/
public String generateAuthUrl(CashierAuthUrlParam param) {
WxMpService wxMpService = this.getWxMpService();
PlatformConfig platformConfig = platformConfigService.getConfig();
String serverUrl = platformConfig.getGatewayMobileUrl();
String redirectUrl = StrUtil.format("{}/wechat/cashier/{}", serverUrl, param.getAppId());
WechatPayConfig config = wechatPayConfigService.getWechatPayConfig();
WxMpService wxMpService = this.getWxMpService(config);
// 如果配置中有地址配置则使用, 没有的话使用平台地址进行拼接
String serverUrl = config.getAuthUrl();
if (StrUtil.isBlank(serverUrl)){
PlatformConfig platformConfig = platformConfigService.getConfig();
serverUrl = platformConfig.getGatewayMobileUrl();
}
String redirectUrl = StrUtil.format("{}/cashier/wechat/{}", serverUrl, param.getCashierCode());
return wxMpService.getOAuth2Service().buildAuthorizationUrl(redirectUrl, WxConsts.OAuth2Scope.SNSAPI_BASE, "");
}
@@ -78,6 +84,12 @@ public class WechatPayCashierService {
*/
private WxMpService getWxMpService() {
WechatPayConfig config = wechatPayConfigService.getAndCheckConfig();
return getWxMpService(config);
}
/**
* 获取微信公众号API的Service
*/
private WxMpService getWxMpService(WechatPayConfig config) {
WxMpService wxMpService = new WxMpServiceImpl();
WxMpDefaultConfigImpl wxMpConfig = new WxMpDefaultConfigImpl();
wxMpConfig.setAppId(config.getWxAppId()); // 设置微信公众号的appid