You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
858 B

<?php
namespace app\common\lib;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
class Token{
/**
* 構造方法
*/
public function __construct(){
}
public static function genToken($payload){
$payload = array_merge($payload,[
'aud' => '',
'exp' => time() + (24 * 60 * 60),
'iat' => time(),
'iss' => '',
'jti' => uniqid(mt_rand(), true),
'nbf' => time(),
'sub' => '',
]);
return JWT::encode($payload, \think\facade\Config::get('jwt.secret'), 'HS256');
}
public static function check($token){
try{
$decode = JWT::decode($token, new Key(\think\facade\Config::get('jwt.secret'), 'HS256'));
return true;
}catch(\Exception $e){
return false;
}
}
}