madbob/laravel-notification-mobyt

Laravel 通知与 Esendex/Mobyt/Skebby/SMSItalia 短信网关集成

0.2 2021-06-22 16:12 UTC

This package is auto-updated.

Last update: 2024-09-22 21:44:01 UTC


README

此包将 Esendex SMS 网关 服务(之前称为 Mobyt,包名由此而来)集成到本地 Laravel 通知 系统,以便能够通过简单的 $user->notify(new YourNotification()) 发送通知。

此库兼容使用相同 API 的其他短信服务,包括

安装

composer require madbob/laravel-notification-mobyt

配置

在你的 config/services.php 文件中,添加以下代码块

'mobyt' => [
    /*
        Identifier of one of the supported SMS services:
        esendex
        skebby
        mobyt // Mobyt no longer exists, this is kept for historical reasons and acts as the "esendex" driver
        smsitaly // SMSItalia no longer exists, this is kept for historical reasons and acts as the "esendex" driver
    */
    'driver' => 'esendex',

    /*
        Custom name to display as "sender"
    */
    'from' => 'YourName',

    /*
        Username for your account
    */
    'username' => env('MOBYT_USERNAME'),

    /*
        Password for your account
    */
    'password' => env('MOBYT_PASSWORD'),
],

使用方法

toMobyt() 函数添加到您想要通过短信发送的通知中,并将 MobytChannel 类添加到相关的通道中。

use MadBob\LaravelNotification\Mobyt\MobytChannel;
use MadBob\LaravelNotification\Mobyt\MobytMessage;
use Illuminate\Notifications\Notification;

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

    public function toMobyt($notifiable)
    {
        return (new MobytMessage())->content("Your message here!");
    }
}

为了让您的通知知道您正在发送到哪个电话号码,通道将查找 Notifiable 模型的 phone_number 属性。如果您想覆盖此行为,请将 routeNotificationForMobyt() 方法添加到您的 Notifiable 模型中。

public function routeNotificationForMobyt()
{
    return '+1234567890';
}

MobytMessage 对象还有其他选项,包括

  • type() 用于指定消息类型,您可以选择 MobytMessage::HI_QUALITYMobytMessage::MID_QUALITYMobytMessage::LOW_QUALITY
  • from() 用于动态更改发送者的自定义名称
  • addRecipient() 用于向消息中添加更多收件人号码。请始终记得添加国际前缀!

许可证

此代码是免费软件,许可协议为 GNU 通用公共许可证版本 3 (GPLv3)。有关详细信息,请参阅 LICENSE.md 文件。

版权 (C) 2017 Roberto Guido bob@linux.it