Commit 19ffa479 authored by huanle's avatar huanle

0527. token

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