jundayw / message
Integrates with SMS, DingTalk, and WeChat through a single API, and supports customizable channels.
Requires
- php: ^8.0
- alibabacloud/dysmsapi-20170525: ^4.5
- w7corp/easywechat: ^6.19
Requires (Dev)
- code-lts/doctum: ^5.0
This package is auto-updated.
Last update: 2026-04-02 08:31:59 UTC
README
Message
Integrates with SMS, DingTalk, and WeChat through a single API, and supports customizable channels.
Table of Contents
Installation
You can install the package via Composer:
composer require jundayw/message
Usage
SMS
method send: specify templateCode, templateParam, and signName explicitly (with a placeholder signName that gets
Message::channel('sms')->send(['136****5922'], [ 'templateCode' => 'SMS_275***212', 'templateParam' => [ 'code' => 123454, ], 'signName' => '${signName}', ], [ 'signName' => 'aliyun', ]);
Custom template sending:
uses a logical template name (e.g., 'demo') instead of the provider's template code
Message::channel('sms')->sendTemplate(['136****5922'], 'demo', [ 'code' => 234567, ]);
Service provider template number:
directly uses the provider's official template code (e.g., 'SMS_275***212')
Message::channel('sms')->sendTemplate(['136****5922'], 'SMS_275***212', [ 'code' => 345678, ]);
DingTalk
$message = Message::channel('dingtalk_robot')->send(['136****5922'], [ 'msgtype' => 'text', 'text' => [ 'content' => 'message.dingtalk_robot.send', ], ]);
Custom template sending:
return [ 'channels' => [ 'dingtalk_robot' => [ 'webhook' => env('DINGTALK_ROBOT_WEBHOOK'), 'secret' => env('DINGTALK_ROBOT_SECRET'), 'templates' => [ 'demo' => [ 'msgtype' => 'text', 'text' => [ 'content' => '${content}', ], ], ], ], ], ];
$message = Message::channel('dingtalk_robot')->sendTemplate(['136****5922'], 'demo', [], [ 'content' => 'message.dingtalk_robot.send', 'at_all' => true, ]);
$message = Message::channel('dingtalk_robot')->sendTemplate(['136****5922'], 'text', [ 'text' => [ 'content' => 'message.dingtalk_robot.send', ], ]);
WechatMiniProgram
$message = Message::channel('wechat_mini_program')->send(['oDx1b*****C3o0'], [ 'template_id' => '1pNJGVRYV***ozu1AJKUlbGQ', 'page' => 'index', 'data' => [ 'thing1' => ['value' => '验证码'], 'thing2' => ['value' => '登录验证'], ], ]); $message = Message::channel('wechat_mini_program')->sendTemplate(['oDx1b*****C3o0'], '1pNJGVRYV***ozu1AJKUlbGQ', [ 'page' => '${page}', 'data' => [ 'thing1' => ['value' => '${data.thing1}'], 'thing2' => '登录验证', ], ], [ 'page' => 'page', 'data' => [ 'thing1' => '验证码', ], ]);
WechatOfficialAccount
$message = Message::channel('wechat_official_account')->sendTemplate(['oDx1b*****C3o0'], '1pNJGVRYV***ozu1AJKUlbGQ', [ 'data' => [ 'thing1' => ['value' => '验证码'], 'thing2' => '登录验证', ], ]);
WechatServiceAccount
$message = Message::channel('wechat_service_account')->sendTemplate(['oDx1b*****C3o0'], '1pNJGVRYV***ozu1AJKUlbGQ', [ 'page' => '${page}', 'data' => [ 'thing1' => ['value' => '验证码'], 'thing2' => '登录验证', ], ], [ 'page' => 'page', ]);
WeWork
$message = Message::channel('wework_robot')->send(['oDx1b*****C3o0'], [ 'msgtype' => 'text', 'text' => [ 'content' => 'message.wework_robot.send', ], ]);
$message = Message::channel('wework_robot')->sendTemplate(['oDx1b*****C3o0'], 'demo', [ 'text' => [ 'content' => '${content}', ], ], [ 'content' => 'content', 'at_all' => true, ]);
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Contributors
Thanks goes to these wonderful people:
Contributions of any kind are welcome!
License
Distributed under the MIT License (MIT). Please see License File for more information.