oscar-team / spryngsms
Spryng SMS 通知通道 for Laravel
1.0.3
2023-06-21 11:20 UTC
Requires
- php: >=8.0
- illuminate/notifications: ~6.0 || ~7.0 || ~8.0 || ~9.0 || ~10.0
- illuminate/support: ~6.0 || ~7.0 || ~8.0 || ~9.0 || ~10.0
- spryng/rest-api-php: ^1.1
Requires (Dev)
- orchestra/testbench: ^8.0
README
本仓库提供了通过 Spryng SMS 发送短信的 Laravel 通知通道。
安装
composer require oscar-team/spryngsms
您还可以使用以下命令发布配置文件:
php artisan vendor:publish --tag=spryngsms-config
spryngsms.php
您可以在这里找到更多配置选项信息
return [ /* |---------------------------------------------------------------------- | Authentication token |---------------------------------------------------------------------- | | Here we need to define the token for api authentication | */ 'token' => env('SPRYNG_SMS_API_TOKEN'), /* |---------------------------------------------------------------------- | From / Originator |---------------------------------------------------------------------- | | The sender of the message. Can be alphanumeric string (max. 11 characters) | or phonenumber (max. 14 digits in E.164 format like 31612345678) | */ 'originator' => env('SPRYNG_SMS_FROM_NAME', 'Oscar'), /* |---------------------------------------------------------------------- | Route |---------------------------------------------------------------------- | | Your given route to send the message on. Can be a valid route | ID supplied by Spryng or the default business route. | */ 'route' => env('SPRYNG_SMS_ROUTE', 'business'), /* |---------------------------------------------------------------------- | Route |---------------------------------------------------------------------- | | Character encoding of the body. Value can be: plain, unicode or auto | */ 'encoding' => env('SPRYNG_SMS_ENCODING', 'auto'), /* |---------------------------------------------------------------------- | Reference |---------------------------------------------------------------------- | | A client reference. | */ 'reference' => env('SPRYNG_SMS_REFERENCE') ];
使用方法?
您可以在通知中的 via()
方法中使用此通道
use Oscar\Spryngsms\SpryngsmsChannel; use Oscar\Spryngsms\SpryngsmsMessage; class BookingNotification extends Notification { public function via(object $notifiable): array { return [ SpryngsmsMessage::class ]; } public function toSpryngsms(mixed $notifiable): SpryngsmsMessage|string { return new SpryngsmsMessage($message, $recipients, $originator, $encoding, $route, $reference); } }
在您的 Notifiable 模型中添加一个 routeNotificationForSpryngsms
方法以返回电话号码
public function routeNotificationForSpryngsms(): string { return $this->phone_number; }
SpryngsmsMessage::class
参数
$message
(必需)$recipients
(可选)$originator
(可选)$encoding
(可选)$reference
(可选)
测试
phpunit 测试
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件。