Token.php
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace app\common\library;
use think\Cache;
/**
* Token类
*/
class Token
{
/**
* 缓存用户的Token及UID
*
* @param string $token
* @param int $uid
* @param int $expire
*/
public static function set($token, $uid, $expire)
{
Cache::set($token, $uid, $expire);
}
/**
* 通过Token获取用户的身份标识
*
* @param string $token
* @return string
*/
public static function identity($token)
{
$uid = Cache::get($token);
return $uid;
}
/**
* 验证Token是否可用
* @param string $token
*/
public static function check($token)
{
return Cache::has($token);
}
/**
* 延长Token的有效期
* key 用户的Token(随机Hash)
*/
public static function refresh($token)
{
$uid = Cache::get($token);
Cache::set($token, $uid);
}
/**
* 删除用户的Token缓存
*
* @param string $token
*/
public static function delete($token)
{
Cache::rm($token);
}
}