Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
fix: acw_tc for user provided cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Dec 20, 2020
1 parent 90ab0fc commit 184d468
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
46 changes: 30 additions & 16 deletions campusphere/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,41 @@ class campusphereApp {
list: `${school.origin}/wec-counselor-sign-apps/stu/sign/queryDailySginTasks`,
detail: `${school.origin}/wec-counselor-sign-apps/stu/sign/detailSignTaskInst`,
sign: `${school.origin}/wec-counselor-sign-apps/stu/sign/completeSignIn`,
home: `${school.origin}/wec-counselor-sign-apps/stu/mobile`,
}
}
}

exports.signApp = class signApp extends (
campusphereApp
) {
constructor(school, cookie, user) {
constructor(school, user) {
super(school)
this.headers = {
'user-agent':
'Mozilla/5.0 (Linux; Android 10; GM1910 Build/QKQ1.190716.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.101 Mobile Safari/537.36 cpdaily/8.2.13 wisedu/8.2.13',
cookie: cookie.campusphere,
'content-type': 'application/json',
connection: 'keep-alive',
}
this.user = user
}

async signInfo() {
async getCookie(cookie) {
if (!cookie.campusphere.includes('acw_tc')) {
const res = await fetch(this.signApi.home, {
headers: this.headers,
})
res.headers.raw()['set-cookie'].forEach(e => {
cookie.campusphere += ';' + e.match(/^(\w|\d|\s)+\=(\w|\d|\s|\-)+;/)[0]
}, '')
}
return cookie.campusphere
}

async signInfo(cookie) {
// set acw_tc for user provided cookie
this.headers.cookie = await this.getCookie(cookie)

const { signApi, headers } = this
try {
const res = await fetch(signApi.list, {
Expand Down Expand Up @@ -67,7 +82,6 @@ exports.signApp = class signApp extends (
signedStuInfo,
} = signDetails.datas

log.object(signedStuInfo)
// format coordinates length
;[longitude, latitude] = this.randomLocale(signPlaceSelected[0]).map(e =>
Number(e.toFixed(6))
Expand All @@ -87,18 +101,18 @@ exports.signApp = class signApp extends (
isNeedExtra,
extraFieldItems,
}
// log.object(form)
headers['Cpdaily-Extension'] = this.extention(form)

res = await fetch(signApi.sign, {
headers,
method: 'POST',
body: JSON.stringify(form),
})
res = await res.json()
log.warning(
`${this.user.alias || this.user.username} 的签到结果: ${res.message}`
)
log.object(form)
// headers['Cpdaily-Extension'] = this.extention(form)

// res = await fetch(signApi.sign, {
// headers,
// method: 'POST',
// body: JSON.stringify(form),
// })
// res = await res.json()
// log.warning(
// `${this.user.alias || this.user.username} 的签到结果: ${res.message}`
// )
}

// construct random coordinates
Expand Down
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async function handleCookie() {
} else {
storeCookie(storeCookiePath, i)
}
sign = new signApp(school, cookie, i)
const isNeedLogIn = await sign.signInfo()
sign = new signApp(school, i)
const isNeedLogIn = await sign.signInfo(cookie)
if (isNeedLogIn) {
await reLogin(i)
try {
Expand All @@ -48,9 +48,11 @@ async function handleCookie() {
}

async function signIn(i) {
const cookie = i.cookie || conf.get(`cookie.${i.alias || i.username}`)
const sign = new signApp(school, cookie, i)
await sign.signInfo()
const cookie = i.cookie
? { campusphere: i.cookie }
: conf.get(`cookie.${i.alias || i.username}`)
const sign = new signApp(school, i)
await sign.signInfo(cookie)
await sign.signWithForm()
}

Expand Down Expand Up @@ -83,7 +85,7 @@ async function sleep(timeout) {
// Pre-loading cookie for sign in
await handleCookie()
// wait 1 minute for signing
await sleep(1)
await sleep(0)

// sign in asynchronizedly with promise all and diff instance of signApp class
Promise.all(users.map(e => signIn(e)))
Expand Down

0 comments on commit 184d468

Please sign in to comment.