where(["adminid"=>$account['id']])->find(); if($has){ Db::name("admin_token")->where(["adminid"=>$account['id']])->update(["token"=>$token,"expiretime"=>date("Y-m-d H:i:s",$now+1800)]); }else{ Db::name("admin_token")->insert(["token"=>$token,"expiretime"=>date("Y-m-d H:i:s",$now+1800),"addtime"=>date("Y-m-d H:i:s",$now+1800), "adminid"=>$account['id']]); } return $token; } /** * @param $token */ function verifyToken($token){ $has = Db::name("admin_token")->where(["token"=>$token])->find(); if(!$has){ return ["code"=>101,"msg"=>"token不存在"]; } if(strtotime($has['expiretime'])<=time()){ return ["code"=>102,"msg"=>"token已失效"]; } $account = Db::name("admin")->where(["id"=>$has['adminid'],"is_del"=>0])->find(); if(!$account){ return ["code"=>103,"msg"=>"未找到账户"]; } if($account['status']!=1){ return ["code"=>104,"msg"=>"账户已禁用"]; } $token_str = base64_decode($token); $account_str= substr($token_str,0,-10); if($account_str==$account['username'].$account['salt']){ Db::name("admin_token")->where(["token"=>$token])->update(["expiretime"=>date("Y-m-d H:i:s",time()+1800)]); return ["code"=>0,"msg"=>"账户有效"]; }else{ return ["code"=>105,"msg"=>"账户token无效"]; } } /** * @param $username * @return bool 账户正则匹配 */ function checkAccount($username){ $match ='/^(1745)([\d]{6})$/'; return preg_match($match,$username)?true:false; } /** * @param $pawd * @return bool 账户正则匹配 */ function checkPasswd($pawd){ $match ='/^([a-zA-z]{2})([\d]{4})$/'; return preg_match($match,$pawd)?true:false; }