diff --git a/application/admin/view/login/login.html b/application/admin/view/login/login.html index be4a295..b1b7bf5 100644 --- a/application/admin/view/login/login.html +++ b/application/admin/view/login/login.html @@ -19,7 +19,6 @@
教育体测管理后台
-

diff --git a/application/app/controller/Card.php b/application/app/controller/Card.php new file mode 100644 index 0000000..25b949c --- /dev/null +++ b/application/app/controller/Card.php @@ -0,0 +1,104 @@ +select(); + $data = []; + if($type == 1){ + for ($i=0; $i < count($result); $i++) { + array_push($data,['id'=>$result[$i]['id'],'name'=>$result[$i]['name']]); + } + }else{ + // 如果需要详细信息再从中编辑信息 + $data = $result; + } + return $this->msg(0,'success',$data); + } + + // 获取默认卡片规则 + // $type 1获取列表,2获取详细信息 + public function get_card_rule(){ + $result = Db::table('app_card_data')->select(); + $data = []; + if($type == 1){ + for ($i=0; $i < count($result); $i++) { + array_push($data,['id'=>$result[$i]['id'],'name'=>$result[$i]['name']]); + } + }else{ + // 如果需要详细信息再从中编辑信息 + $data = $result; + } + return $this->msg(0,'success',$data); + } + + // 新建卡片 + public function create_card(){ + + } + + + + + + ################################################################other################################################################ + ################################################################other################################################################ + ################################################################other################################################################ + + public function verify_parameters($data,$type){ + // 设置验证 + $rule = [ + 'aan_id' => 'require|number', + 'nickname' => 'require|chsAlpha', + 'birthday' => 'require|date', + 'gender' => 'require|number|in:0,1,2', + ]; + $msg = [ + 'aan_id.require' => '账号信息缺失', + 'nickname.require' => '昵称缺失', + 'birthday.require' => '生日缺失', + 'gender.require' => '性别缺失', + + 'aan_id.number' => '账号信息格式错误', + 'nickname.chsAlpha' => '昵称只能是只能是汉字、字母', + 'birthday.date' => '生日信息格式错误', + 'gender.number' => '性别格式错误', + 'gender.in' => '性别信息错误', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + + $parameter['aan_id'] = $data['aan_id']; + $parameter['nickname'] = $data['nickname']; + $parameter['birthday'] = $data['birthday']; + $parameter['gender'] = $data['gender']; + $parameter['create_time'] = date('Y-m-d H:i:s'); + $parameter['last_update_time'] = date('Y-m-d H:i:s'); + + + return $parameter; + } + + public function msg($code,$msg='',$data=[]){ + return json(['code'=>$code,'msg'=>$msg,'data'=>$data]); + } + +} \ No newline at end of file diff --git a/application/app/controller/Index.php b/application/app/controller/Index.php index 103039b..2f72b35 100644 --- a/application/app/controller/Index.php +++ b/application/app/controller/Index.php @@ -24,26 +24,35 @@ class Index extends Controller{ } // 创建用户卡片 - public function create_user_card(){ + public function create_user_data(){ $data = input(); - $result = Db::table('app_user_card')->insert([ - 'aan_id'=>$data['id'], - 'nickname'=>$data['nickname'], - 'birthday'=>$data['birthday'], - 'gender'=>$data['gender'], - 'create_time'=>date('Y-m-d H:i:s'), - 'last_update_time'=>date('Y-m-d H:i:s'), - ]); + + $result = Db::table('app_user_data')->insert($verify_result); if($result){ return $this->msg(0,'success'); }else{ return $this->msg(10001,'创建失败'); } } - // 获取账号下用户卡片列表 + + // 切换用户 + public function switch_user(){ + $data = input(); + $verify_result = $this->verify_parameters($data,'register'); + $result = Db::table('app_user_data')->insert($verify_result); + if($result){ + return $this->msg(0,'success'); + }else{ + return $this->msg(10001,'创建失败'); + } + } + + + // 获取账号下用户列表 // $type 1获取列表,2获取详细信息 - public function user_card_list($aan_id = 1,$type=1){ - $result = Db::table('app_user_card')->where(['aan_id'=>$aan_id])->select(); + public function user_card_list($aan_id,$type=1){ + $result = Db::table('app_user_data')->where(['aan_id'=>$aan_id])->select(); + // $result = Db::table('app_user_data')->where(['aan_id'=>$aan_id])->field('id,nickname')->select(); $data = []; if($type == 1){ for ($i=0; $i < count($result); $i++) { @@ -52,18 +61,21 @@ class Index extends Controller{ }else{ $data = $result; } - return $data; + return $this->msg(0,'success',$data); } - // 获取账号下用户卡片详细信息 + + // 获取账号下用户详细信息 public function user_card_information($id){ $result = Db::table('app_user_card')->where(['id'=>$id])->find(); if($result){ - return $result; + return $this->msg(0,'success',$result); }else{ - return false; + return $this->msg(10001,'error'); } } + + // 创建身体数据 public function create_body_data(){ $data = input(); @@ -117,6 +129,43 @@ class Index extends Controller{ ################################################################other################################################################ ################################################################other################################################################ + public function verify_parameters($data,$type){ + // 设置验证 + $rule = [ + 'aan_id' => 'require|number', + 'nickname' => 'require|chsAlpha', + 'birthday' => 'require|date', + 'gender' => 'require|number|in:0,1,2', + ]; + $msg = [ + 'aan_id.require' => '账号信息缺失', + 'nickname.require' => '昵称缺失', + 'birthday.require' => '生日缺失', + 'gender.require' => '性别缺失', + + 'aan_id.number' => '账号信息格式错误', + 'nickname.chsAlpha' => '昵称只能是只能是汉字、字母', + 'birthday.date' => '生日信息格式错误', + 'gender.number' => '性别格式错误', + 'gender.in' => '性别信息错误', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + + $parameter['aan_id'] = $data['aan_id']; + $parameter['nickname'] = $data['nickname']; + $parameter['birthday'] = $data['birthday']; + $parameter['gender'] = $data['gender']; + $parameter['create_time'] = date('Y-m-d H:i:s'); + $parameter['last_update_time'] = date('Y-m-d H:i:s'); + + + return $parameter; + } + public function msg($code,$msg='',$data=[]){ return json(['code'=>$code,'msg'=>$msg,'data'=>$data]); } diff --git a/application/app/controller/Login.php b/application/app/controller/Login.php index ffe97bb..0f1a0f2 100644 --- a/application/app/controller/Login.php +++ b/application/app/controller/Login.php @@ -4,9 +4,11 @@ namespace app\app\controller; use think\Controller; use think\Db; +use think\Cache; use app\bj\controller\Common; use think\Log; use \think\Validate; +use PHPMailer\PHPMailer\PHPMailer; class Login extends Controller{ @@ -18,41 +20,153 @@ class Login extends Controller{ // 注册 public function register_action(){ $data = input(); - $result = Db::table('app_register')->insert([ - 'account_number'=>$data['account_number'], - 'password'=>$data['password'], - ]); + + $verify_result = $this->verify_parameters($data,'register'); + + if(!is_array($verify_result)){ + return $this->msg(10001,$verify_result); + } + // 记录 + $result = Db::table('app_account_number')->insert($verify_result); if($result){ return $this->msg(0,'success'); }else{ - return $this->msg(10001,'注册失败'); + return $this->msg(10003,'注册失败'); } } // 登录 public function login_action(){ $data = input(); - $result = Db::table('app_register')->where([ - 'account_number'=>$data['account_number'], - 'password'=>$data['password'], - ])->count(); + $verify_result = $this->verify_parameters($data,'login'); + if(!is_array($verify_result)){ + return $this->msg(10001,$verify_result); + } + $result = Db::table('app_register')->where($verify_result)->field('id')->find(); + dump($result); + die; if($result){ + $user_data = Db::table('app_user_data')->where(['aan_id'=>$result['id']])->field('id,nickname')->select(); return $this->msg(0,'success'); }else{ return $this->msg(10001,'未找到账户'); } } - // 登录 - public function phone_code(){ - $data = '696969'; - return $this->msg(0,'success',['phone_code'=>$data]); + // 手机/邮箱验证 + /* 接口说明(发邮件) + * $data(手机或者邮箱信息) 字符串 + * $type(验证类型,是注册用,还是其他用途) 字符串 默认register(注册) + * $road(是手机还是邮箱还是其他) 字符串 默认tel或email + */ + public function phone_email_code(){ + $data = input(); + if(!array_key_exists('data', $data) || !array_key_exists('type', $data) || !array_key_exists('road', $data)){ + return $this->msg(10001,'数据&场景&通道必须'); + } + $num = $this->rand_int(); + if($data['road'] == 'tel'){ + $result = $this->send_tel_code($data['tel'],$num); + }else if($data['road'] == 'email'){ + + } + + if(is_array($result) && $result['code'] == 0){ + cache($data['data']."_".$data['road']."_".$data['type'], $num, 20); + return $this->msg(0,'success'); + }else{ + return $this->msg(10001,'error'); + } } - // 登录 - public function email_code(){ - $data = '696969'; - return $this->msg(0,'success',['email_code'=>$data]); + + + /* 接口说明(发邮件) + * $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格式内容 + + $mail->Body = $content['content']; //邮件主体内容 + + //发送 + if (!$mail->Send()) { + return $this->msg(10001,$mail->ErrorInfo); + // return $mail->ErrorInfo; + } else { + return $this->msg(0,'success'); + // return 'success'; + } + } + + public function send_tel_code($tel,$code){ + // 初始化cURL会话 + $ch = curl_init(); + $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); + // 设置POST数据 + $postData = array( + 'phone' => $tel, + 'content' => '【xxxx】您好,欢迎使用xxx,,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略!' + ); + $postData = json_encode($postData); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); + // 设置返回结果不直接输出,而是返回到变量中 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + // 发送请求并获取响应 + $response = curl_exec($ch); + // 检查是否有错误发生 + if (curl_errno($ch)) { + $error_message = curl_error($ch); + return "请求错误: " . $error_message; + } + // 关闭cURL会话 + curl_close($ch); + // 处理响应 + if ($response) { + return json_decode($response,true); + } else { + echo "未收到响应"; + } } @@ -60,6 +174,80 @@ class Login extends Controller{ ################################################################other################################################################ ################################################################other################################################################ + public function test(){ + dump($this->send_tel_code('18530934717',$this->rand_int())); + // dump(['code']); + + } + + public function rand_int(){ + return mt_rand(100000,999999); + } + + public function verify_parameters($data,$type){ + // 设置验证 + $rule = [ + 'tel' => 'number|length:11', + 'password' => 'require', + 'email' => 'email', + 'code' => 'number', + ]; + $msg = [ + 'password.require' => '密码必须', + 'tel.number' => '手机必须是数字', + 'code.number' => '验证码必须是数字', + 'tel.length' => '手机必须是11位', + 'email' => '邮箱格式错误', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + + // 判断参数 + if(array_key_exists('tel', $data)){ + $parameter['tel'] = $data['tel']; + $parameter['password'] = $data['password']; + $montage_data = 'tel'; + }else if(array_key_exists('email', $data)){ + $parameter['email'] = $data['email']; + $parameter['password'] = $data['password']; + $montage_data = 'email'; + }else{ + return '手机/邮箱必须'; + } + + // 检验是否注册过 + if($montage_data == 'tel'){ + $inspect_repeat = Db::table('app_account_number')->where(['tel'=>$parameter['tel'],'password'=>$parameter['password']])->count(); + }else{ + $inspect_repeat = Db::table('app_account_number')->where(['email'=>$parameter['email'],'password'=>$parameter['password']])->count(); + } + + if($inspect_repeat){ + return '注册失败,账号已存在'; + } + + + if($type == 'register'){ + if(array_key_exists('code', $data)){ + if(cache($parameter[$montage_data]."_".$montage_data."_register") == false){ + return '验证码过期'; + }else{ + if($data['code'] != cache($parameter[$montage_data]."_".$montage_data."_register")){ + return '验证码错误'; + } + } + }else{ + return '验证码必须'; + } + $parameter['create_time'] = date('Y-m-d H:i:s'); + } + + return $parameter; + } + public function msg($code,$msg='',$data=[]){ return json(['code'=>$code,'msg'=>$msg,'data'=>$data]); } diff --git a/composer.json b/composer.json index 61d3fa7..161c830 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ ], "require": { "php": ">=5.4.0", - "topthink/framework": "5.0.*" + "topthink/framework": "5.0.*", + "phpmailer/phpmailer": "^6.9" }, "autoload": { "psr-4": { diff --git a/public/tsf/demoooo.jpg b/public/tsf/demoooo.jpg new file mode 100644 index 0000000..cac00d1 Binary files /dev/null and b/public/tsf/demoooo.jpg differ