gateway/sms

此软件包最新版本(1.8)没有可用的许可证信息。

短信网关

1.8 2021-01-19 16:48 UTC

This package is auto-updated.

Last update: 2024-09-20 00:36:00 UTC


README

Latest Version on Packagist Total Downloads

这是一个用于短信网关集成的Laravel软件包。现在发送短信变得简单。

支持网关列表

  • 日志:用于测试
  • Farazsms
  • 其他正在路上。

软件包:安装

通过Composer

$ composer require gateway/sms

在配置文件中,您可以设置用于所有短信的默认驱动程序。但您也可以在运行时更改驱动程序。

选择您想为应用程序使用的网关。然后将其设置为默认驱动程序,这样您就不必在每处都指定它。但,您也可以在一个项目中使用多个网关。

'default' => 'log',

然后在该网关的驱动程序数组中填写凭证。

// Eg. for farazsms.
'drivers' => [
    'farazsms' => [
        'url'     => env('FARAZSMS_URL', 'http://rest.ippanel.com'),
        'from'    => env('FARAZSMS_FROM'),
        'api_key' => env('FARAZSMS_API_KEY'),
    ],
    ...
]

日志配置

日志默认添加。您只需更改textlocal驱动程序部分的凭证即可。

Kavenegar配置

如果您想使用Kavenegar,则必须首先拉取composer库。

composer require kavenegar/php

用法

在您的代码中,只需像这样使用即可。

# On the top of the file.
use Gateway\Sms\Facades\Sms;

...

# In your Controller.
Sms::content("this message")->to(['Number 1', 'Number 2'])->send();

😍 通道使用

首先,您必须使用php artisan make:notification命令创建通知,然后sms可以像下面这样用作通道

namespace App\Notifications;

use Gateway\Sms\Channels\SmsMessage;use Illuminate\Bus\Queueable;
use Gateway\Sms\Channels\SmsChannel;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;

class VerificationNotification extends Notification
{
    use Queueable;

    /**
     * Get the notification channels.
     *
     * @param  mixed  $notifiable
     * @return array|string
     */
    public function via($notifiable)
    {
        return ['sms'];
    }

    /**
     * Get the repicients and body of the notification.
     *
     * @param  mixed  $notifiable
     * @return Builder
     */
    public function toSms($notifiable)
    {
        # for send message.
        return (new SmsMessage())
            ->via('gateway') # via() is Optional
            ->content('this message')
            ->to('some number')
            ->send();
        # for send by pattern.
        return (new SmsMessage())
            ->via('gateway') # via() is Optional
            ->patternCode('mfgfdm')
            ->patternData(['code' => '45215'])
            ->to('some number')
            ->send();
    }
}