PHPackages                             alarm-dog/noticer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. alarm-dog/noticer

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

alarm-dog/noticer
=================

哮天犬告警平台通知组件

v1.0.0(5y ago)27228PHPPHP &gt;=7.2

Since Oct 27Pushed 5y ago9 watchersCompare

[ Source](https://github.com/tal-tech/alarm-dog-noticer)[ Packagist](https://packagist.org/packages/alarm-dog/noticer)[ RSS](/packages/alarm-dog-noticer/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (2)Used By (0)

哮天犬通知组件
=======

[](#哮天犬通知组件)

适配Hyperf框架的通知组件，支持短信、电话、邮件、钉钉工作通知、钉钉机器人等通知渠道

安装
==

[](#安装)

```
# composer安装依赖
composer require alarm-dog/noticer
```

配置
==

[](#配置)

使用Hyperf框架工具生成默认配置：

```
php bin/hyperf.php vendor:publish alarm-dog/noticer
```

默认配置文件将会被拷贝到框架根目录 `config/autoload/noticer.php`

注意修改配置文件中的 env 环境变量配置

使用
==

[](#使用)

邮件通知
----

[](#邮件通知)

```
use Dog\Noticer\Channel\Email;
use Dog\Noticer\Exception\NoticeException;

/**
 * @var Email
 */
$mail = make(Email::class);
// $mail = $this->container->make(Email::class); // 效果一样

try {
    // 发送纯文本
    $mail->to('yourname@foo.bar', '你的名字')
        ->subject('test')
        ->text('title1')
        ->send();
} catch (NoticeException $e) {
    // do something for exception
}

// 发送html
$mail->init()
    // ->to('yourname@foo.bar', '你的名字')
    ->to('yourname@foo.bar') // 第二个参数可以省略
    ->subject('test')
    ->html('title1')
    ->send();

// 一行一行文本发送
$mail->init()
    // ->to('yourname@foo.bar', '你的名字')
    ->to(['yourname@foo.bar' => '你的名字']) // 可以通过数组格式给多个人发
    ->subject('test')
    ->line('title1')
    ->line('title2')
    ->line('title3')
    ->send();

// 发送视图
$mail->init()
    ->to('yourname@foo.bar', '你的名字')
    ->subject('test')
    ->view('mail', ['name' => '参数值'])
    ->send();
// 视图配置
/*

    Hyperf

Hello, {{ $name }}. You are using blade template now.

*/

// 指定blade模板引擎发送视图
$mail->init()
    ->to('yourname@foo.bar', '你的名字')
    ->subject('test')
    ->blade('mail', ['name' => '参数值'])
    ->send();

// 给多个人发送
// 指定blade模板引擎发送视图
$mail->init()
    ->to([
        'yourname@foo.bar' => '你的名字1',
        'yourname2@foo.bar' => '你的名字2',
    ])
    ->subject('test')
    ->view('mail', ['name' => '参数值'])
    ->send();

// 每次发送之后如果仍使用同一个实例，务必重置，否则可能出现问题
$mail->init()
    ->to('yourname@foo.bar', '你的名字')
    ->subject('test')
    ->html('重置完成')
    ->send();

// 更多功能请扒源码
```

短信通知
----

[](#短信通知)

```
use Dog\Noticer\Channel\Sms;

/**
 * @var Sms
 */
$sms = make(Sms::class);
// $sms = $this->container->make(Sms::class); // 效果一样

try {
    $tplId = '111111111';
    $param = ['name' => '张三'];
    $receivers = ['131xxxxxxxx', '132xxxxxxxx'];
    $sms->send($tplId, $param, $receivers);
} catch (NoticeException $e) {
    // do something for exception
}
```

电话通知
----

[](#电话通知)

```
use Dog\Noticer\Channel\Phone;

/**
 * @var Phone
 */
$phone = make(Phone::class);
// $phone = $this->container->make(Phone::class); // 效果一样

try {
    $content = '您的验证码为：123456';
    $receiver = '131xxxxxxxx'; // 只能单个发送
    $phone->send($content, $receiver);
} catch (NoticeException $e) {
    // do something for exception
}
```

钉钉工作通知
------

[](#钉钉工作通知)

```
use Dog\Noticer\Channel\DingWorker;
use Dog\Noticer\Channel\DingWorker\MsgType\Text;
use Dog\Noticer\Channel\DingWorker\MsgType\Markdown;
use Dog\Noticer\Channel\DingWorker\MsgType\ActionCard;

/**
 * @var DingWorker
 */
$dingworker = make(DingWorker::class);
// $dingworker = $this->container->make(DingWorker::class); // 效果一样

// 发送文本
try {
    // 注意：工作通知相同内容只能一天给一个人发一次，每个人最多一天收到50条消息，为了让通知内容不会因为相同被拦截，可以加上当前发送的时间
    // 其他所有格式都一样，相同会被拦截，建议都加上时间，包括markdown、actionCard
    // $text = new Text('通知内容' . "\n" . date('Y-m-d H:i:s'));
    $text = new Text('通知内容');
    $options = [
        'emails' => 'yourname@foo.bar', // 多一个以|分隔，例如 'emails' => 'yourname@foo.bar|yourname2@foo.bar',
        // 'workcodes' => '1', // 多一个以|分隔，必须带前面0，与邮箱填一个即可
    ];
    $dingworker->send($text, $options);
} catch (NoticeException $e) {
    // do something for exception
}

// 发送markdown，仅支持markdown子集，具体请参考：https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c
$markdown = new Markdown('标题', "
# title1
# title2
---

**加粗** 不加粗
");
$options = [
    'emails' => 'yourname@foo.bar', // 多一个以|分隔，例如 'emails' => 'yourname@foo.bar|yourname2@foo.bar',
    // 'workcodes' => '1', // 多一个以|分隔，必须带前面0，与邮箱填一个即可
];
$dingworker->send($markdown, $options);

// 发送ActionCard
$actionCard = new ActionCard('标题', "
# markdown文本，主体内容
# ---
");
// 单个button
$actionCard->single('button标题', 'button跳转url');
// 或者多个button
$actionCard->btn('button标题1', 'button跳转url1')
    >btn('button标题2', 'button跳转url2')
    >btn('button标题3', 'button跳转url3');
// 或者通过数组设置多个button
$actionCard->btns([
    ['title' => 'button标题1', 'action_url' => 'button跳转url1'],
    ['title' => 'button标题2', 'action_url' => 'button跳转url2'],
]);
// 默认button为横向排列，如果需要竖向，可设置：
$actionCard->setVertical(true);
$dingworker->send($actionCard, $options);

// 更多消息类型请扒源码
```

钉钉机器人（钉钉群）通知
------------

[](#钉钉机器人钉钉群通知)

```
use Dog\Noticer\Channel\DingGroup;
use Dog\Noticer\Channel\DingGroup\MsgType\Text;
use Dog\Noticer\Channel\DingGroup\MsgType\Markdown;
use Dog\Noticer\Channel\DingGroup\MsgType\ActionCard;

/**
 * @var DingGroup
 */
$dinggroup = make(DingGroup::class);
// $dinggroup = $this->container->make(DingGroup::class); // 效果一样

$robots = [
    ['webhook' => '钉钉机器人webhook中的access_token的值', 'secret' => '此参数非必填'],
    ['webhook' => '另外一个机器人'],
];
$options = [

]
// 发送文本
try {
    $text = new Text('通知内容');
    $dinggroup->send($text, $robots, $options);
} catch (NoticeException $e) {
    // do something for exception
}

// 发送markdown，仅支持markdown子集，具体请参考：https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c
$markdown = new Markdown('标题', "
# title1
# title2
---

**加粗** 不加粗
");
$dinggroup->send($markdown, $robots, $options);

// 发送ActionCard
$actionCard = new ActionCard('标题', "
# markdown文本，主体内容
# ---
");
// 单个button
$actionCard->single('button标题', 'button跳转url');
// 或者多个button
$actionCard->btn('button标题1', 'button跳转url1')
    >btn('button标题2', 'button跳转url2')
    >btn('button标题3', 'button跳转url3');
// 或者通过数组设置多个button
$actionCard->btns([
    ['title' => 'button标题1', 'action_url' => 'button跳转url1'],
    ['title' => 'button标题2', 'action_url' => 'button跳转url2'],
]);
// 默认button为横向排列，如果需要竖向，可设置：
$actionCard->setVertical(true);
$dinggroup->send($actionCard, $robots, $options);

// 更多消息类型请扒源码
```

Yach机器人（Yach群）通知
----------------

[](#yach机器人yach群通知)

```
use Dog\Noticer\Channel\YachGroup;
use Dog\Noticer\Channel\YachGroup\MsgType\Text;
use Dog\Noticer\Channel\YachGroup\MsgType\Markdown;
use Dog\Noticer\Channel\YachGroup\MsgType\ActionCard;

/**
 * @var YachGroup
 */
$yachgroup = make(YachGroup::class);
// $yachgroup = $this->container->make(YachGroup::class); // 效果一样

$robots = [
    ['webhook' => 'yach机器人webhook中的access_token的值', 'secret' => '此参数必填'],
];
// 发送文本
try {
    $text = new Text('通知内容');
    $yachgroup->send($text, $robots);
} catch (NoticeException $e) {
    // do something for exception
}

// 发送markdown，仅支持markdown子集，具体请参考（Yach和钉钉差不多）：https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c
$markdown = new Markdown('标题', "
# title1
# title2
---

**加粗** 不加粗
");
$yachgroup->send($markdown, $robots);

// 发送markdown，并带图片地址
$markdown = new Markdown('标题', "
# title1
# title2
---

**加粗** 不加粗
", 'http://bpit-public.oss-cn-beijing.aliyuncs.com/note_1_1572593268.jpg');
$yachgroup->send($markdown, $robots);

// 发送ActionCard
$actionCard = new ActionCard('标题', "
# markdown文本，主体内容
# ---
", $image = '', $contentTitle = ''); // 此处可以填下image和contentTitle的参数
// 单个button
$actionCard->single('button标题', 'button跳转url');
// 或者多个button
$actionCard->btn('button标题1', 'button跳转url1')
    >btn('button标题2', 'button跳转url2')
    >btn('button标题3', 'button跳转url3');
// 或者通过数组设置多个button
$actionCard->btns([
    ['title' => 'button标题1', 'action_url' => 'button跳转url1'],
    ['title' => 'button标题2', 'action_url' => 'button跳转url2'],
]);
// 默认button为横向排列，如果需要竖向，可设置：
$actionCard->setVertical(true);
$yachgroup->send($actionCard, $robots);

// 更多消息类型请扒源码
```

Yach工作通知
--------

[](#yach工作通知)

```
use Dog\Noticer\Channel\YachWorker;
use Dog\Noticer\Channel\YachWorker\MsgType\Text;
use Dog\Noticer\Channel\YachWorker\MsgType\Markdown;
use Dog\Noticer\Channel\YachWorker\MsgType\ActionCard;

/**
 * @var YachWorker
 */
$yachworker = make(YachWorker::class);
// $yachworker = $this->container->make(YachWorker::class); // 效果一样

$options = [
    // 通过邮箱发送（推荐）
    'user_type' => 'email',
    // 多个以|分隔
    'userid_list' => 'tianpian@foo.bar|xxxxxxxxxx@foo.bar',
    // // 通过工号发送
    // 'user_type' => 'workcode',
    // // 多个以|分隔
    // 'userid_list' => '1|999999',
];
// 发送文本
try {
    $text = new Text('通知内容');
    $yachworker->send($text, $options);
} catch (NoticeException $e) {
    // do something for exception
}

// 发送markdown，仅支持markdown子集，具体请参考（Yach和钉钉差不多）：https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c
$markdown = new Markdown('标题', "
# title1
# title2
---

**加粗** 不加粗
");
$yachworker->send($markdown, $options);

// 发送markdown，并带图片地址
$markdown = new Markdown('标题', "
# title1
# title2
---

**加粗** 不加粗
", 'http://bpit-public.oss-cn-beijing.aliyuncs.com/note_1_1572593268.jpg');
$yachworker->send($markdown, $options);

// 发送ActionCard
$actionCard = new ActionCard('标题', "
# markdown文本，主体内容
# ---
", $image = '', $contentTitle = ''); // 此处可以填下image和contentTitle的参数
// 单个button
$actionCard->single('button标题', 'button跳转url');
// 或者多个button
$actionCard->btn('button标题1', 'button跳转url1')
    >btn('button标题2', 'button跳转url2')
    >btn('button标题3', 'button跳转url3');
// 或者通过数组设置多个button
$actionCard->btns([
    ['title' => 'button标题1', 'action_url' => 'button跳转url1'],
    ['title' => 'button标题2', 'action_url' => 'button跳转url2'],
]);
// 默认button为横向排列，如果需要竖向，可设置：
$actionCard->setVertical(true);
$yachworker->send($actionCard, $options);

// 更多消息类型请扒源码
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2023d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5efb919b0cb59ed9fcbea82bb821d5faa5060c0bd2a2d7b0d648fa2a937b8460?d=identicon)[ethananony](/maintainers/ethananony)

![](https://www.gravatar.com/avatar/20c503954779e0ed0ce1c4845ab99ab8c6b727a247995f2c390243a6b8a0f5c7?d=identicon)[lbbniu](/maintainers/lbbniu)

---

Top Contributors

[![ethananony](https://avatars.githubusercontent.com/u/54740729?v=4)](https://github.com/ethananony "ethananony (1 commits)")

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/alarm-dog-noticer/health.svg)

```
[![Health](https://phpackages.com/badges/alarm-dog-noticer/health.svg)](https://phpackages.com/packages/alarm-dog-noticer)
```

###  Alternatives

[cspoo/swiftmailer-mailgun-bundle

Swiftmailer Mailgun bundle

1031.1M](/packages/cspoo-swiftmailer-mailgun-bundle)[wildbit/swiftmailer-postmark

A Swiftmailer Transport for Postmark.

542.8M6](/packages/wildbit-swiftmailer-postmark)[openbuildings/swiftmailer-css-inliner

Inline the css of your html emails

69401.9k3](/packages/openbuildings-swiftmailer-css-inliner)[mailjet/mailjet-swiftmailer

A SwiftMailer transport implementation for Mailjet

261.2M9](/packages/mailjet-mailjet-swiftmailer)[phalcon-ext/mailer

Mailer component as wrapper over SwiftMailer for Phalcon.

39196.9k2](/packages/phalcon-ext-mailer)[openbuildings/postmark

Swiftmailer Transport Class for Postmark

15369.8k2](/packages/openbuildings-postmark)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
