chitranu/textlocal-laravel-notification-channel

Laravel 的 Textlocal SMS 通知渠道

1.0.0 2020-09-27 18:34 UTC

This package is auto-updated.

Last update: 2024-09-28 04:15:55 UTC


README

Latest Version on Packagist Software License StyleCI Total Downloads

此包使得使用 Laravel 框架通过 Textlocal 发送通知变得简单。

内容

安装

您可以通过 composer 安装此包。

composer require chitranu/textlocal-laravel-notification-channel

设置 Textlocal SMS 服务

将您的 Textlocal API 密钥和发送者添加到 config/services.php

<?php

return [

    // ...

    'textlocal' => [
        'key' => env('TEXTLOCAL_KEY'),
        'sender' => env('TEXTLOCAL_SENDER'),
    ],

];

用法

现在您可以在通知内的 via() 方法中使用此通道

<?php

use NotificationChannels\Textlocal\TextlocalChannel;
use NotificationChannels\Textlocal\TextlocalMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [TextlocalChannel::class];
    }

    public function toSms($notifiable)
    {
        // OR explicitly return a TextlocalMessage object passing the message body:
        return new TextlocalMessage("Your {$notifiable->service} account was approved!");
    }
}

为了让您的通知知道您发送到哪个手机,该通道将在可通知模型中查找 phonemobilephone_numberfull_phone 属性。如果您想覆盖此行为,请将 routeNotificationForTextlocal 方法添加到您的可通知模型中。

<?php

use Illuminate\Notifications\Notifiable;

class SomeModel {
    use Notifiable;

    public function routeNotificationForTextlocal($notification)
    {
        return '+1234567890';
    }
}

变更日志

请参阅 CHANGELOG 了解最近发生了哪些变化。

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件 hey@swapnil.dev 联系,而不是使用问题跟踪器。

贡献

有关详细信息,请参阅 CONTRIBUTING

鸣谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件