Skip to content

wangchengtao/laravel-exception-notify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

消息通知组件

功能

  • 支持多种通道(钉钉群机器人 飞书群机器人 企业微信群机器人)
  • 支持扩展自定义通道

环境要求

  • php: >= 7.2
  • laravel >= 6.0

安装

composer require wangchengtao/laravel-exception-notify:^1.0

配置

  1. 创建配置文件:
php artisan vendor:publish --provider="Summer\LaravelExceptionNotify\ExceptionNotifyServiceProvider"
  1. 可选, 添加别名
'aliases' => [
    // ...
    'Notify' => Summer\LaravelExceptionNotify\Notify::class,
],

使用

use Summer\LaravelExceptionNotify\Notify;

$text = new DingtalkText();
$text->setTitle('测试');
$text->setContent('异常测试');
$text->setAt([
    '187*****897',
]);

Notify::send($text);

效果图

效果图

自定义通道

  • 所有自定义通道继承自 AbstractChannel
  • 所有自定义消息继承自 AbstractMessage
use Summer\ExceptionNotify\Channel\AbstractChannel;
use Summer\ExceptionNotify\Message\AbstractMessage;
use Summer\LaravelExceptionNotify\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.
    }
}

$message = new CustomMessage();
$message->setTitle('自定义标题');
$message->setContent('自定义消息');

Notify::channel(CustomChannel::class)->send($message);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages