feat: 新增微信 OAuth 公开配置接口
All checks were successful
Build and Deploy / deploy (push) Successful in 1m51s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m51s
从其他配置 wechat_mp 返回 AppId 与 OAuthRedirectBase,供 H5 网页授权使用。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
ef12db52a0
commit
937f0bb78b
@ -32,6 +32,7 @@ public class WeChatRouteIntegrationTests
|
||||
host.RoutePatterns.Should().Contain("apiwechat/verification");
|
||||
host.RoutePatterns.Should().Contain("wechat/mp/{appId}");
|
||||
host.RoutePatterns.Should().Contain("wechat/mp/login-qrcode");
|
||||
host.RoutePatterns.Should().Contain("wechat/mp/oauth-config");
|
||||
host.RoutePatterns.Should().Contain("wechat/mp/follow-qrcode");
|
||||
host.RoutePatterns.Should().Contain("wechat/oauth/user-info");
|
||||
host.RoutePatterns.Should().Contain("wechat/customer/register");
|
||||
|
||||
@ -159,6 +159,31 @@ public partial class AuthService
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// H5 网页授权公开配置:AppId + OAuth 回调根(来自其他配置 wechat_mp)。
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("/wechat/mp/oauth-config")]
|
||||
[ApiExplorerSettings(GroupName = "WeChat")]
|
||||
public async Task<WxOAuthConfigOutput> GetWeChatOAuthConfigAsync(
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var options = await WeChatMpConfigProvider.GetAsync(cancellationToken);
|
||||
if (string.IsNullOrWhiteSpace(options.AppId))
|
||||
{
|
||||
throw new BusinessException(
|
||||
"未配置微信公众号 AppId。请在「其他配置」维护 wechat_mp,AppKey 填公众号 AppId。");
|
||||
}
|
||||
|
||||
return new WxOAuthConfigOutput
|
||||
{
|
||||
AppId = options.AppId.Trim(),
|
||||
OAuthRedirectBase = string.IsNullOrWhiteSpace(options.OAuthRedirectBase)
|
||||
? null
|
||||
: options.OAuthRedirectBase.Trim().TrimEnd('/')
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 PC 扫码登录二维码。
|
||||
/// </summary>
|
||||
|
||||
@ -12,6 +12,19 @@ public class WxLoginQrcodeOutput
|
||||
public int ExpiresIn { get; set; } = 600;
|
||||
}
|
||||
|
||||
/// <summary>H5 网页授权所需公开配置(不含 Secret/Token)。</summary>
|
||||
public class WxOAuthConfigOutput
|
||||
{
|
||||
/// <summary>公众号 AppId(来自其他配置 wechat_mp.AppKey)。</summary>
|
||||
public string AppId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// OAuth 回调根地址(来自 wechat_mp.BaseUrl),如 https://ideship.com。
|
||||
/// 为空时前端回退到当前页面 origin。
|
||||
/// </summary>
|
||||
public string? OAuthRedirectBase { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>引导关注公众号:优先返回可直接跳转的公众号链接。</summary>
|
||||
public class WxFollowQrcodeOutput
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user