laravel-exception-notify maintained by wangchengtao
消息通知组件
功能
- 支持多种通道(钉钉群机器人 飞书群机器人)
- 支持扩展自定义通道
环境要求
- laravel >= 6.0
安装
composer require wangchengtao/laravel-message-notify
配置
- 创建配置文件:
php artisan vendor:publish --provider="Summer\LaravelMessageNotify\MessageNotifyServiceProvider"
- 修改
config/message.php中对应的参数即可
使用
use Summer\MessageNotify\Message\Dingtalk\DingtalkMarkdown;
use Summer\LaravelMessageNotify\Notify;
// 文本格式
$text = new DingtalkText();
$text->setTitle('测试');
$text->setContent('异常测试');
$text->setAt([
'187*****897',
]);
Notify::send($text);
// markdown 格式
$markdown = new DingtalkMarkdown();
$markdown->setTitle('Markdown消息标题');
$markdown->setContent("#### 这是Markdown消息内容 \n ");
$markdown->atAll();
Notify::send($markdown);
效果图

自定义通道
- 所有自定义通道继承自
AbstractChannel - 所有自定义消息继承自
AbstractMessage
use Summer\MessageNotify\Channel\AbstractChannel;
use Summer\MessageNotify\Message\AbstractMessage;
use Summer\LaravelMessageNotify\Notify;
class CustomChannel extends AbstractChannel
{
public function handleResponse(ResponseInterface $response): void
{
// TODO: Implement getBody() method.
}
public function send(string $content): ResponseInterface
{
// TODO: Implement getBody() method.
}
}
class CustomMessage extends AbstractMessage
{
public function getBody() : array
{
// TODO: Implement getBody() method.
}
}
在 config/message.php 中添加相应配置
return [
'default' => env('NOTIFY_DEFAULT_CHANNEL', 'dingtalk'),
'channels' => [
// 已省略其它配置
'custom' => [
'driver' => CustomChannel::class,
//
],
],
];
发送消息
$message = new CustomMessage();
$message->setTitle('自定义标题');
$message->setContent('自定义消息');
Notify::channel('custom')->send($message);