Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class Startup
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseEmail(option =>
config.UseEmail((option, serviceProvider) =>
{
option.Host = "smtp.qq.com";//SMTP地址
option.Port = 465;//SMTP端口
Expand Down Expand Up @@ -138,7 +138,7 @@ public class Startup
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseDingTalk(option =>
config.UseDingTalk((option, serviceProvider) =>
{
option.WebHook = "https://oapi.dingtalk.com/robot/send?access_token=xxxxx";//通知地址
option.Secret = "secret";//签名校验
Expand Down Expand Up @@ -194,7 +194,7 @@ public class Startup
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseFeishu(option =>
config.UseFeishu((option, serviceProvider) =>
{
option.WebHook = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxx";//通知地址
option.Secret = "secret";//签名校验
Expand Down Expand Up @@ -250,7 +250,7 @@ public class Startup
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseWeixin(option =>
config.UseWeixin((option, serviceProvider) =>
{
option.WebHook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx";//通知地址
});
Expand Down
19 changes: 10 additions & 9 deletions sample/EasyNotice.Demo.WebApi/Controller/NoticeController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using EasyNotice.Core;
using Microsoft.AspNetCore.Mvc;

namespace EasyNotice.Demo.WebApi.Controller
{
Expand Down Expand Up @@ -26,36 +27,36 @@ public NoticeController(IEmailProvider provider,
/// 邮件发送
/// </summary>
[HttpGet]
public async Task SendMail([FromQuery] string str)
public async Task<EasyNoticeSendResponse> SendMail([FromQuery] string str)
{
await _mailProvider.SendAsync(str, new Exception(str));
return await _mailProvider.SendAsync(str, new Exception(str));
}

/// <summary>
/// 钉钉发送
/// </summary>
[HttpGet]
public async Task SendDingTalk([FromQuery] string str)
public async Task<EasyNoticeSendResponse> SendDingTalk([FromQuery] string str)
{
await _dingtalkProvider.SendAsync(str, new Exception(str));
return await _dingtalkProvider.SendAsync(str, new Exception(str));
}

/// <summary>
/// 飞书发送
/// </summary>
[HttpGet]
public async Task SendFeishu([FromQuery] string str)
public async Task<EasyNoticeSendResponse> SendFeishu([FromQuery] string str)
{
await _feishuProvider.SendAsync(str, new Exception(str));
return await _feishuProvider.SendAsync(str, new Exception(str));
}

/// <summary>
/// 企业微信发送
/// </summary>
[HttpGet]
public async Task SendWexin([FromQuery] string str)
public async Task<EasyNoticeSendResponse> SendWexin([FromQuery] string str)
{
await _weixinProvider.SendAsync(str, new Exception(str));
return await _weixinProvider.SendAsync(str, new Exception(str));
}
}
}
26 changes: 13 additions & 13 deletions sample/EasyNotice.Demo.WebApi/Extensions/NoticeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ public static IServiceCollection AddNotice(this IServiceCollection services, ICo
var mailOptions = baseConfiguration.GetSection(EmailOptions.SectionName).Get<EmailOptions>();
if (mailOptions != null)
{
config.UseEmail(x =>
config.UseEmail((option, serviceProvider) =>
{
x.Password = mailOptions.Password;
x.Host = mailOptions.Host;
x.FromAddress = mailOptions.FromAddress;
x.FromName = mailOptions.FromName;
x.Port = mailOptions.Port;
x.ToAddress = mailOptions.ToAddress;
option.Password = mailOptions.Password;
option.Host = mailOptions.Host;
option.FromAddress = mailOptions.FromAddress;
option.FromName = mailOptions.FromName;
option.Port = mailOptions.Port;
option.ToAddress = mailOptions.ToAddress;
});
}

var dingtalkOptions = baseConfiguration.GetSection(DingtalkOptions.SectionName).Get<DingtalkOptions>();
if (dingtalkOptions != null)
{
config.UseDingTalk(x =>
config.UseDingTalk((x, serviceProvider) =>
{
x.Secret = dingtalkOptions.Secret;
x.WebHook = dingtalkOptions.WebHook;
Expand All @@ -44,19 +44,19 @@ public static IServiceCollection AddNotice(this IServiceCollection services, ICo
var feishuOptions = baseConfiguration.GetSection(FeishuOptions.SectionName).Get<DingtalkOptions>();
if (feishuOptions != null)
{
config.UseFeishu(x =>
config.UseFeishu((option, serviceProvider) =>
{
x.Secret = feishuOptions.Secret;
x.WebHook = feishuOptions.WebHook;
option.Secret = feishuOptions.Secret;
option.WebHook = feishuOptions.WebHook;
});
}

var weixinOptions = baseConfiguration.GetSection(WeixinOptions.SectionName).Get<WeixinOptions>();
if (weixinOptions != null)
{
config.UseWeixin(x =>
config.UseWeixin((option, serviceProvider) =>
{
x.WebHook = weixinOptions.WebHook;
option.WebHook = weixinOptions.WebHook;
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/EasyNotice.Dingtalk/Extensions/DingtalkExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class DingtalkExtension
{
public static EasyNoticeOptions UseDingTalk(
this EasyNoticeOptions options,
Action<DingtalkOptions> configure
Action<DingtalkOptions, IServiceProvider> configure
)
{
if (configure == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace EasyNotice.Dingtalk
{
public class DingtalkOptionsExtension : IEasyNoticeOptionsExtension
{
private readonly Action<DingtalkOptions> configure;
private readonly Action<DingtalkOptions, IServiceProvider> configure;

public DingtalkOptionsExtension(Action<DingtalkOptions> configure)
public DingtalkOptionsExtension(Action<DingtalkOptions, IServiceProvider> configure)
{
this.configure = configure;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EasyNotice.Dingtalk/Provider/DingtalkProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private async Task<EasyNoticeSendResponse> SendBaseAsync(MessageBase message)
}
else
{
return new EasyNoticeSendResponse() { ErrCode = dingtalkResponse.ErrCode, ErrMsg = !string.IsNullOrEmpty(dingtalkResponse.Description) ? $"{dingtalkResponse.Description},{dingtalkResponse.Solution}" : dingtalkResponse.ErrMsg };
return new EasyNoticeSendResponse() { ErrCode = dingtalkResponse.ErrCode, ErrMsg = !string.IsNullOrEmpty(dingtalkResponse.Description) ? $"{dingtalkResponse.Description},{dingtalkResponse.Solution}".TrimEnd(',') : dingtalkResponse.ErrMsg };
}
}, message.title, _noticeOptions.IntervalSeconds);
}
Expand Down
2 changes: 1 addition & 1 deletion src/EasyNotice.Email/Extensions/EmailExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class EmailExtension
{
public static EasyNoticeOptions UseEmail(
this EasyNoticeOptions options,
Action<EmailOptions> configure)
Action<EmailOptions, IServiceProvider> configure)
{
if (configure == null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/EasyNotice.Email/Extensions/EmailOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace EasyNotice.Email
{
internal class EmailOptionsExtension : IEasyNoticeOptionsExtension
{
private readonly Action<EmailOptions> configure;
private readonly Action<EmailOptions, IServiceProvider> configure;

public EmailOptionsExtension(Action<EmailOptions> configure)
public EmailOptionsExtension(Action<EmailOptions, IServiceProvider> configure)
{
this.configure = configure;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EasyNotice.Feishu/Extensions/FeishuExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class FeishuExtension
{
public static EasyNoticeOptions UseFeishu(
this EasyNoticeOptions options,
Action<FeishuOptions> configure
Action<FeishuOptions, IServiceProvider> configure
)
{
if (configure == null)
Expand Down
4 changes: 2 additions & 2 deletions src/EasyNotice.Feishu/Extensions/FeishuOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace EasyNotice.Feishu
{
public class FeishuOptionsExtension : IEasyNoticeOptionsExtension
{
private readonly Action<FeishuOptions> configure;
private readonly Action<FeishuOptions, IServiceProvider> configure;

public FeishuOptionsExtension(Action<FeishuOptions> configure)
public FeishuOptionsExtension(Action<FeishuOptions, IServiceProvider> configure)
{
this.configure = configure;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EasyNotice.Weixin/Extensions/WeixinExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class WeixinExtension
{
public static EasyNoticeOptions UseWeixin(
this EasyNoticeOptions options,
Action<WeixinOptions> configure
Action<WeixinOptions, IServiceProvider> configure
)
{
if (configure == null)
Expand Down
4 changes: 2 additions & 2 deletions src/EasyNotice.Weixin/Extensions/WeixinOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace EasyNotice.Weixin
{
public class WeixinOptionsExtension : IEasyNoticeOptionsExtension
{
private readonly Action<WeixinOptions> configure;
private readonly Action<WeixinOptions, IServiceProvider> configure;

public WeixinOptionsExtension(Action<WeixinOptions> configure)
public WeixinOptionsExtension(Action<WeixinOptions, IServiceProvider> configure)
{
this.configure = configure;
}
Expand Down
10 changes: 9 additions & 1 deletion test/EasyNotice.UnitTests/DingTalkNoticeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DingTalkNoticeTest()
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseDingTalk(option =>
config.UseDingTalk((option, serviceProvider) =>
{
option.WebHook = "https://oapi.dingtalk.com/robot/send?access_token=xxx";//通知地址
option.Secret = "secret";//签名校验
Expand All @@ -44,5 +44,13 @@ public async Task DingTalk_Send_AtUser_Should_Be_Succeed()
var response = await _dingtalkProvider.SendAsync("通知标题", new Exception("custom exception"), new EasyNoticeAtUser() { IsAtAll = false, Mobile = new[] { "138xxxxxxxx" } });
Assert.True(response.IsSuccess);
}

[Fact]
public async Task DingTalk_Send_Markdown_Should_Be_Succeed()
{
var response = await _dingtalkProvider.SendMarkdownAsync("通知标题", "#### <font color=#008800>订单审核通过</font> 信息如下:\r\n订单号:11111111111\r\n商品名:手机");
Assert.True(response.IsSuccess);
}

}
}
2 changes: 1 addition & 1 deletion test/EasyNotice.UnitTests/EmailNoticeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public EmailNoticeTest()
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseEmail(option =>
config.UseEmail((option, serviceProvider) =>
{
option.Host = "smtp.qq.com";
option.Port = 465;
Expand Down
2 changes: 1 addition & 1 deletion test/EasyNotice.UnitTests/FeishuNoticeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public FeishuNoticeTest()
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseFeishu(option =>
config.UseFeishu((option, serviceProvider) =>
{
option.WebHook = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxx";//通知地址
option.Secret = "secret";//签名校验
Expand Down
2 changes: 1 addition & 1 deletion test/EasyNotice.UnitTests/WeixinNoticeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public WeixinNoticeTest()
services.AddEasyNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseWeixin(option =>
config.UseWeixin((option, serviceProvider) =>
{
option.WebHook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx";//通知地址
});
Expand Down