-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.inc.php
64 lines (54 loc) · 1.87 KB
/
api.inc.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
55
56
57
58
59
60
61
62
63
64
<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
include_once DISCUZ_ROOT.'./source/plugin/zhaisoul_dzq_api/tools.class.php';
if(empty($_SERVER['HTTP_AUTHORIZATION'])) {
//Apache获取Token
$Header = getallheaders();
$Token = $Header['Authorization'];
} else {
//Nginx获取Token
$Token = $_SERVER['HTTP_AUTHORIZATION'];
}
$is_login = false;
if($Token) {
//获取payload
$payload = Utils::verifyToken(str_replace('Bearer ', '', $Token));
if($payload) {
require_once libfile('function/member');
$member = getuserbyuid($payload['sub'], 1);
setloginstatus($member, 300);
$is_login = true;
} else if(!in_array($_GET['module'], array('users/username.login', 'forum', 'emoji', 'thread.list', 'thread.stick', 'categories'))) {
Utils::outPut(-4011, "无效的Token");
}
}
//以下模块必须要Token才可正常使用
$need_token_module = array(
'thread.create',
'post.create',
'post.update',
'unreadnotification'
);
$origin_path = explode('/', $_GET['module']);
$origin_module = count($origin_path) != 1 ? explode('.', trim($origin_path[1])) : explode('.', trim($_GET['module']));
$module = $origin_module[0];
$ac = !empty($origin_module[1]) ? $origin_module[1] : 'index';
if(in_array($origin_module, $need_token_module) && !$is_login) {
Utils::outPut(-3001, "需要登录后使用");
}
if(count($origin_path) == 1) {
$file = DISCUZ_ROOT . './source/plugin/zhaisoul_dzq_api/module/' . $module . '/' . $ac . '.inc.php';
} else {
$file = DISCUZ_ROOT . './source/plugin/zhaisoul_dzq_api/module/'. $origin_path[0] . '/' . $module . '/' . $ac . '.inc.php';
}
if(file_exists($file)){
try {
require_once $file;
} catch (Exception $exception) {
Utils::outPut(-5002, "后端异常:".$exception);
}
}else{
Utils::outPut(-2001, "参数错误!模块不存在");
}