powertic / utalk-notification-channel
Utalk Laravel 通知通道
1.0.1
2021-01-22 18:49 UTC
Requires
- php: ^7.2.5 || ^8.0
- guzzlehttp/guzzle: ^6.2 || ^7.0
- illuminate/notifications: ^6.0 || ^7.0 || ^8.0
- illuminate/support: ^6.0 || ^7.0 || ^8.0
- propaganistas/laravel-phone: ^4.2
Requires (Dev)
- mockery/mockery: ^1.3
- orchestra/testbench: ^4.0 || ^5.0 || ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-25 21:27:37 UTC
README
此包简化了使用 Laravel 通知系统发送 Utalk 消息的过程。支持 5.5+,6.x,7.x 和 8.x。
内容
安装
您可以通过 composer 安装此包
composer require powertic/utalk-notification-channel
设置
在 app/services.php
文件中添加您的 Utalk 令牌。您可以从这里获取 API 令牌。
... 'utalk' => [ 'token' => env('UTALK_TOKEN'), ],
您需要在您的 .env
文件中创建一个 UTALK_TOKEN
。
使用方法
现在您可以在通知内部的 via()
方法中使用此通道
use Powertic\Utalk\UtalkChannel; use Powertic\Utalk\UtalkMessage; use Illuminate\Notifications\Notification; class TeamCreated extends Notification { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [UtalkChannel::class]; } /** * Get the UTalk representation of the notification. * * @param mixed $notifiable * @return \Powertic\Utalk\UtalkMessage */ public function toUtalk($notifiable) { return UtalkMessage::create() ->message("Hello World!"); } }
为了使通知知道应该接收消息的号码,请将 routeNotificationForUtalk
方法添加到您的 Notifiable 模型中。
此方法期望一个 有效的 E.164 移动号码,通知将通过该号码发送。
/** * Route notifications for the Utalk channel. * * @return string */ public function routeNotificationForUtalk() { return $this->mobile; }
可用方法
message('Hello World!')
:接受要发送的字符串作为消息。
变更日志
有关最近更改的更多信息,请参阅变更日志。
测试
$ composer test
安全
如果您发现任何与安全相关的问题,请通过电子邮件 luizeof@gmail.com 反馈,而不是使用问题跟踪器。
贡献
有关详细信息,请参阅贡献指南。
鸣谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅许可文件。