forked from BH4HPA/xueanquan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
163 lines (140 loc) · 7.39 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
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
const { default: axios } = require('axios')
const qs = require('qs');
const urlencode = require('urlencode');
const fs = require('fs');
let config;
try {
config = require('./config.js');
}
catch {
let exists = fs.existsSync('./config.js');
throw new Error(exists ? "无法导入 config.js ,请尝试运行 node config.js 检查其内容是否存在问题。" : "请将 config_template.js 重命名为 config.js 并按提示修改该文件。")
}
// 登录账号
async function _login (userId, userAccount, reseted) {
let loginRtn = await axios.post(`https://${config.serverside}.xueanquan.com/LoginHandler.ashx`,
qs.stringify({
userName: userAccount,
password: '123456',// 重置后的默认密码
type: 'login',
loginType: 1,
r: Math.random()
}),
{
headers: {
'Referer': `https://${config.serverside}.xueanquan.com/login.html`,
'content-type': 'application/x-www-form-urlencoded'
}
}
)
console.log('登录返回', loginRtn.status, loginRtn.data.Code, loginRtn.data.Code === 1 ? loginRtn.data.UInfo.TrueName : loginRtn.data.ErrorMsg, loginRtn.data.Code === 1 ? loginRtn.data.UInfo.UserId : null);
if (loginRtn.data.Code !== 1) {
if (reseted !== true) {
console.log('登录失败,即将重置密码并重试。')
let adminCookie = config.adminCookie;
let resetRtn = await axios.get(`https://${config.serverside}.xueanquan.com/eduadmin/ClassManagement/StudentPassWordReset?studentid=${userId}`,
{ headers: { 'Cookie': adminCookie } }
)
console.log('重置返回', resetRtn.status, resetRtn.data.statusCode, resetRtn.data.message);
return _login(userId, userAccount, true);
} else {
console.log('重置后仍然登录失败,请检查。')
throw new Error("管理员账号 Cookie 可能已经失效。")
return loginRtn;
}
};
return loginRtn;
}
async function _seeVideo (userId, userAccount) {
let loginRtn = await _login(userId, userAccount, false)
if (loginRtn.data?.Code !== 1) return;
let tmp = {};
tmp.ret = 1
tmp.data = loginRtn.data.UInfo
let UStr = urlencode(JSON.stringify(tmp)).toLowerCase()
let cookies;
loginRtn.headers['set-cookie'].map(v => cookies = cookies + v.split('domain')[0])
cookies = cookies + "_UStr=" + UStr + '; ' + `href=https%3A%2F%2F${config.serverside}.xueanquan.com%2F; accessId=dd39b150-a934-11e9-b073-e9b8d9c630e7; UM_distinctid=178c95abb657c2-0b00fcb023e3f3-c3f3568-15f900-178c95abb66bac; ${loginRtn.data.UInfo.UserId}_workCnt=1; pageViewNum=3; ASP.NET_SessionId=dcnd3fgidv1lka3rasf3cq2m;`
let skill = config.skill;
let videoid = skill.videoid;
let gid = skill.gid;
let courseid = skill.courseid;
let workid = skill.workid;
let fid = skill.fid;
let title = skill.title;
await axios.get(`https://${config.serverside}.xueanquan.com/JiaTing/EscapeSkill/SeeVideo.aspx?gid=${gid}&li=${courseid}`,
{
headers: { 'Cookie': cookies }
})
let secondSee = await axios.post(`https://${config.serverside}.xueanquan.com/jiating/ajax/FamilyEduCenter.EscapeSkill.SeeVideo,FamilyEduCenter.ashx?_method=SkillCheckName&_session=rw`,
`videoid=${videoid}\ngradeid=${gid}\ncourseid=${courseid}`,
{
headers: { 'Cookie': cookies }
})
console.log('看视频 ', secondSee.data)
let seeRtn = await axios.post(`https://${config.serverside}.xueanquan.com/jiating/ajax/FamilyEduCenter.EscapeSkill.SeeVideo,FamilyEduCenter.ashx?_method=TemplateIn2&_session=rw`,
`workid=${workid}\nfid=${fid}\ntitle=${title}\nrequire=\npurpose=\ncontents=\ntestwanser=0|0|0\ntestinfo=已掌握技能\ntestMark=100\ntestReulst=1\nSiteName=\nsiteAddrees=\nwatchTime=\nCourseID=${courseid}`,
{
headers: { 'Cookie': cookies }
})
console.log('答题返回', seeRtn.status, seeRtn.data)
}
async function _doSign (userId, userAccount, reseted) {
let loginRtn = await _login(userId, userAccount, false)
if (loginRtn.data?.Code !== 1) return;
let special = config.special;
let specialId = special.specialId;
let steps = special.steps;
for (stepId = 1; stepId <= steps.length; stepId++) {
let stepRtn = await axios.post(`https://huodongapi.xueanquan.com/p/${config.huodongProvince}/Topic/topic/platformapi/api/v1/records/sign`,
{ "specialId": specialId, "step": stepId },
{
headers: {
'Referer': `https://${config.serverside}.xueanquan.com/login.html`,
'Cookie': `RecordLoginInput_20083=${userAccount}; SafeApp=true; ServerSide=https://${config.serverside}.xueanquan.com; UserID=${loginRtn.data.UInfo.UserId}; _UCodeStr={%0d%0a "Grade": ${loginRtn.data.UInfo.Grade},%0d%0a "ClassRoom": ${loginRtn.data.UInfo.ClassRoom},%0d%0a "CityCode": ${loginRtn.data.UInfo.CityCode}%0d%0a};`
}
})
console.log(steps[stepId - 1], stepRtn.status, stepRtn.data.result, stepRtn.data.msg)
}
}
async function _doSign2 (userId, userAccount, reseted) {
let loginRtn = await _login(userId, userAccount, false)
if (loginRtn.data?.Code !== 1) return;
let holiday = config.holiday;
let schoolYear = holiday.schoolYear;
let semester = holiday.semester;
let steps = holiday.steps;
for (stepId = 1; stepId <= steps.length; stepId++) {
let stepRtn = await axios.post(`https://huodongapi.xueanquan.com/p/${config.huodongProvince}/Topic/topic/platformapi/api/v1/holiday/sign`,
{ "schoolYear": schoolYear, "step": stepId, "semester": semester },
{
headers: {
'Referer': `https://${config.serverside}.xueanquan.com/login.html`,
'Cookie': `RecordLoginInput_20083=${userAccount}; SafeApp=true; ServerSide=https://${config.serverside}.xueanquan.com; UserID=${loginRtn.data.UInfo.UserId}; _UCodeStr={%0d%0a "Grade": ${loginRtn.data.UInfo.Grade},%0d%0a "ClassRoom": ${loginRtn.data.UInfo.ClassRoom},%0d%0a "CityCode": ${loginRtn.data.UInfo.CityCode}%0d%0a};`
}
})
console.log(steps[stepId - 1], stepRtn.status, stepRtn.data.result, stepRtn.data.msg)
}
}
let methods = [_seeVideo, _doSign, _doSign2];
async function study (accounts, type, method) {
console.log(`==========================\n即将开始对 ${accounts.length} 个账号进行自动任务。`)
if (type === 0) { // 并发
accounts.map(v => method(v.split("/")[0], v.split("/")[1]))
} else if (type === 1) { // 顺次
for (processingId = 0; processingId < accounts.length; processingId++) {
console.log('==========================')
console.log('正在处理', accounts[processingId].split("/")[0], accounts[processingId].split("/")[1])
await method(accounts[processingId].split("/")[0], accounts[processingId].split("/")[1])
}
console.log('==========================\n已完成。\n==========================')
} else {
console.log('==========================\n无法理解的操作类型。\n==========================')
}
}
let accounts = config.accounts;
let method = config.willDo;
if (method === 3) {
console.log(`==========================\n欢迎使用,您已经填入了 ${accounts.length} 个账号,${config.adminCookie === "" ? "还未填写" : "已经填写了"}管理员 Cookie${config.adminCookie === "" ? ",请仔细阅读 config.js 中的注释提示" : ",请更换 willDo 中的 method 方式开始操作"}。\n操作网站: https://${config.serverside}.xueanquan.com/ ,活动省份: ${config.huodongProvince}。`)
console.log('==========================\n已完成。\n==========================')
} else study(accounts, 1, methods[method]);