feat(work): 新增通讯录搜索相关接口

This commit is contained in:
Fu Diwei
2022-10-12 19:32:39 +08:00
parent 0cd1af3f24
commit ed9dd4da75
11 changed files with 458 additions and 2 deletions

View File

@@ -149,7 +149,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.Events
/// </summary>
[Obsolete("相关接口或字段于 2022-08-15 下线。")]
[System.Xml.Serialization.XmlElement("MainDepartment", IsNullable = true)]
public int? UserMainDepartmentId { get; set; }
public long? UserMainDepartmentId { get; set; }
/// <summary>
/// 获取或设置用户邮箱。

View File

@@ -425,6 +425,46 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
return await client.SendRequestWithJsonAsync<Models.CgibinServiceContactSortResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/service/contact/search 接口。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91844 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinServiceContactSearchResponse> ExecuteCgibinServiceContactSearchAsync(this WechatWorkClient client, Models.CgibinServiceContactSearchRequest 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", "service", "contact", "search")
.SetQueryParam("provider_access_token", request.ProviderAccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinServiceContactSearchResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/service/contact/batchsearch 接口。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/91844 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinServiceContactBatchSearchResponse> ExecuteCgibinServiceContactBatchSearchAsync(this WechatWorkClient client, Models.CgibinServiceContactBatchSearchRequest 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", "service", "contact", "batchsearch")
.SetQueryParam("provider_access_token", request.ProviderAccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinServiceContactBatchSearchResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
#endregion
#region Batch

View File

@@ -44,7 +44,7 @@
/// </summary>
[Newtonsoft.Json.JsonProperty("is_last")]
[System.Text.Json.Serialization.JsonPropertyName("is_last")]
public bool IsEnding { get; set; }
public bool IsLast { get; set; }
/// <summary>
/// 获取或设置翻页标记。

View File

@@ -0,0 +1,86 @@
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/service/contact/batchsearch 接口的请求。</para>
/// </summary>
public class CgibinServiceContactBatchSearchRequest : WechatWorkRequest
{
public static class Types
{
public class QueryRequest
{
/// <summary>
/// 获取或设置搜索关键词。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_word")]
[System.Text.Json.Serialization.JsonPropertyName("query_word")]
public string QueryWord { get; set; } = string.Empty;
/// <summary>
/// 获取或设置查询类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_type")]
[System.Text.Json.Serialization.JsonPropertyName("query_type")]
public int? QueryType { get; set; }
/// <summary>
/// 获取或设置查询范围。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_range")]
[System.Text.Json.Serialization.JsonPropertyName("query_range")]
public int? QueryRange { get; set; }
/// <summary>
/// 获取或设置精确匹配字段类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("full_match_field")]
[System.Text.Json.Serialization.JsonPropertyName("full_match_field")]
public int? FullMatchField { get; set; }
/// <summary>
/// 获取或设置翻页标记。
/// </summary>
[Newtonsoft.Json.JsonProperty("cursor")]
[System.Text.Json.Serialization.JsonPropertyName("cursor")]
public string? Cursor { get; set; }
/// <summary>
/// 获取或设置分页每页数量。
/// </summary>
[Newtonsoft.Json.JsonProperty("limit")]
[System.Text.Json.Serialization.JsonPropertyName("limit")]
public int? Limit { get; set; }
}
}
/// <summary>
/// 获取或设置服务商 AccessToken。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string ProviderAccessToken { get; set; } = string.Empty;
/// <summary>
/// 获取或设置授权方 CorpId。
/// </summary>
[Newtonsoft.Json.JsonProperty("auth_corpid")]
[System.Text.Json.Serialization.JsonPropertyName("auth_corpid")]
public string AuthorizerCorpId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置应用 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("agentid")]
[System.Text.Json.Serialization.JsonPropertyName("agentid")]
public int? AgentId { get; set; }
/// <summary>
/// 获取或设置搜索请求列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_request_list")]
[System.Text.Json.Serialization.JsonPropertyName("query_request_list")]
public IList<Types.QueryRequest>? QueryRequestList { get; set; }
}
}

View File

@@ -0,0 +1,101 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/service/contact/batchsearch 接口的响应。</para>
/// </summary>
public class CgibinServiceContactBatchSearchResponse : WechatWorkResponse
{
public static class Types
{
public class Query
{
public static class Types
{
public class QueryRequest
{
/// <summary>
/// 获取或设置搜索关键词。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_word")]
[System.Text.Json.Serialization.JsonPropertyName("query_word")]
public string QueryWord { get; set; } = default!;
/// <summary>
/// 获取或设置查询类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_type")]
[System.Text.Json.Serialization.JsonPropertyName("query_type")]
public int? QueryType { get; set; }
/// <summary>
/// 获取或设置查询范围。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_range")]
[System.Text.Json.Serialization.JsonPropertyName("query_range")]
public int? QueryRange { get; set; }
/// <summary>
/// 获取或设置精确匹配字段类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("full_match_field")]
[System.Text.Json.Serialization.JsonPropertyName("full_match_field")]
public int? FullMatchField { get; set; }
/// <summary>
/// 获取或设置翻页标记。
/// </summary>
[Newtonsoft.Json.JsonProperty("cursor")]
[System.Text.Json.Serialization.JsonPropertyName("cursor")]
public string? Cursor { get; set; }
/// <summary>
/// 获取或设置分页每页数量。
/// </summary>
[Newtonsoft.Json.JsonProperty("limit")]
[System.Text.Json.Serialization.JsonPropertyName("limit")]
public int? Limit { get; set; }
}
public class QueryResult : CgibinServiceContactSearchResponse.Types.QueryResult
{
}
}
/// <summary>
/// 获取或设置搜索请求信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_request")]
[System.Text.Json.Serialization.JsonPropertyName("query_request")]
public Types.QueryRequest QueryRequest { get; set; } = default!;
/// <summary>
/// 获取或设置搜索结果信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_result")]
[System.Text.Json.Serialization.JsonPropertyName("query_result")]
public Types.QueryResult QueryResult { get; set; } = default!;
/// <summary>
/// 获取或设置翻页是否结束。
/// </summary>
[Newtonsoft.Json.JsonProperty("is_last")]
[System.Text.Json.Serialization.JsonPropertyName("is_last")]
public bool IsLast { get; set; }
/// <summary>
/// 获取或设置翻页标记。
/// </summary>
[Newtonsoft.Json.JsonProperty("next_cursor")]
[System.Text.Json.Serialization.JsonPropertyName("next_cursor")]
public string? NextCursor { get; set; }
}
}
/// <summary>
/// 获取或设置搜索列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_result_list")]
[System.Text.Json.Serialization.JsonPropertyName("query_result_list")]
public Types.Query[] QueryList { get; set; } = default!;
}
}

View File

@@ -0,0 +1,71 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/service/contact/search 接口的请求。</para>
/// </summary>
public class CgibinServiceContactSearchRequest : WechatWorkRequest
{
/// <summary>
/// 获取或设置服务商 AccessToken。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string ProviderAccessToken { get; set; } = string.Empty;
/// <summary>
/// 获取或设置授权方 CorpId。
/// </summary>
[Newtonsoft.Json.JsonProperty("auth_corpid")]
[System.Text.Json.Serialization.JsonPropertyName("auth_corpid")]
public string AuthorizerCorpId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置应用 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("agentid")]
[System.Text.Json.Serialization.JsonPropertyName("agentid")]
public int? AgentId { get; set; }
/// <summary>
/// 获取或设置搜索关键词。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_word")]
[System.Text.Json.Serialization.JsonPropertyName("query_word")]
public string QueryWord { get; set; } = string.Empty;
/// <summary>
/// 获取或设置查询类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_type")]
[System.Text.Json.Serialization.JsonPropertyName("query_type")]
public int? QueryType { get; set; }
/// <summary>
/// 获取或设置查询范围。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_range")]
[System.Text.Json.Serialization.JsonPropertyName("query_range")]
public int? QueryRange { get; set; }
/// <summary>
/// 获取或设置精确匹配字段类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("full_match_field")]
[System.Text.Json.Serialization.JsonPropertyName("full_match_field")]
public int? FullMatchField { get; set; }
/// <summary>
/// 获取或设置翻页标记。
/// </summary>
[Newtonsoft.Json.JsonProperty("cursor")]
[System.Text.Json.Serialization.JsonPropertyName("cursor")]
public string? Cursor { get; set; }
/// <summary>
/// 获取或设置分页每页数量。
/// </summary>
[Newtonsoft.Json.JsonProperty("limit")]
[System.Text.Json.Serialization.JsonPropertyName("limit")]
public int? Limit { get; set; }
}
}

