hyperf-chat/app/Support/MailerTemplate.php

57 lines
1.5 KiB
PHP
Raw Normal View History

2021-02-04 23:36:14 +08:00
<?php
namespace App\Support;
2021-05-24 11:31:36 +08:00
use Throwable;
2021-02-04 23:36:14 +08:00
/**
* 邮件视图模板
2021-04-20 16:30:57 +08:00
*
2021-02-04 23:36:14 +08:00
* @package App\Support
*/
class MailerTemplate
{
/**
* 获取模板信息
*
2021-04-20 16:30:57 +08:00
* @param string $engine 模板引擎
2021-02-04 23:36:14 +08:00
* @param string $template 模板名称
2021-04-20 16:30:57 +08:00
* @param array $params 模板参数
2021-02-04 23:36:14 +08:00
* @return string
*/
2021-05-24 11:31:36 +08:00
private function view(string $engine, string $template, $params = []): string
2021-02-04 23:36:14 +08:00
{
return container()->get($engine)->render($template, $params, config('view.config', []));
}
/**
2021-05-24 11:31:36 +08:00
* 验证码通知 - 邮件模板
2021-02-04 23:36:14 +08:00
*
* @param string $sms_code 验证码
2021-04-20 16:30:57 +08:00
* @param array $params 模板参数
2021-02-04 23:36:14 +08:00
* @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')
]);
}
/**
2021-05-24 11:31:36 +08:00
* 系统错误通知 - 邮件模板
*
* @param Throwable $throwable
* @return string
2021-02-04 23:36:14 +08:00
*/
2021-05-24 11:31:36 +08:00
public function errorNotice(Throwable $throwable)
2021-02-04 23:36:14 +08:00
{
2021-05-24 11:31:36 +08:00
return $this->view(config('view.engine'), 'emails.error-notice', [
2021-06-30 19:27:49 +08:00
'throwable' => $throwable->getTraceAsString(),
'message' => $throwable->getMessage()
2021-05-24 11:31:36 +08:00
]);
2021-02-04 23:36:14 +08:00
}
}