carropublic / notifications
通知渠道和发送者的集合
1.0.15
2024-09-09 12:47 UTC
Requires
- illuminate/collections: ~5.5|~6|~7|~8|~9|~10
- illuminate/events: ~5|~6|~7|~8|~9|~10
- illuminate/notifications: ~5.5|~6|~7|~8|~9|~10
- illuminate/support: ~5|~6|~7|~8|~9|~10
- linecorp/line-bot-sdk: ^4.3|^7.3
- twilio/sdk: ^6|^7
This package is auto-updated.
Last update: 2024-09-16 09:03:57 UTC
README
安装
通过 Composer
$ composer require carropublic/notifications
运行以下命令发布 Twillo 配置。
php artisan vendor:publish --provider="CarroPublic\Notifications\NotificationServiceProvider"
使用方法
LaravelNotification
以下是用 Laravel 的通知示例使用该软件包的示例。
创建通知类
class ExampleNotification extends Notification
{
// Which channel this notification should be sent to
public function via($notifiable)
{
return [ SMSChannel::class, WhatsAppChannel::class ];
}
// Notification payload (content) will be sent
public function toSMS($notifiable)
{
return new LaravelTwilioMessage("Message Content");
}
// Notification payload (content) will be sent
public function toWhatsApp($notifiable)
{
return new LaravelTwilioMessage("Message Content");
}
}
创建可通知类
class Contact extends Model {
use Notifiable;
// Phone number to receive
public function routeNotificationForSms()
{
return $this->phone;
}
// Phone number to receive
public function routeNotificationForWhatsapp()
{
return $this->phone;
}
}
从可通知实例发送通知
$contact->notify(new ExampleNotification());
从匿名可通知实例发送通知
Notification::route('sms')->notify(new ExampleNotification());
沙盒模式
如何启用沙盒模式
- 注册闭包以返回测试是否启用
\CarroPublic\Notifications\Senders\Sender::registerSandboxValidator
示例
Sender::registerSandboxValidator(function () {
return !is_production();
});
- 否则,使用
NOTIFICATION_SANDBOX_ENABLE
确定是否在沙盒模式下运行。默认false
⛔️ 注意:如果已注册闭包,则将忽略环境变量
如何绕过沙盒验证器
- 注册闭包以返回沙盒是否启用
\CarroPublic\Notifications\Senders\Sender::registerValidForSandbox
$to: 消息将发送到的收件人 $type: 发送者类
- LineSender
- TelerivetSender
- TwilioSender
- MailChannel(由于没有 MailSender,因此将使用 MailChannel)
LaravelTwilioSender::registerValidPhoneForSandbox(function ($to, $type) {
switch ($type) {
case LineSender::class:
return true;
case TwilioSender::class:
return false;
}
}
变更日志
有关最近更改的更多信息,请参阅变更日志。
安全性
如果您发现任何与安全相关的问题,请通过作者电子邮件而不是使用问题跟踪器来报告。
鸣谢
许可证
有关更多信息,请参阅许可证文件。