|
@@ -15,7 +15,7 @@ class Ems
|
|
|
* 验证码有效时长
|
|
|
* @var int
|
|
|
*/
|
|
|
- protected static $expire = 120;
|
|
|
+ protected static $expire = 300;
|
|
|
|
|
|
/**
|
|
|
* 最大允许检测的次数
|
|
@@ -51,25 +51,25 @@ class Ems
|
|
|
*/
|
|
|
public static function send($email, $code = null, $event = 'default')
|
|
|
{
|
|
|
-
|
|
|
- $event = 'default';
|
|
|
$code = is_null($code) ? Random::numeric(config('captcha.length')) : $code;
|
|
|
$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;
|
|
|
- });
|
|
|
+
|
|
|
+
|
|
|
+ $message = self::msg_register($code);
|
|
|
+ if($event == 'resetpwd'){
|
|
|
+ $message = self::msg_pwd($code);
|
|
|
}
|
|
|
- $result = Hook::listen('ems_send', $ems, null, true);
|
|
|
+
|
|
|
+ $obj = new Email();
|
|
|
+ $result = $obj
|
|
|
+ ->to($email)
|
|
|
+ ->subject('Elin Dance Studio')
|
|
|
+// ->message("你的验证码是:" . $code . "," . ceil(self::$expire / 60) . "分钟内有效。")
|
|
|
+ ->message($message)
|
|
|
+ ->send();
|
|
|
+
|
|
|
if (!$result) {
|
|
|
$ems->delete();
|
|
|
return false;
|
|
@@ -77,6 +77,34 @@ class Ems
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ private static function msg_register($code){
|
|
|
+ $str =
|
|
|
+ 'Hello!<br/>
|
|
|
+ We have received your request to create an account for our app.<br>
|
|
|
+ Please use the OTP code below to verify your email address:<br>
|
|
|
+ <strong>'.$code.'</strong><br>
|
|
|
+ The OTP will expire in '. ceil(self::$expire / 60).' minutes.<br>
|
|
|
+ Sincerely,<br>
|
|
|
+ Elin Dance Studio Customer Support
|
|
|
+ ';
|
|
|
+
|
|
|
+ return $str;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static function msg_pwd($code){
|
|
|
+ $str =
|
|
|
+ 'Hello!<br/>
|
|
|
+ We have received your request to reset your password for our app.<br>
|
|
|
+ Please use the OTP code below to verify your email address:<br>
|
|
|
+ <strong>'.$code.'</strong><br>
|
|
|
+ The OTP will expire in '. ceil(self::$expire / 60).' minutes.<br>
|
|
|
+ Sincerely,<br>
|
|
|
+ Elin Dance Studio Customer Support
|
|
|
+ ';
|
|
|
+
|
|
|
+ return $str;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发送通知
|
|
|
*
|
|
@@ -159,7 +187,7 @@ class Ems
|
|
|
{
|
|
|
$event = 'default';
|
|
|
\app\common\model\Ems::
|
|
|
- where(['email' => $email, 'event' => $event])
|
|
|
+ where(['email' => $email])
|
|
|
->delete();
|
|
|
Hook::listen('ems_flush');
|
|
|
return true;
|