SchoolPhysicalExamination/application/app/controller/Login.php

705 lines
35 KiB
PHP
Raw Normal View History

2024-03-06 16:58:11 +08:00
<?php
namespace app\app\controller;
2024-11-23 16:46:38 +08:00
2024-03-06 16:58:11 +08:00
use think\Db;
2024-03-15 18:15:17 +08:00
use PHPMailer\PHPMailer\PHPMailer;
2025-04-03 18:19:04 +08:00
use app\app\controller\Wechat;// 引入Wechat服务类
2024-03-06 16:58:11 +08:00
2024-11-23 16:46:38 +08:00
2024-05-16 10:33:57 +08:00
class Login extends Base{
2024-09-24 18:40:30 +08:00
protected $code_time = 50;
2024-11-23 16:46:38 +08:00
// protected $token_time = 2592000;//30天的秒数
2025-07-23 21:32:05 +08:00
protected $default_head_pic = 'https://tc.pcxbc.com/tsf/head_pic.png';
2024-11-23 16:46:38 +08:00
protected $login_use_db_name = [
'1'=>'app_account_number',
];
2024-06-05 18:10:32 +08:00
2024-05-28 18:43:48 +08:00
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
2024-03-06 16:58:11 +08:00
// 注册
2025-03-12 18:03:31 +08:00
public function register_action($data = ['data'=>13408173311,'password'=>'123','code'=>'746119']){
2024-11-23 16:46:38 +08:00
try {
// 你的业务逻辑
// 验证是否前段发送过来的数据
if(count(input('post.')) > 0){
$data = input('post.');
}
// 验证数据项是否完整
if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){
return $this->msg(10001);
}
// 验证数据值是否合规
if(!$data['data'] || !$data['password'] || !$data['code']){
return $this->msg(10006);
}
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);
}
// 验证是手机还是邮箱
$montage_data = $this->is_tel_email($data['data']);
if($montage_data == false){
return $this->msg(10005);
}
2025-03-12 18:03:31 +08:00
2024-11-23 16:46:38 +08:00
// 查询账号是否已经注册
$inspect_repeat = Db::table($this->login_use_db_name['1'])->where([$montage_data=>$data['data'],'is_del'=>0])->count();
2025-03-12 18:03:31 +08:00
if($inspect_repeat > 0){
2024-11-23 16:46:38 +08:00
return $this->msg(10002,'注册失败,账号已存在');
}
2025-03-12 18:03:31 +08:00
2024-11-23 16:46:38 +08:00
// 检查验证码
$code_result = $this->check_code($data['data'],$data['code']);
if($code_result !== true){
return $this->msg(10002,$code_result);
}
// 验证完之后
$set_data = [];
if($montage_data == 'tel'){
$set_data['tel'] = $data['data'];
}else{
$set_data['email'] = $data['data'];
}
$set_data['password'] = $data['password'];
$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['token'] = md5($data['data'].$this->create_random_string(12).time());
$result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data);
if($result){
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]);
}else{
$return_data = $this->msg(10002);
}
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} 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";
2025-04-19 17:24:07 +08:00
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
2024-11-23 16:46:38 +08:00
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
2024-03-06 16:58:11 +08:00
}
2024-11-23 16:46:38 +08:00
2024-03-06 16:58:11 +08:00
}
2024-05-20 18:49:27 +08:00
// 重置密码
public function reset_password($data = ['data'=>'18530934717','password'=>'ceshi1','c_password'=>'ceshi1','code'=>'491661']){
2024-11-23 16:46:38 +08:00
try {
// 你的业务逻辑
// 验证是否前段发送过来的数据
if(count(input('post.')) > 0){
$data = input('post.');
}
// 验证数据项是否完整
if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){
return $this->msg(10001);
}
// 验证数据值是否合规
if($data['password'] != $data['c_password']){
return $this->msg(10003,'两次密码不一致');
}
if($data['password'] == ''){
return $this->msg(10003,'密码不能为空');
}
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);
}
$t_y = $this->is_tel_email($data['data']);
if($t_y === false){
return $this->msg(10003,'账号格式错误');
}
// 检查账号是否存在
$find_data = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data'],'is_del'=>0])->field('id,token')->find();
if(!$find_data){
return $this->msg(10003);
}
$result = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data']])->update(['password'=>$data['password']]);
if($result){
$return_data = $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]);
}else{
$return_data = $this->msg(10002);
}
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} 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";
2025-04-19 17:24:07 +08:00
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
2024-11-23 16:46:38 +08:00
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
2024-05-20 18:49:27 +08:00
}
2024-11-23 16:46:38 +08:00
2024-05-20 18:49:27 +08:00
}
2024-03-06 16:58:11 +08:00
// 登录
2024-11-23 16:46:38 +08:00
public function login_action($data = ['data'=>'18530934717','validate_data'=>'0932','type'=>'login','validate_type'=>'password']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){
return $this->msg(10001);
}
// 检测是否为手机
$montage_data = $this->is_tel_email($data['data']);
if($montage_data == false){
return $this->msg(10005);
}
$verify_result[$montage_data] = $data['data'];
$verify_result['is_del'] = 0;
// 检测校验途径
if($data['validate_type'] == 'code'){
$code_name = $data['data'];
if($this->check_code($code_name,$data['validate_data']) === true){
$result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token')->find();
2024-06-05 18:10:32 +08:00
if($result){
2024-11-23 16:46:38 +08:00
Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]);
$return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]);
2024-06-05 18:10:32 +08:00
}else{
2024-11-23 16:46:38 +08:00
$set_data['password'] = '';
$set_data[$montage_data] = $data['data'];
$set_data['head_pic'] = $this->default_head_pic;
$set_data['nickname'] = '用户'.$data['data'];
$set_data['create_time'] = date('Y-m-d H:i:s');
$set_data['login_time'] = date('Y-m-d H:i:s');
$set_data['token'] = md5($data['data'].$this->create_random_string(12).time());
$result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data);
if($result){
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功');
}else{
$return_data = $this->msg(10002);
}
2024-06-05 18:10:32 +08:00
}
2024-11-23 16:46:38 +08:00
}else{
$return_data = $this->msg(10003,'登录失败,验证码错误或失效');
2024-05-20 13:56:50 +08:00
}
2024-11-23 16:46:38 +08:00
}else if($data['validate_type'] == 'password'){
// $verify_result['password'] = $data['validate_data'];
$result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token,password')->find();
if($result){
if($result['password'] == ''){
$return_data = $this->msg(10003,'该账户未设密码,请用验证码登录');
}
if($data['validate_data'] != $result['password']){
$return_data = $this->msg(10003,'账号密码错误');
}else{
Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]);
$return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功');
}
2024-06-05 18:10:32 +08:00
}else{
2024-11-23 16:46:38 +08:00
$return_data = $this->msg(10003,'账号未注册,请先注册');
2024-06-05 18:10:32 +08:00
}
2024-05-16 10:33:57 +08:00
}else{
2024-11-23 16:46:38 +08:00
$return_data = $this->msg(10003,'校验参数错误');
2024-05-16 10:33:57 +08:00
}
2024-11-23 16:46:38 +08:00
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} 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";
2025-04-19 17:24:07 +08:00
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
2024-11-23 16:46:38 +08:00
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
2024-03-06 16:58:11 +08:00
}
2024-05-16 10:33:57 +08:00
2024-11-23 16:46:38 +08:00
2025-04-03 18:19:04 +08:00
}
// 微信手机号快捷登录
public function wechat_quick_login(){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('code', $data)){
// return $this->msg(10001,'');
return $this->msg(10001,'code is miss');
}
if(!array_key_exists('encryptedData', $data)){
return $this->msg(10001,'encryptedData is miss');
}
if(!array_key_exists('iv', $data)){
return $this->msg(10001,'iv is miss');
}
// 校验参数
if (empty($data['code'])) {
return $this->msg(10001,'code is miss.');
}
if (empty($data['encryptedData'])) {
return $this->msg(10001,'encryptedData is miss.');
}
if (empty($data['iv'])) {
return $this->msg(10001,'iv is miss.');
}
// 调用Wechat服务类处理微信登录逻辑
$wechatService = new Wechat();
$result = $wechatService->handleWechatLogin($data['code'], $data['encryptedData'], $data['iv']);
// die;
if($result['code'] == 0){
// return $this->msg($result['code'],$result['msg']);
$user_data = Db::table($this->login_use_db_name['1'])->where(['tel'=>$result['data']['phoneNumber'],'is_del'=>0])->find();
if($user_data){
Db::table($this->login_use_db_name['1'])->where(['token'=>$user_data['token']])->update(['login_time'=>date('Y-m-d H:i:s')]);
$return_data = $this->msg(['token'=>$user_data['token'],'aan_id'=>$user_data['id']]);
}else{
$set_data['password'] = '';
$set_data['tel'] = $result['data']['phoneNumber'];
$set_data['head_pic'] = $this->default_head_pic;
$set_data['nickname'] = '用户'.$result['data']['phoneNumber'];
$set_data['create_time'] = date('Y-m-d H:i:s');
$set_data['login_time'] = date('Y-m-d H:i:s');
$set_data['token'] = md5($result['data']['phoneNumber'].$this->create_random_string(12).time());
$set_user_result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data);
if($set_user_result){
$return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$set_user_result],'登录成功');
}else{
$return_data = $this->msg(10002);
}
}
return $return_data;
}else{
return $this->msg($result['code'],$result['msg']);
}
} 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";
2025-04-19 17:24:07 +08:00
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
2025-04-03 18:19:04 +08:00
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
2024-03-06 16:58:11 +08:00
}
2024-05-28 18:43:48 +08:00
// 退出登录操作
public function user_quit_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
2024-11-23 16:46:38 +08:00
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
$return_data = $this->msg(10001);
}
if($this->token_time_validate($data['token']) === false){
$return_data = $this->msg(20001);
}
$result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['login_time'=>'2024-09-01 00:00:00']);
if($result){
$return_data = $this->msg([]);
}else{
$return_data = $this->msg(10002);
}
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} 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";
2025-04-19 17:24:07 +08:00
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
2024-11-23 16:46:38 +08:00
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
2024-05-28 18:43:48 +08:00
}
2024-11-23 16:46:38 +08:00
2024-05-28 18:43:48 +08:00
}
2024-08-26 14:49:12 +08:00
// 删除账号
public function delete_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
2024-11-23 16:46:38 +08:00
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
$return_data = $this->msg(10001);
}
$result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-09-01 00:00:00']);
if($result){
$return_data = $this->msg([]);
}else{
$return_data = $this->msg(10002);
}
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} 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";
2025-04-19 17:24:07 +08:00
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
2024-11-23 16:46:38 +08:00
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
2024-08-26 14:49:12 +08:00
}
2024-11-23 16:46:38 +08:00
2024-08-26 14:49:12 +08:00
}
2024-05-28 18:43:48 +08:00
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
2024-03-06 16:58:11 +08:00
2024-05-16 10:33:57 +08:00
// 发送验证码 手机/邮箱
2024-03-15 18:15:17 +08:00
/* 接口说明(发邮件)
* $data手机或者邮箱信息 字符串
2024-05-16 10:33:57 +08:00
* $type验证类型是注册用还是其他用途 字符串 默认register注册register、login、reset_password
2024-03-15 18:15:17 +08:00
* $road是手机还是邮箱还是其他 字符串 默认tel或email
*/
2025-04-25 19:02:06 +08:00
//18736019909
2025-04-03 18:19:04 +08:00
public function send_phone_email_code($data = ['data'=>'18736019909']){
2024-11-23 16:46:38 +08:00
2024-05-22 21:37:39 +08:00
if(count(input('post.')) > 0){
$data = input('post.');
2024-05-16 10:33:57 +08:00
}
2024-07-26 18:34:47 +08:00
if(!array_key_exists('data', $data)){
2024-05-22 18:36:27 +08:00
return $this->msg(10001);
2024-03-15 18:15:17 +08:00
}
2024-08-03 17:56:26 +08:00
if(cache($data['data'])){
return $this->msg(10002,'60秒仅可发送一次验证码');
}
2024-06-05 18:10:32 +08:00
$num = mt_rand(100000,999999);
2024-05-16 10:33:57 +08:00
if (preg_match('/^\d{11}$/', $data['data'])) {
2025-04-25 19:02:06 +08:00
// 本公司短信
2024-03-29 18:34:01 +08:00
$result = $this->send_tel_code($data['data'],$num);
2025-04-25 19:02:06 +08:00
// 阿里云短信
// $sms_all = new Smsaliyun;
// $result = $sms_all->send_sms($data['data'],$num);
// dump($result);
2024-05-16 10:33:57 +08:00
$road = 'tel';
}else{
2024-07-26 18:34:47 +08:00
$result = $this->send_email_code([$data['data']],['title'=>'体测APP验证码','from_user_name'=>'体测APP','content'=>$num]);
2024-05-16 10:33:57 +08:00
$road = 'email';
2024-03-15 18:15:17 +08:00
}
if(is_array($result) && $result['code'] == 0){
2024-05-20 18:49:27 +08:00
cache($data['data'], $num, $this->code_time);
2024-07-26 18:34:47 +08:00
// return $this->msg(['code'=>$num]);
return $this->msg([]);
2024-05-16 10:33:57 +08:00
// return true;
2024-03-15 18:15:17 +08:00
}else{
2024-09-09 03:35:17 +08:00
return $this->msg(10010,'验证码发送失败');
2024-05-16 10:33:57 +08:00
// return false;
2024-03-15 18:15:17 +08:00
}
2024-03-06 16:58:11 +08:00
}
2024-05-16 10:33:57 +08:00
################################内部调用################################
2024-09-09 03:35:17 +08:00
/* 接口说明(发手机短信)
*/
public function send_tel_code($tel,$code){
// 初始化cURL会话
2025-07-23 21:32:05 +08:00
$ch = curl_init();
2024-09-09 03:35:17 +08:00
$headers = [
'Accept: application/json',
'Content-Type: application/json',
];
// 设置头部信息
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// 设置请求的URL
$url = "http://sms.ybhdmob.com/Message/Send?token=ybhdmob";
curl_setopt($ch, CURLOPT_URL, $url);
// 设置为POST请求
curl_setopt($ch, CURLOPT_POST, 1);
2025-03-07 11:42:26 +08:00
// 设置POST数据
2024-09-09 03:35:17 +08:00
$postData = array(
'phone' => $tel,
2025-07-23 21:32:05 +08:00
// 'content' => '【巨天】您好欢迎使用Reedaw您的手机验证码是'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
// 'content' => '【郑州品传科技】您好欢迎使用Reedaw您的手机验证码是'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
// 'content' => '【每日一称】您好欢迎使用Reedaw您的手机验证码是'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
'content' => '【小白健康】您好欢迎使用Reedaw您的手机验证码是'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
2025-03-07 11:42:26 +08:00
);
2024-09-09 03:35:17 +08:00
$postData = json_encode($postData);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
2025-03-07 11:42:26 +08:00
// 设置返回结果不直接输出,而是返回到变量中
2024-09-09 03:35:17 +08:00
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2025-03-07 11:42:26 +08:00
// 发送请求并获取响应
2024-09-09 03:35:17 +08:00
$response = curl_exec($ch);
2025-04-25 19:02:06 +08:00
// dump($response);
2024-09-09 03:35:17 +08:00
// 检查是否有错误发生
if (curl_errno($ch)) {
$error_message = curl_error($ch);
return "请求错误: " . $error_message;
2025-03-07 11:42:26 +08:00
}
// 关闭cURL会话
curl_close($ch);
// 处理响应
2025-04-25 19:02:06 +08:00
// dump(json_decode($response,true));
2024-09-09 03:35:17 +08:00
if ($response) {
return json_decode($response,true);
} else {
echo "未收到响应";
}
}
2025-07-23 21:32:05 +08:00
// 手机号区分
function getCarrierByPhone($phone) {
// 验证手机号格式11位数字且以1开头
if (!preg_match('/^1[3-9]\d{9}$/', $phone)) {
return '无效手机号';
}
$prefix3 = substr($phone, 0, 3);
// 2025年最新3位号段排除4位号段
$carriers = [
'中国移动' => ['134', '135', '136', '137', '138', '139', '150', '151', '152', '157', '158', '159', '178', '182', '183', '184', '187', '188', '195', '197', '198'],
'中国联通' => ['130', '131', '132', '155', '156', '166', '175', '176', '185', '186', '196'],
'中国电信' => ['133', '153', '173', '177', '180', '181', '189', '190', '191', '193', '199'],
'中国广电' => ['192']
];
foreach ($carriers as $carrier => $segments) {
if (in_array($prefix3, $segments)) {
return $carrier;
}
}
return '未知运营商';
}
2024-03-15 18:15:17 +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']; //发件人姓名
2024-07-26 18:34:47 +08:00
2024-03-15 18:15:17 +08:00
for ($i=0; $i < count($address); $i++) {
$mail->AddAddress($address[$i], ""); //添加收件人(地址,昵称)
}
2024-07-26 18:34:47 +08:00
2024-03-15 18:15:17 +08:00
if($annex != ''){
// $url = ROOT_PATH. 'public' . DS . 'tsf' . DS .'demoooo.jpg';
$mail->AddAttachment($annex,''); // 添加附件,并指定名称
}
$mail->IsHTML(true); //支持html格式内容
2024-07-26 18:34:47 +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;">
2024-11-23 16:46:38 +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;">Reedaw!</span>
2024-07-26 18:34:47 +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;">
2024-11-23 16:46:38 +08:00
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 24px; line-height: 32px;">感谢您选择锐动产品!</span>
2024-07-26 18:34:47 +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;">
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 24px; line-height: 32px;">以下6位数字是邮箱验证码请在需要的位置填写以通过验证</span>
</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;">
<span style="font-family: \'Nunito\', Arial, Tahoma, Geneva, sans-serif; color: #aaaaaa; font-size: 16px; line-height: 32px;">(如果您从未请求发送邮箱验证码,请忽略此邮件)</span>
</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>';
2024-03-15 18:15:17 +08:00
2024-07-26 18:34:47 +08:00
$mail->Body = $neirong; //邮件主体内容
2024-03-15 18:15:17 +08:00
//发送
if (!$mail->Send()) {
2024-07-26 18:34:47 +08:00
return ['code' => 10003,'msg'=>$mail->ErrorInfo];
2024-03-15 18:15:17 +08:00
// return $mail->ErrorInfo;
} else {
2024-07-26 18:34:47 +08:00
return ['code' => 0];
2024-03-15 18:15:17 +08:00
// return 'success';
}
}
2024-09-09 03:35:17 +08:00
2024-05-20 18:49:27 +08:00
public function check_code($data = 18530934717 , $code = 123456){
2024-09-09 03:35:17 +08:00
// // 默认验证码正确
2024-11-23 16:46:38 +08:00
2024-05-20 18:49:27 +08:00
if(cache($data) == false){
return '验证码过期';
}else{
if($code != cache($data)){
return '验证码错误';
}
}
return true;
}
2024-03-06 16:58:11 +08:00
################################################################other################################################################
################################################################other################################################################
################################################################other################################################################
2024-03-15 18:15:17 +08:00
2024-03-29 18:34:01 +08:00
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;
}
2024-06-05 18:10:32 +08:00
2024-03-06 16:58:11 +08:00
}