Compare commits
10 Commits
c827b9dab9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9567fbb889 | |||
| eb39fb1c04 | |||
| a0ef04285e | |||
| 5884aadc13 | |||
| 3a927408c4 | |||
| baff19e775 | |||
| f3ff4cc95e | |||
| e6c922b881 | |||
| 99f3963d08 | |||
| dbda9e648f |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@
|
|||||||
node_modules/*
|
node_modules/*
|
||||||
/pnpm-lock.yaml
|
/pnpm-lock.yaml
|
||||||
/arr.json
|
/arr.json
|
||||||
|
backup
|
||||||
|
resetCookieRequest.txt
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
# 教务cookie
|
# 学号
|
||||||
cookie: "JSESSIONID=asd;"
|
username: "2020123456"
|
||||||
|
# 密码
|
||||||
|
password: "abcdefg123123"
|
||||||
# 在 https://qmsg.zendee.cn 获取
|
# 在 https://qmsg.zendee.cn 获取
|
||||||
qmsgKey: ""
|
qmsgKey: "15rg6s5t1h6t1s5g66"
|
||||||
## telegram api 域名
|
## telegram api 域名
|
||||||
#tgApiDomain: "api.telegram.org"
|
#tgApiDomain: "api.telegram.org"
|
||||||
## @BotFather 建立机器人获取
|
## @BotFather 建立机器人获取
|
||||||
|
|||||||
@@ -5,17 +5,22 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "ts-node src/test.ts",
|
"test": "ts-node src/test.ts",
|
||||||
"start": "ts-node src/index.ts"
|
"start": "ts-node src/index.ts",
|
||||||
|
"draw": "ts-node src/draw.ts",
|
||||||
|
"resetCookie": "ts-node src/resetCookieRequest.ts"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^16.9.1",
|
"@types/node": "^16.9.1",
|
||||||
"@types/qs": "^6.9.7",
|
"@types/qs": "^6.9.7",
|
||||||
|
"@types/tough-cookie": "^4.0.1",
|
||||||
"axios": "^0.21.4",
|
"axios": "^0.21.4",
|
||||||
|
"axios-cookiejar-support": "^1.0.1",
|
||||||
"axios-retry": "^3.1.9",
|
"axios-retry": "^3.1.9",
|
||||||
"dayjs": "^1.10.7",
|
"dayjs": "^1.10.7",
|
||||||
"qs": "^6.10.1",
|
"qs": "^6.10.1",
|
||||||
|
"tough-cookie": "^4.0.0",
|
||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.2.1",
|
||||||
"typescript": "^4.4.3",
|
"typescript": "^4.4.3",
|
||||||
"yaml": "^1.10.2"
|
"yaml": "^1.10.2"
|
||||||
|
|||||||
1029
src/des.js
Normal file
1029
src/des.js
Normal file
File diff suppressed because it is too large
Load Diff
46
src/draw.ts
Normal file
46
src/draw.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import {countStr, getTimeNow, logAndNotifyUser, resetCookie, sduAxios, sleep} from "./includes"
|
||||||
|
import * as fs from "fs"
|
||||||
|
|
||||||
|
export async function draw() {
|
||||||
|
while (true) {
|
||||||
|
let html = ''
|
||||||
|
try {
|
||||||
|
let resp = await sduAxios.get("jsxsd/xsxkjg/comeXkjglb?isktx=true")
|
||||||
|
html = JSON.stringify(resp.data)
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
if (countStr(html, 'cqOper') < 2) {
|
||||||
|
logAndNotifyUser('登录失败,重设cookie ' + getTimeNow())
|
||||||
|
try {
|
||||||
|
await resetCookie()
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (countStr(html, 'cqOper') > 2) {
|
||||||
|
logAndNotifyUser('可以抽签,正在进行抽签')
|
||||||
|
fs.writeFileSync('draw-' + Date.now() + '.html', html)
|
||||||
|
let arr = [
|
||||||
|
'2021202222605',// 英语
|
||||||
|
'2021202225984',// 周易
|
||||||
|
'2021202225817',// 刻瓷
|
||||||
|
'2021202222614',// 众智
|
||||||
|
'2021202222613',// 移动互联网
|
||||||
|
]
|
||||||
|
for (let id of arr) {
|
||||||
|
try {
|
||||||
|
let resp = await sduAxios.get('/jsxsd/xsxkjg/xscqOper?jx0404id=' + id + '&cqqk=3')// 3抽的中,2抽不中
|
||||||
|
logAndNotifyUser(JSON.stringify(resp.data))
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('轮询中:' + getTimeNow())
|
||||||
|
await sleep(1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
draw()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import {IJsonCourse} from "./types"
|
import {IJsonCourse} from "./types"
|
||||||
import {JsonCourseList} from "./poll"
|
import {JsonCourseList} from "./poll"
|
||||||
import {findJsonCourse} from "./includes"
|
import {findJsonCourse, getTimeNow} from "./includes"
|
||||||
import {appConfig} from "./config"
|
import {appConfig} from "./config"
|
||||||
import {scalarOptions} from "yaml"
|
import {scalarOptions} from "yaml"
|
||||||
import Str = scalarOptions.Str
|
import Str = scalarOptions.Str
|
||||||
@@ -33,15 +33,16 @@ export async function health() {
|
|||||||
exitNames.push(currentCourse.kcmc)
|
exitNames.push(currentCourse.kcmc)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
totalAcquireCount += parseInt(lastCourse.syrs) - parseInt(currentCourse.syrs)
|
let num = parseInt(lastCourse.syrs) - parseInt(currentCourse.syrs)
|
||||||
if (!acquireNames.includes(currentCourse.kcmc)) {
|
totalAcquireCount += num
|
||||||
|
if (!acquireNames.includes(currentCourse.kcmc) && num > 0) {
|
||||||
acquireNames.push(currentCourse.kcmc)
|
acquireNames.push(currentCourse.kcmc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('[health]实时总退课人次:' + totalExitCount + '(' + shuffle(exitNames).slice(0, 3).join(',') + '等),总选课人次:'
|
console.log('[health]实时总退课人次:' + totalExitCount + '(' + shuffle(exitNames).slice(0, 3).join(',') + '等),总选课人次:'
|
||||||
+ totalAcquireCount + '(' + shuffle(acquireNames).slice(0, 3).join(',') + '等)')
|
+ totalAcquireCount + '(' + shuffle(acquireNames).slice(0, 3).join(',') + '等) at ' + getTimeNow())
|
||||||
}
|
}
|
||||||
lastJsonCourseList = JSON.parse(JSON.stringify(JsonCourseList))
|
lastJsonCourseList = JSON.parse(JSON.stringify(JsonCourseList))
|
||||||
setTimeout(health, 60 * 1000)
|
setTimeout(health, 60 * 1000)
|
||||||
|
|||||||
102
src/includes.ts
102
src/includes.ts
@@ -3,24 +3,31 @@ import {appConfig} from "./config"
|
|||||||
import * as qs from "qs"
|
import * as qs from "qs"
|
||||||
import dayjs from "dayjs"
|
import dayjs from "dayjs"
|
||||||
import {ICourse, IJsonCourse, TChannel} from "./types"
|
import {ICourse, IJsonCourse, TChannel} from "./types"
|
||||||
import {JsonCourseList} from "./poll"
|
import {JsonCourseList, reqBody} from "./poll"
|
||||||
import axiosRetry from "axios-retry"
|
import axiosRetry from "axios-retry"
|
||||||
|
import tough from "tough-cookie"
|
||||||
|
import axiosCookieJarSupport from "axios-cookiejar-support"
|
||||||
|
import {strEnc} from "./des"
|
||||||
|
import {scalarOptions} from "yaml"
|
||||||
|
import * as process from "process"
|
||||||
|
|
||||||
let sduAxios = axios.create({
|
let sduAxios = axios.create({
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||||
'Cookie': appConfig.cookie,
|
|
||||||
'X-Requested-With': 'XMLHttpRequest',
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0'
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0',
|
||||||
},
|
},
|
||||||
baseURL: 'https://bkzhjx.wh.sdu.edu.cn/',
|
baseURL: 'https://bkzhjx.wh.sdu.edu.cn/',
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
transformResponse: data => {
|
transformResponse: data => {
|
||||||
|
try {
|
||||||
return JSON.parse(data)
|
return JSON.parse(data)
|
||||||
|
} catch (_e) {
|
||||||
|
return data
|
||||||
}
|
}
|
||||||
// maxRedirects: 0
|
},
|
||||||
|
// maxRedirects: 10
|
||||||
})
|
})
|
||||||
|
|
||||||
axiosRetry(sduAxios, {
|
axiosRetry(sduAxios, {
|
||||||
retries: 2,
|
retries: 2,
|
||||||
shouldResetTimeout: true,
|
shouldResetTimeout: true,
|
||||||
@@ -29,17 +36,21 @@ axiosRetry(sduAxios, {
|
|||||||
|
|
||||||
export async function logAndNotifyUser(text: string) {
|
export async function logAndNotifyUser(text: string) {
|
||||||
console.log(text)
|
console.log(text)
|
||||||
await axios.post('https://qmsg.zendee.cn/send/' + appConfig.qmsgKey, qs.stringify({
|
// await axios.post('https://qmsg.zendee.cn/send/' + appConfig.qmsgKey, qs.stringify({
|
||||||
msg: text
|
// msg: text
|
||||||
}), {
|
// }), {
|
||||||
headers: {
|
// headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
// 'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
try {
|
||||||
|
await axios.post('https://' + appConfig.tgApiDomain + '/bot' + appConfig.tgApiKey + '/sendMessage', qs.stringify({
|
||||||
|
chat_id: appConfig.tgChatId,
|
||||||
|
text: text
|
||||||
|
}))
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
// await axios.post('https://' + appConfig.tgApiDomain + '/bot' + appConfig.tgApiKey + '/sendMessage', qs.stringify({
|
|
||||||
// chat_id: appConfig.tgChatId,
|
|
||||||
// text: text
|
|
||||||
// }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sleep(ms: number) {
|
export function sleep(ms: number) {
|
||||||
@@ -73,6 +84,9 @@ export async function acquireCourse(course: IJsonCourse, channel: TChannel): Pro
|
|||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
logAndNotifyUser(resp.data.message)
|
logAndNotifyUser(resp.data.message)
|
||||||
|
if (resp.data.message.includes('当前账号已在别处登录')) {
|
||||||
|
await resetCookie()// TODO 加锁、优化
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -87,6 +101,9 @@ export async function exitCourse(course: IJsonCourse): Promise<boolean> {
|
|||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
logAndNotifyUser('[exitCourse]退课失败:' + resp.data.message)
|
logAndNotifyUser('[exitCourse]退课失败:' + resp.data.message)
|
||||||
|
if (resp.data.message.includes('当前账号已在别处登录')) {
|
||||||
|
await resetCookie()
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -95,4 +112,59 @@ export async function exitCourse(course: IJsonCourse): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let resetCookieLock = false
|
||||||
|
|
||||||
|
export async function resetCookie() {
|
||||||
|
if (resetCookieLock) {
|
||||||
|
console.log('resetCookie 已被锁定')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resetCookieLock = true
|
||||||
|
try {
|
||||||
|
let cookieJar = new tough.CookieJar()
|
||||||
|
let cookieAxios = axios.create({
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0'
|
||||||
|
},
|
||||||
|
timeout: 6000,
|
||||||
|
maxRedirects: 10
|
||||||
|
})
|
||||||
|
axiosCookieJarSupport(cookieAxios)
|
||||||
|
cookieAxios.defaults.jar = cookieJar
|
||||||
|
cookieAxios.defaults.withCredentials = true
|
||||||
|
await cookieAxios.get('http://bkzhjx.wh.sdu.edu.cn/sso.jsp')
|
||||||
|
let casUrl = 'https://pass.sdu.edu.cn/cas/login?service=http%3A%2F%2Fbkzhjx.wh.sdu.edu.cn%2Fsso.jsp'
|
||||||
|
let resp = await cookieAxios.get(casUrl)
|
||||||
|
let ticket = /name="lt" value="(.*?)"/.exec(resp.data)?.[1] || null
|
||||||
|
let rsa = strEnc(appConfig.username + appConfig.password + ticket, '1', '2', '3')
|
||||||
|
resp = await cookieAxios.post(casUrl, qs.stringify({
|
||||||
|
rsa,
|
||||||
|
ul: appConfig.username.length,
|
||||||
|
pl: appConfig.password.length,
|
||||||
|
lt: ticket,
|
||||||
|
execution: 'e1s1',
|
||||||
|
_eventId: 'submit'
|
||||||
|
}))
|
||||||
|
let nextUrl = 'https://bkzhjx.wh.sdu.edu.cn' + /<a href="(.*?)">进入选课/.exec(resp.data)![1]
|
||||||
|
resp = await cookieAxios.get(nextUrl)
|
||||||
|
let xkId = /jrxk\('1','(.*?)'/.exec(resp.data)![1]
|
||||||
|
nextUrl = 'https://bkzhjx.wh.sdu.edu.cn/jsxsd/xsxk/newXsxkzx?jx0502zbid=' + xkId
|
||||||
|
await cookieAxios.get(nextUrl)
|
||||||
|
await cookieAxios.get('https://bkzhjx.wh.sdu.edu.cn/jsxsd/xsxk/selectBottom?jx0502zbid=' + xkId)
|
||||||
|
let cookieString = cookieJar.getCookieStringSync('https://bkzhjx.wh.sdu.edu.cn/jsxsd/xsxk')
|
||||||
|
console.log('[cookie]取得Cookie:' + cookieString)
|
||||||
|
appConfig.cookie = cookieString
|
||||||
|
sduAxios.defaults.headers['Cookie'] = cookieString
|
||||||
|
} catch (e) {
|
||||||
|
throw e
|
||||||
|
} finally {
|
||||||
|
resetCookieLock = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function countStr(str: string, word: string) {
|
||||||
|
return str.split(word).length - 1
|
||||||
|
}
|
||||||
|
|
||||||
export {sduAxios}
|
export {sduAxios}
|
||||||
|
|||||||
11
src/index.ts
11
src/index.ts
@@ -1,10 +1,14 @@
|
|||||||
import {JsonCourseList, poll} from "./poll"
|
import {JsonCourseList, poll} from "./poll"
|
||||||
import {appConfig} from "./config"
|
import {appConfig} from "./config"
|
||||||
import {acquireProcess, monitProcess, replaceProcess} from "./actions"
|
import {acquireProcess, monitProcess, replaceProcess} from "./actions"
|
||||||
import {sleep} from "./includes"
|
import {resetCookie, sleep} from "./includes"
|
||||||
import {health} from "./health"
|
import {health} from "./health"
|
||||||
|
import * as fs from "fs"
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
|
fs.writeFileSync('resetCookieRequest.txt','0')
|
||||||
|
console.log('开始获取Cookie')
|
||||||
|
await resetCookie()
|
||||||
console.log('开始启动轮询进程')
|
console.log('开始启动轮询进程')
|
||||||
poll()
|
poll()
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -20,14 +24,19 @@ async function start() {
|
|||||||
await sleep(50)
|
await sleep(50)
|
||||||
}
|
}
|
||||||
console.log('轮询进程启动完毕')
|
console.log('轮询进程启动完毕')
|
||||||
|
for (let channel of appConfig.channels) {
|
||||||
|
console.log('channel: ' + channel + ': ' + JsonCourseList[channel].length)
|
||||||
|
}
|
||||||
console.log('开始启动用户进程')
|
console.log('开始启动用户进程')
|
||||||
for (let course of appConfig.monit?.list || []) {
|
for (let course of appConfig.monit?.list || []) {
|
||||||
monitProcess(course)
|
monitProcess(course)
|
||||||
}
|
}
|
||||||
for (let course of appConfig.acquire?.list || []) {
|
for (let course of appConfig.acquire?.list || []) {
|
||||||
|
console.log('添加抢课课程:' + course.kch + ' ' + course.kxh)
|
||||||
acquireProcess(course)
|
acquireProcess(course)
|
||||||
}
|
}
|
||||||
if (appConfig.replace) {
|
if (appConfig.replace) {
|
||||||
|
console.log('添加换课课程:' + appConfig.replace.exit.kch + ' ' + appConfig.replace.exit.kxh)
|
||||||
replaceProcess(appConfig.replace.list, appConfig.replace.exit)
|
replaceProcess(appConfig.replace.list, appConfig.replace.exit)
|
||||||
}
|
}
|
||||||
console.log('用户进程启动完毕')
|
console.log('用户进程启动完毕')
|
||||||
|
|||||||
60
src/poll.ts
60
src/poll.ts
@@ -1,10 +1,12 @@
|
|||||||
import {IJsonCourse} from "./types"
|
import {IJsonCourse} from "./types"
|
||||||
import {getTimeNow, logAndNotifyUser, sduAxios, sleep} from "./includes"
|
import {getTimeNow, logAndNotifyUser, resetCookie, sduAxios, sleep} from "./includes"
|
||||||
import {appConfig} from "./config"
|
import {appConfig} from "./config"
|
||||||
import * as qs from "qs"
|
import * as qs from "qs"
|
||||||
|
import * as fs from "fs"
|
||||||
|
|
||||||
export let reqBody = 'sEcho=1&iColumns=15&sColumns=&iDisplayStart=0&iDisplayLength=2000&mDataProp_0=kch&mDataProp_1=kcmc&mDataProp_2=kxhnew&mDataProp_3=jkfs&mDataProp_4=xmmc&mDataProp_5=fzmc&mDataProp_6=ktmc&mDataProp_7=xf&mDataProp_8=skls&mDataProp_9=sksj&mDataProp_10=skdd&mDataProp_11=xqmc&mDataProp_12=syrs&mDataProp_13=ctsm&mDataProp_14=czOper'
|
export let reqBody = 'sEcho=1&iColumns=15&sColumns=&iDisplayStart=0&iDisplayLength=2000&mDataProp_0=kch&mDataProp_1=kcmc&mDataProp_2=kxhnew&mDataProp_3=jkfs&mDataProp_4=xmmc&mDataProp_5=fzmc&mDataProp_6=ktmc&mDataProp_7=xf&mDataProp_8=skls&mDataProp_9=sksj&mDataProp_10=skdd&mDataProp_11=xqmc&mDataProp_12=syrs&mDataProp_13=ctsm&mDataProp_14=czOper'
|
||||||
let errorCount = 0
|
let currentErrorCount = 0
|
||||||
|
let totalErrorCount = 0
|
||||||
|
|
||||||
export const JsonCourseList = <{ bx: IJsonCourse[], xx: IJsonCourse[], rx: IJsonCourse[] }>{
|
export const JsonCourseList = <{ bx: IJsonCourse[], xx: IJsonCourse[], rx: IJsonCourse[] }>{
|
||||||
bx: [],
|
bx: [],
|
||||||
@@ -15,37 +17,50 @@ export const JsonCourseList = <{ bx: IJsonCourse[], xx: IJsonCourse[], rx: IJson
|
|||||||
async function updateBx() {
|
async function updateBx() {
|
||||||
try {
|
try {
|
||||||
let resp = await sduAxios.post('/jsxsd/xsxkkc/xsxkBxxk?1=1&kcxx=&skls=&skfs=&xqid=', reqBody)
|
let resp = await sduAxios.post('/jsxsd/xsxkkc/xsxkBxxk?1=1&kcxx=&skls=&skfs=&xqid=', reqBody)
|
||||||
|
if (resp.data.aaData.length) {
|
||||||
JsonCourseList.bx.length = 0
|
JsonCourseList.bx.length = 0
|
||||||
JsonCourseList.bx.push(...resp.data.aaData)
|
JsonCourseList.bx.push(...resp.data.aaData)
|
||||||
|
} else {
|
||||||
|
throw new Error(resp.data)
|
||||||
|
}
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
processError(_e as Error)
|
|
||||||
console.log('获取必修JsonList失败 at ' + getTimeNow())
|
console.log('获取必修JsonList失败 at ' + getTimeNow())
|
||||||
|
await processError(_e as Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateXx() {
|
async function updateXx() {
|
||||||
try {
|
try {
|
||||||
let resp = await sduAxios.post('/jsxsd/xsxkkc/xsxkXxxk?1=1&kcxx=&skls=&skfs=&xqid=', reqBody)
|
let resp = await sduAxios.post('/jsxsd/xsxkkc/xsxkXxxk?1=1&kcxx=&skls=&skfs=&xqid=', reqBody)
|
||||||
|
if (resp.data.aaData.length) {
|
||||||
JsonCourseList.xx.length = 0
|
JsonCourseList.xx.length = 0
|
||||||
JsonCourseList.xx.push(...resp.data.aaData)
|
JsonCourseList.xx.push(...resp.data.aaData)
|
||||||
|
} else {
|
||||||
|
throw new Error(resp.data)
|
||||||
|
}
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
processError(_e as Error)
|
|
||||||
console.log('获取限选JsonList失败 at ' + getTimeNow())
|
console.log('获取限选JsonList失败 at ' + getTimeNow())
|
||||||
|
await processError(_e as Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateRx() {
|
async function updateRx() {
|
||||||
try {
|
try {
|
||||||
let resp = await sduAxios.post('/jsxsd/xsxkkc/xsxkGgxxkxk?kcxx=&skls=&skxq=&skjc=&sfym=false&sfct=false&szjylb=&sfxx=true&skfs=&xqid=', reqBody)
|
let resp = await sduAxios.post('/jsxsd/xsxkkc/xsxkGgxxkxk?kcxx=&skls=&skxq=&skjc=&sfym=false&sfct=false&szjylb=&sfxx=true&skfs=&xqid=', reqBody)
|
||||||
|
if (resp.data.aaData.length) {
|
||||||
JsonCourseList.rx.length = 0
|
JsonCourseList.rx.length = 0
|
||||||
JsonCourseList.rx.push(...resp.data.aaData)
|
JsonCourseList.rx.push(...resp.data.aaData)
|
||||||
|
} else {
|
||||||
|
throw new Error(resp.data)
|
||||||
|
}
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
processError(_e as Error)
|
|
||||||
console.log('获取任选JsonList失败 at ' + getTimeNow())
|
console.log('获取任选JsonList失败 at ' + getTimeNow())
|
||||||
|
await processError(_e as Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function poll() {
|
export async function poll() {
|
||||||
|
await checkResetCookieRequest()
|
||||||
if (appConfig.channels.includes('bx')) {
|
if (appConfig.channels.includes('bx')) {
|
||||||
await updateBx()
|
await updateBx()
|
||||||
await sleep(appConfig.interval)
|
await sleep(appConfig.interval)
|
||||||
@@ -61,12 +76,35 @@ export async function poll() {
|
|||||||
setImmediate(poll)
|
setImmediate(poll)
|
||||||
}
|
}
|
||||||
|
|
||||||
function processError(e: Error) {
|
async function checkResetCookieRequest() {
|
||||||
if (errorCount != -1) {
|
let req = parseInt(fs.readFileSync('resetCookieRequest.txt').toString())
|
||||||
errorCount++
|
if (req) {
|
||||||
if (errorCount >= 30) {
|
try {
|
||||||
logAndNotifyUser('[error]出现轮询error过多,请检查。上一次异常信息:' + e.message)
|
await resetCookie()
|
||||||
errorCount = -1
|
logAndNotifyUser('[resetCookie]成功')
|
||||||
|
fs.writeFileSync('resetCookieRequest.txt', '0')
|
||||||
|
} catch (e) {
|
||||||
|
logAndNotifyUser('[resetCookie]失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function processError(e: Error) {
|
||||||
|
currentErrorCount++
|
||||||
|
if (currentErrorCount >= 30) {
|
||||||
|
console.log('[error]出现轮询error过多,进行重新登录。上一次异常信息:' + e.message)
|
||||||
|
try {
|
||||||
|
await resetCookie()
|
||||||
|
currentErrorCount = 0
|
||||||
|
} catch (_e) {
|
||||||
|
console.log('[error]重新登录失败')
|
||||||
|
}
|
||||||
|
if (totalErrorCount != -1) {
|
||||||
|
totalErrorCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (totalErrorCount >= 10) {
|
||||||
|
logAndNotifyUser('[error]重新登录失败次数过多,请检查 at ' + getTimeNow())
|
||||||
|
totalErrorCount = -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
4
src/resetCookieRequest.ts
Normal file
4
src/resetCookieRequest.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import * as fs from "fs"
|
||||||
|
|
||||||
|
fs.writeFileSync('resetCookieRequest.txt','1')
|
||||||
|
console.log('已请求resetCookie')
|
||||||
42
src/test.ts
42
src/test.ts
@@ -1,5 +1,5 @@
|
|||||||
import {appConfig} from "./config"
|
import {appConfig} from "./config"
|
||||||
import {sduAxios} from "./includes"
|
import {countStr, logAndNotifyUser, sduAxios, sleep} from "./includes"
|
||||||
import {reqBody} from "./poll"
|
import {reqBody} from "./poll"
|
||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
import {IJsonCourse} from "./types"
|
import {IJsonCourse} from "./types"
|
||||||
@@ -19,15 +19,37 @@ async function test() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sduAxios.defaults.headers['Cookie'] = 'bzb_jsxsd=91B210AA0E876E6C973D8CD52DBB9A5C; bzb_njw=705AF60821F8C9A23CB373F2A0369B85; SERVERID=121'
|
||||||
let resp = await sduAxios.post('/jsxsd/xsxkkc/xsxkGgxxkxk?kcxx=&skls=&skxq=&skjc=&sfym=false&sfct=false&szjylb=&sfxx=true&skfs=&xqid=', reqBody)
|
// let resp = await sduAxios.post('/jsxsd/xsxkkc/xsxkGgxxkxk?kcxx=&skls=&skxq=&skjc=&sfym=false&sfct=false&szjylb=&sfxx=true&skfs=&xqid=', reqBody)
|
||||||
fs.writeFileSync('arr.json', JSON.stringify(resp.data.aaData, null, 2))
|
// console.log(resp.data)
|
||||||
let courseList: IJsonCourse[] = resp.data.aaData
|
// fs.writeFileSync('arr.json', JSON.stringify(resp.data.aaData, null, 2))
|
||||||
courseList = courseList.filter(single => single.kcmc.includes('稷下创新')
|
// let courseList: IJsonCourse[] = resp.data.aaData
|
||||||
&& single.xf >= 2)
|
// courseList = courseList.filter(single => single.kcmc.includes('稷下创新')
|
||||||
for (let course of courseList) {
|
// && single.xf >= 2)
|
||||||
console.log(course.kcmc + ' ' + course.kch + ' ' + course.kxh + ' ' + course.syrs + ' ' + course.xf)
|
// for (let course of courseList) {
|
||||||
}
|
// console.log(course.kcmc + ' ' + course.kch + ' ' + course.kxh + ' ' + course.syrs + ' ' + course.xf)
|
||||||
|
// }
|
||||||
|
// let lastData = ''
|
||||||
|
// let first=true
|
||||||
|
// let count=0
|
||||||
|
// while (true) {
|
||||||
|
// let resp = await sduAxios.get("jsxsd/xsxkjg/comeXkjglb?isktx=true", {
|
||||||
|
// headers: {
|
||||||
|
// 'Cookie': 'bzb_jsxsd=329BCA4E7D8E2421309B14C02587784F; bzb_njw=55FFC1D9D9B2EF5A10D3F28BEC294AE1; SERVERID=123'
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// if (resp.data !== lastData && !first) {
|
||||||
|
// logAndNotifyUser('可以抽签了')
|
||||||
|
// first=false
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// lastData = resp.data
|
||||||
|
// console.log('rotate '+count)
|
||||||
|
// count++
|
||||||
|
// await sleep(1000)
|
||||||
|
// }
|
||||||
|
let str=fs.readFileSync('backup/2.html')
|
||||||
|
console.log(countStr(JSON.stringify(str.toString()),'cqOper'))
|
||||||
}
|
}
|
||||||
|
|
||||||
test()
|
test()
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import {scalarOptions} from "yaml"
|
||||||
|
import Str = scalarOptions.Str
|
||||||
|
|
||||||
export type TChannel = 'bx' | 'xx' | 'rx'
|
export type TChannel = 'bx' | 'xx' | 'rx'
|
||||||
|
|
||||||
export interface ICourse {
|
export interface ICourse {
|
||||||
@@ -7,6 +10,8 @@ export interface ICourse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IAppConfig {
|
export interface IAppConfig {
|
||||||
|
username: string,
|
||||||
|
password: string,
|
||||||
cookie: string,
|
cookie: string,
|
||||||
qmsgKey: string,
|
qmsgKey: string,
|
||||||
tgApiDomain: string,
|
tgApiDomain: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user