feat(wxapi): 新增微信小店商家客服相关接口

This commit is contained in:
Fu Diwei
2025-04-29 22:56:48 +08:00
parent 8aa36c46fa
commit cd03625004
10 changed files with 297 additions and 3 deletions

View File

@@ -1306,6 +1306,72 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
}
#endregion
#region ECCommonKf
/// <summary>
/// <para>异步调用 [POST] /channels/ec/commkf/cosupload 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developers.weixin.qq.com/doc/store/shop/API/kf/upload_cos/upload_cos_api.html ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.ChannelsECCommonKfCosUploadResponse> ExecuteChannelsECCommonKfCosUploadAsync(this WechatApiClient client, Models.ChannelsECCommonKfCosUploadRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
if (request.FileName is null)
{
if ("image".Equals(request.FileType))
request.FileName = Guid.NewGuid().ToString("N").ToLower() + ".png";
else if ("video".Equals(request.FileType))
request.FileName = Guid.NewGuid().ToString("N").ToLower() + ".mp4";
else
request.FileName = Guid.NewGuid().ToString("N").ToLower();
}
if (request.FileContentType is null)
{
request.FileContentType = MimeTypes.GetMimeMapping(request.FileName!);
}
IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Post, "channels", "ec", "commkf", "cosupload")
.SetQueryParam("access_token", request.AccessToken);
using var httpContent = Utilities.HttpContentBuilder.BuildWithFile(fileName: request.FileName, fileBytes: request.FileBytes!, fileContentType: request.FileContentType, formDataName: "file");
httpContent.Add(new StringContent(request.FileType), "msg_type");
httpContent.Add(new StringContent(request.OpenId), "open_id");
return await client.SendFlurlRequestAsync<Models.ChannelsECCommonKfCosUploadResponse>(flurlReq, httpContent: httpContent, cancellationToken: cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// <para>异步调用 [POST] /channels/ec/commkf/sendmsg 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developers.weixin.qq.com/doc/store/shop/API/kf/send_msg/send_msg_api.html ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.ChannelsECCommonKfSendMessageResponse> ExecuteChannelsECCommonKfSendMessageAsync(this WechatApiClient client, Models.ChannelsECCommonKfSendMessageRequest 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", "commkf", "sendmsg")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendFlurlRequestAsJsonAsync<Models.ChannelsECCommonKfSendMessageResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
#endregion
#region ECCompass
/// <summary>
/// <para>异步调用 [POST] /channels/ec/compass/shop/overall/get 接口。</para>

View File

@@ -1,4 +1,4 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/business/register 接口的请求。</para>
@@ -25,5 +25,12 @@
[Newtonsoft.Json.JsonProperty("icon_media_id")]
[System.Text.Json.Serialization.JsonPropertyName("icon_media_id")]
public string IconMediaId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置是否将消息转发到通用客服。
/// </summary>
[Newtonsoft.Json.JsonProperty("transfer_to_commkf")]
[System.Text.Json.Serialization.JsonPropertyName("transfer_to_commkf")]
public bool? IsTransferToCommonKf { get; set; }
}
}

View File

@@ -0,0 +1,43 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/commkf/cosupload 接口的请求。</para>
/// </summary>
public class ChannelsECCommonKfCosUploadRequest : WechatApiRequest, IInferable<ChannelsECCommonKfCosUploadRequest, ChannelsECCommonKfCosUploadResponse>
{
/// <summary>
/// 获取或设置用户的 OpenId。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string OpenId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置文件类型。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string FileType { get; set; } = string.Empty;
/// <summary>
/// 获取或设置文件字节数组。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public byte[]? FileBytes { get; set; }
/// <summary>
/// 获取或设置文件名。如果不指定将由系统自动生成。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string? FileName { get; set; }
/// <summary>
/// 获取或设置文件 Conent-Type。如果不指定将由系统自动生成。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string? FileContentType { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/commkf/cosupload 接口的响应。</para>
/// </summary>
public class ChannelsECCommonKfCosUploadResponse : WechatApiResponse
{
/// <summary>
/// 获取或设置文件 URL。
/// </summary>
[Newtonsoft.Json.JsonProperty("cos_url")]
[System.Text.Json.Serialization.JsonPropertyName("cos_url")]
public string CosUrl { get; set; } = default!;
}
}

View File

