Coder Social home page Coder Social logo

daylanselfwork / easynotice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bryan-cyf/easynotice

0.0 0.0 0.0 27.08 MB

这是一个基于.NET开源的消息通知组件,它包含了邮件、钉钉、飞书、企业微信的群机器人通知,可以帮助我们更容易地发送程序异常通知!

License: MIT License

C# 99.28% Batchfile 0.72%

easynotice's Introduction

EasyNotice

Nuget包

Package Name Version Downloads
EasyNotice.Core NuGet NuGet
EasyNotice.Dingtalk NuGet NuGet
EasyNotice.Email NuGet NuGet
EasyNotice.Feishu NuGet NuGet
EasyNotice.Weixin NuGet NuGet

EasyNotice

这是一个基于.NET开源的消息通知组件,它包含了邮件通知、钉钉、飞书、企业微信通知,可以帮助我们更容易地发送程序异常通知!


功能介绍

  • 支持[邮件]、[钉钉]、[飞书]、[企业微信]方式发送
  • 支持自定义发送间隔,避免同样的异常频繁通知
  • 傻瓜式配置,开箱即用

平台支持

  • SMTP邮箱
  • 钉钉群机器人
  • 飞书群机器人
  • 企业微信群机器人

文档资料


项目接入

项目接入提供了以下发送方式的Demo:邮件通知、钉钉通知、飞书、企业微信通知

1. 邮件通知

邮件通知支持同时发送给多个收件人

Step 1 : 安装包,通过Nuget安装包

Install-Package EasyNotice.Core
Install-Package EasyNotice.Email

Step 2 : 配置 Startup 启动类

public class Startup
{
    //...
    
    public void ConfigureServices(IServiceCollection services)
    {
        //configuration
        services.AddEasyNotice(config =>
        {
            config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
            config.UseEmail(option =>
            {
                option.Host = "smtp.qq.com";//SMTP地址
                option.Port = 465;//SMTP端口
                option.FromName = "System";//发送人名字(自定义)
                option.FromAddress = "[email protected]";//发送邮箱
                option.Password = "passaword";//秘钥
                option.ToAddress = new List<string>()//收件人集合
                {
                    "[email protected]"
                };
            });
        });
    }    
}

Step 3 : IEmailProvider服务接口使用

[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
    private readonly IEmailProvider _mailProvider;
    public NoticeController(IEmailProvider provider)
    {
        _mailProvider = provider;
    }

    [HttpGet]
    public async Task SendMail([FromQuery] string str)
    {
        await _mailProvider.SendAsync(str, new Exception(str));
    }
}

2. 钉钉通知

配置钉钉群机器人官方文档

Step 1 : 安装包,通过Nuget安装包

Install-Package EasyNotice.Core
Install-Package EasyNotice.Dingtalk

Step 2 : 配置 Startup 启动类

public class Startup
{
    //...
    
    public void ConfigureServices(IServiceCollection services)
    {
        //configuration
        services.AddEasyNotice(config =>
        {
            config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
            config.UseDingTalk(option =>
            {
                option.WebHook = "https://oapi.dingtalk.com/robot/send?access_token=xxxxx";//通知地址
                option.Secret = "secret";//签名校验
            });
        });
    }    
}

Step 3 : IDingtalkProvider服务接口使用

[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
    private readonly IDingtalkProvider _dingtalkProvider;
    public NoticeController(IDingtalkProvider dingtalkProvider)
    {
        _dingtalkProvider = dingtalkProvider;
    }

    [HttpGet]
    public async Task SendDingTalk([FromQuery] string str)
    {
        await _dingtalkProvider.SendAsync(str, new Exception(str));
    }
}

3. 飞书通知

配置飞书群机器人官方文档

Step 1 : 安装包,通过Nuget安装包

Install-Package EasyNotice.Core
Install-Package EasyNotice.Feishu

Step 2 : 配置 Startup 启动类

public class Startup
{
    //...
    
    public void ConfigureServices(IServiceCollection services)
    {
        //configuration
        services.AddEasyNotice(config =>
        {
            config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
            config.UseFeishu(option =>
            {
                option.WebHook = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxx";//通知地址
                option.Secret = "secret";//签名校验
            });
        });
    }    
}

Step 3 : IFeishuProvider服务接口使用

[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
    private readonly IFeishuProvider _feishuProvider;
    public NoticeController(IFeishuProvider feishuProvider)
    {
        _feishuProvider = feishuProvider;
    }

    [HttpGet]
    public async Task SendFeishu([FromQuery] string str)
    {
        await _feishuProvider.SendAsync(str, new Exception(str));
    }
}

4. 企业微信通知

配置企业微信群机器人官方文档

Step 1 : 安装包,通过Nuget安装包

Install-Package EasyNotice.Core
Install-Package EasyNotice.Weixin

Step 2 : 配置 Startup 启动类

public class Startup
{
    //...
    
    public void ConfigureServices(IServiceCollection services)
    {
        //configuration
        services.AddEasyNotice(config =>
        {
            config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
            config.UseWeixin(option =>
            {
                option.WebHook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx";//通知地址
            });
        });
    }    
}

Step 3 : IWeixinProvider服务接口使用

[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
    private readonly IWeixinProvider _weixinProvider;
    public NoticeController(IWeixinProvider weixinProvider)
    {
        _weixinProvider = weixinProvider;
    }

    [HttpGet]
    public async Task SendWexin([FromQuery] string str)
    {
        await _weixinProvider.SendAsync(str, new Exception(str));
    }
}

更多示例

  1. 查看 更多使用例子
  2. 查看 更多测试用例

easynotice's People

Contributors

bluegener avatar bryan-cyf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.