This repository has been archived by the owner on Mar 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESWIS.php
108 lines (91 loc) · 2.58 KB
/
ESWIS.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
require_once 'login.php';
/**
* 学生工作信息管理系统登录接口
*
* 原始代码来自:http://t.cn/zQx3h1v
*/
class ESWIS extends AbstractLogin
{
/**
* 学生证号码
*/
protected $username = null;
/**
* 学生工作信息系统登录密码
*/
protected $password = null;
/**
* 登录地址
*/
protected $loginUrl = 'http://eswis.gdut.edu.cn/default.aspx';
/**
* 学生信息地址
*/
protected $infoUrl = 'http://eswis.gdut.edu.cn/opt_xxhz.aspx?key=';
/**
* Session ID
*/
protected $sessionId = null;
/**
* Session key
*/
protected $key = null;
public function setup($username, $password)
{
$this->username = $username;
$this->password = $password;
}
public function login()
{
$ret = $this->request($this->loginUrl);
$form = getASPSessionForm($ret['body']);
$form['ctl00$log_username'] = $this->username;
$form['ctl00$log_password'] = $this->password;
$form['ctl00$logon'] = '登录';
$ret = $this->request($this->loginUrl, $form);
$this->sessionId = parseInformation(
'/ASP.NET_SessionId=([0-9a-z]+)/',
$ret['body']
);
if (!$this->sessionId) {
throw new LoginException('Session ID not found.');
}
$this->key = parseInformation(
'/\?key=([0-9a-zA-Z]+)/',
$ret['body']
);
if (!$this->key) {
throw new LoginException('Key not found.');
}
}
public function getInfos()
{
if (!$this->key || !$this->sessionId) {
throw new GetInfoException();
}
$url = $this->infoUrl . $this->key;
$ret = $this->request($url, null, array(
CURLOPT_COOKIE => 'ASP.NET_SessionId=' . $this->sessionId
));
$body = $ret['body'];
$infos = array(
'student_name' => parseInformation(
'/ctl00_cph_right_inf_xm">([^<]+)</', $body
),
'student_number' => parseInformation(
'/ctl00_cph_right_inf_xh">([^<]+)</', $body
)
);
$details = explode(' ', parseInformation(
'/ctl00_cph_right_inf_dw">([^<]+)</', $body
));
$infos['campus'] = $details[0];
$infos['faculty'] = $details[1];
// 去掉多余的专业两个字
$infos['major'] = mb_substr($details[2], 0, -6);
$infos['grade'] = $details[3];
$infos['class'] = $details[4];
return $infos;
}
}