mirror of https://gitee.com/karson/fastadmin.git
优化邮件发送插件检测
parent
3dd4276ca1
commit
8b55020b3a
|
|
@ -5,6 +5,7 @@ namespace app\api\controller;
|
|||
use app\common\controller\Api;
|
||||
use app\common\library\Ems as Emslib;
|
||||
use app\common\model\User;
|
||||
use think\Hook;
|
||||
|
||||
/**
|
||||
* 邮箱验证码接口
|
||||
|
|
@ -17,15 +18,6 @@ class Ems extends Api
|
|||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
\think\Hook::add('ems_send', function ($params) {
|
||||
$obj = \app\common\library\Email::instance();
|
||||
$result = $obj
|
||||
->to($params->email)
|
||||
->subject('验证码')
|
||||
->message("你的验证码是:" . $params->code)
|
||||
->send();
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -54,6 +54,18 @@ class Ems
|
|||
$time = time();
|
||||
$ip = request()->ip();
|
||||
$ems = \app\common\model\Ems::create(['event' => $event, 'email' => $email, 'code' => $code, 'ip' => $ip, 'createtime' => $time]);
|
||||
if (!Hook::get('ems_send')) {
|
||||
//采用框架默认的邮件推送
|
||||
Hook::add('ems_send', function ($params) {
|
||||
$obj = new Email();
|
||||
$result = $obj
|
||||
->to($params->email)
|
||||
->subject('请查收你的验证码!')
|
||||
->message("你的验证码是:" . $params->code . "," . ceil(self::$expire / 60) . "分钟内有效。")
|
||||
->send();
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
$result = Hook::listen('ems_send', $ems, null, true);
|
||||
if (!$result) {
|
||||
$ems->delete();
|
||||
|
|
@ -77,6 +89,19 @@ class Ems
|
|||
'msg' => $msg,
|
||||
'template' => $template
|
||||
];
|
||||
if (!Hook::get('ems_notice')) {
|
||||
//采用框架默认的邮件推送
|
||||
Hook::add('ems_notice', function ($params) {
|
||||
$subject = '你收到一封新的邮件!';
|
||||
$content = $params['msg'];
|
||||
$email = new Email();
|
||||
$result = $email->to($params['email'])
|
||||
->subject($subject)
|
||||
->message($content)
|
||||
->send();
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
$result = Hook::listen('ems_notice', $params, null, true);
|
||||
return $result ? true : false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue