3 Star 6 Fork 2

嗝嗝/think-restful

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Token.php 1.65 KB
一键复制 编辑 原始数据 按行查看 历史
嗝嗝 提交于 2019-04-14 12:52 . 初始化版本1.0.1_base
<?php
/**
* Created by User: wene<china_wangyu@aliyun.com> Date: 2019/4/3 Time: 17:34
*/
namespace app\api\controller;
use think\Request;
use think\restful\Base;
use think\restful\jwt\Jwt;
use think\restful\response\Json;
class Token extends Base
{
public function __construct()
{
parent::__construct();
}
public function create()
{
$param = $this->param;
if(empty($param['userName']) or empty($param['userLoginKey'])){
return Json::json(404,'参数userName/userLoginKey不能为空~');
}
$token = $tokenTemplate = $this->config['API_AUTHORIZATION_TOKEN'];
$token['iat'] = time();
$token['nbf'] = $token['iat'] + 10;
$token['exp'] = $token['iat'] + 600;
$token['data'] = ['userName'=>$param['userName'],
'userLoginKey'=>$param['userLoginKey']];
$jwt = Jwt::encode($token,$this->config['API_AUTHORIZATION_KEY']);
return Json::json(200,'操作成功~',[
'jwt'=>$jwt,
'tt'=> $token['iat'],
'exp' => $token['exp'],
'signature' => md5(join(',',$token['data']))
]);
}
/**
* 刷新时长
* @return array
*/
public function reset(){
$param = $this->param;
if(empty($param['jwt']))return Json::json(404,'参数jwt不能为空~');
$jwtArr = Jwt::reset($jwt,$this->config['API_AUTHORIZATION_KEY']);
return Json::json(200,'操作成功~',[
'jwt'=> $jwtArr['jwt'],
'tt'=> $jwtArr['jwt']['iat'],
'exp' => $jwtArr['jwt']['exp'],
'signature' => md5(join(',',$jwtArr['token']['data']))
]);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/china_wangyu/think-restful.git
git@gitee.com:china_wangyu/think-restful.git
china_wangyu
think-restful
think-restful
master

搜索帮助