Browse Source

feat(wechat): Improve webhook message

- add a default `TemplateCardHorizontalContent`
- add README.md
pull/1344/head
colin 5 months ago
parent
commit
d2e283a753
  1. 12
      aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/Models/TemplateCardHorizontalContent.cs
  2. 51
      aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/README.md
  3. 1
      aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/WeChatWorkMessageSender.cs
  4. 3
      aspnet-core/framework/wechat/LINGYUN.Abp.WeChat.Work/LINGYUN/Abp/WeChat/Work/Messages/WeChatWorkWebhookMessage.cs

12
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;
}
/// <summary>
/// 创建一个默认二级标题+文本
/// </summary>
/// <param name="keyName">二级标题</param>
/// <param name="value">二级文本</param>
/// <returns></returns>
public static TemplateCardHorizontalContent Default(string keyName, string value = null)
{
Check.NotNullOrWhiteSpace(keyName, nameof(keyName));
return new TemplateCardHorizontalContent(keyName, value: value);
}
/// <summary>
/// 创建一个跳转链接的二级标题+文本
/// </summary>
/// <param name="keyName">二级标题</param>

51
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>
{
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>
{
TemplateCardJump.Link("去OA查看", "https://developer.work.weixin.qq.com/document/path/99110")
})));
}
}
```
## 更多文档
* [企业微信文档](https://developer.work.weixin.qq.com/document/path/90664)

1
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<WeChatWorkResponse> 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);

3
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;
/// <summary>
@ -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));
}
}

Loading…
Cancel
Save