itpalert/web2sms-notification-channel

为Laravel提供Web2sms通知通道。

1.2.0 2024-08-28 16:20 UTC

This package is auto-updated.

Last update: 2024-09-11 17:36:16 UTC


README

此包使得使用Laravel 10.0和web2sms发送通知变得简单。

内容

安装

您可以通过composer安装此包

composer require itpalert/web2sms-notification-channel

设置web2sms服务

将以下环境变量添加到您的.env

// .env
...
WEB2SMS_KEY=8c78axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
WEB2SMS_SECRET=e9a689cfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
WEB2SMS_SMS_FROM=ALERT
WEB2SMS_ACCOUNT_TYPE=prepaid
...

将以下内容添加到config/services.php

    'web2sms' => [
        'key' => env('WEB2SMS_KEY'),
        'secret' => env('WEB2SMS_SECRET'),
        'sms_from' => env('WEB2SMS_SMS_FROM', ''),
        'account_type' => env('WEB2SMS_ACCOUNT_TYPE', 'prepaid'),
    ],

用法

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

use ITPalert\Web2smsChannel\Messages\Web2smsMessage;
use Illuminate\Notifications\Notification;

class ProjectCreated extends Notification
{
    public function via($notifiable)
    {
        return ['web2sms'];
    }

    public function toWeb2sms($notifiable)
    {
        return new Web2smsMessage('Content');
    }
}

为了让通知知道要使用哪个电话号码,将routeNotificationForWeb2sms方法添加到您的可通知模型中。

此方法需要返回一个电话号码。

public function routeNotificationForWeb2sms(Notification $notification)
{
    return $this->phone_number;
}

可用的消息方法

  • content(string $content):接受短信内容的字符串值。
  • from(string $from):接受发送者号码的字符串值。
  • unicode():设置消息类型。
  • clientReference(string $clientReference):设置客户端引用(最多40个字符)。
  • statusCallback(string $callback):设置用于更新消息状态的webhook回调URL。
  • schedule(string $schedule):设置消息应发送的日期。
  • displayedMessage(string $displayedMessage):设置在仪表板中显示的实际消息内容的文本。
  • usingClient(Client $client):设置web2sms客户端实例。

致谢