lookberry / laravel-smsglobal-notifications-channel
SmsGlobal通知通道,适用于Laravel 7, 8, 9
1.1.1
2024-07-12 13:10 UTC
Requires
- php: >=7.4
- guzzlehttp/guzzle: ^6.5 || ^7.2
- hellochef-me/php-styles: ^1.0
- illuminate/http: ^7.0 || ^8.0 || ^9.0 || ^10.0
- illuminate/notifications: ^7.0 || ^8.0 || ^9.0 || ^10.0
- illuminate/support: ^7.0 || ^8.0 || ^9.0 || ^10.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.5
README
使用此包在Laravel 10中通过SmsGlobal发送短信。
安装
composer require lookberry/laravel-smsglobal-notifications-channel
配置
在你的services.php配置文件中添加以下配置。
// ...
'sms_global' => [
'debug' => env('SMS_GLOBAL_DEBUG', true),
'api_key' => env('SMS_GLOBAL_API_KEY'),
'api_secret' => env('SMS_GLOBAL_API_SECRET'),
'origin' => 'YourCompanyName',
],
调试模式
默认情况下启用调试模式,这意味着不会实际发送短信,而是将日志记录添加到/storage/logs/laravel.log
在你的services.php中将sms_global.debug的值更改为false
用法
通知类
使用Laravel 通知类,将SmsGlobalChannel::class添加到via()方法中,如下所示
use Illuminate\Notifications\Notification; use SalamWaddah\SmsGlobal\SmsGlobalChannel; use SalamWaddah\SmsGlobal\SmsGlobalMessage; class OrderPaid extends Notification { public function via($notifiable): array { return [ SmsGlobalChannel::class, ]; } public function toSmsGlobal(): SmsGlobalMessage { $message = 'Order paid, Thank you for your business!'; $smsGlobal = new SmsGlobalMessage(); return $smsGlobal->content($message); } }
按需通知
你可以使用Laravel的按需通知外观直接发送短信到手机号码,而无需在你的应用程序中存储用户。
Notification::send( '+971555555555', new OrderPaid($order) );
通知类中toSmsGlobal的notifiable参数应期望与传递给Notification外观相同的数据类型。
public function toSmsGlobal(): SmsGlobalMessage { $message = 'Order paid, Thank you for your business!'; $smsGlobal = new SmsGlobalMessage(); return $smsGlobal->content($message); }