Laravel 的 Authy 通知通道,能够发送应用内、短信和电话验证令牌。

v10.1.0 2023-05-02 01:02 UTC

README

Authy 通知通道,用于 Laravel,能够发送应用内、短信和电话验证令牌。

Packagist Scrutinizer Code Quality StyleCI Travis License

Authy Notifications

目录

使用方法

  1. 通过 composer 安装包

    composer require laravel-notification-channels/authy
  2. 此包需要 rinvex/laravel-authy 包,因此在进行下一步之前,请确保已遵循其 安装步骤

  3. 接下来,为了将 Authy 通知路由到正确的实体,在你的可通知实体上定义一个 routeNotificationForAuthy 方法。这应该返回应发送通知的 Authy Id。示例

    /**
     * Route notifications for the authy channel.
     *
     * @return int
     */
    public function routeNotificationForAuthy()
    {
        return $this->authy_id;
    }

    注意:正如你所想的,这需要在你的可通知实体中有一个 authy_id 属性,你可能需要在其数据库表创建一个额外的字段。

  4. 现在你可以创建使用 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;
        }
    }
  5. 最后你可以这样消费通知

    $this->notify(new \App\Notifications\PhoneVerificationNotification('sms', true));

    注意:不要忘记阅读 Authy TOTP API 文档以获取更多信息。

  6. 完成!

升级

  • v1.x 升级到 v2.x

    API 实现是 100% 向后兼容的,但沙盒 API 已被弃用。另外请注意,现在需要 PHP7。

变更日志

有关项目的完整历史记录,请参阅 变更日志

支持

以下支持渠道尽在您的指尖

贡献 & 协议

感谢您考虑为此项目做出贡献!贡献指南可以在 CONTRIBUTING.md 中找到。

非常欢迎错误报告、功能请求和拉取请求。

安全漏洞

如果您在此项目中发现安全漏洞,请通过电子邮件发送到 security@rinvex.com。所有安全漏洞都将得到及时处理。

关于 Rinvex

Rinvex 是一家成立于2016年6月的开罗,埃及的软件解决方案初创公司,专注于为中小企业提供集成企业解决方案。我们相信,我们的动力是价值、影响力和范围,这是我们与众不同的地方,并通过软件的力量释放了我们哲学的无尽可能性。我们喜欢称之为“生活节奏的创新”。这就是我们为推进人类文明所做的一份贡献。

商标

许可协议

本软件遵循 MIT 许可协议 (MIT) 发布。

© 2016-2020 Rinvex LLC,部分版权所有。