-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexam.php
67 lines (60 loc) · 2.03 KB
/
exam.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
65
66
67
<?php
/**
* 读取考试信息
*/
header('Content-type: application/json');
require_once __DIR__ . '/lib/url.php';
require_once __DIR__ . '/lib/dbconf.php';
require_once __DIR__ . '/lib/checkstr.php';
require_once __DIR__ . '/lib/table2json.php';
require_once __DIR__ . '/lib/check_eams.php';
require_once __DIR__ . '/lib/jwt_parse.php';
require_once __DIR__ . '/lib/exception.php';
stdlog($_SERVER['REMOTE_ADDR'], 'exam');
try {
if ($_SERVER['REQUEST_METHOD'] != 'POST')
throw new UMBException(206);
if (!(
array_key_exists('token', $_POST) &&
array_key_exists('semesterId', $_POST) &&
array_key_exists('examTypeId', $_POST)
))
throw new UMBException(206);
$jwt = jwt_decode($_POST['token']);
$cookie_str = $jwt['cookie']['eams'] . ';' . $jwt['cookie']['idas'];
if (!check_eams($cookie_str))
throw new UMBException(201);
//以上基本都是抄grade.php的,我觉得甚至可以写个函数
if ($_POST['semesterId'] != '') {
define('EXAM_URL',
'http://eams.uestc.edu.cn/eams/stdExamTable!examTable.action?semester.id=' .
$_POST['semesterId'] .
'&examType.id=' .
$_POST['examTypeId'] .
'&_=' .
(string)time() . '000');
} else {
define('EXAM_URL',
'http://eams.uestc.edu.cn/eams/stdExamTable!examTable.action?semester.id=' .
get('http://eams.uestc.edu.cn/eams/stdExamTable.action', $cookie_str)['cookie']['semester.id'] .
'&examType.id=' .
$_POST['examTypeId'] .
'&_=' .
(string)time() . '000');
}
$res = get(EXAM_URL, $cookie_str);
if ($res['status'] != 200)
throw new UMBException(202);
echo json_encode([
'success' => true,
'error_code' => null,
'error_msg' => '',
'data' => t2jE($res['body'])
]);
} catch (UMBException $e) {
echo json_encode([
'success' => false,
'error_code' => $e->getCode(),
'error_msg' => $e->getMessage()
]);
}