diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientParameterExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientParameterExtensions.cs index b6af4cb0..9f6639c8 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientParameterExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientParameterExtensions.cs @@ -82,6 +82,21 @@ namespace SKIT.FlurlHttpClient.Wechat.Api /// /// public static string GenerateParameterizedUrlForConnectOAuth2Authorize(this WechatApiClient client, string redirectUrl, string scope, string? state = null) + { + return GenerateParameterizedUrlForConnectOAuth2Authorize(client, redirectUrl: redirectUrl, scope: scope, state: state, forcePopup: null); + } + + /// + /// 生成公众号网页授权 URL。 + /// REF: https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html + /// + /// + /// + /// + /// + /// + /// + public static string GenerateParameterizedUrlForConnectOAuth2Authorize(this WechatApiClient client, string redirectUrl, string scope, string? state = null, bool? forcePopup = null) { return new Url(BASE_URL_OPEN) .AppendPathSegments("connect", "oauth2", "authorize") @@ -90,6 +105,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api .SetQueryParam("response_type", "code") .SetQueryParam("scope", scope) .SetQueryParam("state", state) + .SetQueryParam("forcePopup", forcePopup.HasValue ? forcePopup.Value ? "true" : "false" : null) .SetFragment("wechat_redirect") .ToString(); } @@ -105,6 +121,22 @@ namespace SKIT.FlurlHttpClient.Wechat.Api /// /// public static string GenerateParameterizedUrlForComponentConnectOAuth2Authorize(this WechatApiClient client, string appId, string redirectUrl, string scope, string? state = null) + { + return GenerateParameterizedUrlForComponentConnectOAuth2Authorize(client, appId: appId, redirectUrl: redirectUrl, scope: scope, state: state, forcePopup: null); + } + + /// + /// 生成代公众号网页授权 URL。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Official_Accounts/official_account_website_authorization.html + /// + /// + /// + /// + /// + /// + /// + /// + public static string GenerateParameterizedUrlForComponentConnectOAuth2Authorize(this WechatApiClient client, string appId, string redirectUrl, string scope, string? state = null, bool? forcePopup = null) { return new Url(BASE_URL_OPEN) .AppendPathSegments("connect", "oauth2", "authorize") @@ -114,6 +146,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api .SetQueryParam("response_type", "code") .SetQueryParam("scope", scope) .SetQueryParam("state", state) + .SetQueryParam("forcePopup", forcePopup.HasValue ? forcePopup.Value ? "true" : "false" : null) .SetFragment("wechat_redirect") .ToString(); } diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Sns/SnsOAuth2AccessTokenResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Sns/SnsOAuth2AccessTokenResponse.cs index 7b7bd82a..539474fd 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Sns/SnsOAuth2AccessTokenResponse.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Sns/SnsOAuth2AccessTokenResponse.cs @@ -3,36 +3,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.Models /// /// 表示 [GET] /sns/oauth2/access_token 接口的响应。 /// - public class SnsOAuth2AccessTokenResponse : WechatApiResponse + public class SnsOAuth2AccessTokenResponse : SnsOAuth2RefreshTokenResponse { - /// - /// 获取或设置网页授权接口调用凭证。 - /// - [Newtonsoft.Json.JsonProperty("access_token")] - [System.Text.Json.Serialization.JsonPropertyName("access_token")] - public string AccessToken { get; set; } = default!; - - /// - /// 获取或设置凭证有效期(单位:秒)。 - /// - [Newtonsoft.Json.JsonProperty("expires_in")] - [System.Text.Json.Serialization.JsonPropertyName("expires_in")] - public int ExpiresIn { get; set; } - - /// - /// 获取或设置用户刷新 AccessToken。 - /// - [Newtonsoft.Json.JsonProperty("refresh_token")] - [System.Text.Json.Serialization.JsonPropertyName("refresh_token")] - public string RefreshToken { get; set; } = default!; - - /// - /// 获取或设置用户唯一标识。 - /// - [Newtonsoft.Json.JsonProperty("openid")] - [System.Text.Json.Serialization.JsonPropertyName("openid")] - public string OpenId { get; set; } = default!; - /// /// 获取或设置用户全局标识。 /// @@ -41,10 +13,12 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.Models public string? UnionId { get; set; } /// - /// 获取或设置用户授权的作用域,使用逗号分隔。 + /// 获取或设置是否为快照页模式虚拟账号。 /// - [Newtonsoft.Json.JsonProperty("scope")] - [System.Text.Json.Serialization.JsonPropertyName("scope")] - public string Scope { get; set; } = default!; + [Newtonsoft.Json.JsonProperty("is_snapshotuser")] + [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.NumericalBooleanConverter))] + [System.Text.Json.Serialization.JsonPropertyName("is_snapshotuser")] + [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.NumericalBooleanConverter))] + public bool IsSnapshotUser { get; set; } } } diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Sns/SnsOAuth2RefreshTokenResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Sns/SnsOAuth2RefreshTokenResponse.cs index 8a1b2f69..108f1087 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Sns/SnsOAuth2RefreshTokenResponse.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Sns/SnsOAuth2RefreshTokenResponse.cs @@ -1,9 +1,43 @@ -namespace SKIT.FlurlHttpClient.Wechat.Api.Models +namespace SKIT.FlurlHttpClient.Wechat.Api.Models { /// /// 表示 [GET] /sns/oauth2/refresh_token 接口的响应。 /// - public class SnsOAuth2RefreshTokenResponse : SnsOAuth2AccessTokenResponse + public class SnsOAuth2RefreshTokenResponse : WechatApiResponse { + /// + /// 获取或设置网页授权接口调用凭证。 + /// + [Newtonsoft.Json.JsonProperty("access_token")] + [System.Text.Json.Serialization.JsonPropertyName("access_token")] + public string AccessToken { get; set; } = default!; + + /// + /// 获取或设置凭证有效期(单位:秒)。 + /// + [Newtonsoft.Json.JsonProperty("expires_in")] + [System.Text.Json.Serialization.JsonPropertyName("expires_in")] + public int ExpiresIn { get; set; } + + /// + /// 获取或设置用户刷新 AccessToken。 + /// + [Newtonsoft.Json.JsonProperty("refresh_token")] + [System.Text.Json.Serialization.JsonPropertyName("refresh_token")] + public string RefreshToken { get; set; } = default!; + + /// + /// 获取或设置用户唯一标识。 + /// + [Newtonsoft.Json.JsonProperty("openid")] + [System.Text.Json.Serialization.JsonPropertyName("openid")] + public string OpenId { get; set; } = default!; + + /// + /// 获取或设置用户授权的作用域,使用逗号分隔。 + /// + [Newtonsoft.Json.JsonProperty("scope")] + [System.Text.Json.Serialization.JsonPropertyName("scope")] + public string Scope { get; set; } = default!; } } diff --git a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Sns/SnsOAuth2AccessTokenResponse.json b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Sns/SnsOAuth2AccessTokenResponse.json index 2b45263c..aff94c46 100644 --- a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Sns/SnsOAuth2AccessTokenResponse.json +++ b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Sns/SnsOAuth2AccessTokenResponse.json @@ -4,5 +4,6 @@ "refresh_token": "REFRESH_TOKEN", "openid": "OPENID", "scope": "SCOPE", - "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL" + "is_snapshotuser": 1, + "unionid": "UNIONID" }