diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/Extensions/WechatWorkClientParameterExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/Extensions/WechatWorkClientParameterExtensions.cs index 9d96b6fe..3b251ed0 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Work/Extensions/WechatWorkClientParameterExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/Extensions/WechatWorkClientParameterExtensions.cs @@ -1,24 +1,14 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Net.Http; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Web; using Flurl; -using Flurl.Http; namespace SKIT.FlurlHttpClient.Wechat.Work { - /// - /// 为 提供客户端调起 JS-SDK 签名的扩展方法。 - /// public static class WechatWorkClientParameterExtensions { /// - /// 生成客户端 JS-SDK `wx.config` 所需的参数。 + /// 生成企业号 JS-SDK `wx.config` 所需的参数字典。 /// REF: https://open.work.weixin.qq.com/api/doc/90000/90136/90506 /// REF: https://open.work.weixin.qq.com/api/doc/90001/90144/90539 /// REF: https://open.work.weixin.qq.com/api/doc/90002/90152/90777 @@ -27,7 +17,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work /// /// /// - public static IDictionary GenerateParametersForJssdkConfigRequest(this WechatWorkClient client, string jsapiTicket, string url) + public static IDictionary GenerateParametersForJSSDKConfig(this WechatWorkClient client, string jsapiTicket, string url) { if (client is null) throw new ArgumentNullException(nameof(client)); if (jsapiTicket is null) throw new ArgumentNullException(nameof(jsapiTicket)); @@ -47,7 +37,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work } /// - /// 生成客户端 JS-SDK `wx.agentConfig` 所需的参数。 + /// 生成企业号 JS-SDK `wx.agentConfig` 所需的参数字典。 /// REF: https://open.work.weixin.qq.com/api/doc/90000/90136/90506 /// REF: https://open.work.weixin.qq.com/api/doc/90001/90144/90539 /// REF: https://open.work.weixin.qq.com/api/doc/90002/90152/90777 @@ -56,7 +46,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work /// /// /// - public static IDictionary GenerateParametersForJssdkAgentConfigRequest(this WechatWorkClient client, string jsapiTicket, string url) + public static IDictionary GenerateParametersForJSSDKAgentConfig(this WechatWorkClient client, string jsapiTicket, string url) { if (client is null) throw new ArgumentNullException(nameof(client)); if (jsapiTicket is null) throw new ArgumentNullException(nameof(jsapiTicket)); @@ -75,5 +65,52 @@ namespace SKIT.FlurlHttpClient.Wechat.Work { "signature", sign } }); } + + /// + /// 生成企业号网页授权 URL。 + /// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/91022 + /// REF: https://open.work.weixin.qq.com/api/doc/90001/90143/91120 + /// + /// + /// + /// + /// + /// + public static string GenerateParameterizedUrlForConnectOAuth2Authorize(this WechatWorkClient client, string redirectUrl, string scope, string? state = null) + { + return new Url("https://open.weixin.qq.com") + .AppendPathSegments("connect", "oauth2", "authorize") + .SetQueryParam("appid", string.IsNullOrEmpty(client.Credentials.SuiteId) ? client.Credentials.CorpId : client.Credentials.SuiteId) + .SetQueryParam("redirect_uri", redirectUrl) + .SetQueryParam("response_type", "code") + .SetQueryParam("scope", scope) + .SetQueryParam("state", state) + .SetFragment("wechat_redirect") + .ToString(); + } + + /// + /// 生成企业号扫码授权 URL。 + /// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/91019 + /// REF: https://open.work.weixin.qq.com/api/doc/90001/90143/91124 + /// + /// + /// + /// + /// + /// + /// + public static string GenerateParameterizedUrlForSSOQrcodeConnectAuthorize(this WechatWorkClient client, string redirectUrl, string? state = null, string? language = null, string? userType = null) + { + return new Url("https://open.work.weixin.qq.com") + .AppendPathSegments("wwopen", "sso", "qrConnect") + .SetQueryParam("appid", client.Credentials.CorpId) + .SetQueryParam("agentid", client.Credentials.AgentId) + .SetQueryParam("redirect_uri", redirectUrl) + .SetQueryParam("state", state) + .SetQueryParam("lang", language) + .SetQueryParam("usertype", userType) + .ToString(); + } } }