Skip to content

Commit d82869e

Browse files
committed
更新[腾讯视频]签到脚本: 完善Cookie刷新机制
1 parent 56aabe9 commit d82869e

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

‎videoqq/videoqq.js‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,34 @@ function sign() {
1313
if (authUrlVal && authHeaderVal) {
1414
const url = { url: authUrlVal, headers: JSON.parse(authHeaderVal) }
1515
chavy.get(url, (error, response, data) => {
16-
chavy.log(`${cookieName}, auth_refresh - data: ${data}`)
17-
chavy.log(`${cookieName}, auth_refresh - oldCookie: ${cookieVal}`)
18-
let result = JSON.parse(data.match(/\(([^\)]*)\)/)[1])
16+
// chavy.log(`${cookieName}, auth_refresh - data: ${data}`)
17+
// chavy.log(`${cookieName}, auth_refresh - old-cookie: ${cookieVal}`)
18+
// chavy.log(`${cookieName}, auth_refresh - set-cookie: ${response.headers['Set-Cookie']}`)
19+
const result = JSON.parse(data.match(/\(([^\)]*)\)/)[1])
20+
let respcookie = response.headers['Set-Cookie']
21+
// chavy.log(`${cookieName}, auth_refresh - Expires: ${respcookie.indexOf('Expires=') >= 0 ? respcookie.match(/Expires=(.*?)GMT/)[1] : '无'}`)
22+
respcookie = respcookie.replace(/Expires=(.*?)GMT,? ?/g, '')
23+
respcookie = respcookie.replace(/Path=(.*?); ?/g, '')
24+
respcookie = respcookie.replace(/Domain=(.*?); ?/g, '')
25+
respcookie = respcookie.replace(/;$/g, '')
1926
if (result.errcode == 0) {
20-
if (result.vuserid) cookieVal = cookieVal.replace(/vuserid=[^;]*/, `vuserid=${result.vuserid}`)
21-
if (result.vusession) cookieVal = cookieVal.replace(/vusession=[^;]*/, `vusession=${result.vusession}`)
22-
if (result.next_refresh_time) cookieVal = cookieVal.replace(/next_refresh_time=[^;]*/, `next_refresh_time=${result.next_refresh_time}`)
23-
if (result.access_token) cookieVal = cookieVal.replace(/access_token=[^;]*/, `access_token=${result.access_token}`)
24-
chavy.log(`${cookieName}, auth_refresh - newCookie: ${cookieVal}`)
27+
for (setcookie of respcookie.split(';')) {
28+
const setcookieKey = setcookie.split('=')[0]
29+
const setcookieVal = setcookie.split('=')[1]
30+
if (setcookieKey && cookieVal.indexOf(setcookieKey) >= 0) {
31+
cookieVal = cookieVal.replace(new RegExp(`${setcookieKey}=[^;]*`), `${setcookieKey}=${setcookieVal}`)
32+
} else {
33+
cookieVal += `; ${setcookieKey}=${setcookieVal}`
34+
}
35+
// chavy.log(`${cookieName}, auth_refresh - set-cookie: ${setcookieKey} = ${setcookieVal}`)
36+
}
37+
for (resultcookie in result) {
38+
if (cookieVal.indexOf(resultcookie) >= 0) {
39+
cookieVal = cookieVal.replace(new RegExp(`${resultcookie}=[^;]*`, 'g'), `${resultcookie}=${result[resultcookie]}`)
40+
// chavy.log(`${cookieName}, auth_refresh - ret-cookie: ${resultcookie} = ${result[resultcookie]}`)
41+
}
42+
}
43+
// chavy.log(`${cookieName}, auth_refresh - new-cookie: ${cookieVal}`)
2544
chavy.setdata(cookieVal, cookieKey)
2645
signapp()
2746
}
@@ -31,6 +50,8 @@ function sign() {
3150
}
3251
}
3352

53+
function refreshSetCookie() {}
54+
3455
function signapp() {
3556
const timestamp = Math.round(new Date().getTime() / 1000).toString()
3657
let url = { url: `https://vip.video.qq.com/fcgi-bin/comm_cgi?name=hierarchical_task_system&cmd=2&_=${timestamp}`, headers: { Cookie: cookieVal } }
@@ -107,7 +128,7 @@ function init() {
107128
}
108129
if (isQuanX()) {
109130
url.method = 'GET'
110-
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
131+
$task.fetch(url).then((resp) => cb(null, resp, resp.body))
111132
}
112133
}
113134
post = (url, cb) => {
@@ -116,7 +137,7 @@ function init() {
116137
}
117138
if (isQuanX()) {
118139
url.method = 'POST'
119-
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
140+
$task.fetch(url).then((resp) => cb(null, resp, resp.body))
120141
}
121142
}
122143
done = (value = {}) => {

0 commit comments

Comments
 (0)