-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...endedSDK/OpenApi/Extensions/DouyinMicroAppOpenApiClientExecuteThirdPartyFileExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Flurl; | ||
using Flurl.Http; | ||
|
||
namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.OpenApi | ||
{ | ||
public static class DouyinMicroAppOpenApiClientExecuteThirdPartyFileExtensions | ||
{ | ||
/// <summary> | ||
/// <para>异步调用 [POST] /tpapp/v2/file/upload_material 接口。</para> | ||
/// <para> | ||
/// REF: <br/> | ||
/// <![CDATA[ https://developer.open-douyin.com/docs/resource/zh-CN/thirdparty/API/smallprogram/upload-pic-material-v2 ]]> | ||
/// </para> | ||
/// </summary> | ||
/// <param name="client"></param> | ||
/// <param name="request"></param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns></returns> | ||
public static async Task<Models.OpenApiThirdPartyFileUploadMaterialV2Response> ExecuteOpenApiThirdPartyFileUploadMaterialV2Async(this DouyinMicroAppOpenApiClient client, Models.OpenApiThirdPartyFileUploadMaterialV2Request request, CancellationToken cancellationToken = default) | ||
{ | ||
if (client is null) throw new ArgumentNullException(nameof(client)); | ||
if (request is null) throw new ArgumentNullException(nameof(request)); | ||
|
||
if (request.MaterialFileName is null) | ||
request.MaterialFileName = Guid.NewGuid().ToString("N").ToLower() + ".jpg"; | ||
|
||
IFlurlRequest flurlReq = client | ||
.CreateFlurlRequest(request, HttpMethod.Post, "tpapp", "v2", "file", "upload_material") | ||
.WithUrl(url => new Url(client._BASEURL_LEGACY).AppendPathSegments("tpapp", "v2", "file", "upload_material")) | ||
.WithHeader("access-token", request.ComponentAccessToken); | ||
|
||
using var httpContent = Utilities.FileHttpContentBuilder.Build(fileName: request.MaterialFileName, fileBytes: request.MaterialFileBytes, fileContentType: "image/jpeg", formDataName: "material_file"); | ||
httpContent.Add(new ByteArrayContent(Encoding.UTF8.GetBytes(request.MaterialType.ToString())), "material_type"); | ||
|
||
return await client.SendFlurlRequestAsync<Models.OpenApiThirdPartyFileUploadMaterialV2Response>(flurlReq, httpContent: httpContent, cancellationToken: cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ExtendedSDK/OpenApi/Models/ThirdPartyFile/OpenApiThirdPartyFileUploadMaterialV2Request.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
|
||
namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.OpenApi.Models | ||
{ | ||
/// <summary> | ||
/// <para>表示 [POST] /tpapp/v2/file/upload_material 接口的请求。</para> | ||
/// </summary> | ||
public class OpenApiThirdPartyFileUploadMaterialV2Request : DouyinMicroAppOpenApiRequest | ||
{ | ||
/// <summary> | ||
/// 获取或设置上传的文件类型。 | ||
/// </summary> | ||
[Newtonsoft.Json.JsonIgnore] | ||
[System.Text.Json.Serialization.JsonIgnore] | ||
public int MaterialType { get; set; } | ||
|
||
/// <summary> | ||
/// 获取或设置资源文件字节数组。 | ||
/// </summary> | ||
[Newtonsoft.Json.JsonIgnore] | ||
[System.Text.Json.Serialization.JsonIgnore] | ||
public byte[] MaterialFileBytes { get; set; } = Array.Empty<byte>(); | ||
|
||
/// <summary> | ||
/// 获取或设置资源文件文件名。如果不指定将由系统自动生成。 | ||
/// </summary> | ||
[Newtonsoft.Json.JsonIgnore] | ||
[System.Text.Json.Serialization.JsonIgnore] | ||
public string? MaterialFileName { get; set; } | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...xtendedSDK/OpenApi/Models/ThirdPartyFile/OpenApiThirdPartyFileUploadMaterialV2Response.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.OpenApi.Models | ||
{ | ||
/// <summary> | ||
/// <para>表示 [POST] /tpapp/v2/file/upload_material 接口的响应。</para> | ||
/// </summary> | ||
public class OpenApiThirdPartyFileUploadMaterialV2Response : DouyinMicroAppOpenApiResponse | ||
{ | ||
public static class Types | ||
{ | ||
public class Data | ||
{ | ||
/// <summary> | ||
/// 获取或设置文件路径。 | ||
/// </summary> | ||
[Newtonsoft.Json.JsonProperty("path")] | ||
[System.Text.Json.Serialization.JsonPropertyName("path")] | ||
public string FilePath { get; set; } = default!; | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
[Newtonsoft.Json.JsonProperty("err_no")] | ||
[System.Text.Json.Serialization.JsonPropertyName("err_no")] | ||
public override int ErrorNumber { get; set; } | ||
|
||
/// <inheritdoc/> | ||
[Newtonsoft.Json.JsonProperty("err_msg")] | ||
[System.Text.Json.Serialization.JsonPropertyName("err_msg")] | ||
public override string? ErrorMessage { get; set; } | ||
|
||
/// <summary> | ||
/// 获取或设置返回数据。 | ||
/// </summary> | ||
[Newtonsoft.Json.JsonProperty("data")] | ||
[System.Text.Json.Serialization.JsonPropertyName("data")] | ||
public Types.Data Data { get; set; } = default!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...SDK/OpenApi/Models/_Legacy/ThirdParty/OpenApiThirdPartyUploadPictureMaterialV1Response.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ts/ModelSamples/OpenApi/ThirdPartyFile/OpenApiThirdPartyFileUploadMaterialV2Response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"data": { | ||
"path": "xxxxx" | ||
}, | ||
"err_msg": "", | ||
"err_no": 0, | ||
"log_id": "202401151619351CF77AE5F7A43B8393C0" | ||
} |