PHPackages                             quansitech/send-msg - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. quansitech/send-msg

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

quansitech/send-msg
===================

qscmf send msg

v2.2.0(3y ago)01.4k↓100%1MITPHPPHP &gt;=7.2.0

Since Apr 1Pushed 3y ago2 watchersCompare

[ Source](https://github.com/quansitech/qs-sendmsg)[ Packagist](https://packagist.org/packages/quansitech/send-msg)[ RSS](/packages/quansitech-send-msg/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (11)Used By (0)

qs-sendmsg
==========

[](#qs-sendmsg)

统一发送消息队列

队列发送用法
------

[](#队列发送用法)

### 1.安装及配置

[](#1安装及配置)

#### 1.1安装依赖及执行迁移

[](#11安装依赖及执行迁移)

```
composer require quansitech/send-msg
php artisan migrate
```

#### 1.2配置发送的API设置

[](#12配置发送的api设置)

##### 微信公众号发模板消息

[](#微信公众号发模板消息)

```
# 微信公众号
WX_APPID=
WX_APPSECRET=
```

##### 手机短信api

[](#手机短信api)

###### 方案1，采用启瑞云/中国短信网

[](#方案1采用启瑞云中国短信网)

```
# 启瑞云短信
QIRUI_API_KEY=
QIRUI_API_SECRET=
# 签名（即短信开头）
QIRUI_SIGN=
```

###### 方案2，采用其它api，详细配置请查看 [easysms配置](https://github.com/overtrue/easy-sms)

[](#方案2采用其它api详细配置请查看-easysms配置)

在/app/Common/Conf/config.php中加入以下代码

```
'SEND_MSG_SMS_GATEWAY'=> [
    //云片
    'yunpian'=>[
        'api_key'=>'27f03185cb9b6e1a4f274b*******',
        'sign_text'=>'【云片签名】'
    ],
],
```

#### 1.3配置及启动队列

[](#13配置及启动队列)

在后台中新增消息模板，地址 http://\[host\]:\[port\]/admin/MsgTpl/add 或写迁移文件进行添加，建议写迁移文件
启动队列wx(微信)和sms(短信)

```
php resque start --queue=wx #微信消息
php resque start --queue=sms #短信消息
```

### 2.在项目中新建一个消息内容转换器，需继承\[BaseMsgTemplateParse\]，然后加上要转换的所有方法

[](#2在项目中新建一个消息内容转换器需继承basemsgtemplateparse然后加上要转换的所有方法)

```
class MsgTemplateParse extends BaseMsgTemplateParse {

    static protected $_var_func = array(
        '项目名称' => 'parseProjectName',
    );

    static public function parseProjectName($args){
        $project_id = $args['project_id'];
        return D('Project')->where(['id'=>$project_id])->getField('title');
    }
}
```

### 3.构造实例

[](#3构造实例)

```
//MsgTemplateParse为上一步所定义的类
$builder=\QsSendMsg\SendMsgJobBuilder::getInstance()->setTemplateParser(MsgTemplateParse::class);
```

### 4.添加发送的消息内容及对象（可加多条）

[](#4添加发送的消息内容及对象可加多条)

```
/** @var $builder \QsSendMsg\SendMsgJobBuilder */
$builder->setMsgTpl('test_msg',['project_id'=>1])
    ->addSmsMsgJob('13100000000','发送短信')
    ->addWxMsgJob('[openid]','[消息模板id]','[消息内容对象]','[跳转的url]','发送微信消息','[内容填充字段（默认为"first"）]');
```

ps."test\_msg"为数据库中'qs\_msg\_tpl'的数据
ps."消息内容对象"示例

```
$msgData = [
    'first' => ['value' => 'test', 'color' => '#173177'],
    'keyword1' => ['value' => 'keyword1', 'color' => '#173177'],
    'keyword2' => ['value' => 'keyword2', 'color' => '#173177'],
    'remark' => ['value' => 'remark', 'color' => '#173177'],
];
```

### 5.分派消息队列

[](#5分派消息队列)

#### 5.1全部发送

[](#51全部发送)

```
/** @var $builder \QsSendMsg\SendMsgJobBuilder 第4步的$builder*/
$builder->dispatchAll();
```

#### 5.2智能发送，（顺序发送，当一个发送成功时就不会发送后面的消息）

[](#52智能发送顺序发送当一个发送成功时就不会发送后面的消息)

```
/** @var $builder \QsSendMsg\SendMsgJobBuilder 第4步的$builder*/
$builder->dispatch();
```

即时发送用法
------

[](#即时发送用法)

根据队列用法1.1步骤，1.2步骤配置后即可使用

### 微信公众号模板消息发送

[](#微信公众号模板消息发送)

```
$job = new \QsSendMsg\Job\SendWxMsgJob();
$r=$job->send([
    'open_id'=>'微信openid',
    'template_id'=>'微信模板消息ID',
    'url'=>'跳转地址',
    'data'=>'消息内容'
]);
```

### 手机短信发送

[](#手机短信发送)

```
$job = new \QsSendMsg\Job\SendSmsMsgJob();
$r=$job->send([
    'mobile'=>'手机号',
    'content'=>'短信内容',
    //...其它参数
]);
```

发送失败时$r为false，可查看$job-&gt;error错误信息

升级
--

[](#升级)

### 1.0升级至2.0

[](#10升级至20)

在.env文件下增加配置项

```
# 启瑞云短信
QIRUI_API_KEY=
QIRUI_API_SECRET=
# 签名（即短信开头）
QIRUI_SIGN=
```

### 2.1版本后支持自定义短信发送渠道（默认还是采用启瑞云/中国短信网发送）

[](#21版本后支持自定义短信发送渠道默认还是采用启瑞云中国短信网发送)

需要在config文件中加入以下内容

```
'SEND_MSG_SMS_GATEWAY'=> [
    //云片
    'yunpian'=>[
        'api_key'=>'27f03185cb9b6e1a4f274b*******',
        'sign_text'=>'【云片签名】'
    ],
],
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.4% 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 ~115 days

Recently: every ~251 days

Total

10

Last Release

1194d ago

Major Versions

1.0.3 → 2.02020-04-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/15a0610fee78753bdad92fd45c3506455c0fd45ae51924797b1841d260495a3f?d=identicon)[tiderjian](/maintainers/tiderjian)

![](https://www.gravatar.com/avatar/bb006532a148984f2ee6703cbf4f9830af758d740ef02634d89cc7716485ccd1?d=identicon)[Martin Jack](/maintainers/Martin%20Jack)

---

Top Contributors

[![qq958691165](https://avatars.githubusercontent.com/u/13673962?v=4)](https://github.com/qq958691165 "qq958691165 (14 commits)")[![W-CLL](https://avatars.githubusercontent.com/u/60960050?v=4)](https://github.com/W-CLL "W-CLL (2 commits)")[![tiderjian](https://avatars.githubusercontent.com/u/1665649?v=4)](https://github.com/tiderjian "tiderjian (1 commits)")

### Embed Badge

![Health badge](/badges/quansitech-send-msg/health.svg)

```
[![Health](https://phpackages.com/badges/quansitech-send-msg/health.svg)](https://phpackages.com/packages/quansitech-send-msg)
```

PHPackages © 2026

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