From 319cfaf392cbfc1ee29ad9838631f059e973b9ce Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Mon, 10 Jan 2022 12:47:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(work):=20=E6=96=B0=E5=A2=9E=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BC=81=E4=B8=9A=E5=8F=B7=E7=BD=91=E9=A1=B5=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E5=92=8C=E6=89=AB=E7=A0=81=E6=8E=88=E6=9D=83=20URL=20?= =?UTF-8?q?=E7=9A=84=E6=89=A9=E5=B1=95=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WechatWorkClientParameterExtensions.cs | 65 +++++++++++++++---- 1 file changed, 51 insertions(+), 14 deletions(-) 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(); + } } }