Commit 8a80e3a9 authored by huanle's avatar huanle

0527.1

parent 15bc5d97
...@@ -9,6 +9,17 @@ use app\api\model\Doclist; ...@@ -9,6 +9,17 @@ use app\api\model\Doclist;
class Index extends Controller class Index extends Controller
{ {
public function _initialize()
{
$token = input('post.token');
$old_token =Cache::get('token');
if($token!=$old_token){
$rs = json_encode(code([], 10003, 'token不合法'));
exit($rs);
}
}
public function index() public function index()
{ {
......
...@@ -50,9 +50,10 @@ class Index extends Controller ...@@ -50,9 +50,10 @@ class Index extends Controller
$User =new Dingtalk\User(); $User =new Dingtalk\User();
$userid =$User->code($code); $userid =$User->code($code);
//$userid='231115647';
$result= $this->create($userid); $token = md5(create_unique());
return $result; $expireSecond = config('token_expire_second');
$rs = cache('token',$token ,$expireSecond);
if($userid===false){ if($userid===false){
$data['status']=-10001; $data['status']=-10001;
$data['errmsg']='登录失败'; $data['errmsg']='登录失败';
...@@ -60,20 +61,20 @@ class Index extends Controller ...@@ -60,20 +61,20 @@ class Index extends Controller
$data['status']=0; $data['status']=0;
$data['errmsg']='登录成功'; $data['errmsg']='登录成功';
$data['userid']=$userid; $data['userid']=$userid;
$data['token']=$result; $data['token']=$token;
} }
// return json($data); // return json($data);
return json(code([$data], 0, 'ok')); return json(code([$data], 0, 'ok'));
} }
public function create($uid) // public function create($uid)
{ // {
//
$tokenModel = new TokenModel(); // $tokenModel = new TokenModel();
$token = $tokenModel->createToken($uid); // $token = $tokenModel->createToken($uid);
if ($token == false) { // if ($token == false) {
return json(code([], $tokenModel->getErrCode(), $tokenModel->getError())); // return json(code([], $tokenModel->getErrCode(), $tokenModel->getError()));
} else { // } else {
return json(code(['token' => $token, 'expire_second' => config('token_expire_second')])); // return json(code(['token' => $token, 'expire_second' => config('token_expire_second')]));
} // }
} // }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment