From 9be140a9fda3f873ca6efa9c94f6bb449ba5a10a Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Fri, 6 Aug 2021 23:01:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(wxapi):=20=E6=96=B0=E5=A2=9E=E6=99=AE?= =?UTF-8?q?=E9=80=9A=E4=BB=A3=E4=BA=91=E5=BC=80=E5=8F=91=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WechatApiClientExecuteTcbExtensions.cs | 60 +++++++++++++++++++ .../TcbBatchDeleteFileRequest.cs | 25 ++++++++ .../TcbBatchDeleteFileResponse.cs | 45 ++++++++++++++ .../TcbBatchDownloadFileRequest.cs | 45 ++++++++++++++ .../TcbBatchDownloadFileResponse.cs | 52 ++++++++++++++++ .../TcbUploadFileRequest.cs | 25 ++++++++ .../TcbUploadFileResponse.cs | 46 ++++++++++++++ 7 files changed, 298 insertions(+) create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDeleteFileRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDeleteFileResponse.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDownloadFileRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDownloadFileResponse.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbUploadFileRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbUploadFileResponse.cs diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteTcbExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteTcbExtensions.cs index c5433cc2..4f94b01b 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteTcbExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteTcbExtensions.cs @@ -546,6 +546,66 @@ namespace SKIT.FlurlHttpClient.Wechat.Api return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } + + /// + /// 异步调用 [POST] /tcb/batchdeletefile 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/cloudbase/common/batchdeletefile.html + /// + /// + /// + /// + /// + public static async Task ExecuteTcbBatchDeleteFileAsync(this WechatApiClient client, Models.TcbBatchDeleteFileRequest 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, "tcb", "batchdeletefile") + .SetQueryParam("access_token", request.AccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + + /// + /// 异步调用 [POST] /tcb/batchdownloadfile 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/cloudbase/common/batchdownloadfile.html + /// + /// + /// + /// + /// + public static async Task ExecuteTcbBatchDownloadFileAsync(this WechatApiClient client, Models.TcbBatchDownloadFileRequest 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, "tcb", "batchdownloadfile") + .SetQueryParam("access_token", request.AccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + + /// + /// 异步调用 [POST] /tcb/uploadfile 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/cloudbase/common/uploadfile.html + /// + /// + /// + /// + /// + public static async Task ExecuteTcbUploadFileAsync(this WechatApiClient client, Models.TcbUploadFileRequest 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, "tcb", "uploadfile") + .SetQueryParam("access_token", request.AccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } #endregion } } diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDeleteFileRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDeleteFileRequest.cs new file mode 100644 index 00000000..775f2abb --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDeleteFileRequest.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /tcb/batchdeletefile 接口的请求。 + /// + public class TcbBatchDeleteFileRequest : WechatApiRequest + { + /// + /// 获取或设置环境 ID。 + /// + [Newtonsoft.Json.JsonProperty("env")] + [System.Text.Json.Serialization.JsonPropertyName("env")] + public string EnvironmentId { get; set; } = string.Empty; + + /// + /// 获取或设置文件 ID 列表。 + /// + [Newtonsoft.Json.JsonProperty("fileid_list")] + [System.Text.Json.Serialization.JsonPropertyName("fileid_list")] + public IList FileIdList { get; set; } = new List(); + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDeleteFileResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDeleteFileResponse.cs new file mode 100644 index 00000000..55f39ff8 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDeleteFileResponse.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /tcb/batchdeletefile 接口的响应。 + /// + public class TcbBatchDeleteFileResponse : WechatApiResponse + { + public static class Types + { + public class File + { + /// + /// 获取或设置文件 ID。 + /// + [Newtonsoft.Json.JsonProperty("fileid")] + [System.Text.Json.Serialization.JsonPropertyName("fileid")] + public string FileId { get; set; } = default!; + + /// + /// 获取或设置错误码。 + /// + [Newtonsoft.Json.JsonProperty("status")] + [System.Text.Json.Serialization.JsonPropertyName("status")] + public int ErrorCode { get; set; } + + /// + /// 获取或设置错误描述。 + /// + [Newtonsoft.Json.JsonProperty("errmsg")] + [System.Text.Json.Serialization.JsonPropertyName("errmsg")] + public string? ErrorMessage { get; set; } + } + } + + /// + /// 获取或设置文件列表。 + /// + [Newtonsoft.Json.JsonProperty("delete_list")] + [System.Text.Json.Serialization.JsonPropertyName("delete_list")] + public Types.File[] FileList { get; set; } = default!; + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDownloadFileRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDownloadFileRequest.cs new file mode 100644 index 00000000..02f07c3f --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDownloadFileRequest.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /tcb/batchdownloadfile 接口的请求。 + /// + public class TcbBatchDownloadFileRequest : WechatApiRequest + { + public static class Types + { + public class File + { + /// + /// 获取或设置文件 ID。 + /// + [Newtonsoft.Json.JsonProperty("fileid")] + [System.Text.Json.Serialization.JsonPropertyName("fileid")] + public string FileId { get; set; } = string.Empty; + + /// + /// 获取或设置下载链接有效期(单位:秒)。 + /// + [Newtonsoft.Json.JsonProperty("max_age")] + [System.Text.Json.Serialization.JsonPropertyName("max_age")] + public int MaxAge { get; set; } + } + } + + /// + /// 获取或设置环境 ID。 + /// + [Newtonsoft.Json.JsonProperty("env")] + [System.Text.Json.Serialization.JsonPropertyName("env")] + public string EnvironmentId { get; set; } = string.Empty; + + /// + /// 获取或设置文件列表。 + /// + [Newtonsoft.Json.JsonProperty("file_list")] + [System.Text.Json.Serialization.JsonPropertyName("file_list")] + public IList FileList { get; set; } = new List(); + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDownloadFileResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDownloadFileResponse.cs new file mode 100644 index 00000000..b63cf912 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbBatchDownloadFileResponse.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /tcb/batchdownloadfile 接口的响应。 + /// + public class TcbBatchDownloadFileResponse : WechatApiResponse + { + public static class Types + { + public class File + { + /// + /// 获取或设置文件 ID。 + /// + [Newtonsoft.Json.JsonProperty("fileid")] + [System.Text.Json.Serialization.JsonPropertyName("fileid")] + public string FileId { get; set; } = default!; + + /// + /// 获取或设置下载链接。 + /// + [Newtonsoft.Json.JsonProperty("download_url")] + [System.Text.Json.Serialization.JsonPropertyName("download_url")] + public string? DownloadUrl { get; set; } + + /// + /// 获取或设置错误码。 + /// + [Newtonsoft.Json.JsonProperty("status")] + [System.Text.Json.Serialization.JsonPropertyName("status")] + public int ErrorCode { get; set; } + + /// + /// 获取或设置错误描述。 + /// + [Newtonsoft.Json.JsonProperty("errmsg")] + [System.Text.Json.Serialization.JsonPropertyName("errmsg")] + public string? ErrorMessage { get; set; } + } + } + + /// + /// 获取或设置文件列表。 + /// + [Newtonsoft.Json.JsonProperty("file_list")] + [System.Text.Json.Serialization.JsonPropertyName("file_list")] + public Types.File[] FileList { get; set; } = default!; + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbUploadFileRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbUploadFileRequest.cs new file mode 100644 index 00000000..c5e13350 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbUploadFileRequest.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /tcb/uploadfile 接口的请求。 + /// + public class TcbUploadFileRequest : WechatApiRequest + { + /// + /// 获取或设置环境 ID。 + /// + [Newtonsoft.Json.JsonProperty("env")] + [System.Text.Json.Serialization.JsonPropertyName("env")] + public string EnvironmentId { get; set; } = string.Empty; + + /// + /// 获取或设置上传路径。 + /// + [Newtonsoft.Json.JsonProperty("path")] + [System.Text.Json.Serialization.JsonPropertyName("path")] + public string Path { get; set; } = string.Empty; + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbUploadFileResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbUploadFileResponse.cs new file mode 100644 index 00000000..292834ec --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Tcb/ThirdPartyPlatforms/TcbUploadFileResponse.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /tcb/uploadfile 接口的响应。 + /// + public class TcbUploadFileResponse : WechatApiResponse + { + /// + /// 获取或设置上传 URL。 + /// + [Newtonsoft.Json.JsonProperty("url")] + [System.Text.Json.Serialization.JsonPropertyName("url")] + public string Url { get; set; } = default!; + + /// + /// 获取或设置上传凭证。 + /// + [Newtonsoft.Json.JsonProperty("token")] + [System.Text.Json.Serialization.JsonPropertyName("token")] + public string Token { get; set; } = default!; + + /// + /// 获取或设置授权信息。 + /// + [Newtonsoft.Json.JsonProperty("authorization")] + [System.Text.Json.Serialization.JsonPropertyName("authorization")] + public string Authorization { get; set; } = default!; + + /// + /// 获取或设置文件 ID。 + /// + [Newtonsoft.Json.JsonProperty("file_id")] + [System.Text.Json.Serialization.JsonPropertyName("file_id")] + public string FileId { get; set; } = default!; + + /// + /// 获取或设置 COS 文件 ID。 + /// + [Newtonsoft.Json.JsonProperty("cos_file_id")] + [System.Text.Json.Serialization.JsonPropertyName("cos_file_id")] + public string COSFileId { get; set; } = default!; + } +}