From eb39fb1c0461e060ba37b53401c1a7903b88fddc Mon Sep 17 00:00:00 2001 From: juzeon <812312770@qq.com> Date: Mon, 28 Feb 2022 08:35:03 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9AresetCookie=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + package.json | 4 +++- src/draw.ts | 46 +++++++++++++++++++++++++++++++++++++++ src/index.ts | 2 ++ src/poll.ts | 15 +++++++++++++ src/resetCookieRequest.ts | 4 ++++ src/test.ts | 24 ++++++++++++++++++-- 7 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 src/draw.ts create mode 100644 src/resetCookieRequest.ts diff --git a/.gitignore b/.gitignore index 166911b..93f81ae 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules/* /pnpm-lock.yaml /arr.json backup +resetCookieRequest.txt diff --git a/package.json b/package.json index 671a54e..63e623b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "main": "index.js", "scripts": { "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": "", "license": "ISC", diff --git a/src/draw.ts b/src/draw.ts new file mode 100644 index 0000000..01b22d2 --- /dev/null +++ b/src/draw.ts @@ -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() diff --git a/src/index.ts b/src/index.ts index 4e8f32f..17c231a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,10 @@ import {appConfig} from "./config" import {acquireProcess, monitProcess, replaceProcess} from "./actions" import {resetCookie, sleep} from "./includes" import {health} from "./health" +import * as fs from "fs" async function start() { + fs.writeFileSync('resetCookieRequest.txt','0') console.log('开始获取Cookie') await resetCookie() console.log('开始启动轮询进程') diff --git a/src/poll.ts b/src/poll.ts index 2eb9651..f34cd6b 100644 --- a/src/poll.ts +++ b/src/poll.ts @@ -2,6 +2,7 @@ import {IJsonCourse} from "./types" import {getTimeNow, logAndNotifyUser, resetCookie, sduAxios, sleep} from "./includes" import {appConfig} from "./config" 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' let currentErrorCount = 0 @@ -59,6 +60,7 @@ async function updateRx() { } export async function poll() { + await checkResetCookieRequest() if (appConfig.channels.includes('bx')) { await updateBx() await sleep(appConfig.interval) @@ -74,6 +76,19 @@ export async function poll() { setImmediate(poll) } +async function checkResetCookieRequest() { + let req = parseInt(fs.readFileSync('resetCookieRequest.txt').toString()) + if (req) { + try { + await resetCookie() + logAndNotifyUser('[resetCookie]成功') + fs.writeFileSync('resetCookieRequest.txt', '0') + } catch (e) { + logAndNotifyUser('[resetCookie]失败') + } + } +} + async function processError(e: Error) { currentErrorCount++ if (currentErrorCount >= 30) { diff --git a/src/resetCookieRequest.ts b/src/resetCookieRequest.ts new file mode 100644 index 0000000..082cf99 --- /dev/null +++ b/src/resetCookieRequest.ts @@ -0,0 +1,4 @@ +import * as fs from "fs" + +fs.writeFileSync('resetCookieRequest.txt','1') +console.log('已请求resetCookie') diff --git a/src/test.ts b/src/test.ts index c585622..fa2a4dc 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,5 +1,5 @@ import {appConfig} from "./config" -import {logAndNotifyUser, sduAxios} from "./includes" +import {countStr, logAndNotifyUser, sduAxios, sleep} from "./includes" import {reqBody} from "./poll" import * as fs from "fs" import {IJsonCourse} from "./types" @@ -29,7 +29,27 @@ async function test() { // for (let course of courseList) { // console.log(course.kcmc + ' ' + course.kch + ' ' + course.kxh + ' ' + course.syrs + ' ' + course.xf) // } - logAndNotifyUser('log test') + // 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()