feat(work): 新增二次验证相关接口

This commit is contained in:
Fu Diwei 2023-12-02 17:17:06 +08:00
parent 506f9e6cff
commit 69d426e564
9 changed files with 165 additions and 42 deletions

View File

@ -50,5 +50,27 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
return await client.SendRequestWithJsonAsync<Models.CgibinAuthGetUserDetailResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
#region TAF
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/auth/get_tfa_info 接口。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/99499 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinAuthGetTAFInfoResponse> ExecuteCgibinAuthGetTAFInfoAsync(this WechatWorkClient client, Models.CgibinAuthGetTAFInfoRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "auth", "get_tfa_info")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinAuthGetTAFInfoResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
#endregion
}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
@ -281,6 +281,47 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
return await client.SendRequestWithJsonAsync<Models.CgibinUserGetActiveStatResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [GET] /cgi-bin/user/list_selected_ticket_user 接口。</para>
/// <para>REF: https://work.weixin.qq.com/api/doc/90001/90143/94894 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinUserListSelectedTicketUserResponse> ExecuteCgibinUserListSelectedTicketUserAsync(this WechatWorkClient client, Models.CgibinUserListSelectedTicketUserRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Get, "cgi-bin", "user", "list_selected_ticket_user")
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("selected_ticket", request.SelectedTicket);
return await client.SendRequestWithJsonAsync<Models.CgibinUserListSelectedTicketUserResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/user/list_id 接口。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/40856 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinUserListIdResponse> ExecuteCgibinUserListIdAsync(this WechatWorkClient client, Models.CgibinUserListIdRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "user", "list_id")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinUserListIdResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
#region Auth
/// <summary>
/// <para>异步调用 [GET] /cgi-bin/user/authsucc 接口。</para>
@ -305,6 +346,26 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
return await client.SendRequestWithJsonAsync<Models.CgibinUserAuthSuccessResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/user/tfa_succ 接口。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/99500 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinUserTAFSuccessResponse> ExecuteCgibinUserTAFSuccessAsync(this WechatWorkClient client, Models.CgibinUserTAFSuccessRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "user", "tfa_succ")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinUserTAFSuccessResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [GET] /cgi-bin/user/list_member_auth 接口。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/94513 </para>
@ -352,46 +413,5 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
return await client.SendRequestWithJsonAsync<Models.CgibinUserCheckMemberAuthResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
#endregion
/// <summary>
/// <para>异步调用 [GET] /cgi-bin/user/list_selected_ticket_user 接口。</para>
/// <para>REF: https://work.weixin.qq.com/api/doc/90001/90143/94894 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinUserListSelectedTicketUserResponse> ExecuteCgibinUserListSelectedTicketUserAsync(this WechatWorkClient client, Models.CgibinUserListSelectedTicketUserRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Get, "cgi-bin", "user", "list_selected_ticket_user")
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("selected_ticket", request.SelectedTicket);
return await client.SendRequestWithJsonAsync<Models.CgibinUserListSelectedTicketUserResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/user/list_id 接口。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/40856 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinUserListIdResponse> ExecuteCgibinUserListIdAsync(this WechatWorkClient client, Models.CgibinUserListIdRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "user", "list_id")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinUserListIdResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
}
}

View File

@ -0,0 +1,15 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/auth/get_tfa_info 接口的请求。</para>
/// </summary>
public class CgibinAuthGetTAFInfoRequest : WechatWorkRequest
{
/// <summary>
/// 获取或设置用户二次验证 Code。
/// </summary>
[Newtonsoft.Json.JsonProperty("code")]
[System.Text.Json.Serialization.JsonPropertyName("code")]
public string Code { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,22 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/auth/get_tfa_info 接口的响应。</para>
/// </summary>
public class CgibinAuthGetTAFInfoResponse : WechatWorkResponse
{
/// <summary>
/// 获取或设置成员 UserId。
/// </summary>
[Newtonsoft.Json.JsonProperty("userid")]
[System.Text.Json.Serialization.JsonPropertyName("userid")]
public string UserId { get; set; } = default!;
/// <summary>
/// 获取或设置二次验证授权码。
/// </summary>
[Newtonsoft.Json.JsonProperty("tfa_code")]
[System.Text.Json.Serialization.JsonPropertyName("tfa_code")]
public string TFACode { get; set; } = default!;
}
}

View File

@ -0,0 +1,22 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/user/tfa_succ 接口的请求。</para>
/// </summary>
public class CgibinUserTAFSuccessRequest : WechatWorkRequest
{
/// <summary>
/// 获取或设置成员账号。
/// </summary>
[Newtonsoft.Json.JsonProperty("userid")]
[System.Text.Json.Serialization.JsonPropertyName("userid")]
public string UserId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置二次验证授权码。
/// </summary>
[Newtonsoft.Json.JsonProperty("tfa_code")]
[System.Text.Json.Serialization.JsonPropertyName("tfa_code")]
public string TFACode { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,9 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/user/tfa_succ 接口的响应。</para>
/// </summary>
public class CgibinUserTAFSuccessResponse : WechatWorkResponse
{
}
}

View File

@ -0,0 +1,6 @@
{
"errcode": 0,
"errmsg": "ok",
"userid": "USERID",
"tfa_code": "TFA_CODE"
}

View File

@ -0,0 +1,4 @@
{
"userid": "USERID",
"tfa_code": "TFA_CODE"
}