tomatophp / messagebird-notifications
Laravel 5.x 的 MessageBird 通知通道
v1.0.0
2024-03-12 18:58 UTC
Requires
- php: ^8.0|^8.1
- ext-json: *
- guzzlehttp/guzzle: ^7.8
- 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|^11.0
This package is auto-updated.
Last update: 2024-09-12 20:09:21 UTC
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 而不是使用问题跟踪器来报告。
贡献
有关详细信息,请参阅 CONTRIBUTING
致谢
许可协议
MIT 许可证(MIT)。有关更多信息,请参阅 许可文件