webregul / laravel-sms-ru-channel
Laravel sms.ru 频道
v2.0.0
2023-05-03 12:24 UTC
Requires
- php: ^8.0
- illuminate/notifications: ^8.0|^9.0|^10.0
- illuminate/support: ^8.0|^9.0|^10.0
- webregul/sms-ru-client: ^2.0
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-09-03 15:18:18 UTC
README
内容
安装
使用 Composer 安装包
composer require webregul/laravel-sms-ru-channel
使用
配置
注册提供者
// config/app.php 'providers' => [ ... Kafkiansky\SmsRuChannel\SmsRuProvider::class, ],
在 config/services.php
中添加配置
// config/services.php 'sms_ru' => [ 'api_id' => env('SMS_RU_API_ID'), 'login' => env('SMS_RU_LOGIN', null), 'password' => env('SMS_RU_PASSWORD', null), 'partner_id' => env('SMS_RU_PARTNER', null), 'test' => env('SMS_RU_TEST', 1), 'json' => env('SMS_RU_JSON', 1), 'from' => env('SMS_RU_FROM', null), ],
在官方 站点 上了解更多关于配置的信息。
如何
第一种方式
创建通知消息
use Illuminate\Notifications\Notification; use Kafkiansky\SmsRu\Message\SmsRuMessage; use Kafkiansky\SmsRu\Message\To; use Kafkiansky\SmsRuChannel\SmsRuChannel; final class RegistrationComplete extends Notification { public function via($notifiable) { return [SmsRuChannel::class]; } public function toSmsRu($notifiable) { return new SmsRuMessage(new To($notifiable->phone, 'Congratulations, you have become part of our application')); } }
第二种方式
或在可通知实例中创建 routeNotificationForSmsRu
方法
use Illuminate\Notifications\Notifiable; /** * @property string $phone */ class User { use Notifiable; public function routeNotificationForSmsRu() { return $this->phone; // can be array of phone numbers } }
在这种情况下,通知消息应如下所示
use Illuminate\Notifications\Notification; use Kafkiansky\SmsRuChannel\SmsRuChannel; final class RegistrationComplete extends Notification { public function via($notifiable) { return [SmsRuChannel::class]; } public function toSmsRu($notifiable) { return 'Congratulations, you have become part of our application'; } }
测试
$ composer test
许可证
MIT 许可证(MIT)。更多信息请参阅 许可证文件。