Galosys.Foundation.Notification
26.5.20.1
dotnet add package Galosys.Foundation.Notification --version 26.5.20.1
NuGet\Install-Package Galosys.Foundation.Notification -Version 26.5.20.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Galosys.Foundation.Notification" Version="26.5.20.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.Notification" Version="26.5.20.1" />
<PackageReference Include="Galosys.Foundation.Notification" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Galosys.Foundation.Notification --version 26.5.20.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Galosys.Foundation.Notification, 26.5.20.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Galosys.Foundation.Notification@26.5.20.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Galosys.Foundation.Notification&version=26.5.20.1
#tool nuget:?package=Galosys.Foundation.Notification&version=26.5.20.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Galosys.Foundation.Notification
通知统一抽象模块,提供 INotificationProvider 接口 + INotificationDispatcher 调度器,支持单通道路由和多通道广播两种模式。
最小配置
// Program.cs / Startup.cs
services.AddNotification(); // 注册 INotificationDispatcher
无需额外配置项。Notification 模块本身不依赖 IConfiguration。
通道注册
Notification 模块只定义接口和调度器。各通道适配器由对应的模块自行注册,引用通道模块后自动生效:
// 注册邮件通道(需配置 MailKit 节)
services.AddMailkit(configuration);
// 注册钉钉通道(需配置 DingTalk 节)
// DingTalk 模块通过 IModule 自动注册
// 注册短信通道(需配置 Aliyun 节)
services.AddAliyun(configuration);
// 注册微信通道
// Wechat 模块通过 IModule 自动注册
// 注册 WxPusher 通道
// WxPusher 模块通过 IModule 自动注册
使用示例
单通道发送 (SendAsync)
public class MyService
{
private readonly INotificationDispatcher _dispatcher;
public MyService(INotificationDispatcher dispatcher)
{
_dispatcher = dispatcher;
}
// 发送邮件
public async Task SendEmailAsync()
{
var result = await _dispatcher.SendAsync(new NotificationRequest(
Channel: "email",
Recipient: "user@example.com",
Subject: "系统通知",
Content: "这是一封测试邮件"
));
if (!result.Success)
{
// 处理发送失败: result.ErrorMessage
}
}
// 发送短信
public async Task SendSmsAsync()
{
var result = await _dispatcher.SendAsync(new NotificationRequest(
Channel: "sms",
Recipient: "13800138000",
Subject: "SMS_001", // 阿里云短信模板 Code
Content: "您的验证码是 123456"
));
}
// 发送钉钉消息
public async Task SendDingTalkAsync()
{
var result = await _dispatcher.SendAsync(new NotificationRequest(
Channel: "dingtalk",
Content: "钉钉群通知内容"
));
}
}
多通道广播 (BroadcastAsync)
// 向所有已注册通道并行发送通知
var results = await _dispatcher.BroadcastAsync(new NotificationRequest(
Recipient: "user",
Subject: "系统公告",
Content: "系统将于今晚维护"
));
// results 包含每个通道的独立结果
foreach (var result in results)
{
Console.WriteLine($"{result.Channel}: {(result.Success ? "成功" : result.ErrorMessage)}");
}
请求模型
| 属性 | 类型 | 说明 |
|---|---|---|
Channel |
string? |
通道标识(email/dingtalk/sms/wechat/wxpusher),为空时匹配所有通道 |
Recipient |
string? |
接收者(邮箱/手机号/OpenID/UID 等) |
Subject |
string? |
主题 |
Content |
string? |
内容 |
Extra |
IDictionary<string, object?>? |
扩展参数(各通道特定参数) |
Extra 参数说明
微信通道 (wechat)
new NotificationRequest(
Channel: "wechat",
Recipient: "openId",
Content: "模板内容",
Extra: new Dictionary<string, object?>
{
["AccessToken"] = "access_token", // 直接传入 token
// 或通过 AppId/AppSecret 自动获取:
["AppId"] = "wx...",
["AppSecret"] = "secret...",
["TemplateId"] = "template_id",
["Page"] = "pages/index"
}
)
WxPusher 通道 (wxpusher)
new NotificationRequest(
Channel: "wxpusher",
Recipient: "uid1,uid2", // 多个 UID 逗号分隔
Subject: "摘要",
Content: "内容",
Extra: new Dictionary<string, object?>
{
["ContentType"] = 1, // 1=文字 2=HTML 3=Markdown
["Url"] = "https://..."
}
)
阿里云短信通道 (sms)
new NotificationRequest(
Channel: "sms",
Recipient: "13800138000,13900139000", // 多个手机号逗号分隔
Subject: "SMS_TEMPLATE_CODE", // 短信模板 Code
Content: "内容",
Extra: new Dictionary<string, object?>
{
["TemplateCode"] = "SMS_001", // 优先于 Subject
["key1"] = "value1" // 模板参数
}
)
自定义通道
实现 INotificationProvider 接口并注册到 DI:
using Galosys.Foundation.Notification;
using Microsoft.Extensions.Plugining;
public class MyChannelProvider : INotificationProvider
{
public string ChannelName => "my-channel";
public bool Supports(NotificationRequest request)
{
return string.IsNullOrEmpty(request.Channel) ||
string.Equals(request.Channel, ChannelName, StringComparison.OrdinalIgnoreCase);
}
public async Task<NotificationResult> SendAsync(NotificationRequest request, CancellationToken cancellationToken = default)
{
try
{
// 发送逻辑...
return new NotificationResult(true, Channel: ChannelName);
}
catch (Exception ex)
{
return new NotificationResult(false, ex.Message, ChannelName);
}
}
}
// DI 注册
services.TryAddSingleton<INotificationProvider, MyChannelProvider>();
接口一览
| 类型 | 说明 |
|---|---|
INotificationProvider |
通知提供方接口,继承 Plugin<NotificationRequest> |
INotificationDispatcher |
通知调度器接口 |
NotificationDispatcher |
调度器默认实现 |
NotificationRequest |
通知请求 record |
NotificationResult |
通知结果 record |
适配器
| 模块 | ChannelName | 包装类 | 生命周期 |
|---|---|---|---|
| Galosys.Foundation.MailKit | email |
MailKitTemplate |
Singleton |
| Galosys.Foundation.DingTalk | dingtalk |
DingTalkRobot |
Singleton |
| Galosys.Foundation.Aliyun | sms |
AcsSms |
Singleton |
| Galosys.Foundation.Wechat | wechat |
WechatMaService |
Transient |
| Galosys.Foundation.WxPusher | wxpusher |
WxPusherRobot |
Singleton |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Galosys.Foundation.Core (>= 26.5.20.1)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Galosys.Foundation.Notification:
| Package | Downloads |
|---|---|
|
Galosys.Foundation.Aliyun
Galosys.Foundation快速开发库 |
|
|
Galosys.Foundation.MailKit
Galosys.Foundation快速开发库 |
|
|
Galosys.Foundation.WxPusher
Galosys.Foundation快速开发库 |
|
|
Galosys.Foundation.Wechat
Galosys.Foundation快速开发库 |
|
|
Galosys.Foundation.DingTalk
Galosys.Foundation快速开发库 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 26.5.20.1 | 210 | 5/20/2026 |
| 26.5.19.1 | 218 | 5/19/2026 |
| 26.5.18.1 | 204 | 5/18/2026 |
| 26.5.15.1 | 206 | 5/15/2026 |
| 26.5.12.3 | 196 | 5/12/2026 |
| 26.5.12.2 | 206 | 5/12/2026 |
| 26.4.27.1-rc1 | 180 | 4/26/2026 |
| 26.4.25.1-rc1 | 197 | 4/25/2026 |
| 26.4.22.2-rc7 | 191 | 4/22/2026 |
| 26.4.22.2-rc6 | 187 | 4/22/2026 |
| 26.4.22.2-rc4 | 188 | 4/22/2026 |
| 26.4.22.2-rc3 | 180 | 4/22/2026 |
| 26.4.19.1-rc1 | 185 | 4/19/2026 |