xeFi / sms-factor-notification-channel
为laravel提供的短信因子通知通道。
v1.0.0
2024-03-20 15:40 UTC
Requires
- php: ^8.0
- illuminate/notifications: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
- smsfactor/smsfactor-php-sdk: ^1.0.5
Requires (Dev)
- guzzlehttp/guzzle: ^7.2
- mockery/mockery: ^1.0
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.0|^10.4
README
先决条件
在您可以通过SMSFactor发送通知之前,您需要安装xefi/sms-factor-notification-channel
composer require xefi/sms-factor-notification-channel
该软件包包括一个配置文件。然而,您不需要将此配置文件导出到您的应用程序中。您可以直接使用SMS_FACTOR_TOKEN
环境变量来定义您的SMSFactor令牌。
SMS_FACTOR_TOKEN=your-token
通知通道
为了配置通过SMSFactor通道发送通知,您需要在通知的via
方法中指定此设置
/** * Get the notification's delivery channels. * * @return array<int, string> */ public function via(object $notifiable): array { return ['sms-factor']; }
SMS通知格式化
如果通知支持以短信的形式发送,您应该在通知类上定义一个toSmsFactor
方法。此方法将接收一个$notifiable实体,并应该返回一个Xefi\SmsFactor\Messages\SmsFactorMessage
实例
use Xefi\SmsFactor\Messages\SmsFactorMessage; /** * Get the SMSFactor representation of the notification. */ public function toSmsFactor(object $notifiable): SmsFactorMessage { return (new SmsFactorMessage) ->text('Your SMS message content'); }
自定义“收件人”号码
如果您想根据您调用的可通知对象自定义号码,您需要在可通知模型上实现routeNotificationForSmsFactor
方法
use Illuminate\Notifications\Notification; /** * Get the corresponding phone number for the current model. */ public function routeNotificationForSmsFactor(Notification $notification) { return $this->phone; }
自定义“发件人”号码
如果您想从与您的SMS_FACTOR_SMS_FROM
环境变量指定的号码不同的号码发送一些通知,您可以在一个SmsFactorMessage
实例上调用sender
方法
use Xefi\SmsFactor\Messages\SmsFactorMessage; /** * Get the SMSFactor representation of the notification. */ public function toSmsFactor(object $notifiable): SmsFactorMessage { return (new SmsFactorMessage) ->content('Your SMS message content') ->sender('15554443333'); }
支持我们
自1997年以来,xeFi通过其在法国、比利时、瑞士和西班牙的近200家本地机构,已成为中小企业IT性能支持的领导者。IT、办公自动化、软件、数字化转型、打印和云需求的一站式商店。想与我们合作吗?