feat(wxapi): 新增微信小店合作账号小程序相关接口接口

This commit is contained in:
Fu Diwei
2024-11-04 20:03:26 +08:00
parent c50662b5ea
commit 57d28bc405
19 changed files with 610 additions and 43 deletions

View File

@@ -65,7 +65,7 @@
<summary>[展开查看]</summary>
| | 微信 API | 平台能力 | 备注 |
| :-: | :-----------------------------------: | :------: | :------------------: |
| :-: | :------------------------: | :------: | :------------------: |
| √ | 接口调用凭证 | | |
| √ | OpenAPI 管理 | | |
| √ | 小程序登录 | | |
@@ -103,7 +103,7 @@
| √ | 卡券 | 商业能力 | |
| √ | 小程序支付管理服务 | 商业能力 | |
| √ | 小程序发货信息管理服务 | 商业能力 | |
| × | <del>微信小店合作账号小程序接口</del> | 商业能力 | _开发中_ |
| | 微信小店合作账号小程序接口 | 商业能力 | |
| √ | 多端能力 | 多端能力 | |
| √ | 服务市场 | 服务市场 | |
| √ | 城市服务 | 城市服务 | |

View File

@@ -0,0 +1,42 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Events
{
/// <summary>
/// <para>表示 EVENT.cooperation_shop_order 事件的数据。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/cooperation_shop/order_callback.html ]]>
/// </para>
/// </summary>
public class CooperationShopOrderEvent : WechatApiEvent
{
public static class Types
{
public class EventData
{
/// <summary>
/// 获取或设置店铺 AppId。
/// </summary>
[Newtonsoft.Json.JsonProperty("shop_appid")]
[System.Text.Json.Serialization.JsonPropertyName("shop_appid")]
[System.Xml.Serialization.XmlElement("shop_appid")]
public string ShopAppId { get; set; } = default!;
/// <summary>
/// 获取或设置订单 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("order_id")]
[System.Text.Json.Serialization.JsonPropertyName("order_id")]
[System.Xml.Serialization.XmlElement("order_id")]
public string OrderId { get; set; } = default!;
}
}
/// <summary>
/// 获取或设置事件参数。
/// </summary>
[Newtonsoft.Json.JsonProperty("EventData")]
[System.Text.Json.Serialization.JsonPropertyName("EventData")]
[System.Xml.Serialization.XmlElement("EventData")]
public Types.EventData EventData { get; set; } = default!;
}
}

View File

@@ -1060,6 +1060,100 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
}
#endregion
#region ECCooperation
/// <summary>
/// <para>异步调用 [POST] /channels/ec/cooperation/shop/list 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/cooperation_shop/list_shop.html ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.ChannelsECCooperationShopListResponse> ExecuteChannelsECCooperationShopListAsync(this WechatApiClient client, Models.ChannelsECCooperationShopListRequest 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, "channels", "ec", "cooperation", "shop", "list")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendFlurlRequestAsJsonAsync<Models.ChannelsECCooperationShopListResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// <para>异步调用 [POST] /channels/ec/cooperation/product/list 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/cooperation_shop/list_cooperation_shop_product.html ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.ChannelsECCooperationProductListResponse> ExecuteChannelsECCooperationProductListAsync(this WechatApiClient client, Models.ChannelsECCooperationProductListRequest 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, "channels", "ec", "cooperation", "product", "list")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendFlurlRequestAsJsonAsync<Models.ChannelsECCooperationProductListResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// <para>异步调用 [POST] /channels/ec/cooperation/product/get 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/cooperation_shop/get_product.html ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.ChannelsECCooperationProductGetResponse> ExecuteChannelsECCooperationProductGetAsync(this WechatApiClient client, Models.ChannelsECCooperationProductGetRequest 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, "channels", "ec", "cooperation", "product", "get")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendFlurlRequestAsJsonAsync<Models.ChannelsECCooperationProductGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// <para>异步调用 [POST] /channels/ec/cooperation/order/get 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/cooperation_shop/get_order.html ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.ChannelsECCooperationOrderGetResponse> ExecuteChannelsECCooperationOrderGetAsync(this WechatApiClient client, Models.ChannelsECCooperationOrderGetRequest 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, "channels", "ec", "cooperation", "order", "get")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendFlurlRequestAsJsonAsync<Models.ChannelsECCooperationOrderGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
#endregion
#region ECCoupon
/// <summary>
/// <para>异步调用 [POST] /channels/ec/coupon/create 接口。</para>

