Skip to content

Commit

Permalink
feat(tiktokshop): 新增新版商品品牌相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
fudiwei committed May 11, 2024
1 parent c0de056 commit 7b6052a
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 7 deletions.
6 changes: 6 additions & 0 deletions docs/TikTokGlobalShop/Basic_ModelDefinition.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Naming Policies:
- Seller
- Get Seller Permissions: `SellerGetPermissions`
- Get Active Shops: `SellerGetShops`
- Products
- Get Brands: `ProductGetBrands`
- Create Custom Brands: `ProductCreateBrand`
- Orders
- Get Order List: `OrderSearchOrders`
- Get Order Detail: `OrderGetOrderDetail`
- Supply Chain
- Confirm Package Shipment: `SupplyChainSyncPackages`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public IFlurlRequest CreateFlurlRequest(TikTokShopLegacyRequest request, HttpMet
return flurlRequest
.SetQueryParam("app_key", Credentials.AppKey)
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("timestamp", request.Timestamp)
.SetQueryParam("shop_id", request.ShopId)
.SetQueryParam("shop_cipher", request.ShopCipher)
.SetQueryParam("timestamp", request.Timestamp)
.SetQueryParam("version", request.ApiVersion);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ public abstract class TikTokShopLegacyRequest : CommonRequestBase, ICommonReques
public virtual string? AccessToken { get; set; }

/// <summary>
/// 获取或设置系统时间戳。如果不指定将由系统自动生成
/// 获取或设置店铺 ID
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public virtual long? Timestamp { get; set; }
public virtual string? ShopId { get; set; }

/// <summary>
/// 获取或设置店铺 ID
/// 获取或设置店铺密码
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public virtual string? ShopId { get; set; }
public virtual string? ShopCipher { get; set; }

/// <summary>
/// 获取或设置店铺密码
/// 获取或设置系统时间戳。如果不指定将由系统自动生成
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public virtual string? ShopCipher { get; set; }
public virtual long? Timestamp { get; set; }

/// <summary>
/// 获取或设置 API 版本号。如果不指定将使用系统所支持的最高版本号。
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Flurl.Http;

namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop
{
public static class TikTokShopClientExecuteProductExtensions
{
#region Brand
/// <summary>
/// <para>异步调用 [GET] /product/{version}/brands 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://partner.tiktokshop.com/docv2/page/6503075656e2bb0289dd5d01 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.ProductGetBrandsResponse> ExecuteProductGetBrandsAsync(this TikTokShopClient client, Models.ProductGetBrandsRequest 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, "product", request.ApiVersion, "brands")
.SetQueryParam("category_id", request.CategoryId)
.SetQueryParam("brand_name", request.BrandName)
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page_token", request.PageToken);

if (request.IsAuthorized is not null)
flurlReq.SetQueryParam("is_authorized", request.IsAuthorized.Value ? "true" : "false");

return await client.SendFlurlRequesAsJsontAsync<Models.ProductGetBrandsResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// <para>异步调用 [POST] /product/{version}/brands 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://partner.tiktokshop.com/docv2/page/650a0926f1fd3102b91bbfb0 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.ProductCreateBrandResponse> ExecuteProductCreateBrandAsync(this TikTokShopClient client, Models.ProductCreateBrandRequest 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.Post, "product", request.ApiVersion, "brands");

return await client.SendFlurlRequesAsJsontAsync<Models.ProductCreateBrandResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop.Models
{
/// <summary>
/// <para>表示 [POST] /product/{version}/brands 接口的请求。</para>
/// </summary>
public class ProductCreateBrandRequest : TikTokShopRequest
{
/// <summary>
/// 获取或设置品牌名称。
/// </summary>
[Newtonsoft.Json.JsonProperty("name")]
[System.Text.Json.Serialization.JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop.Models
{
/// <summary>
/// <para>表示 [POST] /product/{version}/brands 接口的响应。</para>
/// </summary>
public class ProductCreateBrandResponse : TikTokShopResponse<ProductCreateBrandResponse.Types.Data>
{
public static class Types
{
public class Data
{
/// <summary>
/// 获取或设置品牌 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Common.NumericalStringReadOnlyConverter))]
public string BrandId { get; set; } = default!;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop.Models
{
/// <summary>
/// <para>表示 [GET] /product/{version}/brands 接口的请求。</para>
/// </summary>
public class ProductGetBrandsRequest : TikTokShopRequest
{
/// <summary>
/// 获取或设置分类 ID。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string? CategoryId { get; set; }

/// <summary>
/// 获取或设置是否仅返回已授权品牌。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public bool? IsAuthorized { get; set; }

/// <summary>
/// 获取或设置品牌名称。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string? BrandName { get; set; }

/// <summary>
/// 获取或设置分页每页数量。
/// <para>默认值:10</para>
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public int PageSize { get; set; } = 10;

/// <summary>
/// 获取或设置分页令牌。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string? PageToken { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop.Models
{
/// <summary>
/// <para>表示 [GET] /product/{version}/brands 接口的响应。</para>
/// </summary>
public class ProductGetBrandsResponse : TikTokShopResponse<ProductGetBrandsResponse.Types.Data>
{
public static class Types
{
public class Data
{
public static class Types
{
public class Brand
{
/// <summary>
/// 获取或设置品牌 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Common.NumericalStringReadOnlyConverter))]
public string BrandId { get; set; } = default!;

/// <summary>
/// 获取或设置品牌名称。
/// </summary>
[Newtonsoft.Json.JsonProperty("name")]
[System.Text.Json.Serialization.JsonPropertyName("name")]
public string Name { get; set; } = default!;

/// <summary>
/// 获取或设置授权状态。
/// </summary>
[Newtonsoft.Json.JsonProperty("authorized_status")]
[System.Text.Json.Serialization.JsonPropertyName("authorized_status")]
public string AuthorizedStatus { get; set; } = default!;

/// <summary>
/// 获取或设置品牌状态。
/// </summary>
[Newtonsoft.Json.JsonProperty("brand_status")]
[System.Text.Json.Serialization.JsonPropertyName("brand_status")]
public string BrandStatus { get; set; } = default!;

/// <summary>
/// 获取或设置是否是 T1 品牌。
/// </summary>
[Newtonsoft.Json.JsonProperty("is_t1_brand")]
[System.Text.Json.Serialization.JsonPropertyName("is_t1_brand")]
public bool IsT1Brand { get; set; }
}
}

/// <summary>
/// 获取或设置品牌列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("brands")]
[System.Text.Json.Serialization.JsonPropertyName("brands")]
public Types.Brand[] BrandList { get; set; } = default!;

/// <summary>
/// 获取或设置总数量。
/// </summary>
[Newtonsoft.Json.JsonProperty("total_count")]
[System.Text.Json.Serialization.JsonPropertyName("total_count")]
public int TotalCount { get; set; }

/// <summary>
/// 获取或设置下一页分页令牌。
/// </summary>
[Newtonsoft.Json.JsonProperty("next_page_token")]
[System.Text.Json.Serialization.JsonPropertyName("next_page_token")]
public string? NextPageToken { get; set; }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Teas"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"code": 0,
"data": {
"id": "7082427311584347905"
},
"message": "Success",
"request_id": "202203070749000101890810281E8C70B7"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"code": 0,
"data": {
"brands": [
{
"authorized_status": "UNAUTHORIEZD",
"brand_status": "AVAILABLE",
"id": "7082427311584347905",
"is_t1_brand": true,
"name": "Teas"
}
],
"next_page_token": "b2Zmc2V0PTAK",
"total_count": 10000
},
"message": "Success",
"request_id": "202203070749000101890810281E8C70B7"
}

0 comments on commit 7b6052a

Please sign in to comment.