tarre/laravel-46elks

1.4.3 2024-04-06 08:17 UTC

This package is auto-updated.

Last update: 2024-09-06 09:12:35 UTC


README

关于 Laravel-46Elks

Laravel-46Elks 是一个 SMS 通知驱动程序,用于 Laravel Notifications,旨在简化 46elks API 与您的 Laravel 应用程序之间的交互。对于通用的 PHP 使用,请查看 php-46elks

安装

使用 composer 安装

composer require tarre/laravel-46elks

发布配置

php artisan vendor:publish --tag="laravel-46elks"

调整配置

将以下内容添加到您的 .env 文件中

e46ELKS_FROM=MyApp
e46ELKS_USERNAME=xxx
e46ELKS_PASSWORD=yyy
e46ELKS_DRY_RUN=false
e46ELKS_WHEN_DELIVERED=false

示例用法

用户模型

class User Extends Model
{
    use Notifiable;

    public function routeNotificationFor46elks()
    {
        return '+46701474417'; // could also be an array of strings ['number1', 'number2'] etc
    }
}

通知

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Tarre\Laravel46Elks\Messages\SmsMessage;

class TestNotification extends Notification
{
    use Queueable;

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['46elks'];
    }


    /**
     * Send the message via 46elks
     *
     * @param mixed $notifiable
     * @return SmsMessage
     */
    public function to46elks($notifiable)
    {
        return (new SmsMessage)
            ->line('Hello ' . $notifiable->name)
            ->line('') // will produce new line
            ->line('Wsup?');
    }
}

如果您已经使用了 toMail,请查看 在通知 toMail 方法上叠加

可用的 SmsMessage 方法

  • __construct(array $lines) 替代 ->line('')
  • ->line($line) 添加文本消息行
  • from($senderId) 覆盖 .env 文件
  • cc($e164Number) 添加更多 e164 收件人
  • whenDelivered($url) 覆盖 .env 文件
  • flash($state = true) 短信会立即在接收者的手机上显示,并且不会消失,直到接收者确认消息。这个功能非常适合必须由接收者阅读的消息。

更多