grigio / notifications
通知处理程序
v2.1.0
2020-03-09 08:59 UTC
Requires
- php: >=5.5
- ext-json: *
- guzzlehttp/guzzle: ^6.5.2
- league/pipeline: ^1.0.0
README
PHP 通知处理程序
支持的通知渠道
- Sms.ir
- Laravel 邮件
安装
-
composer require grigio/notifications
-
php artisan vendor:publish
并选择配置 -
将以下环境变量添加到 .env 文件中
SMSIR_SECRET_KEY= SMSIR_API_KEY= SMSIR_NUMBER=
-
电子邮件渠道使用
MAIL_USERNAME
作为发件人地址,使用APP_NAME
作为发送电子邮件的名称 -
创建如下通知类
class YourNotification extends GrigioNotification { public function viaSmsIR() { $data = $this->data(); $this->setReceiver( //Get mobile from $data ); $this->setMessage( //Put your message here ); return $this->sendPrepration(); } public function viaEmail() { $data = $this->data(); $this->setSubject( // Email title ); $this->setReceiver( //Reciver email address ); $this->setMessage(view('Your Email Template', ['data' => $data])); return $this->sendPrepration(); } }
-
在您的模型中使用
Notifible
特性 -
现在在您想要发送通知的方法中
$order->notify(new YourNotification($order));
渠道开发
- 创建如下类
class SmsIRChannel extends GerigioChannel implements ChannelContract
{
/**
* Name of the method for this channel in notification class
*/
public $channel = 'fill with notification class method name';
/**
* Channel Send Method
* Do process of sending message
*/
public function send()
{
// You access seted datas in notification class as an array
$message = $this->getMessage();
// Do the process of sending notification
}
}
- 在 config/grigionotification.php 中注册它
- 将通道方法添加到您的通知类中。现在您有一个新的通道了 :)