@@ -0,0 +1,117 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/commkf/sendmsg 接口的请求。</para>
/// </summary>
public class ChannelsECCommonKfSendMessageRequest : WechatApiRequest, IInferable<ChannelsECCommonKfSendMessageRequest, ChannelsECCommonKfSendMessageResponse>
{
public static class Types
{
public class TextMessage
{
/// <summary>
/// 获取或设置文本内容。
/// </summary>
[Newtonsoft.Json.JsonProperty("content")]
[System.Text.Json.Serialization.JsonPropertyName("content")]
public string Content { get; set; } = string.Empty;
}
public class ImageMessage
{
/// <summary>
/// 获取或设置图片 URL。
/// </summary>
[Newtonsoft.Json.JsonProperty("cos_url")]
[System.Text.Json.Serialization.JsonPropertyName("cos_url")]
public string CosUrl { get; set; } = string.Empty;
}
public class FileMessage
{
/// <summary>
/// 获取或设置文件 URL。
/// </summary>
[Newtonsoft.Json.JsonProperty("cos_url")]
[System.Text.Json.Serialization.JsonPropertyName("cos_url")]
public string CosUrl { get; set; } = string.Empty;
}
public class OrderShareMessage
{
/// <summary>
/// 获取或设置订单 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("order_id")]
[System.Text.Json.Serialization.JsonPropertyName("order_id")]
public string OrderId { get; set; } = string.Empty;
}
public class ProductShareMessage
{
/// <summary>
/// 获取或设置商品 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("product_id")]
[System.Text.Json.Serialization.JsonPropertyName("product_id")]
public string ProductId { get; set; } = string.Empty;
}
}
/// <summary>
/// 获取或设置唯一任务 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("request_id")]
[System.Text.Json.Serialization.JsonPropertyName("request_id")]
public string? RequestId { get; set; }
/// <summary>
/// 获取或设置用户的 OpenId。
/// </summary>
[Newtonsoft.Json.JsonProperty("open_id")]
[System.Text.Json.Serialization.JsonPropertyName("open_id")]
public string OpenId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置消息类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("msg_type")]
[System.Text.Json.Serialization.JsonPropertyName("msg_type")]
public string MessageType { get; set; } = string.Empty;
/// <summary>
/// 获取或设置文本消息内容。
/// </summary>
[Newtonsoft.Json.JsonProperty("text")]
[System.Text.Json.Serialization.JsonPropertyName("text")]
public Types.TextMessage? MessageContentForText { get; set; }
/// <summary>
/// 获取或设置图片消息内容。
/// </summary>
[Newtonsoft.Json.JsonProperty("image")]
[System.Text.Json.Serialization.JsonPropertyName("image")]
public Types.ImageMessage? MessageContentForImage { get; set; }
/// <summary>
/// 获取或设置文件消息内容。
/// </summary>
[Newtonsoft.Json.JsonProperty("file")]
[System.Text.Json.Serialization.JsonPropertyName("file")]
public Types.FileMessage? MessageContentForFile { get; set; }
/// <summary>
/// 获取或设置订单分享卡片消息内容。
/// </summary>
[Newtonsoft.Json.JsonProperty("order_share")]
[System.Text.Json.Serialization.JsonPropertyName("order_share")]
public Types.OrderShareMessage? MessageContentForOrderShare { get; set; }
/// <summary>
/// 获取或设置商品分享卡片消息内容。
/// </summary>
[Newtonsoft.Json.JsonProperty("product_share")]
[System.Text.Json.Serialization.JsonPropertyName("product_share")]
public Types.ProductShareMessage? MessageContentForProductShare { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /channels/ec/commkf/sendmsg 接口的响应。</para>
/// </summary>
public class ChannelsECCommonKfSendMessageResponse : WechatApiResponse
{
/// <summary>
/// 获取或设置消息 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("msg_id")]
[System.Text.Json.Serialization.JsonPropertyName("msg_id")]
public string MessageId { get; set; } = default!;
}
}

View File

@@ -1,5 +1,6 @@
{
{
"account_name": "apple",
"nickname": "苹果",
"icon_media_id": "media_id"
"icon_media_id": "media_id",
"transfer_to_commkf": true
}

View File

@@ -0,0 +1,5 @@
{
"cos_url": "https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxxx&timestamp=xxxxx&openid=xxxxxx&msg_type=xxx",
"errcode": 0,
"errmsg": "ok"
}

View File

@@ -0,0 +1,20 @@
{
"request_id": "63abd34b-656b-4082-b364-5f74226e1a20",
"open_id": "o7eep4jVQelr2eyoDSmE1xxxxxx",
"msg_type": "xxx",
"text": {
"content": "测试消息123"
},
"image": {
"cos_url": "https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxx&timestamp=xxxx&openid=o7eep4jVQelr2eyoDSmE1xxxxxx&msg_type=2"
},
"file": {
"cos_url": "https://channels.weixin.qq.com/shop/commkf/downloadmedia?encrypted_param=xxxx&timestamp=xxxx&openid=o7eep4jVQelr2eyoDSmE1xxxxxx&msg_type=8"
},
"order_share": {
"order_id": "372647xxxxxxxxxxx"
},
"product_share": {
"product_id": "10000xxxxxxx"
}
}

View File

@@ -0,0 +1,5 @@
{
"msg_id": "3895464567618158592",
"errcode": 0,
"errmsg": "ok"
}