Commit 19ffa479 authored by huanle's avatar huanle

0527. token

parent ddf7d445
<?php <?php
namespace app\login\controller; namespace app\login\controller;
use app\login\model\Token as TokenModel; use app\login\model\Token as TokenModel;
use cjango\Dingtalk\User;
use src\Dingtalk\Utils; use src\Dingtalk\Utils;
use think\Controller; use think\Controller;
use think\Db; use think\Db;
...@@ -42,17 +41,16 @@ class Index extends Controller ...@@ -42,17 +41,16 @@ class Index extends Controller
return json(code([$config], 0, 'ok')); return json(code([$config], 0, 'ok'));
//return json($data); //return json($data);
} }
public function getSsoToken(){
public function login(){
$code = input('post.code'); $code = input('post.code');
//var_dump($code); //var_dump($code);
//$access_token= Session::get('access_token'); //$access_token= Session::get('access_token');
$User =new Dingtalk\User(); $User =new Dingtalk\User();
$userid =$User->code($code); $userid =$User->code($code);
$result= $this->create($userid);
$token =new Token();
$gettoken = $token->create($userid);
if($userid===false){ if($userid===false){
$data['status']=-10001; $data['status']=-10001;
$data['errmsg']='登录失败'; $data['errmsg']='登录失败';
...@@ -60,12 +58,20 @@ class Index extends Controller ...@@ -60,12 +58,20 @@ class Index extends Controller
$data['status']=0; $data['status']=0;
$data['errmsg']='登录成功'; $data['errmsg']='登录成功';
$data['userid']=$userid; $data['userid']=$userid;
$data['token']=$result;
} }
// return json($data); // return json($data);
return json(code([$data], 0, 'ok')); return json(code([$data], 0, 'ok'));
// var_dump($_SESSION);
} }
public function checkToken(){ public function create($uid)
{
$tokenModel = new TokenModel();
$token = $tokenModel->createToken($uid);
if ($token == false) {
return json(code([], $tokenModel->getErrCode(), $tokenModel->getError()));
} else {
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