Laravel 的 Authy 通知通道,能够发送应用内、短信和电话验证令牌。
Requires
- php: ^8.1.0
- illuminate/notifications: ^10.0.0 || ^11.0.0
- illuminate/queue: ^10.0.0 || ^11.0.0
- rinvex/laravel-authy: ^10.0.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.32.0
- mockery/mockery: ^1.4.0
- phpunit/phpunit: ^9.5.0
README
Authy 通知通道,用于 Laravel,能够发送应用内、短信和电话验证令牌。
目录
使用方法
-
通过 composer 安装包
composer require laravel-notification-channels/authy
-
此包需要
rinvex/laravel-authy
包,因此在进行下一步之前,请确保已遵循其 安装步骤。 -
接下来,为了将 Authy 通知路由到正确的实体,在你的可通知实体上定义一个
routeNotificationForAuthy
方法。这应该返回应发送通知的 Authy Id。示例/** * Route notifications for the authy channel. * * @return int */ public function routeNotificationForAuthy() { return $this->authy_id; }
注意:正如你所想的,这需要在你的可通知实体中有一个
authy_id
属性,你可能需要在其数据库表创建一个额外的字段。 -
现在你可以创建使用 Authy 通道的通知如下
// app/Notifications/PhoneVerificationNotification.php namespace App\Notifications; use Illuminate\Notifications\Notification; use NotificationChannels\Authy\AuthyChannel; use NotificationChannels\Authy\AuthyMessage; class PhoneVerificationNotification extends Notification { /** * The notification method (sms/call). * * @var string */ public $method; /** * Determine whether to force the notification over cellphone network. * * @var bool */ public $force; /** * The notification message action. * * @var string */ public $action; /** * The notification message action message. * * @var string */ public $actionMessage; /** * Create a notification instance. * * @param string $method * @param bool $force * @param string $action * @param string $actionMessage * * @return void */ public function __construct($method = 'sms', $force = false, $action = null, $actionMessage = null) { $this->method = $method; $this->force = $force; $this->action = $action; $this->actionMessage = $actionMessage; } /** * Get the notification's channels. * * @param mixed $notifiable * * @return array|string */ public function via($notifiable) { return [AuthyChannel::class]; } /** * Build the Authy representation of the notification. * * @return \NotificationChannels\Authy\AuthyMessage */ public function toAuthy() { $message = AuthyMessage::create()->method($this->method); if ($this->force) { $message->force(); } if ($this->action) { $message->action($action); } if ($this->actionMessage) { $message->actionMessage($actionMessage); } return $message; } }
-
最后你可以这样消费通知
$this->notify(new \App\Notifications\PhoneVerificationNotification('sms', true));
注意:不要忘记阅读 Authy TOTP API 文档以获取更多信息。
-
完成!
升级
-
从
v1.x
升级到v2.x
API 实现是 100% 向后兼容的,但沙盒 API 已被弃用。另外请注意,现在需要 PHP7。
变更日志
有关项目的完整历史记录,请参阅 变更日志。
支持
以下支持渠道尽在您的指尖
贡献 & 协议
感谢您考虑为此项目做出贡献!贡献指南可以在 CONTRIBUTING.md 中找到。
非常欢迎错误报告、功能请求和拉取请求。
安全漏洞
如果您在此项目中发现安全漏洞,请通过电子邮件发送到 security@rinvex.com。所有安全漏洞都将得到及时处理。
关于 Rinvex
Rinvex 是一家成立于2016年6月的开罗,埃及的软件解决方案初创公司,专注于为中小企业提供集成企业解决方案。我们相信,我们的动力是价值、影响力和范围,这是我们与众不同的地方,并通过软件的力量释放了我们哲学的无尽可能性。我们喜欢称之为“生活节奏的创新”。这就是我们为推进人类文明所做的一份贡献。
商标
- Authy™ 是 Twilio Inc. 的商标。
- Laravel™ 是 TAYLOR OTWELL 的商标。
许可协议
本软件遵循 MIT 许可协议 (MIT) 发布。
© 2016-2020 Rinvex LLC,部分版权所有。