View File

@@ -0,0 +1,22 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/cooperation/order/get 接口的请求。</para>
/// </summary>
public class ChannelsECCooperationOrderGetRequest : WechatApiRequest, IInferable<ChannelsECCooperationOrderGetRequest, ChannelsECCooperationOrderGetResponse>
{
/// <summary>
/// 获取或设置店铺 AppId。
/// </summary>
[Newtonsoft.Json.JsonProperty("shop_appid")]
[System.Text.Json.Serialization.JsonPropertyName("shop_appid")]
public string ShopAppId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置订单 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("order_id")]
[System.Text.Json.Serialization.JsonPropertyName("order_id")]
public string OrderId { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,73 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/cooperation/order/get 接口的响应。</para>
/// </summary>
public class ChannelsECCooperationOrderGetResponse : WechatApiResponse
{
public static class Types
{
public class Order
{
public static class Types
{
public class OrderDetail
{
public static class Types
{
public class Product : ChannelsECOrderGetResponse.Types.Order.Types.OrderDetail.Types.Product
{
}
public class Amount : ChannelsECOrderGetResponse.Types.Order.Types.OrderDetail.Types.Amount
{
}
}
/// <summary>
/// 获取或设置商品列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("product_infos")]
[System.Text.Json.Serialization.JsonPropertyName("product_infos")]
public Types.Product[] ProductList { get; set; } = default!;
/// <summary>
/// 获取或设置金额信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("price_info")]
[System.Text.Json.Serialization.JsonPropertyName("price_info")]
public Types.Amount Amount { get; set; } = default!;
}
}
/// <summary>
/// 获取或设置订单详细信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("order_detail")]
[System.Text.Json.Serialization.JsonPropertyName("order_detail")]
public Types.OrderDetail OrderDetail { get; set; } = default!;
/// <summary>
/// 获取或设置下单用户 OpenId。
/// </summary>
[Newtonsoft.Json.JsonProperty("openid")]
[System.Text.Json.Serialization.JsonPropertyName("openid")]
public string OpenId { get; set; } = default!;
/// <summary>
/// 获取或设置下单用户 UnionId。
/// </summary>
[Newtonsoft.Json.JsonProperty("unionid")]
[System.Text.Json.Serialization.JsonPropertyName("unionid")]
public string? UnionId { get; set; }
}
}
/// <summary>
/// 获取或设置订单信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("order")]
[System.Text.Json.Serialization.JsonPropertyName("order")]
public Types.Order Order { get; set; } = default!;
}
}

View File

@@ -0,0 +1,22 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/cooperation/product/get 接口的请求。</para>
/// </summary>
public class ChannelsECCooperationProductGetRequest : WechatApiRequest, IInferable<ChannelsECCooperationProductGetRequest, ChannelsECCooperationProductGetResponse>
{
/// <summary>
/// 获取或设置店铺 AppId。
/// </summary>
[Newtonsoft.Json.JsonProperty("shop_appid")]
[System.Text.Json.Serialization.JsonPropertyName("shop_appid")]
public string ShopAppId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置商品 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("product_id")]
[System.Text.Json.Serialization.JsonPropertyName("product_id")]
public long ProductId { get; set; }
}
}

View File

