Browse Source

Merge pull request #1344 from colinin/wecom-webhook

feat(wechat): Improve webhook message
pull/1351/head
yx lin 5 months ago
committed by GitHub
parent
commit
1db9d6ef7f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  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; UserId = userId;
} }
/// <summary> /// <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> /// </summary>
/// <param name="keyName">二级标题</param> /// <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 // 消息发送频率限制: 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) 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); var client = HttpClientFactory.CreateClient(AbpWeChatWorkGlobalConsts.ApiClient);
using var response = await client.SendMessageAsync(webhookKey, message, cancellationToken); 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 JetBrains.Annotations;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Volo.Abp;
namespace LINGYUN.Abp.WeChat.Work.Messages; namespace LINGYUN.Abp.WeChat.Work.Messages;
/// <summary> /// <summary>
@ -17,6 +18,6 @@ public abstract class WeChatWorkWebhookMessage : WeChatWorkRequest
public string MsgType { get; set; } public string MsgType { get; set; }
protected WeChatWorkWebhookMessage(string msgType) protected WeChatWorkWebhookMessage(string msgType)
{ {
MsgType = msgType; MsgType = Check.NotNullOrWhiteSpace(msgType, nameof(msgType));
} }
} }

Loading…
Cancel
Save