Skip to content

Commit 4663bea

Browse files
committed
添加[CSDN]签到脚本
1 parent 5f18f1b commit 4663bea

5 files changed

Lines changed: 282 additions & 1 deletion

File tree

‎QuantumultX_Local_Cookie.conf‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
hostname = wapside.189.cn, *.acfun.cn, apk.tw, *.bilibili.com, api.dongqiudi.com, *.feng.com, www.flyertea.com, music.163.com, *.m.163.com, user.qunar.com, *.rr.tv, *.weixinjia.net, *.smzdm.com, tieba.baidu.com, *.v2ex.com, *.video.qq.com, mobwsa.ximalaya.com, *.you.163.com, *.rrys2019.com, ios.zmzapi.com
1+
hostname = *.csdn.net, wapside.189.cn, *.acfun.cn, apk.tw, *.bilibili.com, api.dongqiudi.com, *.feng.com, www.flyertea.com, music.163.com, *.m.163.com, user.qunar.com, *.rr.tv, *.weixinjia.net, *.smzdm.com, tieba.baidu.com, *.v2ex.com, *.video.qq.com, mobwsa.ximalaya.com, *.you.163.com, *.rrys2019.com, ios.zmzapi.com
22

33
# 电信营业厅
44
# 190及以后版本
@@ -23,6 +23,10 @@ hostname = wapside.189.cn, *.acfun.cn, apk.tw, *.bilibili.com, api.dongqiudi.com
2323
# 190及以后版本
2424
^https:\/\/(www|live)\.bilibili\.com\/?.? url script-request-header chavyleung/bilibili/bilibili.cookie.js
2525

26+
# CSDN
27+
^https:\/\/passport.csdn.net\/v1\/api\/app\/login\/checkToken url script-request-header chavyleung/csdn/csdn.cookie.js
28+
^https:\/\/gw.csdn.net\/mini-app\/v2\/lucky_draw\/login\/sign_in\? url script-request-header chavyleung/csdn/csdn.cookie.js
29+
2630
# 懂球帝
2731
# 189及以前版本
2832
# ^https:\/\/api\.dongqiudi\.com\/v2\/user\/is_login url script-response-body chavyleung/dongqiudi/dongqiudi.cookie.js

‎QuantumultX_Local_Task.conf‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@
3838
# 4 0 * * * chavyleung/yanxuan/yanxuan.js
3939
# 字幕组
4040
3 0 * * * chavyleung/zimuzu/zimuzu.js
41+
# CSDN
42+
4 0 * * * chavyleung/csdn/csdn.js

