meshgroup / megafon-notification-channel
v1.0.8
2022-07-28 13:41 UTC
Requires
- php: >=5.6.4
- ext-mbstring: *
- guzzlehttp/guzzle: ^7.4.5
- illuminate/notifications: 5.1 - 8.9
- illuminate/queue: 5.1 - 8.9
- illuminate/support: 5.1 - 8.9
README
此包使得使用 Laravel 5.3+ 通过 megafon 发送通知变得简单。
内容
安装
您可以通过 composer 安装此包
composer require meshgroup/megafon-notification-channel
然后您必须安装服务提供者
// config/app.php 'providers' => [ ... Meshgroup\Megafon\MegafonServiceProvider::class, ],
设置 Megafon 服务
将您的 Megafon 登录名、密码和默认发送者名称(或电话号码)添加到您的 config/services.php
// config/services.php ... 'megafon' => [ 'login' => env('MEGAFON_LOGIN'), 'password' => env('MEGAFON_PASSWORD'), 'sender' => 'John_Doe' ], ...
如果您想使用除
https://a2p-api.megalabs.ru/
之外的其他主机,您必须设置带有尾斜杠的自定义主机。
// .env
...
MEGAFON_HOST=https://a2p-api.megalabs.ru/
...
// config/services.php ... 'megafon' => [ ... 'host' => env('MEGAFON_HOST'), ... ], ...
用法
您可以在通知中的 via()
方法中使用此通道
use Illuminate\Notifications\Notification; use Meshgroup\Megafon\MegafonMessage; use Meshgroup\Megafon\MegafonChannel; class AccountApproved extends Notification { public function via($notifiable) { return [MegafonChannel::class]; } public function toMegafon($notifiable) { return MegafonMessage::create("Task #{$notifiable->id} is complete!"); } }
在您的可通知模型中,请确保包含一个 routeNotificationForMegafon()
方法,该方法返回一个电话号码或电话号码数组。
public function routeNotificationForMegafon() { return $this->phone; }
可用方法
from()
:设置发送者的名称或电话号码。
content()
:设置通知消息的内容。
sendAt()
:设置安排通知消息的时间。
变更日志
请参阅CHANGELOG以获取更多最近更改的信息。
测试
$ composer test