From d7932a4c5f8a66aec76e8cb514cf213b05e59919 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Thu, 7 Oct 2021 20:39:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(wxapi):=20=E6=96=B0=E5=A2=9E=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E4=BA=A4=E6=98=93=E7=BB=84=E4=BB=B6=E6=8E=A8?= =?UTF-8?q?=E5=B9=BF=E5=91=98=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 --- .../WechatApiClientExecuteShopExtensions.cs | 42 +++++++++++++++++ .../Shop/Promoter/ShopPromoterListRequest.cs | 25 +++++++++++ .../Shop/Promoter/ShopPromoterListResponse.cs | 45 +++++++++++++++++++ .../Shop/Register/ShopRegisterApplyRequest.cs | 6 --- .../Register/ShopRegisterApplySceneRequest.cs | 18 ++++++++ .../ShopRegisterApplySceneResponse.cs | 12 +++++ .../Promoter/ShopPromoterListRequest.json | 4 ++ .../Promoter/ShopPromoterListResponse.json | 18 ++++++++ .../Register/ShopRegisterApplyRequest.json | 4 +- .../ShopRegisterApplySceneRequest.json | 3 ++ .../ShopRegisterApplySceneResponse.json | 4 ++ 11 files changed, 172 insertions(+), 9 deletions(-) create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Promoter/ShopPromoterListRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Promoter/ShopPromoterListResponse.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplySceneRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplySceneResponse.cs create mode 100644 test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Promoter/ShopPromoterListRequest.json create mode 100644 test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Promoter/ShopPromoterListResponse.json create mode 100644 test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplySceneRequest.json create mode 100644 test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplySceneResponse.json diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteShopExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteShopExtensions.cs index ac880683..20238a58 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteShopExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteShopExtensions.cs @@ -63,6 +63,26 @@ namespace SKIT.FlurlHttpClient.Wechat.Api return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } + /// + /// 异步调用 [POST] /shop/register/apply_scene 接口。 + /// REF: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/enter/scene_apply.html + /// + /// + /// + /// + /// + public static async Task ExecuteShopRegisterApplySceneAsync(this WechatApiClient client, Models.ShopRegisterApplySceneRequest 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, "shop", "register", "apply_scene") + .SetQueryParam("access_token", request.AccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + /// /// 异步调用 [POST] /shop/register/check 接口。 /// REF: https://developers.weixin.qq.com/miniprogram/dev/framework/ministore/minishopopencomponent2/API/enter/enter_check.html @@ -935,5 +955,27 @@ namespace SKIT.FlurlHttpClient.Wechat.Api return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } #endregion + + #region Promoter + /// + /// 异步调用 [POST] /shop/promoter/list 接口。 + /// REF: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/promoter/list.html + /// + /// + /// + /// + /// + public static async Task ExecuteShopPromoterListAsync(this WechatApiClient client, Models.ShopPromoterListRequest 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, "shop", "promoter", "list") + .SetQueryParam("access_token", request.AccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + #endregion } } diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Promoter/ShopPromoterListRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Promoter/ShopPromoterListRequest.cs new file mode 100644 index 00000000..c3ff6987 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Promoter/ShopPromoterListRequest.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /shop/promoter/list 接口的请求。 + /// + public class ShopPromoterListRequest : WechatApiRequest + { + /// + /// 获取或设置分页页数(从 1 开始)。 + /// + [Newtonsoft.Json.JsonProperty("page")] + [System.Text.Json.Serialization.JsonPropertyName("page")] + public int Page { get; set; } = 1; + + /// + /// 获取或设置分页每页数量。 + /// + [Newtonsoft.Json.JsonProperty("page_size")] + [System.Text.Json.Serialization.JsonPropertyName("page_size")] + public int Limit { get; set; } = 10; + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Promoter/ShopPromoterListResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Promoter/ShopPromoterListResponse.cs new file mode 100644 index 00000000..78db99fe --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Promoter/ShopPromoterListResponse.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /shop/promoter/list 接口的响应。 + /// + public class ShopPromoterListResponse : WechatApiResponse + { + public static class Types + { + public class Promoter + { + /// + /// 获取或设置推广员 ID。 + /// + [Newtonsoft.Json.JsonProperty("promoter_id")] + [System.Text.Json.Serialization.JsonPropertyName("promoter_id")] + public string PromoterId { get; set; } = default!; + + /// + /// 获取或设置推广员视频号昵称。 + /// + [Newtonsoft.Json.JsonProperty("finder_nickname")] + [System.Text.Json.Serialization.JsonPropertyName("finder_nickname")] + public string FinderNickname { get; set; } = default!; + } + } + + /// + /// 获取或设置推广员列表。 + /// + [Newtonsoft.Json.JsonProperty("promoters")] + [System.Text.Json.Serialization.JsonPropertyName("promoters")] + public Types.Promoter[] PromoterList { get; set; } = default!; + + /// + /// 获取或设置推广员总数。 + /// + [Newtonsoft.Json.JsonProperty("total_num")] + [System.Text.Json.Serialization.JsonPropertyName("total_num")] + public int TotalCount { get; set; } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplyRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplyRequest.cs index fb2a4a26..62dba145 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplyRequest.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplyRequest.cs @@ -8,11 +8,5 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.Models /// public class ShopRegisterApplyRequest : WechatApiRequest { - /// - /// 获取或设置场景 ID。 - /// - [Newtonsoft.Json.JsonProperty("scene_group_id")] - [System.Text.Json.Serialization.JsonPropertyName("scene_group_id")] - public int SceneGroupId { get; set; } } } diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplySceneRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplySceneRequest.cs new file mode 100644 index 00000000..da388b77 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplySceneRequest.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /shop/register/apply_scene 接口的请求。 + /// + public class ShopRegisterApplySceneRequest : WechatApiRequest + { + /// + /// 获取或设置场景 ID。 + /// + [Newtonsoft.Json.JsonProperty("scene_group_id")] + [System.Text.Json.Serialization.JsonPropertyName("scene_group_id")] + public int SceneGroupId { get; set; } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplySceneResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplySceneResponse.cs new file mode 100644 index 00000000..f6abbe0c --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/Shop/Register/ShopRegisterApplySceneResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /shop/register/apply_scene 接口的响应。 + /// + public class ShopRegisterApplySceneResponse : WechatApiResponse + { + } +} diff --git a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Promoter/ShopPromoterListRequest.json b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Promoter/ShopPromoterListRequest.json new file mode 100644 index 00000000..705087f2 --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Promoter/ShopPromoterListRequest.json @@ -0,0 +1,4 @@ +{ + "page": 1, + "page_size": 10 +} \ No newline at end of file diff --git a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Promoter/ShopPromoterListResponse.json b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Promoter/ShopPromoterListResponse.json new file mode 100644 index 00000000..33697743 --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Promoter/ShopPromoterListResponse.json @@ -0,0 +1,18 @@ +{ + "errcode": 0, + "total_num": 3, + "promoters": [ + { + "finder_nickname": "XXXX", + "promoter_id": "a-***************************************po" + }, + { + "finder_nickname": "XXXX", + "promoter_id": "N1***************************************BE" + }, + { + "finder_nickname": "XXXX", + "promoter_id": "9Z***************************************Vk" + } + ] +} \ No newline at end of file diff --git a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplyRequest.json b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplyRequest.json index c9d4676e..22fdca1b 100644 --- a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplyRequest.json +++ b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplyRequest.json @@ -1,3 +1 @@ -{ - "scene_group_id": 1 -} \ No newline at end of file +{} \ No newline at end of file diff --git a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplySceneRequest.json b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplySceneRequest.json new file mode 100644 index 00000000..c9d4676e --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplySceneRequest.json @@ -0,0 +1,3 @@ +{ + "scene_group_id": 1 +} \ No newline at end of file diff --git a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplySceneResponse.json b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplySceneResponse.json new file mode 100644 index 00000000..f752befe --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/Shop/Register/ShopRegisterApplySceneResponse.json @@ -0,0 +1,4 @@ +{ + "errcode": 0, + "errmsg": "ok" +} \ No newline at end of file