checktoken($token); if($res == -1){ return $res; } $user_id = explode('/',base64_decode($token))['2']; $userInfo = db('accounts')->where('id', $user_id)->find(); //print_r($userInfo);exit; $this->assign([ 'userInfo' => $userInfo ]); return $this->fetch(); } // 修改密码 public function uqdatePwd() { $token = input("param.token/s"); $res = model('Accounts')->checktoken($token); if($res == -1){ return $res; } $user_id = explode('/',base64_decode($token))['2']; if(request()->isPost()){ $password = input("param.password/s"); $newPassword = input("param.newPassword/s"); $confirmPassword = input("param.confirmPassword/s"); } if(empty($password)){ return json(['code' => -1, 'data' => '', 'msg' => '原密码不能为空']); } if(empty($newPassword)){ return json(['code' => -2, 'data' => '', 'msg' => '新密码不能为空']); } if(empty($confirmPassword)){ return json(['code' => -3, 'data' => '', 'msg' => '确认新密码不能为空']); } if($newPassword != $confirmPassword){ return json(['code' => -3, 'data' => '', 'msg' => '新密码不一致']); } $userInfo = db('accounts')->where('id', $user_id)->find(); if(md5($password . config('salt')) != $userInfo['password']){ return json(['code' => -3, 'data' => '', 'msg' => '原密码不正确']); } $param = [ 'password' => md5($newPassword . config('salt')) ]; try{ db('accounts')->where('id', $user_id)->update($param); }catch(\Exception $e){ return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]); } return json(['code' => 1, 'data' => url('user/index'), 'msg' => '密码修改成功']); } // 用户留言 public function LeavingMessage() { if(request()->isPost()){ $account_id = input("param.account_id/s"); $nick_name = input("param.nick_name/s"); $email = input("param.email/s"); $phone = input("param.phone/s"); $content = input("param.content/s"); $account_ip = $_SERVER["REMOTE_ADDR"]; //获得访问者浏览器 $browse = $this->browse_info(); //获得访客操作系统 $system = $this->get_os(); $image = input("param.file/s"); if(empty($account_id)){ return json(['code' => -1, 'data' => '', 'msg' => '用户id不能为空']); } // if(empty($email)){ // return json(['code' => -2, 'data' => '', 'msg' => '邮箱不能为空']); // } // if(empty($qq)){ // return json(['code' => -3, 'data' => '', 'msg' => 'QQ不能为空']); // } // if(empty($wechat)){ // return json(['code' => -4, 'data' => '', 'msg' => '微信不能为空']); // } // if(empty($content)){ // return json(['code' => -5, 'data' => '', 'msg' => '内容不能为空']); // } // if(empty($phone)){ // return json(['code' => -6, 'data' => '', 'msg' => '电话不能为空']); // } // if(empty($image)){ // return json(['code' => -7, 'data' => '', 'msg' => '附件不能为空']); // } $param = [ 'account_id' => $account_id, 'content' => $content, 'account_ip' => $account_ip, 'browse' => $browse, 'system' => $system, 'image' => $image, 'message_status' => 0, 'add_time' => time() ]; $info = array(); if(!empty($nick_name)){ $param['nick_name'] = $nick_name; $info['nick_name'] = $nick_name; } if(!empty($email)){ $param['email'] = $email; $info['account_email'] = $email; } if(!empty($phone)){ $param['phone'] = $phone; $info['account_phone'] = $phone; } try{ db('accountsmessage')->insertGetId($param); if(!empty($info)){ db('accounts')->where('id',$account_id)->update($info); } }catch(\Exception $e){ return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]); } return json(['code' => 1, 'data' => url('user/index'), 'msg' => '留言成功']); } } // 上传图片 public function uplodeImg() { if(request()->isPost()){ $file = request()->file('file'); if(empty($file)){ return json(['code' => -7, 'data' => '', 'msg' => '附件不能为空']); } $fileInfo = $file->getInfo(); /*if($fileInfo['size'] > 1024 * 1024 * 2){ // 上传失败获取错误信息 return json( ['code' => -8, 'data' => '', 'msg' => '文件超过2M'] ); }*/ //检测图片格式 $ext = explode('.', $fileInfo['name']); $ext = array_pop($ext); $extArr = explode('|', 'jpg|png|gif|jpeg'); if(!in_array($ext, $extArr)){ return json(['code' => -9, 'data' => '', 'msg' => '只能上传jpg|png|gif|jpeg的文件']); } // 移动到框架应用根目录/public/uploads/ 目录下 $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads'); if($info){ $src = '/uploads' . '/' . date('Ymd') . '/' . $info->getFilename(); }else{ // 上传失败获取错误信息 return json(['code' => -10, 'data' => '', 'msg' => $file->getError()]); } } } /** * 获得访客操作系统 * @return string */ // public static function get_os(){ // if (!empty($_SESSION['userAgent'])) { // $os = $_SESSION['userAgent']; // if (preg_match('/win/i', $os)) { // $os = 'Windows'; // } else if (preg_match('/mac/i', $os)) { // $os = 'MAC'; // } else if (preg_match('/linux/i', $os)) { // $os = 'Linux'; // } else if (preg_match('/unix/i', $os)) { // $os = 'Unix'; // } else if (preg_match('/bsd/i', $os)) { // $os = 'BSD'; // } else { // $os = 'Other'; // } // return $os; // } else { // return 'unknow'; // } // } function get_os() { $agent = $_SERVER['HTTP_USER_AGENT']; $os = false; if (stristr($agent,'win')) { $os = 'Windows'; } else if (stristr($agent,'win') && stristr($agent, '95')) { $os = 'Windows 95'; } else if (stristr($agent,'win 9x') && stristr($agent, '4.90')) { $os = 'Windows ME'; } else if (stristr($agent,'win') && stristr($agent,'98')) { $os = 'Windows 98'; } else if (stristr($agent,'win') && stristr($agent,'nt 5.1')) { $os = 'Windows XP'; } else if (stristr($agent,'win') && stristr($agent,'nt 5')) { $os = 'Windows 2000'; } else if (stristr($agent,'win') && stristr($agent,'nt')) { $os = 'Windows NT'; } else if (stristr($agent,'win') && stristr($agent,'32')) { $os = 'Windows 32'; } else if (stristr($agent,'linux')) { $os = 'Linux'; } else if (stristr($agent,'unix')) { $os = 'Unix'; } else if (stristr($agent,'sun') && stristr($agent,'os')) { $os = 'SunOS'; } else if (stristr($agent,'ibm') && stristr($agent,'os')) { $os = 'IBM OS/2'; } else if (stristr($agent,'Mac')) { $os = 'Mac OS X'; } else if (stristr($agent,'PowerPC')) { $os = 'PowerPC'; } else if (stristr($agent,'AIX')) { $os = 'AIX'; } else if (stristr($agent,'HPUX')) { $os = 'HPUX'; } else if (stristr($agent,'NetBSD')) { $os = 'NetBSD'; } else if (stristr($agent,'BSD')) { $os = 'BSD'; } else if (stristr($agent,'OSF1')) { $os = 'OSF1'; } else if (stristr($agent,'IRIX')) { $os = 'IRIX'; } else if (stristr($agent,'FreeBSD')) { $os = 'FreeBSD'; } else if (stristr($agent,'teleport')) { $os = 'teleport'; } else if (stristr($agent,'flashget')) { $os = 'flashget'; } else if (stristr($agent,'webzip')) { $os = 'webzip'; } else if (stristr($agent,'offline')) { $os = 'offline'; } else{ $os = ''; } return $os; } /** * 获得访问者浏览器 * @return string */ // public static function browse_info(){ // if (!empty($_SESSION['userAgent'])) { // $br = $_SESSION['userAgent']; // if (preg_match('/MSIE/i', $br)) { // $br = 'MSIE'; // } else if (preg_match('/Firefox/i', $br)) { // $br = 'Firefox'; // } else if (preg_match('/Chrome/i', $br)) { // $br = 'Chrome'; // } else if (preg_match('/Safari/i', $br)) { // $br = 'Safari'; // } else if (preg_match('/Opera/i', $br)) { // $br = 'Opera'; // } else { // $br = 'Other'; // } // return $br; // } else { // return 'unknow'; // } // } public function browse_info(){ $sys = $_SERVER['HTTP_USER_AGENT']; //获取用户代理字符串 if (stripos($sys, "Firefox/") > 0) { preg_match("/Firefox/([^;)]+)+/i", $sys, $b); $exp[0] = "Firefox"; $exp[1] = $b[1]; //获取火狐浏览器的版本号 } elseif (stripos($sys, "Maxthon") > 0) { preg_match("/Maxthon/([d.]+)/", $sys, $aoyou); $exp[0] = "傲游"; $exp[1] = $aoyou[1]; } elseif (stripos($sys, "Baiduspider") > 0) { $exp[0] = "百度"; $exp[1] = '蜘蛛'; }elseif (stripos($sys, "YisouSpider") > 0) { $exp[0] = "一搜"; $exp[1] = '蜘蛛'; }elseif (stripos($sys, "Googlebot") > 0) { $exp[0] = "谷歌"; $exp[1] = '蜘蛛'; }elseif (stripos($sys, "Android 4.3") > 0) { $exp[0] = "安卓"; $exp[1] = '4.3'; } elseif (stripos($sys, "MSIE") > 0) { preg_match("/MSIEs+([^;)]+)+/i", $sys, $ie); $exp[0] = "IE"; $exp[1] = $ie[1]; //获取IE的版本号 } elseif (stripos($sys, "OPR") > 0) { preg_match("/OPR/([d.]+)/", $sys, $opera); $exp[0] = "Opera"; $exp[1] = $opera[1]; } elseif(stripos($sys, "Edge") > 0) { //win10 Edge浏览器 添加了chrome内核标记 在判断Chrome之前匹配 preg_match("/Edge/([d.]+)/", $sys, $Edge); $exp[0] = "Edge"; $exp[1] = $Edge[1]; } elseif (stripos($sys, "Chrome") > 0) { preg_match("/Chrome/([d.]+)/", $sys, $google); $exp[0] = "Chrome"; $exp[1] = $google[1]; //获取google chrome的版本号 } elseif(stripos($sys,'rv:')>0 && stripos($sys,'Gecko')>0){ preg_match("/rv:([d.]+)/", $sys, $IE); $exp[0] = "IE"; $exp[1] = $IE[1]; }else if(stripos($sys,'AhrefsBot')>0){ $exp[0] = "AhrefsBot"; $exp[1] = '蜘蛛'; }else if(stripos($sys,'Safari')>0){ preg_match("/([d.]+)/", $sys, $safari); $exp[0] = "Safari"; $exp[1] = $safari[1]; }else if(stripos($sys,'bingbot')>0){ $exp[0] = "必应"; $exp[1] = '蜘蛛'; }else if(stripos($sys,'WinHttp')>0){ $exp[0] = "windows"; $exp[1] = 'WinHttp 请求接口工具'; }else if(stripos($sys,'iPhone OS 10')>0){ $exp[0] = "iPhone"; $exp[1] = 'OS 10'; }else if(stripos($sys,'Sogou')>0){ $exp[0] = "搜狗"; $exp[1] = '蜘蛛'; }else if(stripos($sys,'HUAWEIM')>0){ $exp[0] = "华为"; $exp[1] = '手机端'; }else if(stripos($sys,'Dalvik')>0){ $exp[0] = "安卓"; $exp[1] = 'Dalvik虚拟机'; }else if(stripos($sys,'Mac OS X 10')>0){ $exp[0] = "MAC"; $exp[1] = 'OS X10'; }else if(stripos($sys,'Opera/9.8')>0){ $exp[0] = "Opera"; $exp[1] = '9.8'; }else if(stripos($sys,'JikeSpider')>0){ $exp[0] = "即刻"; $exp[1] = '蜘蛛'; }else if(stripos($sys,'Baiduspider')>0){ $exp[0] = "百度"; $exp[1] = '蜘蛛'; } else { $exp[0] = ""; $exp[1] = ""; } // return $exp[0].' '.$exp[1]; return $exp[0]; } }