diff --git a/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/Models/TemplateCardHorizontalContent.cs b/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/Models/TemplateCardHorizontalContent.cs index f3f58d1fa..4018a040e 100644 --- a/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/Models/TemplateCardHorizontalContent.cs +++ b/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/Models/TemplateCardHorizontalContent.cs @@ -67,6 +67,18 @@ public class TemplateCardHorizontalContent UserId = userId; } /// + /// 创建一个默认二级标题+文本 + /// + /// 二级标题 + /// 二级文本 + /// + public static TemplateCardHorizontalContent Default(string keyName, string value = null) + { + Check.NotNullOrWhiteSpace(keyName, nameof(keyName)); + + return new TemplateCardHorizontalContent(keyName, value: value); + } + /// /// 创建一个跳转链接的二级标题+文本 /// /// 二级标题 diff --git a/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/README.md b/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/README.md new file mode 100644 index 000000000..ccbd8eb6d --- /dev/null +++ b/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/README.md @@ -0,0 +1,51 @@ +# 企业微信消息通知 + +## 功能特性 + +* [发送应用消息](https://developer.work.weixin.qq.com/document/path/90236) +* [发送群聊消息](https://developer.work.weixin.qq.com/document/path/90248) +* [发送Webhook消息](https://developer.work.weixin.qq.com/document/path/99110) + + +## 使用方法 + +- 发送Webhook消息 +```csharp +public class Demo +{ + private readonly IWeChatWorkMessageSender _sender; + + public Demo(IWeChatWorkMessageSender sender) + { + _sender = sender; + } + + public async Task Send() + { + await _sender.SendAsync( + "693a91f6-7xxx-4bc4-97a0-0ec2sifa5aaa", + new WeChatWorkWebhookTemplateCardMessage( + new WebhookTextNoticeCardMessage( + TemplateCardAction.Link("https://developer.work.weixin.qq.com/document/path/99110"), + new TemplateCardMainTitle("请假通过通知", "您的请假申请已通过,请前往查看!"), + source: TemplateCardSource.Black("https://wwcdn.weixin.qq.com/node/wework/images/wecom-logo.a61830413b.svg", "企业微信"), + horizontalContents: new List + { + TemplateCardHorizontalContent.Default("审批单号", "QJ20251000000136"), + TemplateCardHorizontalContent.Default("请假日期", "2025/10/01-2025/10/10"), + TemplateCardHorizontalContent.Default("通过时间", "2025-10-01 15:30:00"), + TemplateCardHorizontalContent.Default("审批备注", "做好考勤及交接事项"), + }, + jumps: new List + { + TemplateCardJump.Link("去OA查看", "https://developer.work.weixin.qq.com/document/path/99110") + }))); + } +} +``` + + +## 更多文档 + +* [企业微信文档](https://developer.work.weixin.qq.com/document/path/90664) + diff --git a/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/WeChatWorkMessageSender.cs b/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/WeChatWorkMessageSender.cs index 856d83cae..f1bf103e1 100644 --- a/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/WeChatWorkMessageSender.cs +++ b/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/WeChatWorkMessageSender.cs @@ -91,7 +91,6 @@ public class WeChatWorkMessageSender : IWeChatWorkMessageSender, ISingletonDepen // 消息发送频率限制: https://developer.work.weixin.qq.com/document/path/99110#%E6%B6%88%E6%81%AF%E5%8F%91%E9%80%81%E9%A2%91%E7%8E%87%E9%99%90%E5%88%B6 public async virtual Task SendAsync(string webhookKey, WeChatWorkWebhookMessage message, CancellationToken cancellationToken = default) { - var token = await WeChatWorkTokenProvider.GetTokenAsync(cancellationToken); var client = HttpClientFactory.CreateClient(AbpWeChatWorkGlobalConsts.ApiClient); using var response = await client.SendMessageAsync(webhookKey, message, cancellationToken); diff --git a/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/WeChatWorkWebhookMessage.cs b/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/WeChatWorkWebhookMessage.cs index 79a6dba87..290569913 100644 --- a/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/WeChatWorkWebhookMessage.cs +++ b/aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/WeChatWorkWebhookMessage.cs @@ -1,6 +1,7 @@ using JetBrains.Annotations; using Newtonsoft.Json; using System.Text.Json.Serialization; +using Volo.Abp; namespace LINGYUN.Abp.WeChat.Work.Messages; /// @@ -17,6 +18,6 @@ public abstract class WeChatWorkWebhookMessage : WeChatWorkRequest public string MsgType { get; set; } protected WeChatWorkWebhookMessage(string msgType) { - MsgType = msgType; + MsgType = Check.NotNullOrWhiteSpace(msgType, nameof(msgType)); } }