@@ -0,0 +1,50 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/cooperation/product/get 接口的响应。</para>
/// </summary>
public class ChannelsECCooperationProductGetResponse : WechatApiResponse
{
public static class Types
{
public class Product
{
/// <summary>
/// 获取或设置商品 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("product_id")]
[System.Text.Json.Serialization.JsonPropertyName("product_id")]
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
public long ProductId { get; set; }
/// <summary>
/// 获取或设置商品标题。
/// </summary>
[Newtonsoft.Json.JsonProperty("title")]
[System.Text.Json.Serialization.JsonPropertyName("title")]
public string Title { get; set; } = default!;
/// <summary>
/// 获取或设置图片 URL 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("img_urls")]
[System.Text.Json.Serialization.JsonPropertyName("img_urls")]
public string[] ImageUrlList { get; set; } = default!;
/// <summary>
/// 获取或设置最低价格(单位:分)。
/// </summary>
[Newtonsoft.Json.JsonProperty("min_price")]
[System.Text.Json.Serialization.JsonPropertyName("min_price")]
public int MinPrice { get; set; }
}
}
/// <summary>
/// 获取或设置商品信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("product")]
[System.Text.Json.Serialization.JsonPropertyName("product")]
public Types.Product Product { get; set; } = default!;
}
}

View File

@@ -0,0 +1,30 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/cooperation/product/list 接口的请求。</para>
/// </summary>
public class ChannelsECCooperationProductListRequest : WechatApiRequest, IInferable<ChannelsECCooperationProductListRequest, ChannelsECCooperationProductListResponse>
{
/// <summary>
/// 获取或设置店铺 AppId。
/// </summary>
[Newtonsoft.Json.JsonProperty("shop_appid")]
[System.Text.Json.Serialization.JsonPropertyName("shop_appid")]
public string ShopAppId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置分页每页页数。
/// <para>默认值10</para>
/// </summary>
[Newtonsoft.Json.JsonProperty("page_size")]
[System.Text.Json.Serialization.JsonPropertyName("page_size")]
public int Limit { get; set; } = 10;
/// <summary>
/// 获取或设置翻页标记。
/// </summary>
[Newtonsoft.Json.JsonProperty("next_key")]
[System.Text.Json.Serialization.JsonPropertyName("next_key")]
public string? Cursor { get; set; }
}
}

View File

@@ -0,0 +1,43 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/cooperation/product/list 接口的响应。</para>
/// </summary>
public class ChannelsECCooperationProductListResponse : WechatApiResponse
{
public static class Types
{
public class Product
{
/// <summary>
/// 获取或设置商品 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("product_id")]
[System.Text.Json.Serialization.JsonPropertyName("product_id")]
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
public long ProductId { get; set; }
}
}
/// <summary>
/// 获取或设置商品列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("products")]
[System.Text.Json.Serialization.JsonPropertyName("products")]
public Types.Product[] ProductList { get; set; } = default!;
/// <summary>
/// 获取或设置总数量。
/// </summary>
[Newtonsoft.Json.JsonProperty("total_num")]
[System.Text.Json.Serialization.JsonPropertyName("total_num")]
public int TotalCount { get; set; }
/// <summary>
/// 获取或设置翻页标记。
/// </summary>
[Newtonsoft.Json.JsonProperty("next_key")]
[System.Text.Json.Serialization.JsonPropertyName("next_key")]
public string? NextCursor { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/cooperation/shop/list 接口的请求。</para>
/// </summary>
public class ChannelsECCooperationShopListRequest : WechatApiRequest, IInferable<ChannelsECCooperationShopListRequest, ChannelsECCooperationShopListResponse>
{
}
}

View File

@@ -0,0 +1,63 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/cooperation/shop/list 接口的响应。</para>
/// </summary>
public class ChannelsECCooperationShopListResponse : WechatApiResponse
{
public static class Types
{
public class Shop
{
/// <summary>
/// 获取或设置店铺 AppId。
/// </summary>
[Newtonsoft.Json.JsonProperty("appid")]
[System.Text.Json.Serialization.JsonPropertyName("appid")]
public string AppId { get; set; } = default!;
/// <summary>
/// 获取或设置店铺名称。
/// </summary>
[Newtonsoft.Json.JsonProperty("nickname")]
[System.Text.Json.Serialization.JsonPropertyName("nickname")]
public string Nickname { get; set; } = default!;
/// <summary>
/// 获取或设置绑定状态。
/// </summary>
[Newtonsoft.Json.JsonProperty("status")]
[System.Text.Json.Serialization.JsonPropertyName("status")]
public int Status { get; set; }
/// <summary>
/// 获取或设置绑定时间毫秒级时间戳。
/// </summary>
[Newtonsoft.Json.JsonProperty("bind_time")]
[System.Text.Json.Serialization.JsonPropertyName("bind_time")]
public long? BindTimeMilliseconds { get; set; }
/// <summary>
/// 获取或设置解绑时间毫秒级时间戳。
/// </summary>
[Newtonsoft.Json.JsonProperty("unbind_time")]
[System.Text.Json.Serialization.JsonPropertyName("unbind_time")]
public long? UnbindTimeMilliseconds { get; set; }
/// <summary>
/// 获取或设置取消时间毫秒级时间戳。
/// </summary>
[Newtonsoft.Json.JsonProperty("cancel_time")]
[System.Text.Json.Serialization.JsonPropertyName("cancel_time")]
public long? CancelTimeMilliseconds { get; set; }
}
}
/// <summary>
/// 获取或设置店铺列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("shop_list")]
[System.Text.Json.Serialization.JsonPropertyName("shop_list")]
public Types.Shop[] ShopList { get; set; } = default!;
}
}

