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
/
Library.php
90 lines (76 loc) · 2.19 KB
/
Library.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
<?php
require_once 'login.php';
/**
* 图书馆系统登录接口
*/
class Library extends AbstractLogin
{
/**
* 学生证号码
*/
protected $username = null;
/**
* 图书馆系统登录密码
*/
protected $password = null;
/**
* 登录地址
*/
protected $loginUrl = 'http://222.200.98.171:81/login.aspx';
/**
* 学生信息页地址
*/
protected $infoUrl = 'http://222.200.98.171:81/user/userinfo.aspx';
/**
* 登录 session cookie
*/
protected $cookie = 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$ContentPlaceHolder1$txtUsername_Lib'] = $this->username;
$form['ctl00$ContentPlaceHolder1$txtPas_Lib'] = $this->password;
$form['ctl00$ContentPlaceHolder1$txtlogintype'] = 0;
$form['ctl00$ContentPlaceHolder1$btnLogin_Lib'] ='登录';
$ret = $this->request($this->loginUrl, $form);
$login_error = parseInformation(
'/ctl00_ContentPlaceHolder1_lblErr_Lib"><font color="#ff0000">([^<]+)</',
$ret['body']
);
if ($login_error) {
throw new LoginException($login_error);
}
$this->cookie = parseInformation(
'/sulcmiswebpac=([0-9a-zA-Z]+)/',
$ret['body']
);
if (!$this->cookie) {
throw new LoginException();
}
}
public function getInfos()
{
if (!$this->cookie) {
throw new GetInfoException();
}
$ret = $this->request($this->infoUrl, null, array(
CURLOPT_COOKIE => 'sulcmiswebpac=' . $this->cookie
));
preg_match_all(
'/class="inforight">([^<]+)</',
$ret['body'],
$val
);
$info['student_number'] = trim($val[1][0]);
$info['student_name'] = trim($val[1][1]);
$info['faculty'] = trim($val[1][3]);
$info['major'] = trim($val[1][7]);
return $info;
}
}