PHPackages                             dongdavid/notify - 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. dongdavid/notify

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

dongdavid/notify
================

消息通知发送组件

2.0.1(5y ago)5141MITPHP

Since Aug 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/DongDavid/notify)[ Packagist](https://packagist.org/packages/dongdavid/notify)[ RSS](/packages/dongdavid-notify/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (2)Dependencies (5)Versions (4)Used By (0)

消息发送组件
======

[](#消息发送组件)

[![Build Status](https://camo.githubusercontent.com/6dfd199465d2adf32f31ecbf2159ff743bf885809c48b8b504158eb4ebb49a2a/68747470733a2f2f7472617669732d63692e636f6d2f446f6e6744617669642f6e6f746966792e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/DongDavid/notify)[![StyleCI](https://camo.githubusercontent.com/c63b58131c234535e8b6d71fc5b39ea51ed59b227db150e0fc8a87d21af2412a/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3238363936343633332f736869656c64)](https://github.styleci.io/repos/286964633)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7606019bc1736fafc5c6e72680f4e79632b0fd86a6b6471d76eee72595cec891/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f446f6e6744617669642f6e6f746966792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/DongDavid/notify/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/ffaf00d6c6e5bf3305e9e0372b68dd84b04ddb2a8f5c868ee2d5ba1145044178/68747470733a2f2f706f7365722e707567782e6f72672f646f6e6764617669642f6e6f746966792f646f776e6c6f616473)](https://packagist.org/packages/dongdavid/notify)[![License](https://camo.githubusercontent.com/6506f8a0cbb1379891898a3469bde8c7d8ab541691d79a36f0b5b0eb7171c7aa/68747470733a2f2f706f7365722e707567782e6f72672f646f6e6764617669642f6e6f746966792f6c6963656e7365)](https://packagist.org/packages/dongdavid/notify)

```
function offical($account)
{
    $data = [
        'access_token'=>$account['wechatoffical']['token'],
        'openid'=>$account['wechatoffical']['openid'],
        'template_id'=>$account['wechatoffical']['template_id'],
        'data'=>[
            'first'=>['value'=>'first is me'],
            'keyword1'=>['value'=>'哈哈哈'],
            'keyword2'=>['value'=>number_format(23.32,2)],
            'remark'=>['value'=>'备注信息'],
        ],

    ];

    $d = QuickSend::offical($data['access_token'],$data['openid'],$data['template_id'],$data['data']);
    var_dump($d);
}
function mini($account)
{
    $data = [
        'access_token'=>$account['miniprogram']['token'],
        'openid'=>$account['miniprogram']['openid'],
        'template_id'=>$account['miniprogram']['template_id'],
        'data'=>[
            'thing1'=>['value'=>'first is me'],
            'thing3'=>['value'=>'哈哈哈'],
            'time2'=>['value'=>23.32],
        ],

    ];

    $d = QuickSend::miniProgram($data['access_token'],$data['openid'],$data['template_id'],$data['data']);
    var_dump($d);
}
function email($account)
{
    // to、cc、bcc 可以支持字符串、数组，如果是二维数组， 则子数组必须要有键[email]保存邮箱地址
    // attachments 支持字符串、数组，如果是二维数组，则子数组必须要有键[filepath]来保存文件路径，会自动转换成绝对路径
    // config参考phpmailer，
    $data = [
        'config'=>$account['mail'],
        'subject'=>'测试邮件',
        'body'=>'邮件正文',
        'to'=>[
            'xxx@outlook.com',
        ],
        'cc'=>[
            ['email'=>'xxx@live.com','name'=>'收件人昵称'],
        ],
        'bcc'=>'xxx@qq.com',
        'attachments'=>[
            './aa.md',
            ['filepath'=>'./bb.md','filename'=>'说明文件.txt']
        ],
        //'attachments'=>'./aa.md',
    ];
    $d = QuickSend::mail($data['config'],$data['subject'],$data['body'],$data['to'],$data['attachments'],$data['cc'],$data['bcc']);
    var_dump($d);
}
function alisms($account)
{
    $data = [
        'config'=>[
            'accessKeyId'=>$account['alisms']['accessKeyId'],
            'accessKeySecret'=>$account['alisms']['accessKeySecret'],
            'SignName'=>$account['alisms']['SignName'],
            'template_code'=>$account['alisms']['template_code'],
        ],
        'phone'=>$account['alisms']['phone'],
        'template_param'=>[
            'name'=>'皮皮虾',
            'course_name'=>'如何上天',
        ],
    ];
    $d = QuickSend::alisms($data['config'],$data['phone'],$data['template_param']);
    var_dump($d);
}
```

Requirements
------------

[](#requirements)

- PHP &gt;= 5.6
- Redis PHP Extension
- guzzlehttp/guzzle ^6.3
- phpmailer/phpmailer ^ 6.1

Installing
----------

[](#installing)

```
$ composer require dongdavid/notify -vvv
```

Usage
-----

[](#usage)

如使用微信公众号/企业微信/微信小程序消息通知，则需要配置redis缓存access\_token

```
# 修改配置
\Dongdavid\Notify\cache(
    // 默认配置
    'host'     => '127.0.0.1',
    'port'     => '6379',
    'password' => '',
    'select'   => 6,
    'timeout'  => 3,
])
```

有两种使用方式，一种是直接将配置参数一并传入，另一种是定义`config`方法来获取配置，传入配置名称

### 第一种方式

[](#第一种方式)

#### 邮件

[](#邮件)

```
$mail = [
    'type'   => 'email',
    'config' => [
        'type'       => 'email',
        'signature'  => 'email_tx',
        'host'       => 'smtp.exmail.qq.com',
        'port'       => '465',
        'username'   => 'noreply@xxx.com',
        'password'   => '', //腾讯的要用专用密码登陆
        'SMTPSecure' => 'ssl',
        'fromEmail'  => 'noreply@xxx.com',
        'fromName'   => 'name',
    ],
    'msg'    => [
        'subject'     => '邮件主旨',
        'body'        => '邮件内容',
        'touser'      => [
            [
                'emailAddress' => 'receiver@outlook.com',
                'name'         => '收件人名字',
            ],
        ],
        'cc'          => [],
        'attachments' => [
            './public/robots.txt',
        ],
    ],
];

Notify::send($mail);
```

#### 企业微信

[](#企业微信)

```
$qy = [
    'type'   => 'wechatwork',
    'config' => [
        'type'      => 'wechatwork',
        'signature' => 'work_xxx_1000002',
        'appid'     => 'xxx',
        'appsecret' => 'xxxxx',
        'agentid'   => '1000002',
    ],
    'msg'    => [
        'touser'   => '001',
        'msgtype'  => 'textcard',
        'textcard' => [
            'title'       => '测试通知',
            'description' => "我是通知内容\n第二行开始了\n加上一个链接2016年9月26日 恭喜你抽中iPhone 7一台，领奖码：xxxx请于2016年10月10日前联系行政同事领取",
            'url'         => 'https://www.dongdavid.com',
        ],
    ],
];

Notify::send($qy);
```

#### 微信公众号

[](#微信公众号)

```
$wechat = [
    'type'   => 'wechatoffical',
    'config' => [
        'type'      => 'wechatoffical',
        'signature' => 'offical_xxx',
        'appid'     => 'xxx',
        'appsecret' => 'xxxxx',
    ],
    'msg'    => [
        'touser'      => 'openid',
        'template_id' => 'template_id',
        'url'         => 'https://www.dongdavid.com',
        'miniprogram' => [
            'appid'    => '',
            'pagepath' => '',
        ],
        'data'        => [
            'first'    => [
                'value' => '哈喽，我是first one',
            ],
            'keyword1' => [
                'value' => '我是关键词一号',
                'color' => '#17317',
            ],
            'keyword2' => [
                'value' => '我是关键词二号',
            ],
            'remark'   => [
                'value' => '我是备注了啊',
            ],
        ],
    ],
];
Notify::send($notify);
```

#### 微信小程序

[](#微信小程序)

```
$wechat = [
    'type'   => 'miniprogram',
    'config' => [
        'type'      => 'miniprogram',
        'signature' => 'mini_xxx',
        'appid'     => 'xxx',
        'appsecret' => 'xxxx',
    ],
    'msg'    => [
        'touser'            => 'oBEIa0cr36R6FTCppAvgKLoKG9FY',
        'template_id'       => '0OHAj375XtCEVwJaASmRv79c4KhlqzN_mtsmNn6qHGg',
        'page'              => '',
        'miniprogram_state' => 'developer', //跳转小程序类型：developer为开发版；trial为体验版；formal为正式版；默认为正式版
        'data'              => [
            'thing1' => [
                'value' => '哈喽，我是first one',
            ],
            'time2'  => [
                'value' => date('Y-m-d H:i'),
            ],
        ],
    ],
];
Notify::send($notify);
```

### 第二种方式

[](#第二种方式)

在框架中使用,或者自定义一个`config`方法来获取配置

在`helper.php`中会使用`\Dongdavid\Notify\config('notify_config')`来获取所有的消息发送配置， 所以需要确保你能够通过`config('notify_config')['config_name']`来获取到对应的配置

```
if (!function_exists('config')) {
    function config($name, $value = null)
    {
        if (null !== $value) {
            \Dongdavid\Notify\cache('notify-config', $value);
        } else {
            return \Dongdavid\Notify\cache('notify-config');
        }
    }
} else {
    function config($name, $value = null)
    {
        return \config($name, $value);
    }
}
```

```
# 预定义一个config方法用于获取配置
function config($config_name)
{
    $config = [
        'notify_config'=>[
            'work_xxx_1000002' => [
                'type'      => 'wechatwork',
                'signature' => 'work_xxx_1000002',
                'appid'     => 'xxx',
                'appsecret' => 'xxxxx',
                'agentid'   => '1000002',
            ],
            'offical_xxx'      => [
                'type'      => 'wechatoffical',
                'signature' => 'offical_xxx',
                'appid'     => 'xxx',
                'appsecret' => 'xxx',
            ],
            'email_tx'                        => [
                'type'       => 'email',
                'signature'  => 'email_tx',
                'host'       => 'smtp.exmail.qq.com',
                'port'       => '465',
                'username'   => 'noreply@xxx.com',
                'password'   => '', //腾讯的要用专用密码登陆
                'SMTPSecure' => 'ssl',
                'fromEmail'  => 'noreply@xxx.com',
                'fromName'   => 'name',

            ],
            'mini_xxx'         => [
                'type'      => 'miniprogram',
                'signature' => 'mini_xxx',
                'appid'     => 'xxx',
                'appsecret' => 'xxxxx',
            ],
        ]
    ];
    return $config[$config_name];
}
# 动态注入配置
\Dongdavid\Notify\config('notify_config',$configs);

$data = [
    'type'   => 'email',
    'config' => 'email_tx',
    'msg'    => [
        .
        .
        .
    ],
];

$data = [
    'type'   => 'wechatwork',
    'config' => 'work_xxx_1000002',
    'msg'    => [
        .
        .
        .
    ],
];
$data = [
    'type'   => 'wechatoffical',
    'config' => 'offical_xxx',
    'msg'    => [
        .
        .
        .
    ],
];
$data = [
    'type'   => 'miniprogram',
    'config' => 'mini_xxx',
    'msg'    => [
        .
        .
        .
    ],
];

Notify::send($data);
```

Test
----

[](#test)

```
#本地调试
mkdir notify-test
cd notify-test
composer init
composer config repositories.notify path ../notify
composer require dongdavid/notify:dev-master
touch index.php
```

TODO
----

[](#todo)

- 增加单元测试 - 我可能把单元测试写成了功能测试了，我得先去学一下怎么做单元测试😭

例子
--

[](#例子)

[结合think-queue实现消息发送队列教程](./docs/install-with-think-queue.md)

Contributing
------------

[](#contributing)

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/dongdavid/notify/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/dongdavid/notify/issues).
3. Contribute new features or update the wiki.

*The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.*

License
-------

[](#license)

MIT

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

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

Every ~193 days

Total

2

Last Release

1893d ago

Major Versions

1.0.0 → 2.0.12021-03-10

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18623095?v=4)[DongDavid](/maintainers/dongdavid)[@DongDavid](https://github.com/DongDavid)

---

Top Contributors

[![DongDavid](https://avatars.githubusercontent.com/u/18623095?v=4)](https://github.com/DongDavid "DongDavid (31 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dongdavid-notify/health.svg)

```
[![Health](https://phpackages.com/badges/dongdavid-notify/health.svg)](https://phpackages.com/packages/dongdavid-notify)
```

###  Alternatives

[laravel-notification-channels/telegram

Telegram Notifications Channel for Laravel

1.1k3.4M35](/packages/laravel-notification-channels-telegram)[s-ichikawa/laravel-sendgrid-driver

This library adds a 'sendgrid' mail driver to Laravel.

4139.3M1](/packages/s-ichikawa-laravel-sendgrid-driver)[laravel-notification-channels/microsoft-teams

A Laravel Notification Channel for Microsoft Teams

1603.0M7](/packages/laravel-notification-channels-microsoft-teams)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)[guanguans/notify

Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

682104.9k7](/packages/guanguans-notify)[tzsk/sms

A robust and unified SMS gateway integration package for Laravel, supporting multiple providers.

320244.3k6](/packages/tzsk-sms)

PHPackages © 2026

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