Skip to content

Commit

Permalink
feat(microapp): 变更部分因新旧版接口入口点不同而变化的接口模型
Browse files Browse the repository at this point in the history
  • Loading branch information
fudiwei committed Mar 7, 2024
1 parent 0f65d6f commit 1540246
Show file tree
Hide file tree
Showing 497 changed files with 4,085 additions and 4,432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SKIT.FlurlHttpClient.ByteDance.MicroApp
public abstract class DouyinMicroAppRequest : CommonRequestBase, ICommonRequest
{
/// <summary>
/// 获取或设置抖音小程序的 AccessToken。
/// 获取或设置抖音小程序的 AccessToken/ClientToken/BusinessToken
/// <para>
/// 注意:部分第三方平台的接口中该字段表示授权方的 AuthorizerAccessToken。
/// </para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ namespace SKIT.FlurlHttpClient.ByteDance.MicroApp
public abstract class DouyinMicroAppResponse : CommonResponseBase, ICommonResponse
{
/// <summary>
/// 获取抖音小程序 API 返回的详细错误号
/// 获取抖音小程序 API 返回的错误号
/// </summary>
[Newtonsoft.Json.JsonProperty("errcode")]
[System.Text.Json.Serialization.JsonPropertyName("errcode")]
public virtual long ErrorCode { get; set; }
[Newtonsoft.Json.JsonProperty("err_no")]
[System.Text.Json.Serialization.JsonPropertyName("err_no")]
public virtual int ErrorNumber { get; set; }

/// <summary>
/// 获取抖音小程序 API 返回的错误信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("err_tips")]
[System.Text.Json.Serialization.JsonPropertyName("err_tips")]
public virtual string? ErrorTips { get; set; }

/// <summary>
/// 获取抖音小程序 API 返回的错误描述。
/// </summary>
[Newtonsoft.Json.JsonProperty("errmsg")]
[System.Text.Json.Serialization.JsonPropertyName("errmsg")]
[Newtonsoft.Json.JsonProperty("err_msg")]
[System.Text.Json.Serialization.JsonPropertyName("err_msg")]
public virtual string? ErrorMessage { get; set; }

/// <summary>
Expand All @@ -30,13 +37,13 @@ public abstract class DouyinMicroAppResponse : CommonResponseBase, ICommonRespon
/// <summary>
/// 获取一个值,该值指示调用抖音小程序 API 是否成功。
/// <para>
///(即 HTTP 状态码为 200,且 <see cref="ErrorCode"/> 值为 0)
///(即 HTTP 状态码为 200,且 <see cref="ErrorNumber"/> 值为 0)
/// </para>
/// </summary>
/// <returns></returns>
public override bool IsSuccessful()
{
return GetRawStatus() == 200 && ErrorCode == 0;
return GetRawStatus() == 200 && ErrorNumber == 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.ProductApi
{
public static class ByteDanceMicroAppProductApiClientExecuteProductExtensions
public static class DouyinMicroAppProductApiClientExecuteProductExtensions
{
/// <summary>
/// <para>异步调用 [POST] /add 接口。</para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public class VideoAnchorInfo
}

/// <summary>
/// 获取或设置小程序的 AppId。如果不指定将使用构造 <see cref="DouyinMicroAppClient"/> 时的 <see cref="DouyinMicroAppClientOptions.AppId"/> 参数。
/// 获取或设置小程序 AppId。如果不指定将使用构造 <see cref="DouyinMicroAppClient"/> 时的 <see cref="DouyinMicroAppClientOptions.AppId"/> 参数。
/// </summary>
[Newtonsoft.Json.JsonProperty("appid")]
[System.Text.Json.Serialization.JsonPropertyName("appid")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static ErroredResult VerifyResponseSignature<TResponse>(this DouyinMicroA

bool valid = Utilities.RSAUtility.Verify(
publicKeyPem: client.Credentials.PlatformPublicKey,
messageData: new EncodedString(stringBuilder.ToString(), EncodingKinds.Literal),
messageData: stringBuilder.ToString(),
encodingSignature: new EncodedString(response.ByteSignature, EncodingKinds.Base64),
Utilities.RSAUtility.DIGEST_ALGORITHM_SHA256
);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Flurl.Http;

namespace SKIT.FlurlHttpClient.ByteDance.MicroApp
{
public static class DouyinMicroAppClientExecuteAppsCategoryExtensions
{
/// <summary>
/// <para>异步调用 [GET] /apps/v1/category/query_app_categories/ 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/category/query-app-categories ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.AppsCategoryQueryAppCategoriesV1Response> ExecuteAppsCategoryQueryAppCategoriesV1Async(this DouyinMicroAppClient client, Models.AppsCategoryQueryAppCategoriesV1Request 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
.CreateFlurlRequest(request, HttpMethod.Get, "apps", "v1", "category", "query_app_categories", "")
.WithHeader("access-token", request.AccessToken);

return await client.SendFlurlRequestAsJsonAsync<Models.AppsCategoryQueryAppCategoriesV1Response>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Flurl.Http;

namespace SKIT.FlurlHttpClient.ByteDance.MicroApp
{
public static class DouyinMicroAppClientExecuteAppsCensorExtensions
{
/// <summary>
/// <para>异步调用 [POST] /apps/v1/censor/image 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/content-security/picture-detect-v3 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.AppsCensorImageV1Response> ExecuteAppsCensorImageV1Async(this DouyinMicroAppClient client, Models.AppsCensorImageV1Request request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));

if (request.AppId is null)
request.AppId = client.Credentials.AppId;

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Post, "apps", "v1", "censor", "image")
.WithHeader("access-token", request.AccessToken);

return await client.SendFlurlRequestAsJsonAsync<Models.AppsCensorImageV1Response>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Loading

0 comments on commit 1540246

Please sign in to comment.