feat(work): 新增生成第三方单点登录扫码授权 URL 的扩展方法

This commit is contained in:
Fu Diwei 2023-03-22 22:21:22 +08:00
parent 2de062c0ea
commit b3706b35e0
5 changed files with 40 additions and 15 deletions

View File

@ -44,7 +44,7 @@ var options = new WechatTenpayClientOptions()
MerchantV3Secret = "微信商户 v3 API 密钥", MerchantV3Secret = "微信商户 v3 API 密钥",
MerchantCertificateSerialNumber = "微信商户证书序列号", MerchantCertificateSerialNumber = "微信商户证书序列号",
MerchantCertificatePrivateKey = "-----BEGIN PRIVATE KEY-----微信商户证书私钥,即 `apiclient_key.pem` 文件内容-----END PRIVATE KEY-----", MerchantCertificatePrivateKey = "-----BEGIN PRIVATE KEY-----微信商户证书私钥,即 `apiclient_key.pem` 文件内容-----END PRIVATE KEY-----",
PlatformCertificateManager = manager // 证书管理器的具体用法请参阅下文的高级技巧与加密、验签有关的章节 PlatformCertificateManager = manager // 平台证书管理器的具体用法请参阅下文的基础用法与加密、验签有关的章节
}; };
var client = new WechatTenpayClient(options); var client = new WechatTenpayClient(options);
``` ```

View File

