1. Go to this page and download the library: Download yzh52521/think-notification library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yzh52521 / think-notification example snippets
php think make:notification InvoicePaid
namespace app\model;
use yzh52521\notification\Notifiable;
class User
{
use Notifiable;
}
use app\notification\InvoicePaid;
$user->notify(new InvoicePaid($invoice));
use yzh52521\facade\Notification;
Notification::send($users, new InvoicePaid($invoice));
Notification::sendNow($developers, new DeploymentCompleted($deployment));
namespace app\notifications;
use think\queue\ShouldQueue;
use yzh52521\Notification;
use yzh52521\notification\message\Mail;
use yzh52521\notification\Notifiable;
class InvoicePaid extends Notification implements ShouldQueue
{
// ...
}
$user->notify(new InvoicePaid($invoice));
public function __construct(Order $order)
{
$this->order = $order;
$this->delay =5;
}
public function __construct(Order $order)
{
$this->order = $order;
public $connection = 'redis';
$this->delay =5;
}
/**
* 获取通知的邮件描述。
*
* @param mixed $notifiable
* @return \yzh52521\notification\messages\Mail
*/
public function toMail($notifiable)
{
$url = url('/invoice/'.$this->invoice->id);
return (new Mail)
->greeting('Hello!')
->line('你的一张发票已经付款了!')
->action('查看发票', $url)
->line('感谢您使用我们的应用程序!');
}
public function toMail($notifiable)
{
return (new Mail)
->to($to)
->subject('找回密码')
->view('emails.name', ['invoice' => $this->invoice]);
}
public function toMail($notifiable)
{
return (new Mail)
->from('[email protected]', 'Barrett Blair')
->line('...');
}
public function toSendcloud($notifiable)
{
return (new Sendcloud($user,$key))
->data('Your SMS message content');
}
public function toSendcloud($notifiable)
{
return (new Sendcloud($user,$key))
->data('Your SMS message content');
}
public function toSendcloud($notifiable)
{
return (new Sendcloud($user,$key))
->to('15556666666')
->data('Your SMS message content');
}
public function toSendcloud($notifiable)
{
return (new Sendcloud($user,$key))
->to('15556666666')
->template('40438')
->data('Your SMS message content');
}
public function toSendcloud($notifiable)
{
return (new Sendcloud($user,$key))
->to('15556666666')
->isMultimedia()
->data('Your SMS message content');
}
public function toSendcloud($notifiable)
{
return (new Sendcloud($user,$key))
->to('15556666666')
->isVoice()
->data('Your SMS message content');
}
namespace app\notification;
use yzh52521\notification\message\Easysms;
class ValidateCode extends Notification
{
public function channels($notifiable)
{
return ['easysms'];
}
public function toEasysms($notifiable)
{
return ( new Easysms )
->to('13188888888')
->template('SMS_001')
->content('您的验证码{$code},该验证码5分钟内有效,请勿泄漏于他人!')
->data(['code' =>6379]);
}
}
namespace app\notification;
use yzh52521\notification\Notifiable;
use yzh52521\notification\Channel;
use yzh52521\Notification;
class VoiceChannel extends Channel
{
/**
* 发送给定的通知
* @param Notifiable $notifiable
* @param Notification $notification
* @return mixed
*/
public function send($notifiable, Notification $notification): void
{
$message = $notification->toVoice($notifiable);
// 将通知发送给 $notifiable 实例...
}
}
use yzh52521\Notification;
use yzh52521\notification\Notifiable;
class InvoicePaid extends Notification
{
/**
* 获取通知频道
* @param Notifiable $notifiable
*/
public function channels( $notifiable)
{
return VoiceChannel::class;
}
/**
* 获取通知的语音表示形式
* @param Notifiable $notifiable
*/
public function toVoice($notifiable): VoiceMessage
{
// ...
}
}
class VoiceMessage
{
// ...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.