From 419eba171517f9a678aee7ae4bf742aa48ed3f63 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Fri, 6 Aug 2021 14:00:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(wxapi):=20=E6=96=B0=E5=A2=9E=E6=89=B9?= =?UTF-8?q?=E9=87=8F=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 --- ...tApiClientExecuteComponentTcbExtensions.cs | 82 +++++++++++++++++++ .../COS/ComponentTcbBatchDeleteFileRequest.cs | 32 ++++++++ .../ComponentTcbBatchDeleteFileResponse.cs | 45 ++++++++++ .../ComponentTcbBatchDownloadFileRequest.cs | 52 ++++++++++++ .../ComponentTcbBatchDownloadFileResponse.cs | 52 ++++++++++++ .../COS/ComponentTcbGetBucketRequest.cs | 46 +++++++++++ .../COS/ComponentTcbGetBucketResponse.cs | 62 ++++++++++++++ .../COS/ComponentTcbUploadFileRequest.cs | 32 ++++++++ .../COS/ComponentTcbUploadFileResponse.cs | 46 +++++++++++ 9 files changed, 449 insertions(+) create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDeleteFileRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDeleteFileResponse.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDownloadFileRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDownloadFileResponse.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbGetBucketRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbGetBucketResponse.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbUploadFileRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbUploadFileResponse.cs diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteComponentTcbExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteComponentTcbExtensions.cs index 80ba7fa3..10e4e1d6 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteComponentTcbExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteComponentTcbExtensions.cs @@ -559,5 +559,87 @@ namespace SKIT.FlurlHttpClient.Wechat.Api return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } #endregion + + #region COS + /// + /// 异步调用 [POST] /componenttcb/uploadfile 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/cloudbase/batch/uploadfile.html + /// + /// + /// + /// + /// + public static async Task ExecuteComponentTcbUploadFileAsync(this WechatApiClient client, Models.ComponentTcbUploadFileRequest 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, "componenttcb", "uploadfile") + .SetQueryParam("access_token", request.ComponentAccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + + /// + /// 异步调用 [POST] /componenttcb/batchdownloadfile 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/cloudbase/batch/batchdownloadfile.html + /// + /// + /// + /// + /// + public static async Task ExecuteComponentTcbBatchDownloadFileAsync(this WechatApiClient client, Models.ComponentTcbBatchDownloadFileRequest 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, "componenttcb", "batchdownloadfile") + .SetQueryParam("access_token", request.ComponentAccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + + /// + /// 异步调用 [POST] /componenttcb/batchdeletefile 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/cloudbase/batch/batchdeletefile.html + /// + /// + /// + /// + /// + public static async Task ExecuteComponentTcbBatchDeleteFileAsync(this WechatApiClient client, Models.ComponentTcbBatchDeleteFileRequest 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, "componenttcb", "batchdeletefile") + .SetQueryParam("access_token", request.ComponentAccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + + /// + /// 异步调用 [POST] /componenttcb/getbucket 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/cloudbase/batch/getbucket.html + /// + /// + /// + /// + /// + public static async Task ExecuteComponentTcbGetBucketAsync(this WechatApiClient client, Models.ComponentTcbGetBucketRequest 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, "componenttcb", "getbucket") + .SetQueryParam("access_token", request.ComponentAccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + #endregion } } diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDeleteFileRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDeleteFileRequest.cs new file mode 100644 index 00000000..2e54b102 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDeleteFileRequest.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /componenttcb/batchdeletefile 接口的请求。 + /// + public class ComponentTcbBatchDeleteFileRequest : WechatApiRequest + { + /// + /// 获取或设置第三方平台 AccessToken。 + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public string ComponentAccessToken { get; set; } = string.Empty; + + /// + /// 获取或设置环境 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/ComponentTcb/COS/ComponentTcbBatchDeleteFileResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDeleteFileResponse.cs new file mode 100644 index 00000000..9c03a464 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDeleteFileResponse.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /componenttcb/batchdeletefile 接口的响应。 + /// + public class ComponentTcbBatchDeleteFileResponse : 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/ComponentTcb/COS/ComponentTcbBatchDownloadFileRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDownloadFileRequest.cs new file mode 100644 index 00000000..2d4d1399 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDownloadFileRequest.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /componenttcb/batchdownloadfile 接口的请求。 + /// + public class ComponentTcbBatchDownloadFileRequest : 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; } + } + } + + /// + /// 获取或设置第三方平台 AccessToken。 + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public string ComponentAccessToken { get; set; } = string.Empty; + + /// + /// 获取或设置环境 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/ComponentTcb/COS/ComponentTcbBatchDownloadFileResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDownloadFileResponse.cs new file mode 100644 index 00000000..773c26a3 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbBatchDownloadFileResponse.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /componenttcb/batchdownloadfile 接口的响应。 + /// + public class ComponentTcbBatchDownloadFileResponse : 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/ComponentTcb/COS/ComponentTcbGetBucketRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbGetBucketRequest.cs new file mode 100644 index 00000000..13b4044d --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbGetBucketRequest.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /componenttcb/getbucket 接口的请求。 + /// + public class ComponentTcbGetBucketRequest : WechatApiRequest + { + /// + /// 获取或设置第三方平台 AccessToken。 + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public string ComponentAccessToken { get; set; } = string.Empty; + + /// + /// 获取或设置环境 ID。 + /// + [Newtonsoft.Json.JsonProperty("env")] + [System.Text.Json.Serialization.JsonPropertyName("env")] + public string EnvironmentId { get; set; } = string.Empty; + + /// + /// 获取或设置前缀匹配。 + /// + [Newtonsoft.Json.JsonProperty("prefix")] + [System.Text.Json.Serialization.JsonPropertyName("prefix")] + public string? Prefix { get; set; } + + /// + /// 获取或设置定界符。 + /// + [Newtonsoft.Json.JsonProperty("delimiter")] + [System.Text.Json.Serialization.JsonPropertyName("delimiter")] + public string? Delimiter { get; set; } + + /// + /// 获取或设置标志位。 + /// + [Newtonsoft.Json.JsonProperty("marker")] + [System.Text.Json.Serialization.JsonPropertyName("marker")] + public string? Marker { get; set; } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbGetBucketResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbGetBucketResponse.cs new file mode 100644 index 00000000..193a0c0c --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbGetBucketResponse.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /componenttcb/getbucket 接口的响应。 + /// + public class ComponentTcbGetBucketResponse : WechatApiResponse + { + public static class Types + { + public class File + { + /// + /// 获取或设置文件名称。 + /// + [Newtonsoft.Json.JsonProperty("key")] + [System.Text.Json.Serialization.JsonPropertyName("key")] + public string FileKey { get; set; } = default!; + + /// + /// 获取或设置文件的 MD5 值。 + /// + [Newtonsoft.Json.JsonProperty("md5")] + [System.Text.Json.Serialization.JsonPropertyName("md5")] + public string FileMd5 { get; set; } = default!; + + /// + /// 获取或设置文件大小(单位:字节)。 + /// + [Newtonsoft.Json.JsonProperty("size")] + [System.Text.Json.Serialization.JsonPropertyName("size")] + [System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)] + public int FileSize { get; set; } + + /// + /// 获取或设置最近修改时间。 + /// + [Newtonsoft.Json.JsonProperty("last_modified")] + [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.RFC3339DateTimeOffsetConverter))] + [System.Text.Json.Serialization.JsonPropertyName("last_modified")] + [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.RFC3339DateTimeOffsetConverter))] + public DateTimeOffset LastModifiedTime { get; set; } = default!; + } + } + + /// + /// 获取或设置文件列表。 + /// + [Newtonsoft.Json.JsonProperty("contents")] + [System.Text.Json.Serialization.JsonPropertyName("contents")] + public Types.File[] FileList6 { get; set; } = default!; + + /// + /// 获取或设置内容是否被截断。 + /// + [Newtonsoft.Json.JsonProperty("is_truncated")] + [System.Text.Json.Serialization.JsonPropertyName("is_truncated")] + public bool IsTruncated { get; set; } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbUploadFileRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbUploadFileRequest.cs new file mode 100644 index 00000000..5916ed44 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbUploadFileRequest.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /componenttcb/uploadfile 接口的请求。 + /// + public class ComponentTcbUploadFileRequest : WechatApiRequest + { + /// + /// 获取或设置第三方平台 AccessToken。 + /// + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public string ComponentAccessToken { get; set; } = string.Empty; + + /// + /// 获取或设置环境 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/ComponentTcb/COS/ComponentTcbUploadFileResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbUploadFileResponse.cs new file mode 100644 index 00000000..21ceb807 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/ComponentTcb/COS/ComponentTcbUploadFileResponse.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /componenttcb/uploadfile 接口的响应。 + /// + public class ComponentTcbUploadFileResponse : 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!; + } +}