diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/Extensions/WechatWorkClientExecuteCgibinDepartmentExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/Extensions/WechatWorkClientExecuteCgibinDepartmentExtensions.cs index b99d1197..aa91d39c 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Work/Extensions/WechatWorkClientExecuteCgibinDepartmentExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/Extensions/WechatWorkClientExecuteCgibinDepartmentExtensions.cs @@ -102,5 +102,51 @@ namespace SKIT.FlurlHttpClient.Wechat.Work return await client.SendRequestWithJsonAsync(flurlReq, cancellationToken: cancellationToken); } + + /// + /// 异步调用 [GET] /cgi-bin/department/simplelist 接口。 + /// REF: https://developer.work.weixin.qq.com/document/path/95350 + /// REF: https://developer.work.weixin.qq.com/document/path/95406 + /// + /// + /// + /// + /// + public static async Task ExecuteCgibinDepartmentSimpleListAsync(this WechatWorkClient client, Models.CgibinDepartmentSimpleListRequest 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", "department", "simplelist") + .SetQueryParam("access_token", request.AccessToken); + + if (request.ParentDepartmentId != null) + flurlReq.SetQueryParam("id", request.ParentDepartmentId.Value); + + return await client.SendRequestWithJsonAsync(flurlReq, cancellationToken: cancellationToken); + } + + /// + /// 异步调用 [GET] /cgi-bin/department/get 接口。 + /// REF: https://developer.work.weixin.qq.com/document/path/95351 + /// REF: https://developer.work.weixin.qq.com/document/path/95407 + /// + /// + /// + /// + /// + public static async Task ExecuteCgibinDepartmentGetAsync(this WechatWorkClient client, Models.CgibinDepartmentGetRequest 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", "department", "get") + .SetQueryParam("access_token", request.AccessToken) + .SetQueryParam("id", request.DepartmentId); + + return await client.SendRequestWithJsonAsync(flurlReq, cancellationToken: cancellationToken); + } } } diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentGetRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentGetRequest.cs new file mode 100644 index 00000000..c47a88b0 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentGetRequest.cs @@ -0,0 +1,15 @@ +namespace SKIT.FlurlHttpClient.Wechat.Work.Models +{ + /// + /// 表示 [GET] /cgi-bin/department/get 接口的请求。 + /// + public class CgibinDepartmentGetRequest : WechatWorkRequest + { + /// + /// 获取或设置部门 ID。 + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public int DepartmentId { get; set; } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentGetResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentGetResponse.cs new file mode 100644 index 00000000..fccc652d --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentGetResponse.cs @@ -0,0 +1,22 @@ +namespace SKIT.FlurlHttpClient.Wechat.Work.Models +{ + /// + /// 表示 [GET] /cgi-bin/department/get 接口的响应。 + /// + public class CgibinDepartmentGetResponse : WechatWorkResponse + { + public static class Types + { + public class Department : CgibinDepartmentListResponse.Types.Department + { + } + } + + /// + /// 获取或设置部门信息。 + /// + [Newtonsoft.Json.JsonProperty("department")] + [System.Text.Json.Serialization.JsonPropertyName("department")] + public Types.Department Department { get; set; } = default!; + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentSimpleListRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentSimpleListRequest.cs new file mode 100644 index 00000000..087defbb --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentSimpleListRequest.cs @@ -0,0 +1,15 @@ +namespace SKIT.FlurlHttpClient.Wechat.Work.Models +{ + /// + /// 表示 [GET] /cgi-bin/department/simplelist 接口的请求。 + /// + public class CgibinDepartmentSimpleListRequest : WechatWorkRequest + { + /// + /// 获取或设置指定上级部门 ID。 + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public int? ParentDepartmentId { get; set; } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentSimpleListResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentSimpleListResponse.cs new file mode 100644 index 00000000..45770414 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinDepartment/CgibinDepartmentSimpleListResponse.cs @@ -0,0 +1,42 @@ +namespace SKIT.FlurlHttpClient.Wechat.Work.Models +{ + /// + /// 表示 [GET] /cgi-bin/department/simplelist 接口的响应。 + /// + public class CgibinDepartmentSimpleListResponse : WechatWorkResponse + { + public static class Types + { + public class Department + { + /// + /// 获取或设置部门 ID。 + /// + [Newtonsoft.Json.JsonProperty("id")] + [System.Text.Json.Serialization.JsonPropertyName("id")] + public int DepartmentId { get; set; } + + /// + /// 获取或设置上级部门 ID。 + /// + [Newtonsoft.Json.JsonProperty("parentid")] + [System.Text.Json.Serialization.JsonPropertyName("parentid")] + public int ParentDepartmentId { get; set; } + + /// + /// 获取或设置在上级部门中的次序值。 + /// + [Newtonsoft.Json.JsonProperty("order")] + [System.Text.Json.Serialization.JsonPropertyName("order")] + public long DepartmentOrder { get; set; } + } + } + + /// + /// 获取或设置部门列表。 + /// + [Newtonsoft.Json.JsonProperty("department_id")] + [System.Text.Json.Serialization.JsonPropertyName("department_id")] + public Types.Department[] DepartmentList { get; set; } = default!; + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkEndpoints.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkEndpoints.cs index d2867676..c149567e 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkEndpoints.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkEndpoints.cs @@ -1,6 +1,4 @@ -using System; - -namespace SKIT.FlurlHttpClient.Wechat.Work +namespace SKIT.FlurlHttpClient.Wechat.Work { /// /// 企业微信 API 接口域名。 diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkEvent.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkEvent.cs index 35a69f1a..b1ff0fae 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkEvent.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkEvent.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Xml.Serialization; namespace SKIT.FlurlHttpClient.Wechat.Work diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkRequest.cs index b293eb78..5657a134 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkRequest.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkRequest.cs @@ -1,6 +1,4 @@ -using System; - -namespace SKIT.FlurlHttpClient.Wechat.Work +namespace SKIT.FlurlHttpClient.Wechat.Work { /// /// 表示企业微信 API 请求的基类。 diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkResponse.cs index 32e91b9a..a2b22ee3 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkResponse.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/WechatWorkResponse.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace SKIT.FlurlHttpClient.Wechat.Work { diff --git a/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentDeleteRequest.json b/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentDeleteRequest.json deleted file mode 100644 index 22fdca1b..00000000 --- a/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentDeleteRequest.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentGetResponse.json b/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentGetResponse.json new file mode 100644 index 00000000..9553dee7 --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentGetResponse.json @@ -0,0 +1,12 @@ +{ + "errcode": 0, + "errmsg": "ok", + "department": { + "id": 2, + "name": "广州研发中心", + "name_en": "RDGZ", + "department_leader": [ "zhangsan", "lisi" ], + "parentid": 1, + "order": 10 + } +} \ No newline at end of file diff --git a/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentListRequest.json b/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentListRequest.json deleted file mode 100644 index 22fdca1b..00000000 --- a/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentListRequest.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentSimpleListResponse.json b/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentSimpleListResponse.json new file mode 100644 index 00000000..51faf218 --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinDepartment/CgibinDepartmentSimpleListResponse.json @@ -0,0 +1,16 @@ +{ + "errcode": 0, + "errmsg": "ok", + "department_id": [ + { + "id": 2, + "parentid": 1, + "order": 10 + }, + { + "id": 3, + "parentid": 2, + "order": 40 + } + ] +} \ No newline at end of file