6
0
Fork 0
jiqu-library-server/app/Notifications/SmsCodeCreated.php

56 lines
1.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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,
];
});
}
}