SchoolPhysicalExamination/application/KitchenScale3/controller/app/Login.php

655 lines
32 KiB
PHP
Raw Normal View History

2025-12-22 03:58:08 +08:00
<?php
2025-12-27 21:27:08 +08:00
namespace app\KitchenScale3\controller\app;
2025-12-22 03:58:08 +08:00
use think\Db;
use PHPMailer\PHPMailer\PHPMailer;
class Login extends Base{
2026-03-06 18:02:49 +08:00
protected $code_time = 55;
2025-12-22 03:58:08 +08:00
// protected $token_time = 2592000;//30天的秒数
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
protected $login_use_db_name = [
2025-12-27 21:27:08 +08:00
'account'=>'app_user_data_multilingual',
];
protected $language_country = [
'zh' => ['中文','zh'], // 中文(简体)★
'en' => ['English','en'], // 英语(通用)★
'jp' => ['日本語(Japanese)','ja'], // 日语(变化)
'fra' => ['Français(French)','fr'], // 法语(变化)
'de' => ['Deutsch(German)','de'], // 德语
'kor' => ['한국어(Korean)','ko'], // 韩语(变化)
'ru' => ['Русский(Russian)','ru'], // 俄语
'pt' => ['Português(Portuguese)','pt'], // 葡萄牙
'spa' => ["Español(Spanish)",'es'], // 西班牙(变化)
'ara' => ['Arabic(العربية)','ar'], // 阿拉伯(变化)
2025-12-22 03:58:08 +08:00
];
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 注册
2025-12-27 21:27:08 +08:00
public function register_action(){
2025-12-22 03:58:08 +08:00
try {
// 你的业务逻辑
// 验证是否前段发送过来的数据
2025-12-27 21:27:08 +08:00
$data = input('post.');
2025-12-22 03:58:08 +08:00
// 验证数据项是否完整
2025-12-27 21:27:08 +08:00
if(!array_key_exists('data', $data)){
return $this->msg(10001,'data is miss');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
if(!array_key_exists('password', $data)){
return $this->msg(10001,'password is miss');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
if(!array_key_exists('confirm_password', $data)){
return $this->msg(10001,'confirm_password is miss');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
if(!array_key_exists('code', $data)){
return $this->msg(10001,'code is miss');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
if(!array_key_exists('language', $data)){
return $this->msg(10001,'language is miss');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
if (!preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/', $data['data'])) {
return $this->msg(10005,'data type is error');
}else{
2026-03-06 18:02:49 +08:00
if(strlen($data['data']) > 50){
return $this->msg(10005,'email too long');
2025-12-27 21:27:08 +08:00
}
}
2026-03-06 18:02:49 +08:00
2025-12-27 21:27:08 +08:00
if(!$this->verify_data_is_ok($data['password'],'str')){
return $this->msg(10005,'password type is error');
}else{
2026-03-06 18:02:49 +08:00
if(!strlen($data['password']) > 50){
2025-12-27 21:27:08 +08:00
return $this->msg(10005,'password too long');
}else{
if($data['password'] != $data['confirm_password']){
2026-03-06 18:02:49 +08:00
return $this->msg(10005,'The two passwords entered do not match.');
2025-12-27 21:27:08 +08:00
}
}
}
if(!array_key_exists($data['language'],$this->language_country)){
return $this->msg(10005,'language type is error');
}
2025-12-22 03:58:08 +08:00
2025-12-27 21:27:08 +08:00
$cfc = Db::connect('cfc_db');
2025-12-22 03:58:08 +08:00
// 查询账号是否已经注册
2025-12-27 21:27:08 +08:00
$inspect_repeat = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data'],'is_del'=>0])->field('id,token')->find();
2025-12-22 03:58:08 +08:00
2025-12-27 21:27:08 +08:00
if($inspect_repeat){
2026-03-06 18:02:49 +08:00
return $this->msg(10002,'Registration failed. Account already exists.');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
2025-12-22 03:58:08 +08:00
// 检查验证码
$code_result = $this->check_code($data['data'],$data['code']);
if($code_result !== true){
2026-03-06 18:02:49 +08:00
return $this->msg(10002,'Verification code is incorrect or invalid.');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
2025-12-22 03:58:08 +08:00
// 验证完之后
$set_data = [];
$set_data['password'] = $data['password'];
2025-12-27 21:27:08 +08:00
$set_data['account'] = $data['data'];
2025-12-22 03:58:08 +08:00
$set_data['head_pic'] = $this->default_head_pic;
$set_data['nickname'] = '用户'.time();
$set_data['create_time'] = date('Y-m-d H:i:s');
$set_data['login_time'] = date('Y-m-d H:i:s');
2025-12-27 21:27:08 +08:00
$set_data['language'] = $data['language'];
2025-12-22 03:58:08 +08:00
$set_data['token'] = md5($data['data'].$this->create_random_string(12).time());
2025-12-27 21:27:08 +08:00
$result = $cfc->table($this->login_use_db_name['account'])->insertGetId($set_data);
2025-12-22 03:58:08 +08:00
if($result){
2025-12-27 21:27:08 +08:00
return $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]);
2025-12-22 03:58:08 +08:00
}else{
2025-12-27 21:27:08 +08:00
return $this->msg(10002);
2025-12-22 03:58:08 +08:00
}
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
2025-12-27 21:27:08 +08:00
// 登录
public function login_action(){
2025-12-22 03:58:08 +08:00
try {
// 你的业务逻辑
2025-12-27 21:27:08 +08:00
$data = input('post.');
if(!array_key_exists('data', $data)){
return $this->msg(10001,'data is miss');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
if(!array_key_exists('validate_data', $data)){
return $this->msg(10001,'validate_data is miss');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
if(!array_key_exists('validate_type', $data)){
return $this->msg(10001,'validate_type is miss');
2025-12-22 03:58:08 +08:00
}
2026-02-03 18:56:47 +08:00
if(!array_key_exists('language', $data)){
return $this->msg(10001,'language is miss');
}
2025-12-27 21:27:08 +08:00
if (!preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/', $data['data'])) {
return $this->msg(10005,'data type is error');
2025-12-22 03:58:08 +08:00
}else{
2026-03-06 18:02:49 +08:00
if(strlen($data['data']) > 50){
return $this->msg(10005,'email too long');
2025-12-27 21:27:08 +08:00
}
2025-12-22 03:58:08 +08:00
}
2026-02-03 18:56:47 +08:00
if(!array_key_exists($data['language'],$this->language_country)){
return $this->msg(10005,'language type is error');
}
2025-12-22 03:58:08 +08:00
2025-12-27 21:27:08 +08:00
$cfc = Db::connect('cfc_db');
2025-12-22 03:58:08 +08:00
if($data['validate_type'] == 'code'){
2025-12-27 21:27:08 +08:00
if(!$this->verify_data_is_ok($data['validate_data'],'intnum')){
return $this->msg(10005,'validate_data type is error');
}
// 检查验证码
$code_result = $this->check_code($data['data'],$data['validate_data']);
if($code_result !== true){
2026-03-06 18:02:49 +08:00
return $this->msg(20001,'Verification code is incorrect or invalid.');
2025-12-27 21:27:08 +08:00
}
2025-12-22 03:58:08 +08:00
$code_name = $data['data'];
if($this->check_code($code_name,$data['validate_data']) === true){
2025-12-27 21:27:08 +08:00
// 查询账号是否已经注册
2026-03-06 18:02:49 +08:00
$inspect_repeat = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data'],'is_del'=>0])->field('id,token,language')->find();
2025-12-27 21:27:08 +08:00
if($inspect_repeat){
2026-02-03 18:56:47 +08:00
$cfc->table($this->login_use_db_name['account'])->where(['token'=>$inspect_repeat['token']])->update(['login_time'=>date('Y-m-d H:i:s'),'language'=>$data['language']]);
return $this->msg(['token'=>$inspect_repeat['token'],'aan_id'=>$inspect_repeat['id'],'language'=>$this->language_country[$data['language']][1]]);
2025-12-22 03:58:08 +08:00
}else{
2026-02-03 18:56:47 +08:00
// $set_data = [];
$set_data['password'] = '123456';
$set_data['account'] = $data['data'];
$set_data['head_pic'] = $this->default_head_pic;
$set_data['nickname'] = '用户'.time();
$set_data['create_time'] = date('Y-m-d H:i:s');
$set_data['login_time'] = date('Y-m-d H:i:s');
$set_data['language'] = $data['language'];
$set_data['token'] = md5($data['data'].$this->create_random_string(12).time());
$result_add = $cfc->table($this->login_use_db_name['account'])->insertGetId($set_data);
if($result_add){
return $this->msg(['token'=>$set_data['token'],'aan_id'=>$result_add,'language'=>$this->language_country[$data['language']][1]]);
}else{
2026-03-06 18:02:49 +08:00
return $this->msg(10002,'Login failed. Please try again later.');
2026-02-03 18:56:47 +08:00
}
2025-12-22 03:58:08 +08:00
}
}else{
2026-03-06 18:02:49 +08:00
return $this->msg(10002,'Login failed. Verification code is incorrect or expired.');
2025-12-22 03:58:08 +08:00
}
}else if($data['validate_type'] == 'password'){
2025-12-27 21:27:08 +08:00
if(!$this->verify_data_is_ok($data['validate_data'],'str')){
return $this->msg(10005,'validate_data type is error');
}else{
2026-03-06 18:02:49 +08:00
if(strlen($data['validate_data']) > 50){
return $this->msg(10005,'password too long');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
}
// 查询账号是否已经注册
2026-03-06 18:02:49 +08:00
$inspect_repeat = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data'],'password'=>$data['validate_data'],'is_del'=>0])->field('id,token,language')->find();
2025-12-27 21:27:08 +08:00
if($inspect_repeat){
$cfc->table($this->login_use_db_name['account'])->where(['token'=>$inspect_repeat['token']])->update(['login_time'=>date('Y-m-d H:i:s')]);
2026-02-03 18:56:47 +08:00
return $this->msg(['token'=>$inspect_repeat['token'],'aan_id'=>$inspect_repeat['id'],'language'=>$this->language_country[$inspect_repeat['language']][1]]);
2025-12-22 03:58:08 +08:00
}else{
2026-03-06 18:02:49 +08:00
return $this->msg(10003,'Account not registered. Please sign up first.');
2026-02-03 18:56:47 +08:00
$set_data['password'] = $data['validate_data'];
$set_data['account'] = $data['data'];
$set_data['head_pic'] = $this->default_head_pic;
$set_data['nickname'] = '用户'.time();
$set_data['create_time'] = date('Y-m-d H:i:s');
$set_data['login_time'] = date('Y-m-d H:i:s');
$set_data['language'] = $data['language'];
$set_data['token'] = md5($data['data'].$this->create_random_string(12).time());
$result_add = $cfc->table($this->login_use_db_name['account'])->insertGetId($set_data);
if($result_add){
return $this->msg(['token'=>$set_data['token'],'aan_id'=>$result_add,'language'=>$this->language_country[$data['language']][1]]);
}else{
2026-03-06 18:02:49 +08:00
return $this->msg(10002,'Login failed. Please try again later.');
2026-02-03 18:56:47 +08:00
}
2025-12-22 03:58:08 +08:00
}
}else{
2025-12-27 21:27:08 +08:00
return $this->msg(10005,'validate_type type is error');
2025-12-22 03:58:08 +08:00
}
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
2025-12-27 21:27:08 +08:00
// 退出登录操作
public function user_quit_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
2026-03-06 18:02:49 +08:00
try {
2025-12-22 03:58:08 +08:00
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
2025-12-27 21:27:08 +08:00
if(!array_key_exists('token', $data)){
$return_data = $this->msg(10001);
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
// if($this->token_time_validate($data['token']) === false){
// $return_data = $this->msg(20001);
// }
$cfc = Db::connect('cfc_db');
$result = $cfc->table($this->login_use_db_name['account'])->where(['token'=>$data['token']])->update(['login_time'=>'2000-01-01 00:00:00']);
if($result){
$return_data = $this->msg([]);
2025-12-22 03:58:08 +08:00
}else{
2025-12-27 21:27:08 +08:00
$return_data = $this->msg(10002);
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
2026-03-06 18:02:49 +08:00
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
2025-12-27 21:27:08 +08:00
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
// 重置密码
2026-03-06 18:02:49 +08:00
public function reset_password(){
$data = input('post.');
2025-12-22 03:58:08 +08:00
try {
// 你的业务逻辑
2025-12-27 21:27:08 +08:00
// 验证是否前段发送过来的数据
2026-03-06 18:02:49 +08:00
2025-12-27 21:27:08 +08:00
// 验证数据项是否完整
2026-03-06 18:02:49 +08:00
if(!array_key_exists('token', $data) || !array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){
2025-12-27 21:27:08 +08:00
return $this->msg(10001);
}
// 验证数据值是否合规
if($data['password'] != $data['c_password']){
2026-03-06 18:02:49 +08:00
return $this->msg(10003,'The two passwords entered do not match.');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
if($data['password'] == ''){
2026-03-06 18:02:49 +08:00
return $this->msg(10003,'Password cannot be empty.');
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
if(!$this->verify_data_is_ok($data['password'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['code'],'num')){
return $this->msg(10005);
}
// 检查验证码
$code_result = $this->check_code($data['data'],$data['code']);
if($code_result !== true){
return $this->msg(10003,$code_result);
}
2026-03-06 18:02:49 +08:00
if (!preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/', $data['data'])) {
return $this->msg(10005,'data type is error');
}else{
if(strlen($data['data']) > 50){
return $this->msg(10005,'email too long');
}
2025-12-27 21:27:08 +08:00
}
2026-03-06 18:02:49 +08:00
// $t_y = $this->is_tel_email($data['data']);
// if($t_y === false){
// return $this->msg(10003,'账号格式错误');
// }
$cfc = Db::connect('cfc_db');
2025-12-27 21:27:08 +08:00
// 检查账号是否存在
2026-03-06 18:02:49 +08:00
$find_data = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data'],'is_del'=>0])->field('id,token')->find();
2025-12-27 21:27:08 +08:00
if(!$find_data){
return $this->msg(10003);
}
2026-03-06 18:02:49 +08:00
$result = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data']])->update(['password'=>$data['password']]);
2025-12-22 03:58:08 +08:00
if($result){
2026-03-06 18:02:49 +08:00
return $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]);
2025-12-22 03:58:08 +08:00
}else{
2026-03-06 18:02:49 +08:00
return $this->msg(10002);
2025-12-22 03:58:08 +08:00
}
2025-12-27 21:27:08 +08:00
2025-12-22 03:58:08 +08:00
// 成功
2026-03-06 18:02:49 +08:00
// $this->record_api_log($data, null, $return_data);
// return $return_data;
2025-12-22 03:58:08 +08:00
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
2025-12-27 21:27:08 +08:00
2025-12-22 03:58:08 +08:00
// 删除账号
2026-03-06 18:02:49 +08:00
public function delete_account(){
$data = input('post.');
2025-12-22 03:58:08 +08:00
try {
// 你的业务逻辑
2026-03-06 18:02:49 +08:00
if(!array_key_exists('token', $data) || !array_key_exists('code', $data)){
return $this->msg(10001);
2025-12-22 03:58:08 +08:00
}
2026-03-06 18:02:49 +08:00
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['code'],'num')){
return $this->msg(10005);
2025-12-22 03:58:08 +08:00
}
2026-03-06 18:02:49 +08:00
$cfc = Db::connect('cfc_db');
$account_data = $cfc->table($this->login_use_db_name['account'])->where(['token'=>$data['token']])->field('id,token,account')->find();
// dump($account_data);
// die;
// 检查验证码
$code_result = $this->check_code($account_data['account'],$data['code']);
if($code_result !== true){
return $this->msg(10003,$code_result);
}
$result = $cfc->table($this->login_use_db_name['account'])->where(['token'=>$data['token']])->update(['is_del'=>1]);
2025-12-22 03:58:08 +08:00
if($result){
2026-03-06 18:02:49 +08:00
return $this->msg([]);
2025-12-22 03:58:08 +08:00
}else{
2026-03-06 18:02:49 +08:00
return $this->msg(10002);
2025-12-22 03:58:08 +08:00
}
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 发送验证码 手机/邮箱
/* 接口说明(发邮件)
* $data手机或者邮箱信息 字符串
* $type验证类型是注册用还是其他用途 字符串 默认register注册register、login、reset_password
* $road是手机还是邮箱还是其他 字符串 默认tel或email
*/
//18736019909
public function send_phone_email_code($data = ['data'=>'18736019909']){
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('data', $data)){
return $this->msg(10001);
}
2025-12-27 21:27:08 +08:00
if(cache($data['data'].'_cfc_multilingual')){
2026-03-06 18:02:49 +08:00
return $this->msg(10002,'You can only send a verification code once every 60 seconds.');
2025-12-22 03:58:08 +08:00
}
$num = mt_rand(100000,999999);
2025-12-27 21:27:08 +08:00
$result = $this->send_email_code([$data['data']],['title'=>'CAPTCHA','from_user_name'=>'Wendu','content'=>$num]);
2025-12-22 03:58:08 +08:00
if(is_array($result) && $result['code'] == 0){
2025-12-27 21:27:08 +08:00
cache($data['data'].'_cfc_multilingual', $num, $this->code_time);
2025-12-22 03:58:08 +08:00
return $this->msg([]);
}else{
2026-03-06 18:02:49 +08:00
return $this->msg(10010,'Failed to send verification code.');
2025-12-22 03:58:08 +08:00
}
}
2025-12-27 21:27:08 +08:00
################################内部调用################################
2025-12-22 03:58:08 +08:00
/* 接口说明(发邮件)
* $address收件人的邮箱地址 数组 格式: ['460834639@qq.com','460834639@qq.com'.......]
* $content邮件的主题数据信息 数组 格式:['title'=>'123','from_user_name'=>'123','content'=>'123']
* $annex附件路径信息 字符串
*/
public function send_email_code($address,$content,$annex=''){
// $ad = '460834639@qq.com';
$ad1 = '295155911@qq.com';
$mail = new PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host = "smtp.126.com"; //SMTP服务器 163邮箱例子
$mail->Port = 465; //邮件发送端口
$mail->SMTPAuth = true; //启用SMTP认证
$mail->SMTPSecure = 'ssl';
$mail->CharSet = "UTF-8"; //字符集
$mail->Encoding = "base64"; //编码方式
$mail->Username = "tsf3920322@126.com"; //你的邮箱
$mail->Password = "HLWXNRPUCTHJFIIX"; //你的密码(邮箱后台的授权密码)
$mail->From = "tsf3920322@126.com"; //发件人地址(也就是你的邮箱)
// $mail->Subject = "微盟测试邮件"; //邮件标题
$mail->Subject = $content['title']; //邮件标题
// $mail->FromName = "微盟体测中心"; //发件人姓名
$mail->FromName = $content['from_user_name']; //发件人姓名
for ($i=0; $i < count($address); $i++) {
$mail->AddAddress($address[$i], ""); //添加收件人(地址,昵称)
}
if($annex != ''){
// $url = ROOT_PATH. 'public' . DS . 'tsf' . DS .'demoooo.jpg';
$mail->AddAttachment($annex,''); // 添加附件,并指定名称
}
$mail->IsHTML(true); //支持html格式内容
2025-12-27 21:27:08 +08:00
$huashu1 = 'Wendu';
$huashu2 = 'Thank you for choosing Wendu products!';
$huashu3 = 'The following 6-digit number is the email verification code. Please enter it in the required field to pass verification.';
$huashu4 = '(If you did not request an email verification code, please ignore this message.)';
2025-12-22 03:58:08 +08:00
$neirong = '<div style="margin: 0; padding: 0;">
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="background: #f3f3f3; min-width: 350px; font-size: 1px; line-height: normal;">
<tbody><tr>
<td align="center" valign="top">
<table cellpadding="0" cellspacing="0" border="0" width="750" class="table750" style="width: 100%; max-width: 750px; min-width: 350px; background: #f3f3f3;">
<tbody><tr>
<td class="mob_pad" width="25" style="width: 25px; max-width: 25px; min-width: 25px;">&nbsp;</td>
<td align="center" valign="top" style="background: #ffffff;">
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;">
<tbody><tr>
<td align="right" valign="top">
<div class="top_pad" style="height: 25px; line-height: 25px; font-size: 23px;">&nbsp;</div>
</td>
</tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
<tbody><tr>
<td align="left" valign="top">
<div style="height: 39px; line-height: 39px; font-size: 37px;">&nbsp;</div>
<font class="mob_title1" face="\'Source Sans Pro\', sans-serif" color="#1a1a1a" style="font-size: 52px; line-height: 55px; font-weight: 300; letter-spacing: -1.5px;">
2025-12-27 21:27:08 +08:00
<span class="mob_title1" style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #fb966e; font-size: 48px; line-height: 55px; font-weight: 700; letter-spacing: -1.5px;">'.$huashu1.'</span>
2025-12-22 03:58:08 +08:00
</font>
<div style="height: 73px; line-height: 73px; font-size: 71px;">&nbsp;</div>
</td>
</tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
<tbody><tr>
<td align="left" valign="top">
<div style="height: 33px; line-height: 33px; font-size: 31px;">&nbsp;</div>
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
2025-12-27 21:27:08 +08:00
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 24px; line-height: 32px;">'.$huashu2.'</span>
2025-12-22 03:58:08 +08:00
</font>
<div style="height: 33px; line-height: 33px; font-size: 31px;">&nbsp;</div>
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
2025-12-27 21:27:08 +08:00
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 24px; line-height: 32px;">'.$huashu3.'</span>
2025-12-22 03:58:08 +08:00
</font>
<div style="height: 18px; line-height: 33px; font-size: 31px;">&nbsp;</div>
<font face="\'Nunito\', sans-serif" color="#585858" style="font-size: 24px; line-height: 32px;">
2025-12-27 21:27:08 +08:00
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #aaaaaa; font-size: 16px; line-height: 32px;">'.$huashu4.'</span>
2025-12-22 03:58:08 +08:00
</font>
<div style="height: 33px; line-height: 33px; font-size: 31px;">&nbsp;</div>
<table class="mob_btn" cellpadding="0" cellspacing="0" border="0" style="background: #fb966e; border-radius: 4px;">
<tbody><tr>
<td align="center" valign="top">
<span style="display: block; border: 1px solid #fb966e; border-radius: 0px; padding: 6px 12px; font-family: \'Nunito\', Arial, Verdana, Tahoma, Geneva, sans-serif; color: #ffffff; font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">
<font face="\'Nunito\', sans-serif" color="#ffffff" style="font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">
<span style="font-family: \'Nunito\', Arial, Verdana, Tahoma, Geneva, sans-serif; color: #ffffff; font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;">'.$content['content'].'</span>
</font>
</span>
</td>
</tr>
</tbody></table>
<div style="height: 75px; line-height: 75px; font-size: 73px;">&nbsp;</div>
</td>
</tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;">
<tbody><tr>
<td align="center" valign="top">
<div style="height: 34px; line-height: 34px; font-size: 32px;">&nbsp;</div>
<table cellpadding="0" cellspacing="0" border="0" width="88%" style="width: 88% !important; min-width: 88%; max-width: 88%;">
<tbody><tr>
<td align="center" valign="top">
<div style="height:12px; line-height: 34px; font-size: 32px;">&nbsp;</div>
<font face="\'Nunito\', sans-serif" color="#868686" style="font-size: 17px; line-height: 20px;">
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #868686; font-size: 17px; line-height: 20px;">© Zhengzhou Pinchuan Technology Co., Ltd. </span>
</font>
<div style="height: 3px; line-height: 3px; font-size: 1px;">&nbsp;</div>
<font face="\'Nunito\', sans-serif" color="#1a1a1a" style="font-size: 17px; line-height: 20px;">
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #1a1a1a; font-size: 17px; line-height: 20px;"><a target="_blank" style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #1a1a1a; font-size: 17px; line-height: 20px; text-decoration: none;" href="https://paoluz.link/"></a></span>
</font>
<div style="height: 35px; line-height: 35px; font-size: 33px;">&nbsp;</div>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</td>
<td class="mob_pad" width="25" style="width: 25px; max-width: 25px; min-width: 25px;">&nbsp;</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</div>';
$mail->Body = $neirong; //邮件主体内容
//发送
if (!$mail->Send()) {
return ['code' => 10003,'msg'=>$mail->ErrorInfo];
// return $mail->ErrorInfo;
} else {
return ['code' => 0];
// return 'success';
}
}
public function check_code($data = 18530934717 , $code = 123456){
// // 默认验证码正确
2025-12-27 21:27:08 +08:00
if(cache($data.'_cfc_multilingual') == false){
2025-12-22 03:58:08 +08:00
return '验证码过期';
}else{
2025-12-27 21:27:08 +08:00
if($code != cache($data.'_cfc_multilingual')){
2025-12-22 03:58:08 +08:00
return '验证码错误';
}
}
return true;
}
################################################################other################################################################
################################################################other################################################################
################################################################other################################################################
public function create_random_string($length = 12)
{
//创建随机字符
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
}