Smsapi 通知通道用于 Laravel

0.7.0 2023-05-05 00:58 UTC

This package is auto-updated.

Last update: 2024-09-05 03:49:47 UTC


README

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads PHP 7 ready

此包使您能够通过 Smsapi 在 Laravel 5.5+、6.x 和 7.x 中轻松发送通知

内容

安装

您可以通过 composer 安装此包

composer require laravel-notification-channels/smsapi

您也可以使用以下命令发布配置文件:

php artisan vendor:publish --provider="NotificationChannels\Smsapi\SmsapiServiceProvider"

配置 Smsapi 服务

登录到您的 Smsapi 控制面板并配置您首选的认证方法。存在一个 波兰语版本 和一个 国际版本,它们具有独立的账户。在 config/smsapi.php 中设置您的凭据和默认值

'auth' => [
    'method' => 'token',
    // 'method' => 'password',
    'credentials' => [
        'token' => env('SMSAPI_AUTH_TOKEN'),
        // 'username' => env('SMSAPI_AUTH_USERNAME'),
        // 'password' => env('SMSAPI_AUTH_PASSWORD'), // Hashed by MD5
    ],
    // Service of smsapi. Can be SmsapiClient::SERVICE_PL or SmsapiClient::SERVICE_COM.
    'service' => SmsapiClient::SERVICE_PL,
],
'defaults' => [
    'common' => [
        // 'notify_url' => env('SMSAPI_NOTIFY_URL'),
        // 'partner' => env('SMSAPI_PARTNER'),
        // 'test' => env('SMSAPI_TEST', true),
    ],
    'sms' => [
        // 'from' => env('SMSAPI_FROM'),
        // 'fast' => false,
        // 'flash' => false,
        // 'encoding' => 'utf-8',
        // 'normalize' => false,
        // 'nounicode' => false,
        // 'single' => false,
    ],
    'mms' => [
    ],
    'vms' => [
        // 'from' => env('SMSAPI_FROM'),
        // 'tries' => 2,
        // 'interval' => 300,
        // 'tts_lector' => 'Agnieszka',
        // 'skip_gsm' => false,
    ],
],

使用方法

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

use Illuminate\Notifications\Notification;
use NotificationChannels\Smsapi\SmsapiChannel;
use NotificationChannels\Smsapi\SmsapiSmsMessage;

class FlightFound extends Notification
{
    public function via($notifiable)
    {
        return [SmsapiChannel::class];
    }

    public function toSmsapi($notifiable)
    {
        return (new SmsapiSmsMessage())->content("Buy now your flight!");
    }
}
use Illuminate\Notifications\Notification;
use NotificationChannels\Smsapi\SmsapiChannel;
use NotificationChannels\Smsapi\SmsapiMmsMessage;

class AnimalTrespassed extends Notification
{
    public $photoId;

    public function via($notifiable)
    {
        return [SmsapiChannel::class];
    }

    public function toSmsapi($notifiable)
    {
        return (new SmsapiMmsMessage())->subject('Animal!')->smil($this->smil());
    }

    private function smil()
    {
        $url = route('photos', ['id' => $this->photoId]);
        $smil =
            "<smil>" .
                "<head>" .
                    "<layout>" .
                        "<root-layout height='100%' width='100%'/>" .
                        "<region id='Image' width='100%' height='100%' left='0' top='0'/>" .
                    "</layout>" .
                "</head>" .
                "<body><par><img src='{$url}' region='Image' /></par></body>" .
            "</smil>";
        return $smil;
    }
}

routeNotificationForSmsapi 方法添加到您的可通知模型中,以返回电话号码

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

或者添加一个 routeNotificationForSmsapiGroup 方法以返回联系人组

public function routeNotificationForSmsapiGroup()
{
    return $this->contacts_group;
}

可用的消息方法

SmsapiSmsMessage

  • to(string|string[] $to)
  • group(string $group)
  • content(string $content)
  • template(string $template)
  • from(string $from)
  • fast(bool $fast = true)
  • flash(bool $flash = true)
  • encoding(string $encoding)
  • normalize(bool $normalize = true)
  • nounicode(bool $nounicode = true)
  • single(bool $single = true)
  • date(int|string $date)
  • notifyUrl(string $notifyUrl)
  • partner(string $partner)
  • test(bool $test = true)

SmsapiMmsMessage

  • to(string|string[] $to)
  • group(string $group)
  • subject(string $subject)
  • smil(string $smil)
  • date(int|string $date)
  • notifyUrl(string $notifyUrl)
  • partner(string $partner)
  • test(bool $test = true)

SmsapiVmsMessage

  • to(string|string[] $to)
  • group(string $group)
  • file(string $file)
  • tts(string $tts)
  • ttsLector(string $ttsLector)
  • from(string $from)
  • tries(int $tries)
  • interval(int $interval)
  • skipGsm(bool $skipGsm = true)
  • date(int|string $date)
  • notifyUrl(string $notifyUrl)
  • partner(string $partner)
  • test(bool $test = true)

更新日志

有关最近更改的更多信息,请参阅 更新日志

测试

$ composer test

安全性

如果您发现任何与安全性相关的问题,请通过电子邮件 mat.drost@gmail.com 而不是使用问题跟踪器来报告

贡献

有关详细信息,请参阅 贡献

致谢

许可协议

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