Skip to content

Commit

Permalink
feat(microapp): 新增服务商平台上传资源 v2 接口
Browse files Browse the repository at this point in the history
  • Loading branch information
fudiwei committed Mar 8, 2024
1 parent 995d4a4 commit 0fbdf73
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static class DouyinMicroAppOpenApiClientExecuteLegacyThirdPartyExtensions
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2024-01-23 下线。")]
public static async Task<Models.OpenApiThirdPartyUploadPictureMaterialV1Response> ExecuteOpenApiThirdPartyUploadPictureMaterialV1Async(this DouyinMicroAppOpenApiClient client, Models.OpenApiThirdPartyUploadPictureMaterialV1Request request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
Expand Down
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);
}
}
}
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; }
}
}
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!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.OpenApi.Models
/// <summary>
/// <para>表示 [POST] /v1/tp/upload_pic_material 接口的请求。</para>
/// </summary>
[Obsolete("相关接口或字段于 2024-01-23 下线。")]
public class OpenApiThirdPartyUploadPictureMaterialV1Request : DouyinMicroAppOpenApiRequest
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;

namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.OpenApi.Models
{
/// <summary>
/// <para>表示 [POST] /v1/tp/upload_pic_material 接口的响应。</para>
/// </summary>
[Obsolete("相关接口或字段于 2024-01-23 下线。")]
public class OpenApiThirdPartyUploadPictureMaterialV1Response : DouyinMicroAppOpenApiResponse
{
public static class Types
Expand Down
3 changes: 2 additions & 1 deletion src/SKIT.FlurlHttpClient.ByteDance.MicroApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
### 【功能特性】

- 基于抖音小程序开放平台 API 封装。
- 提供了抖音小程序所需的 AES、MD5、SHA-1、HMAC-SHA-256 等算法工具类。
- 提供了抖音小程序所需的 RSA、AES、MD5、SHA-1、HMAC-SHA-256 等算法工具类。
- 提供了解析回调通知事件等扩展方法。
- 配合 [SKIT.FlurlHttpClient.ByteDance.DouyinOpen](https://www.nuget.org/packages/SKIT.FlurlHttpClient.ByteDance.DouyinOpen) 模块,可无缝对接抖音开放平台。

---

Expand Down
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"
}

0 comments on commit 0fbdf73

Please sign in to comment.