View File

@@ -0,0 +1,11 @@
{
"ToUserName": "gh_2defbb026678",
"FromUserName": "OPENID",
"CreateTime": 1706518830,
"MsgType": "event",
"Event": "cooperation_shop_order",
"EventData": {
"order_id": "order_id_xxx",
"shop_appid": "店铺appid"
}
}

View File

@@ -0,0 +1,4 @@
{
"shop_appid": "SHOP_APPID",
"order_id": "ORDER_ID"
}

View File

@@ -0,0 +1,55 @@
{
"order": {
"openid": "OPENID",
"order_detail": {
"product_infos": [
{
"product_id": 234245,
"sku_id": 23424,
"sku_cnt": 10,
"title": "健身环",
"thumb_img": "https://mmecimage.cn/p/wx37f38d59298839c3/HJE9eJaEc5bJk-eaArVdILSB7MMaHgdK2-JIn51nMQ",
"sale_price": 2000,
"market_price": 2000,
"sku_attrs": [
{
"attr_key": "产地",
"attr_value": "四川成都"
},
{
"attr_key": "材质",
"attr_value": "玻璃"
},
{
"attr_key": "适用人群",
"attr_value": "青年;中年"
},
{
"attr_key": "数量",
"attr_value": "33"
},
{
"attr_key": "精度",
"attr_value": "3.001"
},
{
"attr_key": "重量",
"attr_value": "38 mg"
},
{
"attr_key": "毛重",
"attr_value": "380 kg"
}
]
}
],
"price_info": {
"product_price": 20000,
"order_price": 10500,
"freight": 500,
"discounted_price": 10000,
"is_discounted": true
}
}
}
}

View File

@@ -0,0 +1,4 @@
{
"shop_appid": "wx2b255582a7b4bfd0",
"product_id": 10000157022254
}

View File

@@ -0,0 +1,13 @@
{
"product": {
"product_id": 10000157022254,
"title": "测试商品",
"img_urls": [
"IMG_URL0",
"IMG_URL1"
],
"min_price": 2800
},
"errcode": 0,
"errmsg": "ok"
}

View File

@@ -0,0 +1,4 @@
{
"shop_appid": "wx***************0",
"page_size": 2
}

View File

@@ -0,0 +1,14 @@
{
"products": [
{
"product_id": 10000157022254
},
{
"product_id": 10000157016507
}
],
"total_num": 124,
"next_key": "EhgIi/2/voWjAhCjzK24BhjAhZCBgICAgAI=",
"errcode": 0,
"errmsg": "ok"
}

View File

@@ -0,0 +1,14 @@
{
"shop_list": [
{
"appid": "wx***************0",
"nickname": "测试店",
"status": 1,
"bind_time": 1728979333943,
"unbind_time": 0,
"cancel_time": 0
}
],
"errcode": 0,
"errmsg": "ok"
}