diff --git a/application/NewReedaw/controller/app/Login.php b/application/NewReedaw/controller/app/Login.php index be4c45c..a518d58 100644 --- a/application/NewReedaw/controller/app/Login.php +++ b/application/NewReedaw/controller/app/Login.php @@ -5,11 +5,11 @@ namespace app\NewReedaw\controller\app; use think\Db; use PHPMailer\PHPMailer\PHPMailer; -use app\app\controller\Wechat;// 引入Wechat服务类 - +use app\NewReedaw\controller\app\Wechat;// 引入Wechat服务类 +use app\NewReedaw\controller\app\Smsaliyun;// 引入Wechat服务类 class Login extends Base{ - protected $code_time = 50; + protected $code_time = 55; // protected $token_time = 2592000;//30天的秒数 protected $default_head_pic = 'https://tc.pcxbc.com/tsf/head_pic.png'; protected $login_use_db_name = [ @@ -87,9 +87,227 @@ class Login extends Base{ $this->record_api_log($data, $logContent, null); return $this->msg(99999); } + } + // 重置密码 + public function reset_password(){ + try { + $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); + } + return $this->reset_password_action($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"; + $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); + } + } + // 微信手机号快捷登录 + public function wechat_quick_login(){ + try { + $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']); + if($result['code'] == 0){ + $user_data = Db::table($this->login_use_db_name['zhanghao'])->where(['tel'=>$result['data']['phoneNumber']])->fidle('token,id,is_del')->find(); + if($user_data){ + if($user_data['is_del'] == 1){ + return $this->msg(10002,'该账号已注销'); + } + Db::table($this->login_use_db_name['zhanghao'])->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['zhanghao'])->insertGetId($set_data); + if($set_user_result){ + return $this->msg(['token'=>$set_data['token'],'aan_id'=>$set_user_result],'登录成功'); + }else{ + return $this->msg(10002); + } + } + }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"; + $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); + } + } + // 退出登录操作 + public function quit_account(){ + try { + $data = input('post.'); + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->count(); + if($result <= 0){ + return $this->msg(10003,'账号不存在'); + } + $quit_result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->update(['login_time'=>'2024-09-01 00:00:00']); + if($quit_result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } 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); + } } + // 账号注销 + public function delete_account(){ + try { + $data = input('post.'); + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->count(); + if($result <= 0){ + return $this->msg(10003,'账号不存在'); + } + $quit_result = Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-08-08 00:00:00']); + if($quit_result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } 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); + } + + if(cache($data['data'])){ + return $this->msg(10002,'60秒仅可发送一次验证码'); + } + $num = mt_rand(100000,999999); + // 验证是手机还是邮箱 + $montage_data = $this->is_tel_email($data['data']); + if($montage_data == false){ + return $this->msg(10005,'账号格式错误,不是手机号或者邮箱'); + } + if($montage_data == 'tel'){ + // 本公司短信 + // $result = $this->send_tel_code($data['data'],$num); + // 阿里云短信 + $sms_all = new Smsaliyun; + $result = $sms_all->send_sms($data['data'],$num); + }else{ + $result = $this->send_email_code([$data['data']],['title'=>'Reedaw验证码','from_user_name'=>'Reedaw验证码','content'=>$num]); + } + if(is_array($result) && $result['code'] == 0){ + cache($data['data'], $num, $this->code_time); + // return $this->msg(['code'=>$num]); + return $this->msg([]); + }else{ + return $this->msg(10010,'验证码发送失败'); + } + } ###############################################################action################################################################ ###############################################################action################################################################ ###############################################################action################################################################ @@ -101,7 +319,7 @@ class Login extends Base{ } // 查询账号是否已经注册 - $inspect_repeat = Db::table($this->login_use_db_name['zhanghao'])->where([$montage_data=>$data['data'],'is_del'=>0])->count(); + $inspect_repeat = Db::table($this->login_use_db_name['zhanghao'])->where([$montage_data=>$data['data']])->count(); if($inspect_repeat > 0){ return $this->msg(10002,'注册失败,账号已存在'); } @@ -138,13 +356,16 @@ class Login extends Base{ return $this->msg(10005); } $verify_result[$montage_data] = $data['data']; - $verify_result['is_del'] = 0; + // $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['zhanghao'])->where($verify_result)->field('id,token')->find(); + $result = Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->field('id,token,is_del')->find(); if($result){ + if($result['is_del'] == 1){ + return $this->msg(10002,'该账号已注销'); + } Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]); $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]); }else{ @@ -163,19 +384,21 @@ class Login extends Base{ } } }else{ - $return_data = $this->msg(10003,'登录失败,验证码错误或失效'); + $return_data = $this->msg(10002,'登录失败,验证码错误或失效'); } }else if($data['validate_type'] == 'password'){ // $verify_result['password'] = $data['validate_data']; - $result = Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->field('id,token,password')->find(); + $result = Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->field('id,token,password,is_del')->find(); if($result){ + if($result['is_del'] == 1){ + return $this->msg(10002,'该账号已注销'); + } if($result['password'] == ''){ - $return_data = $this->msg(10003,'该账户未设密码,请用验证码登录'); + $return_data = $this->msg(10002,'该账户未设密码,请用验证码登录'); } if($data['validate_data'] != $result['password']){ - $return_data = $this->msg(10003,'账号密码错误'); + $return_data = $this->msg(10002,'账号或密码错误'); }else{ - Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]); $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功'); } @@ -188,281 +411,33 @@ class Login extends Base{ return $return_data; } - - - - // 重置密码 - public function reset_password($data = ['data'=>'18530934717','password'=>'ceshi1','c_password'=>'ceshi1','code'=>'491661']){ - 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['zhanghao'])->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['zhanghao'])->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"; - $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); + public function reset_password_action($data){ + // 检查验证码 + $code_result = $this->check_code($data['data'],$data['code']); + if($code_result !== true){ + return $this->msg(10003,$code_result); } - - } - - // 微信手机号快捷登录 - 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['zhanghao'])->where(['tel'=>$result['data']['phoneNumber'],'is_del'=>0])->find(); - - if($user_data){ - Db::table($this->login_use_db_name['zhanghao'])->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['zhanghao'])->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"; - $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); - } - } - // 退出登录操作 - public function user_quit_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - 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['zhanghao'])->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"; - $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); + $t_y = $this->is_tel_email($data['data']); + if($t_y === false){ + return $this->msg(10003,'账号格式错误'); } - - } - // 删除账号 - public function delete_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - 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['zhanghao'])->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"; - $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); + // 检查账号是否存在 + $find_data = Db::table($this->login_use_db_name['zhanghao'])->where([$t_y=>$data['data']])->field('id,token,password')->find(); + if(!$find_data){ + return $this->msg(10003,'未核实到账号信息'); } - - } - - ################################################################接口################################################################ - ################################################################接口################################################################ - ################################################################接口################################################################ - - - - // 发送验证码 手机/邮箱 - /* 接口说明(发邮件) - * $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($find_data['password'] == $data['password']){ + return $this->msg(10002,'新密码不可与旧密码相同'); } - if(!array_key_exists('data', $data)){ - return $this->msg(10001); - } - - if(cache($data['data'])){ - return $this->msg(10002,'60秒仅可发送一次验证码'); - } - - $num = mt_rand(100000,999999); - if (preg_match('/^\d{11}$/', $data['data'])) { - // 本公司短信 - // $result = $this->send_tel_code($data['data'],$num); - // 阿里云短信 - $sms_all = new Smsaliyun; - $result = $sms_all->send_sms($data['data'],$num); - // dump($result); - $road = 'tel'; + $result = Db::table($this->login_use_db_name['zhanghao'])->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{ - $result = $this->send_email_code([$data['data']],['title'=>'Reedaw验证码','from_user_name'=>'Reedaw验证码','content'=>$num]); - $road = 'email'; - } - if(is_array($result) && $result['code'] == 0){ - cache($data['data'], $num, $this->code_time); - // return $this->msg(['code'=>$num]); - return $this->msg([]); - // return true; - }else{ - return $this->msg(10010,'验证码发送失败'); - // return false; + $return_data = $this->msg(10002); } + return $return_data; } - - ################################内部调用################################ - /* 接口说明(发手机短信) - - */ + // 发送手机短信(本公司接口) public function send_tel_code($tel,$code){ // 初始化cURL会话 $ch = curl_init(); @@ -508,14 +483,12 @@ class Login extends Base{ } } // 手机号区分 - function getCarrierByPhone($phone) { + public 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'], @@ -523,13 +496,11 @@ class Login extends Base{ '中国电信' => ['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 '未知运营商'; } /* 接口说明(发邮件) @@ -678,8 +649,11 @@ class Login extends Base{ } } - - + + ################################################################other################################################################ + ################################################################other################################################################ + ################################################################other################################################################ + // 检查验证码 public function check_code($data = 18530934717 , $code = 123456){ // 默认验证码正确start if($code == 88888888){ @@ -695,10 +669,6 @@ class Login extends Base{ } return true; } - ################################################################other################################################################ - ################################################################other################################################################ - ################################################################other################################################################ - public function create_random_string($length = 12) { diff --git a/application/NewReedaw/controller/app/Role.php b/application/NewReedaw/controller/app/Role.php index 3c2fd5d..2548d7c 100644 --- a/application/NewReedaw/controller/app/Role.php +++ b/application/NewReedaw/controller/app/Role.php @@ -107,7 +107,7 @@ class Role extends Base{ return $this->msg(99999); } } - // 添加角色 + // 更新角色 public function update_member(){ try { // 你的业务逻辑 diff --git a/application/NewReedaw/controller/app/Smsaliyun.php b/application/NewReedaw/controller/app/Smsaliyun.php new file mode 100644 index 0000000..99ea6c9 --- /dev/null +++ b/application/NewReedaw/controller/app/Smsaliyun.php @@ -0,0 +1,135 @@ + 'LTAI5tQCdWe9Epir3ydXWbzp', + 'accessKeySecret' => 'JKLzF0b5AXw2ajhwtem2fhPSUZVOZ5', + 'signName' => '郑州巨天信息', + // 'signName' => '郑州品传科技', + // 'templateCode' => 'SMS_484085215',//reedaw模板 :您好,欢迎使用Reedaw,您的手机验证码是: ${code},验证码一分钟内有效,若非本人操作,请忽略本短信 + 'templateCode' => 'SMS_491550200',//巨天通用模板 :您好,您的手机验证码是: ${code},请尽快输入避免验证码失效,若非本人操作,请忽略本短信 + // 'templateCode' => 'SMS_491320295',//品传通用模板 :您好,您的手机验证码是: ${code},请尽快输入避免验证码失效,若非本人操作,请忽略本短信 + 'regionId' => 'cn-hangzhou' + ]; + + + public function send_sms_api(){ + $data = input(); + if(!array_key_exists('tel',$data)){ + return json([ + 'code'=>10001, + 'msg'=>'缺少手机号码', + 'data'=>[], + ]); + } + if(!array_key_exists('code',$data)){ + return json([ + 'code'=>10002, + 'msg'=>'缺少验证码', + 'data'=>[], + ]); + } + if(!$this->validatePhoneNumber($data['tel'])){ + return json([ + 'code'=>10001, + 'msg'=>'手机号码格式错误', + 'data'=>[], + ]); + } + if(!$this->validateSixDigitCode($data['code'])){ + return json([ + 'code'=>10002, + 'msg'=>'验证码格式错误', + 'data'=>[], + ]); + } + + $result = $this->send_sms($data['tel'],$data['code']); + + return json($result); + } + // 验证函数定义(可以放在单独的文件中) + public function validatePhoneNumber($phone) { + $pattern = '/^1[3-9]\d{9}$/'; + return preg_match($pattern, $phone) === 1; + } + + public function validateSixDigitCode($code) { + $pattern = '/^\d{6}$/'; + return preg_match($pattern, $code) === 1; + } + + + /** + * 发送短信接口 + * @param string $phone 手机号 + * @param string $code 验证码 + */ + public function send_sms($phone, $code) + { + try { + // 初始化阿里云客户端 + AlibabaCloud::accessKeyClient( + $this->smsConfig['accessKeyId'], + $this->smsConfig['accessKeySecret'] + ) + ->regionId($this->smsConfig['regionId']) + ->asDefaultClient(); + + // 发送短信请求 + $result = AlibabaCloud::rpc() + ->product('Dysmsapi') + ->version('2017-05-25') + ->action('SendSms') + ->method('POST') + ->host('dysmsapi.aliyuncs.com') + ->options([ + 'query' => [ + 'RegionId' => $this->smsConfig['regionId'], + 'PhoneNumbers' => $phone, + 'SignName' => $this->smsConfig['signName'], + 'TemplateCode' => $this->smsConfig['templateCode'], + 'TemplateParam' => json_encode(['code' => $code]), + ], + ]) + ->request(); + + $result = $result->toArray(); + // return $result; + if ($result['Code'] == 'OK') { + return [ + 'code' => 0, + 'message' => '短信发送成功', + 'data' => $result + ]; + } else { + return [ + 'code' => 99999, + 'message' => $result['Message'], + 'error' => $result + ]; + } + } catch (ClientException $e) { + return [ + 'code' => 99998, + 'message' => '客户端异常: ' . $e->getErrorMessage(), + 'error' => $e->getMessage() + ]; + } catch (ServerException $e) { + return [ + 'code' => 99997, + 'message' => '服务端异常: ' . $e->getErrorMessage(), + 'error' => $e->getMessage() + ]; + } + } +} \ No newline at end of file diff --git a/application/NewReedaw/controller/app/Wechat.php b/application/NewReedaw/controller/app/Wechat.php index 53d19e4..d544794 100644 --- a/application/NewReedaw/controller/app/Wechat.php +++ b/application/NewReedaw/controller/app/Wechat.php @@ -1,11 +1,6 @@