avto-dev / smspilot-notifications-laravel
SMS Pilot服务的通知通道
v2.6.0
2024-05-31 11:42 UTC
Requires
- php: ^8.1
- ext-json: *
- guzzlehttp/guzzle: ~7.0
- illuminate/contracts: ~10.0 || ~11.0
- illuminate/notifications: ~10.0 || ~11.0
- illuminate/support: ~10.0 || ~11.0
Requires (Dev)
- laravel/laravel: ~10.0 || ~11.0
- mockery/mockery: ^1.6.5
- phpstan/phpstan: ^1.10.66
- phpunit/phpunit: ^10.5
README
这里是关于Laravel通知系统的最新文档:https://laravel.net.cn/docs/master/notifications
SMS Pilot通知通道 | 适用于laravel
此包使您能够通过Laravel 5轻松使用SMS Pilot发送通知。
安装
使用以下命令通过composer安装此包:
$ composer require avto-dev/smspilot-notifications-laravel "^2.0"
需要安装
composer
(如何安装composer)。
您需要修复包的主版本。
Laravel 5.5及以上版本使用包自动发现,因此不需要手动注册服务提供者。否则,您必须在./config/app.php
中的providers
数组中添加服务提供者。
'providers' => [ // ... AvtoDev\SmsPilotNotifications\SmsPilotServiceProvider::class, ],
如果您想禁用包服务提供者自动发现,只需在您的composer.json
中添加以下行:
{ "extra": { "laravel": { "dont-discover": [ "avto-dev/smspilot-notifications-laravel" ] } } }
SMS Pilot服务的设置
您需要在配置文件./config/services.php
中设置SMS Pilot通道
<?php return [ // ... 'sms-pilot' => [ 'key' => env('SMS_PILOT_API_KEY'), 'sender_name' => env('SMS_PILOT_SENDER_NAME'), ], ];
并在./.env
文件中添加以下行
SMS_PILOT_API_KEY=%your_api_key% SMS_PILOT_SENDER_NAME=%your_sender_name%
其中SMS_PILOT_API_KEY
是SMS Pilot授权密钥(令牌)(您可以在此页面上尝试获取),SMS_PILOT_SENDER_NAME
是发送者名称,该名称在服务仪表板中设置 (默认将用作发送者名称)。
使用方法
现在您可以在通知中的via()
方法中使用该通道,以及发送推送通知
<?php use AvtoDev\SmsPilotNotifications\SmsPilotChannel; use AvtoDev\SmsPilotNotifications\Messages\SmsPilotMessage; class Notification extends \Illuminate\Notifications\Notification { /** * Get the notification channels. * * @param mixed $notifiable * * @return array|string */ public function via($notifiable) { return [SmsPilotChannel::class]; } /** * Get the SMS Pilot Message representation of the notification. * * @param mixed $notifiable * * @return SmsPilotMessage */ public function toSmsPilot($notifiable): SmsPilotMessage { return (new SmsPilotMessage) ->content('Some SMS notification message'); } }
<?php class Notifiable { use \Illuminate\Notifications\Notifiable; /** * Get route for 'SMS Pilot' notification. * * @param mixed $notifiable * * @return string */ public function routeNotificationForSmsPilot($notifiable): string { return '71112223344'; } }
测试
对于包测试,我们使用phpunit
框架和docker-ce
+ docker-compose
作为开发环境。因此,在克隆存储库后,只需在终端中写入
$ make build $ make latest # or 'make lowest' $ make test
变更日志
变更日志可以在这里找到。
支持
如果您发现任何包错误,请在当前存储库中创建一个问题。
许可证
这是一个开源软件,许可协议为MIT许可证。