kduma/sms

适用于Laravel 5的带有通知通道的短信发送器

v1.0.1 2018-02-10 21:53 UTC

This package is auto-updated.

Last update: 2024-08-29 18:33:26 UTC


README

Latest Version on Packagist Software License Total Downloads

适用于Laravel 5的带有通知通道的短信发送器

安装

通过Composer

$ composer require kduma/sms

在Laravel 5.6中,服务提供器会自动发现。如果你不使用包发现,请将服务提供器添加到config/app.php中的提供者数组中

KDuma\SMS\SMSServiceProvider::class,

并以下列方式添加到门面数组中

'SMS' => KDuma\SMS\Facades\SMS::class,

使用以下命令发布sms.php配置文件

php artisan vendor:publish --provider="KDuma\SMS\SMSServiceProvider"

现在你可以安装和配置短信通道和驱动程序。配置选项可以在驱动程序的readme中找到。

可用驱动程序

用法

SMS::send('phone number', 'Message.');
SMS::balance();
SMS::driver('serwersms')->send('phone number', 'Message.');

Laravel 5.3通知通道用法

按照Laravel文档添加你的通知类通道,例如

use Illuminate\Notifications\Notification;
use KDuma\SMS\NotificationChannel\SMSChannel;
use KDuma\SMS\NotificationChannel\SMSMessage;

class NotificationSMSChannelTestNotification extends Notification
{
    public function via($notifiable)
    {
        return [SMSChannel::class];
    }
    
    public function toSMS($notifiable)
    {
        return SMSMessage::create('This is a test SMS sent via Simple SMS using Laravel Notifications!');
    }
}

你还需要在你的可通知模型中添加一个routeNotificationForSMS方法来返回手机号码,例如

public function routeNotificationForSMS()
{
    return $this->phone_number;
}

SMSMessage可用方法

  • content() - 短信内容
  • channel() - 设置配置的短信通道

致谢

许可证

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