@ -26,10 +26,12 @@ var paramMap = client.GenerateParametersForJssdkConfigRequest(response.Ticket, "
### 【附】生成参数相关扩展方法速查表: ### 【附】生成参数相关扩展方法速查表:
- 生成企业号 JS-SDK `wx.config` 所需的参数字典:`GenerateParametersForJSSDKConfig` - 生成 JS-SDK `wx.config` 所需的参数字典:`GenerateParametersForJSSDKConfig`
- 生成企业号 JS-SDK `wx.agentConfig` 所需的参数字典:`GenerateParametersForJSSDKAgentConfig` - 生成 JS-SDK `wx.agentConfig` 所需的参数字典:`GenerateParametersForJSSDKAgentConfig`
- 生成企业号网页授权 URL`GenerateParameterizedUrlForConnectOAuth2Authorize` - 生成网页授权 URL`GenerateParameterizedUrlForConnectOAuth2Authorize`
- 生成企业号扫码授权 URL`GenerateParameterizedUrlForSSOQrcodeConnectAuthorize` - 生成扫码授权 URL`GenerateParameterizedUrlForSSOQrcodeConnectAuthorize`
- 生成第三方单点登录扫码授权 URL`GenerateParameterizedUrlForSSO3rdQrcodeConnectAuthorize`

View File

@ -8,8 +8,11 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
{ {
public static class WechatWorkClientParameterExtensions public static class WechatWorkClientParameterExtensions
{ {
private const string BASE_URL_OPEN = "https://open.weixin.qq.com/";
private const string BASE_URL_OPENWORK = "https://open.work.weixin.qq.com/";
/// <summary> /// <summary>
/// <para>生成企业号 JS-SDK `wx.config` 所需的参数字典。</para> /// <para>生成企业微信 JS-SDK `wx.config` 所需的参数字典。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/90506 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/90506 </para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/90539 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/90539 </para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/90777 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/90777 </para>
@ -38,7 +41,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
} }
/// <summary> /// <summary>
/// <para>生成企业 JS-SDK `wx.agentConfig` 所需的参数字典。</para> /// <para>生成企业微信 JS-SDK `wx.agentConfig` 所需的参数字典。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/90506 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/90506 </para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/90539 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/90539 </para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/90777 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/90777 </para>
@ -68,7 +71,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
} }
/// <summary> /// <summary>
/// <para>生成企业网页授权 URL。</para> /// <para>生成企业微信网页授权 URL。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91022 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/91022 </para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91120 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/91120 </para>
/// </summary> /// </summary>
@ -83,7 +86,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
} }
/// <summary> /// <summary>
/// <para>生成企业网页授权 URL。</para> /// <para>生成企业微信网页授权 URL。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91022 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/91022 </para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91120 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/91120 </para>
/// </summary> /// </summary>
@ -95,7 +98,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
/// <returns></returns> /// <returns></returns>
public static string GenerateParameterizedUrlForConnectOAuth2Authorize(this WechatWorkClient client, int agentId, string redirectUrl, string scope, string? state = null) public static string GenerateParameterizedUrlForConnectOAuth2Authorize(this WechatWorkClient client, int agentId, string redirectUrl, string scope, string? state = null)
{ {
return new Url("https://open.weixin.qq.com") return new Url(BASE_URL_OPEN)
.AppendPathSegments("connect", "oauth2", "authorize") .AppendPathSegments("connect", "oauth2", "authorize")
.SetQueryParam("appid", string.IsNullOrEmpty(client.Credentials.SuiteId) ? client.Credentials.CorpId : client.Credentials.SuiteId) .SetQueryParam("appid", string.IsNullOrEmpty(client.Credentials.SuiteId) ? client.Credentials.CorpId : client.Credentials.SuiteId)
.SetQueryParam("redirect_uri", redirectUrl) .SetQueryParam("redirect_uri", redirectUrl)
@ -108,7 +111,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
} }
/// <summary> /// <summary>
/// <para>生成企业扫码授权 URL。</para> /// <para>生成企业微信扫码授权 URL。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91019 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/91019 </para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91124 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/91124 </para>
/// </summary> /// </summary>
@ -124,7 +127,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
} }
/// <summary> /// <summary>
/// <para>生成企业扫码授权 URL。</para> /// <para>生成企业微信扫码授权 URL。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91019 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/91019 </para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91124 </para> /// <para>REF: https://developer.work.weixin.qq.com/document/path/91124 </para>
/// </summary> /// </summary>
@ -137,7 +140,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
/// <returns></returns> /// <returns></returns>
public static string GenerateParameterizedUrlForSSOQrcodeConnectAuthorize(this WechatWorkClient client, int agentId, string redirectUrl, string? state = null, string? language = null, string? userType = null) public static string GenerateParameterizedUrlForSSOQrcodeConnectAuthorize(this WechatWorkClient client, int agentId, string redirectUrl, string? state = null, string? language = null, string? userType = null)
{ {
return new Url("https://open.work.weixin.qq.com") return new Url(BASE_URL_OPENWORK)
.AppendPathSegments("wwopen", "sso", "qrConnect") .AppendPathSegments("wwopen", "sso", "qrConnect")
.SetQueryParam("appid", client.Credentials.CorpId) .SetQueryParam("appid", client.Credentials.CorpId)
.SetQueryParam("agentid", agentId) .SetQueryParam("agentid", agentId)
@ -147,5 +150,25 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
.SetQueryParam("usertype", userType) .SetQueryParam("usertype", userType)
.ToString(); .ToString();
} }
/// <summary>
/// <para>生成企业微信第三方单点登录扫码授权 URL。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/10991 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="redirectUrl"></param>
/// <param name="state"></param>
/// <param name="userType"></param>
/// <returns></returns>
public static string GenerateParameterizedUrlForSSO3rdQrcodeConnectAuthorize(this WechatWorkClient client, string redirectUrl, string? state = null, string? userType = null)
{
return new Url(BASE_URL_OPENWORK)
.AppendPathSegments("wwopen", "sso", "3rd_qrConnect")
.SetQueryParam("appid", client.Credentials.CorpId)
.SetQueryParam("redirect_uri", redirectUrl)
.SetQueryParam("state", state)
.SetQueryParam("usertype", userType)
.ToString();
}
} }
} }

View File

@ -17,6 +17,6 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.Models
/// </summary> /// </summary>
[Newtonsoft.Json.JsonProperty("conflict_date")] [Newtonsoft.Json.JsonProperty("conflict_date")]
[System.Text.Json.Serialization.JsonPropertyName("conflict_date")] [System.Text.Json.Serialization.JsonPropertyName("conflict_date")]
public string[]? ConflictDateTimestampList { get; set; } public long[]? ConflictDateTimestampList { get; set; }
} }
} }

View File

@ -17,6 +17,6 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.Models
/// </summary> /// </summary>
[Newtonsoft.Json.JsonProperty("conflict_date")] [Newtonsoft.Json.JsonProperty("conflict_date")]
[System.Text.Json.Serialization.JsonPropertyName("conflict_date")] [System.Text.Json.Serialization.JsonPropertyName("conflict_date")]
public string[]? ConflictDateTimestampList { get; set; } public long[]? ConflictDateTimestampList { get; set; }
} }
} }