laravel-notification-channels / messagebird
Laravel 5.x 的 MessageBird 通知通道
v4.2.0
2024-04-13 16:56 UTC
Requires
- php: ^8.0|^8.1
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- illuminate/notifications: ^9.0|^10.0|^11.0
- illuminate/queue: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
Requires (Dev)
- mockery/mockery: ^1.4.4
- phpunit/phpunit: ^9.5.10|^10.0
README
此包使您能够通过 Laravel 发送 Messagebird SMS 通知。
内容
要求
- 免费注册 MessageBird 账户
- 在开发者部分创建一个新的 access_key
安装
您可以通过 composer 安装此包
composer require laravel-notification-channels/messagebird
对于 Laravel 5.4 或更低的版本,您必须将服务提供者添加到您的配置中
// config/app.php 'providers' => [ ... NotificationChannels\Messagebird\MessagebirdServiceProvider::class, ],
设置您的 Messagebird 账户
将环境变量添加到您的 config/services.php
// config/services.php ... 'messagebird' => [ 'access_key' => env('MESSAGEBIRD_ACCESS_KEY'), 'originator' => env('MESSAGEBIRD_ORIGINATOR'), 'recipients' => env('MESSAGEBIRD_RECIPIENTS'), ], ...
将您的 Messagebird Access Key、默认发送者(名称或号码)和默认收件人添加到您的 .env
// .env ... MESSAGEBIRD_ACCESS_KEY= MESSAGEBIRD_ORIGINATOR= MESSAGEBIRD_RECIPIENTS= ], ...
注意:发送者最多可包含 11 个字母数字字符。
使用
现在您可以在通知中的 via()
方法中使用此通道
use NotificationChannels\Messagebird\MessagebirdChannel; use NotificationChannels\Messagebird\MessagebirdMessage; use Illuminate\Notifications\Notification; class VpsServerOrdered extends Notification { public function via($notifiable) { return [MessagebirdChannel::class]; } public function toMessagebird($notifiable) { return (new MessagebirdMessage("Your {$notifiable->service} was ordered!")); } }
此外,您还可以添加收件人(单个值或数组)
return (new MessagebirdMessage("Your {$notifiable->service} was ordered!"))->setRecipients($recipients);
为了处理状态报告,您还可以设置一个参考
return (new MessagebirdMessage("Your {$notifiable->service} was ordered!"))->setReference($id);
变更日志
请参阅 变更日志 了解最近有哪些更改。
测试
$ composer test
安全
如果您发现任何安全相关的问题,请通过电子邮件 psteenbergen@gmail.com 反馈,而不是使用问题跟踪器。
贡献
请参阅 贡献指南 了解详细信息。
致谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。