This repository has been archived by the owner on Jun 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (46 loc) · 1.47 KB
/
index.js
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
var urllib = require('urllib'),
iconv = require('iconv-lite'),
utils = require('./lib/utils'),
fs = require('fs');
module.exports = Kingo;
function Kingo(options, sessionId) {
this.options = options;
this.sessionId = sessionId || utils.generateSessionId();
}
Kingo.prototype.request = function (url, options, callback) {
url = this.options.baseUrl + url;
options.headers = {
cookie: 'ASP.NET_SessionId=' + this.sessionId,
referer: options.referer || url,
};
urllib.request(url, options, function (error, data, response) {
callback(error, iconv.decode(data, 'gbk'), response);
});
};
Kingo.prototype.GET = function (url, data, callback) {
callback = callback || data;
this.request(url, {data: data}, callback);
};
Kingo.prototype.POST = function (url, data, callback) {
callback = callback || data;
this.request(url, {data: data, method: 'post'}, callback);
};
Kingo.prototype.login = function (sid, pwd, callback) {
this.POST('_data/Index_LOGIN_tfc.aspx', {
Sel_Type: 'STU',
UserID: sid,
PassWord: pwd,
}, function (error, data, response) {
if (data.toString().indexOf('正在加载权限数据') != -1 ||
response.statusCode == 302) {
callback(error, true);
} else {
callback(error, false);
}
});
};
fs.readdirSync(__dirname + '/lib/functions').forEach(function (file) {
if (file.substr(-3) == '.js') {
Kingo.prototype[file.split('.')[0]] = require('./lib/functions/' + file);
}
});