admin/src/SimpleAdmin.Api/WeChat/Services/WeChatMpTemplateSenderAdapter.cs
zzh 2014ec3065
All checks were successful
Build and Deploy / deploy (push) Successful in 1m21s
feat: 接入微信公众号订单状态模板通知
支持入库/出库/签收/派送失败/问题件推送,客户默认可选订阅,运营可配模板并试发。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-15 14:10:01 +08:00

32 lines
1.0 KiB
C#

using Oms.Application.Integrations.WeChat;
namespace SimpleAdmin.Api.WeChat.Services;
/// <summary>
/// 将 <see cref="IWeChatMpApiClient"/> 适配为 Application 层模板发送接口。
/// </summary>
internal sealed class WeChatMpTemplateSenderAdapter(IWeChatMpApiClient apiClient) : IWeChatMpTemplateSender
{
public async Task<WeChatMpTemplateSendResult> SendAsync(
string openId,
string templateId,
string? url,
IReadOnlyDictionary<string, WeChatMpTemplateDataItem> data,
CancellationToken cancellationToken = default)
{
var mapped = data.ToDictionary(
x => x.Key,
x => new WeChatTemplateDataValue(x.Value.Value, x.Value.Color),
StringComparer.OrdinalIgnoreCase);
var result = await apiClient.SendTemplateMessageAsync(
openId,
templateId,
url,
mapped,
cancellationToken);
return new WeChatMpTemplateSendResult(result.Success, result.MsgId, result.ErrCode, result.ErrMsg);
}
}