lotuashvili/laravel-smsoffice

此包最新版本(v1.4)没有可用的许可信息。

SMSOffice.ge 服务和 Laravel 通知通道

v1.4 2022-12-24 19:13 UTC

This package is auto-updated.

Last update: 2024-09-24 23:06:53 UTC


README

Latest Stable Version Total Downloads Downloads Month

此包允许您使用 SmsOffice.ge API 发送 SMS 消息

您可以使用通知类或直接使用 SmsOffice 类发送短信

Laravel SmsOffice

目录

安装

composer require lotuashvili/laravel-smsoffice

对于 Laravel <= 5.4

如果您使用 Laravel 5.4 或更低版本,您必须手动在您的 config/app.php 文件中添加服务提供者。打开 config/app.php 并将 SmsOfficeServiceProvider 添加到 providers 数组中。

'providers' => [
    # Other providers
    Lotuashvili\LaravelSmsOffice\SmsOfficeServiceProvider::class,
],

然后运行

php artisan vendor:publish --provider="Lotuashvili\LaravelSmsOffice\SmsOfficeServiceProvider"

将您的 API 密钥和发送者名称放入 config/smsoffice.php 文件中

开发模式配置

如果您想在开发中使用日志而不是发送真实的短信,则将 SMSOFFICE_DRIVER=log 添加到您的 .env 文件中

使用方法

使用通知类发送

User 类中,添加 routeNotificationForSms() 方法并返回用户的电话号码

class User extends Authenticatable
{
    # Code...

    public function routeNotificationForSms()
    {
        return $this->phone;
    }
}

创建通知

php artisan make:notification FooNotification

在我们的新创建的通知中,导入 SmsOfficeChannel 并将其添加到 via() 方法中。在 toSms() 方法中写入通知内容

use Illuminate\Notifications\Notification;
use Lotuashvili\LaravelSmsOffice\SmsOfficeChannel;

class FooNotification extends Notification
{
    public function via($notifiable)
    {
        return [SmsOfficeChannel::class];
    }
    
    public function toSms($notifiable)
    {
        return 'Test Notification';
    }
}

然后向用户发送通知

$user->notify(new FooNotification)

直接发送不使用通知

您必须注入或初始化 SmsOffice 类,然后调用 send 函数

use Lotuashvili\LaravelSmsOffice\SmsOffice;

public function sendSms(SmsOffice $smsoffice)
{
    $smsoffice->send('599123123', 'Test Message');
}

获取余额

use Lotuashvili\LaravelSmsOffice\SmsOffice;

public function getBalance(SmsOffice $smsoffice)
{
    $smsoffice->balance();
}