70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (c) 2021 勾股工作室
|
|
* @license https://opensource.org/licenses/Apache-2.0
|
|
* @link https://blog.gougucms.com
|
|
*/
|
|
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\base\BaseController;
|
|
use app\admin\validate\ConfCheck;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Db;
|
|
use think\facade\View;
|
|
|
|
class Api
|
|
// extends BaseController
|
|
{
|
|
//清空缓存
|
|
public function cache_clear()
|
|
{
|
|
\think\facade\Cache::clear();
|
|
return to_assign(0, '系统缓存已清空');
|
|
}
|
|
|
|
//发送测试邮件
|
|
public function email_to($email)
|
|
{
|
|
$name = empty(get_config('webconfig.admin_title')) ? '系统' : get_config('webconfig.admin_title');
|
|
if (send_email($email, "一封来自{$name}的测试邮件。")) {
|
|
return to_assign(0, '发送成功,请注意查收');
|
|
}
|
|
return to_assign(1, '发送失败');
|
|
}
|
|
|
|
|
|
|
|
// 测试邮件发送
|
|
public function email_test()
|
|
{
|
|
$sender = get_params('email');
|
|
//检查是否邮箱格式
|
|
if (!is_email($sender)) {
|
|
return to_assign(1, '测试邮箱码格式有误');
|
|
}
|
|
$email_config = \think\facade\Db::name('config')
|
|
->where('name', 'email')
|
|
->find();
|
|
$config = unserialize($email_config['content']);
|
|
$content = $config['template'];
|
|
print_r($content);
|
|
//所有项目必须填写
|
|
if (empty($config['smtp']) || empty($config['smtp_port']) || empty($config['smtp_user']) || empty($config['smtp_pwd'])) {
|
|
return to_assign(1, '请完善邮件配置信息!');
|
|
}
|
|
|
|
$send = send_email($sender, '测试邮件', $content);
|
|
if ($send) {
|
|
return to_assign(0, '邮件发送成功!');
|
|
} else {
|
|
return to_assign(1, '邮件发送失败!');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|