aldemeery / bulksms-notification-channel
laravel 的批量短信通知通道。
v1.2.0
2020-09-10 07:22 UTC
Requires
- php: >=7.0
- illuminate/contracts: ^5.5|^6.0|^7.0|^8.0
- illuminate/notifications: ^5.5|^6.0|^7.0|^8.0
- illuminate/support: ^5.5|^6.0|^7.0|^8.0
This package is auto-updated.
Last update: 2024-09-10 16:02:02 UTC
README
BulkSMS 通知通道,适用于laravel。
安装
此包需要 php 7.0
或更高版本,并且与 Laravel 5.5
或更高版本兼容。
在项目根目录打开命令行并输入
composer require aldemeery/bulksms-notification-channel
服务提供程序将自动注册。或者,您可以在 config/app.php
文件中手动添加服务提供程序
'providers' => [ // ... Aldemeery\BulkSMS\BulkSMSChannelServiceProvider::class, ];
接下来,您需要在 config/services.php
配置文件中添加一些配置选项。您可以将以下示例配置复制到开始
'bulk_sms' => [ 'username' => env('BULK_SMS_USERNAME'), 'password' => env('BULK_SMS_PASSWORD'), 'sms_from' => env('BULK_SMS_FROM'), 'base_url' => env('BULK_SMS_BASEURL'), ],
sms_from
选项是您的短信将从该手机号码发送。
最后,在您的模型中添加 routeNotificationForBulkSms
方法,该方法将用于获取应发送短信的手机号码。
/** * Get the notification routing information for the Bulk SMS driver. * * @param \Illuminate\Notifications\Notification|null $notification Notification instance. * * @return mixed */ public function routeNotificationForBulkSms($notification = null) { return $this->phone_number; // or whatever field name that has the phone number. }
发送短信通知
如果通知支持作为短信发送,您应该在通知类上定义一个 toBulkSms
方法。此方法将接收一个 $notifiable
实体,并应返回一个 Aldemeery\BulkSMS\Messages\BulkSMSMessage
实例
/** * Get the BulkSMS representation of the notification. * * @param mixed $notifiable Notifiable instance. * * @return \Aldemeery\BulkSMS\Messages\BulkSMSMessage */ public function toBulkSms($notifiable) { return new BulkSMSMessage('Your verification code is 1234'); }
您还需要在 via
方法中将 bulkSms
通道添加到您的通知通道中
/** * Get the notification channels. * * @param mixed $notifiable * * @return array|string */ public function via($notifiable) { return ['bulkSms']; }
许可证
MIT 许可证(MIT)。请参阅 许可证文件 获取更多信息。