-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
211 lines (177 loc) · 6.29 KB
/
util.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
const dateFormatter = require('dateformat');
const crypto = require('crypto');
require('./statics');
const public_key = "-----BEGIN PUBLIC KEY-----\n" + PARAM_ENCYPT_RSA_PUBLIC_KEY + "\n-----END PUBLIC KEY-----";
function hmac_sha1(key, text) {
return crypto.createHmac('sha1', key).update(text).digest('hex');
}
function md5(text) {
return crypto.createHash('md5').update(text).digest('hex').toUpperCase();
}
function param_encrypt(param) {
var encryptedData = crypto.publicEncrypt({
key: public_key,
padding: crypto.constants.RSA_PKCS1_PADDING,
},
Buffer.from(param)
)
return encryptedData.toString("base64");
}
function login_signature(url, time, params) {
var text = url + '|' + time;
for (var key in params) {
var item = params[key];
text = text + '|' + key + '=' + item
}
return hmac_sha1(HMAC_SHA1_KEY_LOGIN, text);
}
function pure_post_signature(url, time, user_id, access_secret, additional_items) {
var text = url + '|' + user_id + '|' + time
for (var item of additional_items) {
text = text + '|' + item
}
return hmac_sha1(access_secret, text);
}
function current_date_string() {
let now = new Date();
var output = dateFormatter(now, "ddd, dd mmm yyyy h:MM:ss") + ' GMT';
return output;
}
function is_in_Config(name, config) {
for (let key in config.courses) {
if (name == key) {
return true;
}
}
return false;
}
function is_valid_Config(config) {
if (config.account == null) {
console.log(current_date_string() + " Error: 未设置account字段,这将导致登陆失败!");
return false;
}
if (config.pwd == null) {
console.log(current_date_string() + " Error: 未设置pwd字段,这将导致登陆失败!");
return false;
}
if (config.courses.length == 0) {
console.log(current_date_string() + " Warning: 未设置courses字段,这将导致没有任何课程将会被加入监听列表!");
}
if (config.timeout == null) {
config.timeout = 0;
console.log(current_date_string() + " Notice: 未设置timeout字段,使用默认值:0 (永不自动停止)");
}
if (config.sleep == null) {
config.sleep = 5;
console.log(current_date_string() + " Notice: 未设置sleep字段,使用默认值:5 (秒)");
}
for (let course in config.courses) {
let courseDetail = config.courses[course];
if (courseDetail.delay == null) {
console.log(current_date_string() + " Notice: " + course + "未设置delay字段,使用默认值:5 (秒)");
}
if (courseDetail.lat == null) {
console.log(current_date_string() + " Notice: " + course + "未设置lat字段,使用默认值:0 (不发送GPS信息)");
}
if (courseDetail.lng == null) {
console.log(current_date_string() + " Notice: " + course + "未设置lng字段,使用默认值:0 (不发送GPS信息)");
}
}
return true;
}
function login_header_model() {
return {
'Host': 'api.mosoteach.cn',
'x-app-id': HEADER_APP_ID,
'content-type': 'application/x-www-form-urlencoded',
'accept': 'application/json',
'x-app-machine': HEADER_APP_MACHINE,
'x-app-system-version': HEADER_APP_SYSTEM_VERSION,
'x-device-code': HEADER_DEVICE_CODE,
'x-scheme': 'https',
'x-dpr': HEADER_DPR,
'accept-language': 'zh-Hans-US;q=1, en-US;q=0.9',
'x-mssvc-signature': '',
'date': '',
'user-agent': HEADER_USER_AGENT,
'x-app-version': HEADER_APP_VERSION
};
}
function login_form_model() {
return {
'account_name': '',
'app_id': FORM_APP_ID,
'app_version_name': FORM_APP_VERSION_NAME,
'app_version_number': FORM_APP_VERSION_NUMBER,
'device_code': FORM_DEVICE_CODE,
'device_pn_code': FORM_DEVICE_PN_CODE,
'device_type': FORM_DEVICE_TYPE,
'public_key': FROM_LOGIN_PUBLIC_KEY,
'system_version': FORM_SYSTEM_VERSION,
'user_pwd': ''
}
}
function pure_post_header_model() {
return {
'Host': 'api.mosoteach.cn',
'x-app-id': HEADER_APP_ID,
'content-type': 'application/x-www-form-urlencoded',
'accept': 'application/json',
'x-mssvc-sec-ts': '',
'x-mssvc-access-id': '',
'x-app-machine': HEADER_APP_MACHINE,
'x-app-system-version': HEADER_APP_SYSTEM_VERSION,
'x-device-code': HEADER_DEVICE_CODE,
'x-scheme': 'https',
'x-dpr': HEADER_DPR,
'accept-language': 'zh-Hans-US;q=1, en-US;q=0.9',
'x-mssvc-signature': '',
'date': '',
'user-agent': HEADER_USER_AGENT,
'x-app-version': HEADER_APP_VERSION
};
}
function cc_list_joined_header_model() {
return pure_post_header_model();
}
function checkin_current_open_header_model() {
return pure_post_header_model();
}
function checkin_current_open_form_model() {
return {
'clazz_course_id': ''
}
}
function checkin_header_model() {
return pure_post_header_model();
}
function checkin_GPS_form_model() {
return {
'checkin_id': '',
'lat': '',
'lng': '',
'report_pos_flag': 'Y'
}
}
function checkin_NO_GPS_form_model() {
return {
'checkin_id': '',
'report_pos_flag': 'N'
}
}
module.exports.hmac_sha1 = hmac_sha1;
module.exports.md5 = md5;
module.exports.param_encrypt = param_encrypt;
module.exports.login_signature = login_signature;
module.exports.pure_post_signature = pure_post_signature;
module.exports.current_date_string = current_date_string;
module.exports.is_in_Config = is_in_Config;
module.exports.is_valid_Config = is_valid_Config;
module.exports.login_header_model = login_header_model;
module.exports.login_form_model = login_form_model;
module.exports.cc_list_joined_header_model = cc_list_joined_header_model;
module.exports.checkin_current_open_header_model = checkin_current_open_header_model;
module.exports.checkin_current_open_form_model = checkin_current_open_form_model;
module.exports.checkin_header_model = checkin_header_model;
module.exports.checkin_GPS_form_model = checkin_GPS_form_model;
module.exports.checkin_NO_GPS_form_model = checkin_NO_GPS_form_model;