‎csdn/README.md‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# CSDN
2+
3+
> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
4+
5+
## 配置 (Surge)
6+
7+
```properties
8+
[MITM]
9+
*.csdn.net
10+
11+
[Script]
12+
# 注意获取Cookie有两条脚本
13+
http-request ^https:\/\/passport.csdn.net\/v1\/api\/app\/login\/checkToken script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/csdn.cookie.js
14+
http-request ^https:\/\/gw.csdn.net\/mini-app\/v2\/lucky_draw\/login\/sign_in\? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/csdn.cookie.js
15+
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/csdn/csdn.js
16+
```
17+
18+
## 配置 (QuanX)
19+
20+
```properties
21+
[MITM]
22+
*.csdn.net
23+
24+
[rewrite_local]
25+
# 注意获取Cookie有两条脚本
26+
^https:\/\/passport.csdn.net\/v1\/api\/app\/login\/checkToken url script-request-header csdn.cookie.js
27+
^https:\/\/gw.csdn.net\/mini-app\/v2\/lucky_draw\/login\/sign_in\? url script-request-header csdn.cookie.js
28+
29+
[task_local]
30+
1 0 * * * csdn.js
31+
```
32+
33+
## 说明
34+
35+
1. 先把`*.csdn.net`加到`[MITM]`
36+
2. 再配置重写规则:
37+
- Surge: 把两条远程脚本放到`[Script]`
38+
- QuanX: 把`csdn.cookie.js`和`csdn.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
39+
3. 打开 APP , 系统提示: `获取刷新链接: 成功`
40+
4. 然后手动签到 1 次, 系统提示: `获取Cookie: 成功`
41+
5. 最后就可以把两条脚本注释掉了
42+
6. 运行一次脚本, 如果提示重复签到, 那就算成功了!
43+
44+
> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
45+
46+
> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次.
47+
48+
## 常见问题
49+
50+
1. 无法写入 Cookie
51+
52+
- 检查 Surge 系统通知权限放开了没
53+
- 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴)
54+
55+
2. 写入 Cookie 成功, 但签到不成功
56+
57+
- 看看是不是在登录前就写入 Cookie 了
58+
- 如果是,请确保在登录成功后,再尝试写入 Cookie
59+
60+
3. 为什么有时成功有时失败
61+
62+
- 很正常,网络问题,哪怕你是手工签到也可能失败(凌晨签到容易拥堵就容易失败)
63+
- 暂时不考虑代码级的重试机制,但咱有配置级的(暴力美学):
64+
65+
- `Surge`配置:
66+
67+
```properties
68+
# 没有什么是一顿饭解决不了的:
69+
cron "10 0 0 * * *" script-path=xxx.js # 每天00:00:10执行一次
70+
# 如果有,那就两顿:
71+
cron "20 0 0 * * *" script-path=xxx.js # 每天00:00:20执行一次
72+
# 实在不行,三顿也能接受:
73+
cron "30 0 0 * * *" script-path=xxx.js # 每天00:00:30执行一次
74+
75+
# 再粗暴点,直接:
76+
cron "* */60 * * * *" script-path=xxx.js # 每60分执行一次
77+
```
78+
79+
- `QuanX`配置:
80+
81+
```properties
82+
[task_local]
83+
1 0 * * * xxx.js # 每天00:01执行一次
84+
2 0 * * * xxx.js # 每天00:02执行一次
85+
3 0 * * * xxx.js # 每天00:03执行一次
86+
87+
*/60 * * * * xxx.js # 每60分执行一次
88+
```
89+
90+
## 感谢
91+
92+
[@NobyDa](https://github.com/NobyDa)
93+
94+
[@lhie1](https://github.com/lhie1)
95+
96+
[@ConnersHua](https://github.com/ConnersHua)

‎csdn/csdn.cookie.js‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const cookieName = 'CSDN'
2+
const tokenurlKey = 'chavy_tokenurl_csdn'
3+
const tokenheaderKey = 'chavy_tokenheader_csdn'
4+
const signurlKey = 'chavy_signurl_csdn'
5+
const signheaderKey = 'chavy_signheader_csdn'
6+
const chavy = init()
7+
8+
let title = ``
9+
let detail = ``
10+
if ($request && $request.method != 'OPTIONS' && $request.headers.Host == 'passport.csdn.net') {
11+
const tokenurlVal = $request.url
12+
const tokenheaderVal = JSON.stringify($request.headers)
13+
if (tokenurlVal) chavy.setdata(tokenurlVal, tokenurlKey)
14+
if (tokenheaderVal) chavy.setdata(tokenheaderVal, tokenheaderKey)
15+
title = `获取刷新链接: 成功`
16+
detail = `请进入 "我的>签到" 并手动签到1次`
17+
chavy.msg(`${cookieName}`, title, detail)
18+
} else if ($request && $request.method != 'OPTIONS' && $request.headers.Host == 'gw.csdn.net') {
19+
const signurlVal = $request.url
20+
const signheaderVal = JSON.stringify($request.headers)
21+
if (signurlVal) chavy.setdata(signurlVal, signurlKey)
22+
if (signheaderVal) chavy.setdata(signheaderVal, signheaderKey)
23+
title = `获取Cookie: 成功 (手动签到)`
24+
chavy.msg(`${cookieName}`, title, detail)
25+
}
26+
27+
function init() {
28+
isSurge = () => {
29+
return undefined === this.$httpClient ? false : true
30+
}
31+
isQuanX = () => {
32+
return undefined === this.$task ? false : true
33+
}
34+
getdata = (key) => {
35+
if (isSurge()) return $persistentStore.read(key)
36+
if (isQuanX()) return $prefs.valueForKey(key)
37+
}
38+
setdata = (key, val) => {
39+
if (isSurge()) return $persistentStore.write(key, val)
40+
if (isQuanX()) return $prefs.setValueForKey(key, val)
41+
}
42+
msg = (title, subtitle, body) => {
43+
if (isSurge()) $notification.post(title, subtitle, body)
44+
if (isQuanX()) $notify(title, subtitle, body)
45+
}
46+
log = (message) => console.log(message)
47+
get = (url, cb) => {
48+
if (isSurge()) {
49+
$httpClient.get(url, cb)
50+
}
51+
if (isQuanX()) {
52+
url.method = 'GET'
53+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
54+
}
55+
}
56+
post = (url, cb) => {
57+
if (isSurge()) {
58+
$httpClient.post(url, cb)
59+
}
60+
if (isQuanX()) {
61+
url.method = 'POST'
62+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
63+
}
64+
}
65+
done = (value = {}) => {
66+
$done(value)
67+
}
68+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
69+
}
70+
chavy.done()

‎csdn/csdn.js‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
const cookieName = 'CSDN'
2+
const tokenurlKey = 'chavy_tokenurl_csdn'
3+
const tokenheaderKey = 'chavy_tokenheader_csdn'
4+
const signurlKey = 'chavy_signurl_csdn'
5+
const signheaderKey = 'chavy_signheader_csdn'
6+
const chavy = init()
7+
const tokenurlVal = chavy.getdata(tokenurlKey)
8+
const tokenheaderVal = chavy.getdata(tokenheaderKey)
9+
const signurlVal = chavy.getdata(signurlKey)
10+
let signheaderVal = chavy.getdata(signheaderKey)
11+
12+
sign()
13+
14+
function sign() {
15+
loginapp((logininfo) => {
16+
if (logininfo.code == '0') {
17+
const url = { url: signurlVal, headers: JSON.parse(signheaderVal) }
18+
url.body = '{}'
19+
chavy.post(url, (error, response, data) => {
20+
chavy.log(`${cookieName}, data: ${data}`)
21+
const title = `${cookieName}`
22+
let subTitle = ''
23+
let detail = ''
24+
let result = JSON.parse(data)
25+
if (result.code == 200) {
26+
if (result.data.isSigned === false) {
27+
subTitle = `签到结果: 成功`
28+
detail = `共签: ${result.data.totalCount}天, 连签: ${result.data.keepCount}天`
29+
} else if (result.data.isSigned === true) {
30+
subTitle = `签到结果: 成功 (重复签到)`
31+
} else {
32+
subTitle = `签到结果: 失败`
33+
detail = `编码: ${result.code}, 说明: ${result.msg}`
34+
}
35+
} else {
36+
subTitle = `签到结果: 失败`
37+
detail = `说明: 详见日志`
38+
}
39+
chavy.msg(title, subTitle, detail)
40+
chavy.done()
41+
})
42+
chavy.done()
43+
} else {
44+
const title = `${cookieName}`
45+
const subTitle = '签到结果: 失败'
46+
const detail = `原因: ${logininfo.message}`
47+
chavy.msg(title, subTitle, detail)
48+
chavy.log(`${cookieName}, ${subTitle}, ${detail}`)
49+
chavy.done()
50+
}
51+
})
52+
}
53+
54+
function loginapp(cb) {
55+
const url = { url: tokenurlVal, headers: JSON.parse(tokenheaderVal) }
56+
chavy.get(url, (error, response, data) => {
57+
chavy.log(`${cookieName}, loginapp: ${data}`)
58+
let result = JSON.parse(data)
59+
let signheaderObj = JSON.parse(signheaderVal)
60+
signheaderObj['JWT-TOKEN'] = result.data.token
61+
signheaderObj['Cookie'] = signheaderObj['Cookie'].replace(/JWT-TOKEN=[^;]*/, `JWT-TOKEN=${result.data.token}`)
62+
signheaderVal = JSON.stringify(signheaderObj)
63+
cb(result)
64+
})
65+
}
66+
67+
function init() {
68+
isSurge = () => {
69+
return undefined === this.$httpClient ? false : true
70+
}
71+
isQuanX = () => {
72+
return undefined === this.$task ? false : true
73+
}
74+
getdata = (key) => {
75+
if (isSurge()) return $persistentStore.read(key)
76+
if (isQuanX()) return $prefs.valueForKey(key)
77+
}
78+
setdata = (key, val) => {
79+
if (isSurge()) return $persistentStore.write(key, val)
80+
if (isQuanX()) return $prefs.setValueForKey(key, val)
81+
}
82+
msg = (title, subtitle, body) => {
83+
if (isSurge()) $notification.post(title, subtitle, body)
84+
if (isQuanX()) $notify(title, subtitle, body)
85+
}
86+
log = (message) => console.log(message)
87+
get = (url, cb) => {
88+
if (isSurge()) {
89+
$httpClient.get(url, cb)
90+
}
91+
if (isQuanX()) {
92+
url.method = 'GET'
93+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
94+
}
95+
}
96+
post = (url, cb) => {
97+
if (isSurge()) {
98+
$httpClient.post(url, cb)
99+
}
100+
if (isQuanX()) {
101+
url.method = 'POST'
102+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
103+
}
104+
}
105+
done = (value = {}) => {
106+
$done(value)
107+
}
108+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
109+
}

0 commit comments

Comments
 (0)