From e5359a27d3a47d079062c5ebf8207d72f575b0ef Mon Sep 17 00:00:00 2001 From: gzydong Date: Thu, 4 Feb 2021 23:36:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E6=9C=AC=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/MailerService.php | 83 ++++++++++++++++++++++++++++++++++ app/Service/SmsService.php | 13 ++++++ app/Service/TalkService.php | 5 -- app/Support/MailerTemplate.php | 48 ++++++++++++++++++++ 4 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 app/Service/MailerService.php create mode 100644 app/Service/SmsService.php create mode 100644 app/Support/MailerTemplate.php diff --git a/app/Service/MailerService.php b/app/Service/MailerService.php new file mode 100644 index 0000000..c898e67 --- /dev/null +++ b/app/Service/MailerService.php @@ -0,0 +1,83 @@ +queueSwitch) { + + } + + return $this->realSend($email, $subject, $template); + } + + /** + * 发送邮件 + * + * @param string $email 邮箱 + * @param string $subject 标题 + * @param string $template 对应邮件模板 + * @return bool + */ + public function realSend($email, $subject, $template) + { + try { + return $this->mail($email, $subject, $template); + } catch (Exception $e) { + return false; + } + } + + /** + * 推送邮件 + * + * @param string $address 收件人 + * @param string $subject 邮件标题 + * @param string $view 邮件内容 + * @return bool + * @throws Exception + */ + private function mail(string $address, string $subject, string $view): bool + { + $config = config('mail'); + $mail = new PHPMailer(); + $mail->CharSet = 'UTF-8'; + $mail->IsSMTP(); // 设定使用SMTP服务 + $mail->SMTPDebug = 0; // 关闭SMTP调试功能 + $mail->SMTPAuth = true; // 启用 SMTP 验证功能 + $mail->SMTPSecure = 'ssl'; // 使用安全协议 + $mail->Host = $config['host']; + $mail->Port = $config['port']; + $mail->Username = $config['username']; + $mail->Password = $config['password']; + $mail->SetFrom($config['from'], $config['name']); + $mail->Subject = $subject; + $mail->MsgHTML($view); + $mail->AddAddress($address); // 收件人 + return $mail->Send(); + } +} diff --git a/app/Service/SmsService.php b/app/Service/SmsService.php new file mode 100644 index 0000000..eb1ca73 --- /dev/null +++ b/app/Service/SmsService.php @@ -0,0 +1,13 @@ +get($engine)->render($template, $params, config('view.config', [])); + } + + /** + * 邮件验证码模板 + * + * @param string $sms_code 验证码 + * @param array $params 模板参数 + * @return string + */ + public function emailCode(string $sms_code, array $params = []) + { + return $this->view(config('view.engine'), 'emails.verify-code', [ + 'service_name' => $params['service_name'] ?? "邮箱绑定", + 'sms_code' => $sms_code, + 'domain' => $params['web_url'] ?? config('domain.web_url') + ]); + } + + /** + * 注册成功通知 + */ + public function register() + { + + } +}