mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-10-14 05:40:25 +00:00
feat 微信通道添加单独的认证跳转地址
This commit is contained in:
@@ -34,6 +34,9 @@ public class WechatPayConfig implements ToResult<WechatPayConfigResult> {
|
||||
/** 是否启用 */
|
||||
private Boolean enable;
|
||||
|
||||
/** 授权认证地址 */
|
||||
private String authUrl;
|
||||
|
||||
/** 支付限额 */
|
||||
private BigDecimal limitAmount;
|
||||
|
||||
|
@@ -38,6 +38,10 @@ public class WechatPayConfigParam {
|
||||
@Schema(description = "是否启用")
|
||||
private Boolean enable;
|
||||
|
||||
/** 授权认证地址 */
|
||||
@Schema(description = "授权认证地址")
|
||||
private String authUrl;
|
||||
|
||||
/** 支付限额 */
|
||||
@NotNull(message = "支付限额不可为空")
|
||||
@Schema(description = "支付限额")
|
||||
|
@@ -33,6 +33,10 @@ public class WechatPayConfigResult {
|
||||
@Schema(description = "是否启用")
|
||||
private Boolean enable;
|
||||
|
||||
/** 授权认证地址 */
|
||||
@Schema(description = "授权认证地址")
|
||||
private String authUrl;
|
||||
|
||||
/** 支付限额 */
|
||||
@Schema(description = "支付限额")
|
||||
private BigDecimal limitAmount;
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user