56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
||
|
||
namespace App\Notifications;
|
||
|
||
use App\Models\SmsCode;
|
||
use App\Notifications\Channels\SmsChannel;
|
||
use App\Notifications\Messages\SmsMessage;
|
||
use Illuminate\Bus\Queueable;
|
||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
use Illuminate\Notifications\Notification;
|
||
|
||
class SmsCodeCreated extends Notification implements ShouldQueue
|
||
{
|
||
use Queueable;
|
||
|
||
/**
|
||
* @param \App\Models\SmsCode $smsCode
|
||
*/
|
||
public function __construct(
|
||
protected SmsCode $smsCode,
|
||
) {
|
||
}
|
||
|
||
/**
|
||
* Get the notification's delivery channels.
|
||
*
|
||
* @param mixed $notifiable
|
||
* @return array
|
||
*/
|
||
public function via($notifiable)
|
||
{
|
||
return [SmsChannel::class];
|
||
}
|
||
|
||
/**
|
||
* 发送短信消息通知.
|
||
*
|
||
* @param mixed $notifiable
|
||
* @return \App\Notifications\Messages\SmsMessage
|
||
*/
|
||
public function toSms($notifiable): SmsMessage
|
||
{
|
||
return (new SmsMessage())->setTemplate(function ($gateway) {
|
||
if ($gateway->getName() == 'aliyun') {
|
||
return $this->smsCode->getAliyunTemplate();
|
||
}
|
||
})->setContent(function ($gateway) {
|
||
return "您的验证码为: {$this->smsCode->code},该验证码5分钟内有效,请勿泄露于他人";
|
||
})->setData(function ($gateway) {
|
||
return [
|
||
'code' => $this->smsCode->code,
|
||
];
|
||
});
|
||
}
|
||
}
|