liuwave/think-notification-easysms-channel
Composer 安装命令:
composer require liuwave/think-notification-easysms-channel
包简介
EasySms Notification channel For ThinkPHP6
README 文档
README
使用 overtrue/easy-sms 发送 ThinkPHP6 消息通知。
安装
$ composer require liuwave/think-notification-easysms-channel
配置
1、安装插件会自动生成 config/easysms.php 文件,若未生成,可以执行以下命令:
$ php think vendor:publish
2、在config/easysms.php 中修改配置。
使用
1、创建通知
通知类,需要实现channels和toEasySms方法
namespace app\common\notification; use liuwave\notification\channel\EasySms as EasySmsChannel; use liuwave\notification\message\EasySms as EasySmsMessage; use yunwuxin\Notification; /** * Class ValidateCode * @package app\common\notification */ class ValidateCode extends Notification { /** * @var string */ public $code = ''; /** * @var string */ public $template = ""; /** * ValidateCode constructor. * * @param $template * @param string $code */ public function __construct(string $template, string $code = '') { $this->template = $template; $this->code = $code; } /** * @inheritDoc */ public function channels($notifiable) { return [ EasySmsChannel::class ]; } /** * @param \yunwuxin\notification\Notifiable $notifiable * * @return \liuwave\notification\message\EasySms */ public function toEasySms($notifiable) { return ( new EasySmsMessage )->setContent('验证码是$code') ->setTemplate($this->template) ->setData([ 'code' => empty($this->code) ? rand(1000, 9999) : $this->code, ]); } }
发送短信通知
继承创建手机号码类,需要插入trait yunwuxin\notification\Notifiable ,这里直接继承\Overtrue\EasySms\PhoneNumber,并实现prepareEasySms方法。
namespace app\common\notification\user; use yunwuxin\notification\Notifiable; /** * Class PhoneNumber * @package app\common\notification\notifiable * @mixin Notifiable */ class PhoneNumber extends \Overtrue\EasySms\PhoneNumber { use Notifiable; /** * @return $this */ public function prepareEasySms() { return $this; } }
执行发送短信
$to = '181*****932'; // 使用 Notifiable Trait 发送 (new \app\common\notification\user\PhoneNumber($to)) ->notify(new \app\common\notification\ValidateCode('SMS_15****670')); // 使用 Notification Facade 发送 \yunwuxin\facade\Notification::send( new \app\common\notification\user\PhoneNumber($to), new \app\common\notification\ValidateCode('SMS_15****670'));
liuwave/think-notification-easysms-channel 适用场景与选型建议
liuwave/think-notification-easysms-channel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 liuwave/think-notification-easysms-channel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 liuwave/think-notification-easysms-channel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 31
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2019-12-07