View File

@@ -0,0 +1,86 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/service/contact/search 接口的响应。</para>
/// </summary>
public class CgibinServiceContactSearchResponse : WechatWorkResponse
{
public static class Types
{
public class QueryResult
{
public static class Types
{
public class User
{
/// <summary>
/// 获取或设置查询到的用户 UserId 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("userid")]
[System.Text.Json.Serialization.JsonPropertyName("userid")]
public string[]? UserIdList { get; set; } = default!;
/// <summary>
/// 获取或设置查询到的用户 OpenUserId 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("open_userid")]
[System.Text.Json.Serialization.JsonPropertyName("open_userid")]
public string[]? OpenUserIdList { get; set; } = default!;
}
public class Department
{
/// <summary>
/// 获取或设置查询到的部门 ID 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("department_id")]
[System.Text.Json.Serialization.JsonPropertyName("department_id")]
public long[]? DepartmentIdList { get; set; } = default!;
}
}
/// <summary>
/// 获取或设置查询到的用户信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("user")]
[System.Text.Json.Serialization.JsonPropertyName("user")]
public Types.User? User { get; set; }
/// <summary>
/// 获取或设置查询到的部门信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("party")]
[System.Text.Json.Serialization.JsonPropertyName("party")]
public Types.Department? Department { get; set; }
/// <summary>
/// 获取或设置查询到的已离职用户信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("dismiss_user")]
[System.Text.Json.Serialization.JsonPropertyName("dismiss_user")]
public Types.User? DismissUser { get; set; }
}
}
/// <summary>
/// 获取或设置搜索结果信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("query_result")]
[System.Text.Json.Serialization.JsonPropertyName("query_result")]
public Types.QueryResult QueryResult { get; set; } = default!;
/// <summary>
/// 获取或设置翻页是否结束。
/// </summary>
[Newtonsoft.Json.JsonProperty("is_last")]
[System.Text.Json.Serialization.JsonPropertyName("is_last")]
public bool IsLast { get; set; }
/// <summary>
/// 获取或设置翻页标记。
/// </summary>
[Newtonsoft.Json.JsonProperty("next_cursor")]
[System.Text.Json.Serialization.JsonPropertyName("next_cursor")]
public string? NextCursor { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
{
"auth_corpid": "wwxxxxxx",
"agentid": 1000046,
"query_request_list": [
{
"query_word": "zhangsan",
"query_type": 1,
"query_range": 1,
"limit": 50,
"full_match_field": 1,
"cursor": "CURSOR"
}
]
}

View File

@@ -0,0 +1,29 @@
{
"errcode": 0,
"errmsg": "ok",
"query_result_list": [
{
"query_request": {
"query_word": "zhangsan",
"query_type": 1,
"limit": 50,
"cursor": "CURSOR"
},
"query_result": {
"user": {
"userid": ["zhangshan", "lisi"],
"open_userid": ["wwxxxx", "wwxxxa"]
},
"party": {
"department_id": [1, 2, 3]
},
"dismiss_user": {
"userid": ["zhangshan", "lisi"],
"open_userid": ["wwxxxx", "wwxxxa"]
}
},
"is_last": false,
"next_cursor": "NEXT_CURSOR"
}
]
}

View File

@@ -0,0 +1,10 @@
{
"auth_corpid": "wwxxxxxx",
"query_word": "zhangsan",
"query_type": 1,
"query_range": 1,
"agentid": 1000046,
"limit": 50,
"full_match_field": 1,
"cursor": "CURSOR"
}

View File

@@ -0,0 +1,19 @@
{
"errcode": 0,
"errmsg": "ok",
"query_result": {
"user": {
"userid": ["zhangshan", "lisi"],
"open_userid": ["wwxxxx", "wwxxxa"]
},
"party": {
"department_id": [1, 2, 3]
},
"dismiss_user": {
"userid": ["zhangshan", "lisi"],
"open_userid": ["wwxxxx", "wwxxxa"]
}
},
"is_last": false,
"next_cursor": "NEXT_CURSOR"
}