This repository has been archived by the owner on Apr 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.php
54 lines (48 loc) · 1.87 KB
/
token.php
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
<?php
namespace sgpublic\scit\tool;
define('SCIT_EDU_TOOL_ROOT', dirname(__FILE__));
require SCIT_EDU_TOOL_ROOT.'/base/NormalAPI.php';
use sgpublic\scit\tool\base\NormalAPI;
use sgpublic\scit\tool\core\Debug;
use sgpublic\scit\tool\core\Verify;
use sgpublic\scit\tool\helper\TokenHelper;
use sgpublic\scit\tool\token\TokenChecker;
class token extends NormalAPI {
public function __construct(array $args) {
parent::__construct($args);
}
protected function API(Verify $sign) {
$helper = TokenHelper::getInterface($sign->getParameter('access_token'), TokenChecker::$ACCESS);
switch ($helper->check()){
case 0:
case -1:
$helper = TokenHelper::getInterface($sign->getParameter('refresh_token'), TokenChecker::$REFRESH);
if ($helper->check() == 0){
$this->result = $helper->refresh($sign->getParameter('refresh_token'));
} else {
Debug::getTrack(
$this->result, 504, 'refresh_token无效',
__DIR__, __FILE__, __LINE__, __METHOD__
);
}
break;
case -4:
Debug::getTrack(
$this->result, 504, '登录状态失效,请重新登陆',
__DIR__, __FILE__, __LINE__, __METHOD__,
$helper->check()
);
break;
default:
Debug::getTrack(
$this->result, 504, 'access_token无效',
__DIR__, __FILE__, __LINE__, __METHOD__,
$helper->check()
);
}
}
}
new token([
'access_token' => isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : null,
'refresh_token' => isset($_COOKIE['refresh_token']) ? $_COOKIE['refresh_token'] : null
]);