nerdify/laravel-smsgateway-notification-channel

此包已被废弃,不再维护。未建议替代包。

此包使您能够使用 Laravel 通过短信网关轻松发送通知。

v1.1.0 2018-06-02 00:25 UTC

This package is not auto-updated.

Last update: 2022-11-26 17:32:55 UTC


README

Latest Version on Packagist Software License StyleCI

此包使您能够使用 短信网关 与 Laravel 一起轻松发送通知。

内容

需求

注册 网上短信网关账户。

安装

您可以通过 composer 安装此包

composer require nerdify/laravel-smsgateway-notification-channel

您必须安装服务提供者

// config/app.php
'providers' => [
    ...
    Nerdify\SmsGateway\SmsGatewayServiceProvider::class,
],

设置您的短信网关账户

将您的短信网关电子邮件、密码和设备 ID 添加到您的 config/services.php

// config/services.php
...
'smsgateway' => [
    'email' => env('SMSGATEWAY_EMAIL'),
    'password' => env('SMSGATEWAY_PASSWORD'),
    'device' => env('SMSGATEWAY_DEVICE'),
],
...

使用

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

use Illuminate\Notifications\Notification;
use Nerdify\SmsGateway\SmsGatewayChannel;
use Nerdify\SmsGateway\SmsGatewayMessage;

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

    public function toSmsGateway($notifiable)
    {
        return (new SmsGatewayMessage)
            ->content('Your invoice has been paid!');
    }
}

在发送通知时,通知系统将自动在可通知实体上查找 phone_number 属性。如果您想自定义通知发送到的电话号码,在实体上定义一个 routeNotificationForSmsGateway 方法

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

可用的消息方法

SmsGatewayMessage

  • content():要发送的消息内容。
  • expiresAt():以 Unix 时间格式尝试发送消息的放弃时间。
  • sendAt():以 Unix 时间格式发送消息的时间。

许可证

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