batyukovstudio / laravel-notification-channels-pushsms-ru
Laravel 的 PushSMS 通知通道
dev-master
2024-07-05 08:58 UTC
Requires
- php: >=7.4
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^7.0.1
- illuminate/notifications: 5.1 - 5.8|^6.0|^7.0|^8.0|^9.0
- illuminate/queue: 5.1 - 5.8|^6.0|^7.0|^8.0|^9.0
- illuminate/support: 5.1 - 5.8|^6.0|^7.0|^8.0|^9.0
Requires (Dev)
- mockery/mockery: ^1.3.1
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2024-09-05 09:19:21 UTC
README
此包简化了使用 Laravel 通过 pushsms.ru 发送通知的过程。
内容
安装
使用 Composer 安装此包
composer require batyukovstudio/laravel-notification-channels-pushsms-ru
服务提供者会自动加载。或者您可以手动进行
// config/app.php 'providers' => [ ... NotificationChannels\PushSMS\PushSmsServiceProvider::class, ],
设置 PushSms 服务
将您的 PushSms 令牌添加到 .env
文件中
// .env ... PUSHSMS_TOKEN=qwerty123
用法
您需要将 Notification
扩展为 PushSmsNotification
类。
namespace App\Notifications; use NotificationChannels\PushSMS\Notifications\PushSmsNotification; class MyNotification extends PushSmsNotification { use Queueable; // ... }
PushSmsNotification
包含用于文本消息的 $content
变量和 toPushSms
方法。此方法将接收一个 $notifiable
实例并应返回一个 NotificationChannels\PushSMS\ApiActions\PushSmsMessage
实例
// PushSmsNotification } use Illuminate\Notifications\Notification; use NotificationChannels\PushSMS\ApiActions\PushSmsMessage; use NotificationChannels\PushSMS\Notifications\Interfaces\PushSmsable; abstract class PushSmsNotification extends Notification implements PushSmsable { protected string $content; public function toPushSms($notifiable): PushSmsMessage { return PushSmsMessage::create()->content($this->content); } }
您可以在通知的 via()
方法中使用此通道
namespace App\Notifications; use NotificationChannels\PushSMS\Notifications\PushSmsNotification; use NotificationChannels\PushSMS\PushSmsChannel; class MyNotification extends PushSmsNotification { public function via($notifiable) { return [PushSmsChannel::class]; } }
确保在可通知模型中包含一个 routeNotificationForPushsms()
方法,该方法返回一个电话号码或电话号码数组。
public function routeNotificationForPushsms() { return $this->phone; }
消息方法
content()
: 设置通知消息的内容。