feat 微信通道添加单独的认证跳转地址

This commit is contained in:
DaxPay
2024-10-28 17:43:48 +08:00
parent 0c51fa76d1
commit 87c9b1a8a5
6 changed files with 31 additions and 5 deletions

View File

@@ -34,6 +34,9 @@ public class WechatPayConfig implements ToResult<WechatPayConfigResult> {
/** 是否启用 */
private Boolean enable;
/** 授权认证地址 */
private String authUrl;
/** 支付限额 */
private BigDecimal limitAmount;

View File

@@ -38,6 +38,10 @@ public class WechatPayConfigParam {
@Schema(description = "是否启用")
private Boolean enable;
/** 授权认证地址 */
@Schema(description = "授权认证地址")
private String authUrl;
/** 支付限额 */
@NotNull(message = "支付限额不可为空")
@Schema(description = "支付限额")

View File

@@ -33,6 +33,10 @@ public class WechatPayConfigResult {
@Schema(description = "是否启用")
private Boolean enable;
/** 授权认证地址 */
@Schema(description = "授权认证地址")
private String authUrl;
/** 支付限额 */
@Schema(description = "支付限额")
private BigDecimal limitAmount;

View File

@@ -37,16 +37,21 @@ public class WechatAuthService {
* 构建微信oauth2授权的url连接
*/
public AuthUrlResult generateAuthUrl(GenerateAuthUrlParam param) {
WxMpService wxMpService = this.getWxMpService();
WechatPayConfig config = wechatPayConfigService.getWechatPayConfig();
WxMpService wxMpService = this.getWxMpService(config);
// 手段传输回调地址, 直接拼接不做处理
if (StrUtil.isNotBlank(param.getAuthRedirectUrl())){
String url = wxMpService.getOAuth2Service()
.buildAuthorizationUrl(param.getAuthRedirectUrl(), WxConsts.OAuth2Scope.SNSAPI_BASE, "");
return new AuthUrlResult().setAuthUrl(url);
} else {
PlatformConfig platformConfig = platformsConfigService.getConfig();
String serverUrl = platformsConfigService.getConfig().getGatewayMobileUrl();
// 如果配置中有地址配置则使用, 没有的话使用平台地址进行拼接
if (StrUtil.isNotBlank(config.getAuthUrl())){
PlatformConfig platformConfig = platformsConfigService.getConfig();
serverUrl = platformConfig.getGatewayMobileUrl();
}
String queryCode = RandomUtil.randomString(10);
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);
@@ -70,6 +75,12 @@ public class WechatAuthService {
*/
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