{"id":20144198,"url":"https://github.com/quansitech/qs-sendmsg","last_synced_at":"2026-05-15T05:12:59.993Z","repository":{"id":62531971,"uuid":"252102596","full_name":"quansitech/qs-sendmsg","owner":"quansitech","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-30T10:46:53.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-03-24T14:11:02.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quansitech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-01T07:25:36.000Z","updated_at":"2023-01-30T10:43:45.000Z","dependencies_parsed_at":"2023-02-16T06:30:37.991Z","dependency_job_id":null,"html_url":"https://github.com/quansitech/qs-sendmsg","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/quansitech/qs-sendmsg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quansitech%2Fqs-sendmsg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quansitech%2Fqs-sendmsg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quansitech%2Fqs-sendmsg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quansitech%2Fqs-sendmsg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quansitech","download_url":"https://codeload.github.com/quansitech/qs-sendmsg/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quansitech%2Fqs-sendmsg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33054570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-15T02:00:06.351Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T22:09:13.664Z","updated_at":"2026-05-15T05:12:59.976Z","avatar_url":"https://github.com/quansitech.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# qs-sendmsg\n统一发送消息队列\n\n## 队列发送用法\n### 1.安装及配置\n#### 1.1安装依赖及执行迁移\n```shell script\ncomposer require quansitech/send-msg\nphp artisan migrate\n```\n\n#### 1.2配置发送的API设置\n##### 微信公众号发模板消息\n```env\n# 微信公众号\nWX_APPID=\nWX_APPSECRET=\n```\n\n##### 手机短信api\n###### 方案1，采用启瑞云/中国短信网\n```env\n# 启瑞云短信\nQIRUI_API_KEY=\nQIRUI_API_SECRET=\n# 签名（即短信开头）\nQIRUI_SIGN=\n```\n###### 方案2，采用其它api，详细配置请查看 [easysms配置](https://github.com/overtrue/easy-sms)\n在/app/Common/Conf/config.php中加入以下代码\n```php\n'SEND_MSG_SMS_GATEWAY'=\u003e [\n    //云片\n    'yunpian'=\u003e[\n        'api_key'=\u003e'27f03185cb9b6e1a4f274b*******',\n        'sign_text'=\u003e'【云片签名】'\n    ],\n],\n```\n\n\n#### 1.3配置及启动队列\n在后台中新增消息模板，地址 http://[host]:[port]/admin/MsgTpl/add 或写迁移文件进行添加，建议写迁移文件\u003cbr\u003e\n启动队列wx(微信)和sms(短信)\n```shell script\nphp resque start --queue=wx #微信消息\nphp resque start --queue=sms #短信消息\n```\n\n### 2.在项目中新建一个消息内容转换器，需继承[BaseMsgTemplateParse]，然后加上要转换的所有方法 \n```php\nclass MsgTemplateParse extends BaseMsgTemplateParse {\n    \n    static protected $_var_func = array(\n        '项目名称' =\u003e 'parseProjectName',\n    );\n    \n    static public function parseProjectName($args){\n        $project_id = $args['project_id'];\n        return D('Project')-\u003ewhere(['id'=\u003e$project_id])-\u003egetField('title');\n    }\n}\n```\n\n### 3.构造实例\n```php\n//MsgTemplateParse为上一步所定义的类\n$builder=\\QsSendMsg\\SendMsgJobBuilder::getInstance()-\u003esetTemplateParser(MsgTemplateParse::class);\n```\n\n### 4.添加发送的消息内容及对象（可加多条）\n```php\n/** @var $builder \\QsSendMsg\\SendMsgJobBuilder */\n$builder-\u003esetMsgTpl('test_msg',['project_id'=\u003e1])\n    -\u003eaddSmsMsgJob('13100000000','发送短信')\n    -\u003eaddWxMsgJob('[openid]','[消息模板id]','[消息内容对象]','[跳转的url]','发送微信消息','[内容填充字段（默认为\"first\"）]');\n```\nps.\"test_msg\"为数据库中'qs_msg_tpl'的数据 \u003cbr\u003e\nps.\"消息内容对象\"示例\n```php\n$msgData = [\n    'first' =\u003e ['value' =\u003e 'test', 'color' =\u003e '#173177'],\n    'keyword1' =\u003e ['value' =\u003e 'keyword1', 'color' =\u003e '#173177'],\n    'keyword2' =\u003e ['value' =\u003e 'keyword2', 'color' =\u003e '#173177'],\n    'remark' =\u003e ['value' =\u003e 'remark', 'color' =\u003e '#173177'],\n];\n```\n\n### 5.分派消息队列\n#### 5.1全部发送\n```php\n/** @var $builder \\QsSendMsg\\SendMsgJobBuilder 第4步的$builder*/\n$builder-\u003edispatchAll();\n```\n\n#### 5.2智能发送，（顺序发送，当一个发送成功时就不会发送后面的消息）\n```php\n/** @var $builder \\QsSendMsg\\SendMsgJobBuilder 第4步的$builder*/\n$builder-\u003edispatch();\n```\n\n## 即时发送用法\n根据队列用法1.1步骤，1.2步骤配置后即可使用\n### 微信公众号模板消息发送\n```php\n$job = new \\QsSendMsg\\Job\\SendWxMsgJob();\n$r=$job-\u003esend([\n    'open_id'=\u003e'微信openid',\n    'template_id'=\u003e'微信模板消息ID',\n    'url'=\u003e'跳转地址',\n    'data'=\u003e'消息内容'\n]);\n```\n### 手机短信发送\n```php\n$job = new \\QsSendMsg\\Job\\SendSmsMsgJob();\n$r=$job-\u003esend([\n    'mobile'=\u003e'手机号',\n    'content'=\u003e'短信内容',\n    //...其它参数\n]);\n```\n发送失败时$r为false，可查看$job-\u003eerror错误信息\n\n## 升级\n### 1.0升级至2.0\n在.env文件下增加配置项\n```env\n# 启瑞云短信\nQIRUI_API_KEY=\nQIRUI_API_SECRET=\n# 签名（即短信开头）\nQIRUI_SIGN=\n```\n\n### 2.1版本后支持自定义短信发送渠道（默认还是采用启瑞云/中国短信网发送）\n需要在config文件中加入以下内容\n```php\n'SEND_MSG_SMS_GATEWAY'=\u003e [\n    //云片\n    'yunpian'=\u003e[\n        'api_key'=\u003e'27f03185cb9b6e1a4f274b*******',\n        'sign_text'=\u003e'【云片签名】'\n    ],\n],\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquansitech%2Fqs-sendmsg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquansitech%2Fqs-sendmsg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquansitech%2Fqs-sendmsg/lists"}