sideso / hablame
Hablame 通知渠道,适用于 Laravel 6、7、8、9 和 10
Requires
- php: ^8.1
- ext-json: *
- guzzlehttp/guzzle: ^6.4 || ^7.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
- sideso/sms-message: ^1.1.2
Requires (Dev)
- mockery/mockery: ^1.3
- orchestra/testbench: ^4.0 || ^5.0 || ^6.0 || ^7.0
- phpunit/phpunit: ^8.0 || ^9.0 || ^10.0
README
该包使得使用 Hablame 在 Laravel 6.x、7.x、8.x 和 9.x 中发送通知变得简单。
内容
安装
您可以通过 composer 安装此包。
composer require sideso/hablame
设置 hablame 服务
您可以发布配置文件,并将您的 hablame 令牌、API 密钥和账户号添加到 config/hablame.php 中。
php artisan vendor:publish --provider="Sideso\Hablame\HablameServiceProvider" --tag="config"
// config/hablame.php ... 'hablame' => [ 'account' => env('HABLAME_ACCOUNT',''), 'api_key' => env('HABLAME_API_KEY',''), 'token' => env('HABLAME_TOKEN'.''), 'source_code' => env('HABLAME_SOURCE_CODE',''), ], ...
使用
您可以在通知内部的 via() 方法中使用该通道。
use Illuminate\Notifications\Notification; use NotificationChannels\hablame\HablameMessage; class AccountApproved extends Notification { public function via($notifiable) { return ["hablame"]; } public function tohablame($notifiable) { return (new HablameMessage)->content("Your account was approved!"); } }
在您的可通知模型中,请确保包含 routeNotificationForhablame() 或 routeNotificationForSMS() 方法,该方法返回一个电话号码。
public function routeNotificationForhablame() { return $this->phone; }
按需通知
有时您可能需要向未作为您的应用程序“用户”存储的人发送通知。使用 Notification::route 方法,在发送通知之前可以指定临时通知路由信息。
Notification::route('hablame', '573001234567') ->notify(new InvoicePaid($invoice));
批量消息
如果您预计要发送批量消息,您可以使用以下方法向多个收件人发送消息。
use Sideso\Hablame\HablameChannel; use Sideso\Hablame\Hablame; $bulk = [ [ 'numero' => '3000000001', 'sms' => 'Hello World!', ], [ 'numero' => '3000000002', 'sms' => 'Hello World! (again)', ], ; $sms = new HablameChannel(app(Hablame::class)); $sms->bulkSend($bulk);
可用消息方法
content()
:设置通知消息的内容。此参数不应超过 918 个字符(6 个消息部分)。
sourceCode()
:设置要作为源使用的源代码名称。
requestProofOfDelivery()
:设置要作为源使用的请求投递证明(额外费用)。
priority()
:设置消息的优先级。(True = 事务性,False = 营销)。
flash()
:设置消息是否应该闪光。(True = 闪光,False = 正常)。
senDate()
:设置消息应该发送的日期和时间。(如果设置了优先级为 true,则不使用)。
withCallback()
:设置在消息发送时执行的回调函数。
callBackFunction($notifiable, \Illuminate\Notifications\Notification $notification, \Sideso\SMS\Message $message){ //Do something } $message->withCallback('callBackFunction');
tags()
:设置用于发送消息的标签。
可用事件
Sideso\SMS\SMSSent
:当消息发送时触发此事件。
更新日志
请参阅 CHANGELOG 了解最近更改的更多信息。
测试
$ composer test
安全
如果您发现任何与安全相关的问题,请通过电子邮件 ctrujillo@sideso.com.co 而不是使用问题跟踪器。
致谢
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。