placeholderReplace() public static method

对邮件占位符进行替换 支持:
     {SITE_NAME} : 站点名称
     {nickname}  : 当前用户名称
     {email}     : 用户电子邮件
     {code}      : 验证码
     {newPassword}: 新密码
     {useTraffic}: 已用流量
     {transfer}  : 总流量
     {expireTime}: 到期时间
     {avatar}:     用户头像 (必须与 {email} 同时使用)
     {REGISTER_URL}: 注册校验链接
public static placeholderReplace ( $content, $params ) : string
$content
$params array
return string
Ejemplo n.º 1
0
 public function run()
 {
     $users = User::getUserArrayByExpire();
     $notificationMail = Option::get('mail_stop_expire_notification');
     $mailContentTemplate = Option::get('custom_mail_stop_expire_content');
     if (!$notificationMail) {
         Option::set('mail_stop_expire_notification', 0);
         // 设置邮件提醒的系统参数
     }
     $mailer = Mailer::getInstance();
     $mailer->toQueue(true);
     foreach ($users as $user) {
         $user->stop();
         Logger::getInstance()->info('user [' . $user->email . '] 未续费或流量超用已被暂停服务');
         if ($notificationMail) {
             $mail = new Mail();
             $mail->to = $user->email;
             $mail->subject = '[' . SITE_NAME . '] ' . "用户 {$user->nickname},您的账户由于未续费或流量超用已被暂停服务";
             $params = ['nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime)];
             $mailContent = Utils::placeholderReplace($mailContentTemplate, $params);
             $mailContent .= "<p style=\"padding: 1.5em 1em 0; color: #999; font-size: 12px;\">—— 本邮件由 " . SITE_NAME . " (<a href=\"" . BASE_URL . "\">" . BASE_URL . "</a>) 账户管控系统发送</p>";
             $mail->content = $mailContent;
             $mailer->send($mail);
         }
     }
     // 避免频繁更新 Option 单例对象,循环结束后再执行
     if ($notificationMail) {
         Option::set('mail_queue', 1);
     }
     // 2016-04-26 15:00 - by @Sendya Fixed issue #62
     // User::enableUsersByExpireTime(); // 启用已续费且流量未超过的用户
 }
Ejemplo n.º 2
0
 /**
  * @JSON
  * @return array
  * @throws \Core\Error
  */
 public function postAll()
 {
     $subject = $_POST['mailer_subject'];
     $content = htmlspecialchars($_POST['mailer_content']);
     $content .= "<p style=\"padding: 1.5em 1em 0; color: #999; font-size: 12px;\">—— 本邮件由 " . SITE_NAME . " (<a href=\"" . BASE_URL . "\">" . BASE_URL . "</a>) 管理员发送</p>";
     if ($subject == null || $subject == '' || $content == null || $content == '') {
         return array('error' => 1, 'message' => '请求错误,您提交的参数不对。');
     }
     $users = User::getUserList();
     $mailer = Mailer1::getInstance();
     $mailer->toQueue(true);
     foreach ($users as $user) {
         $mail = new Mail();
         $params = ['nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime), 'avatar' => true];
         $mail->subject = $subject;
         $mail->content = Utils::placeholderReplace($content, $params);
         $mail->to = $user->email;
         $mailer->send($mail);
     }
     return array('error' => 0, 'message' => '邮件列队正在工作,将在稍后开始发送..');
 }
Ejemplo n.º 3
0
 /**
  * @JSON
  * @throws \Core\Error
  */
 public function forgePwd()
 {
     $result = array('error' => 1, 'message' => '请求找回密码失败,请刷新页面重试。');
     $siteName = SITE_NAME;
     if (isset($_POST['email']) && $_POST['email'] != '') {
         $user = User::getUserByEmail(htmlspecialchars(trim($_POST['email'])));
         if (!$user) {
             return $result;
         }
         if ($user->enable == 0) {
             $verify_code = json_decode($user->forgePwdCode, true)['verification'];
             if ($verify_code != null) {
                 $result['message'] = '您的账户还未进行邮箱校验,请校验完毕后再试!';
                 return $result;
             }
         }
         $user->lastFindPasswdTime = time();
         if ($user->lastFindPasswdCount != 0 && $user->lastFindPasswdCount > 2) {
             $result['message'] = '找回密码重试次数已达上限!';
             return $result;
         }
         $code = Utils::randomChar(10);
         $forgePwdCode['code'] = $code;
         $forgePwdCode['time'] = time();
         $user->forgePwdCode = json_encode($forgePwdCode);
         $content = Option::get('custom_mail_forgePassword_content');
         $params = ['code' => $code, 'nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime)];
         $content = Utils::placeholderReplace($content, $params);
         $mailer = Mailer::getInstance();
         $mail = new \Model\Mail();
         $mail->to = $user->email;
         $mail->subject = "[" . SITE_NAME . "] Password Recovery";
         $mail->content = $content;
         $mailer->toQueue(true);
         // 添加到邮件列队
         $isOk = $mailer->send($mail);
         $user->save();
         $result['uid'] = $user->uid;
         if ($isOk) {
             $result['message'] = '验证代码已经发送到该注册邮件地址,请注意查收!<br/>请勿关闭本页面,您还需要验证码来验证您的账户所有权才可重置密码!!';
             $result['error'] = 0;
         } else {
             $result['message'] = '邮件发送失败, 请联系管理员检查邮件系统设置!';
             $result['error'] = 1;
         }
         return $result;
     } else {
         if ($_POST['code'] != '' && $_POST['uid'] != '') {
             $uid = $_POST['uid'];
             $code = trim($_POST['code']);
             $user = User::GetUserByUserId(trim($uid));
             $forgePwdCode = json_decode($user->forgePwdCode, true);
             // forgePwdCode.length > 1 且 验证码一样 且 时间不超过600秒(10分钟)
             if (count($forgePwdCode) > 1 && $forgePwdCode['code'] == $code && time() - intval($forgePwdCode['time']) < 600) {
                 $newPassword = Utils::randomChar(10);
                 $user->setPassword($newPassword);
                 $user->lastFindPasswdCount = 0;
                 $user->lastFindPasswdTime = 0;
                 $user->save();
                 $content = Option::get('custom_mail_forgePassword_content_2');
                 $params = ['code' => $code, 'newPassword' => $newPassword, 'nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime)];
                 $content = Utils::placeholderReplace($content, $params);
                 $mailer = Mailer::getInstance();
                 $mail = new \Model\Mail();
                 $mail->to = $user->email;
                 $mail->subject = "[" . SITE_NAME . "] Your new Password";
                 $mail->content = $content;
                 $mailer->toQueue(true);
                 // 添加到邮件列队
                 $isOk = $mailer->send($mail);
                 if ($isOk) {
                     $result['message'] = '新密码已经发送到该账户邮件地址,请注意查收!<br/> 并且请在登录后修改密码!';
                     $result['error'] = 0;
                 } else {
                     $result['message'] = '邮件发送失败, 请联系管理员检查邮件系统设置!';
                     $result['error'] = 1;
                 }
             } else {
                 $result['message'] = '验证码已经超时或者 验证码填写不正确。请再次确认';
                 $result['error'] = -1;
             }
             return $result;
         } else {
             Template::putContext('user', User::getCurrent());
             Template::setView('panel/forgePwd');
         }
     }
     return $result;
 }