Skip to content

Commit 9d75d65

Browse files
committed
添加[AcFun]签到脚本 (beta)
1 parent 43502e5 commit 9d75d65

3 files changed

Lines changed: 255 additions & 0 deletions

File tree

acfun/README.md

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

acfun/acfun.cookie.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const cookieName = 'AcFun'
2+
const cookieKey = 'chavy_cookie_acfun'
3+
const tokenKey = 'chavy_token_acfun'
4+
const chavy = init()
5+
const cookieVal = $request.headers['Cookie']
6+
const tokenVal = $request.headers['access_token']
7+
if (cookieVal) {
8+
if (chavy.setdata(cookieVal, cookieKey)) {
9+
chavy.msg(`${cookieName}`, '获取Cookie: 成功', '')
10+
chavy.log(`[${cookieName}] 获取Cookie: 成功, cookie: ${cookieVal}`)
11+
}
12+
if (chavy.setdata(tokenVal, tokenKey)) {
13+
chavy.msg(`${cookieName}`, '获取Token: 成功', '')
14+
chavy.log(`[${cookieName}] 获取Token: 成功, token: ${tokenVal}`)
15+
}
16+
}
17+
18+
function init() {
19+
isSurge = () => {
20+
return undefined === this.$httpClient ? false : true
21+
}
22+
isQuanX = () => {
23+
return undefined === this.$task ? false : true
24+
}
25+
getdata = (key) => {
26+
if (isSurge()) return $persistentStore.read(key)
27+
if (isQuanX()) return $prefs.valueForKey(key)
28+
}
29+
setdata = (key, val) => {
30+
if (isSurge()) return $persistentStore.write(key, val)
31+
if (isQuanX()) return $prefs.setValueForKey(key, val)
32+
}
33+
msg = (title, subtitle, body) => {
34+
if (isSurge()) $notification.post(title, subtitle, body)
35+
if (isQuanX()) $notify(title, subtitle, body)
36+
}
37+
log = (message) => console.log(message)
38+
get = (url, cb) => {
39+
if (isSurge()) {
40+
$httpClient.get(url, cb)
41+
}
42+
if (isQuanX()) {
43+
url.method = 'GET'
44+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
45+
}
46+
}
47+
post = (url, cb) => {
48+
if (isSurge()) {
49+
$httpClient.post(url, cb)
50+
}
51+
if (isQuanX()) {
52+
url.method = 'POST'
53+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
54+
}
55+
}
56+
done = (value = {}) => {
57+
$done(value)
58+
}
59+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
60+
}
61+
chavy.done()

acfun/acfun.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
const cookieName = 'AcFun'
2+
const cookieKey = 'chavy_cookie_acfun'
3+
const tokenKey = 'chavy_token_acfun'
4+
const chavy = init()
5+
const cookieVal = chavy.getdata(cookieKey)
6+
const tokenVal = chavy.getdata(tokenKey)
7+
8+
sign()
9+
10+
function sign() {
11+
let url = { url: `https://api-new.acfunchina.com/rest/app/user/signIn`, headers: { Cookie: cookieVal } }
12+
url.headers['access_token'] = `${tokenVal}`
13+
url.headers['acPlatform'] = 'IPHONE'
14+
url.headers['User-Agent'] = 'AcFun/6.14.2 (iPhone; iOS 13.3; Scale/2.00)'
15+
url.body = `access_token=${cookieVal}`
16+
chavy.post(url, (error, response, data) => {
17+
const result = JSON.parse(data)
18+
const title = `${cookieName}`
19+
let subTitle = ``
20+
let detail = ``
21+
if (result.result == 0 || result.result == 122) {
22+
getinfo(result)
23+
} else {
24+
subTitle = `签到结果: 失败`
25+
detail = `编码: ${result.result}, 说明: ${result.error_msg}`
26+
chavy.msg(title, subTitle, detail)
27+
}
28+
chavy.log(`${cookieName}, data: ${data}`)
29+
})
30+
chavy.done()
31+
}
32+
33+
function getinfo(signresult) {
34+
let url = { url: `https://api-new.acfunchina.com/rest/app/user/hasSignedIn`, headers: { Cookie: cookieVal } }
35+
url.headers['access_token'] = `${tokenVal}`
36+
url.headers['acPlatform'] = 'IPHONE'
37+
url.headers['User-Agent'] = 'AcFun/6.14.2 (iPhone; iOS 13.3; Scale/2.00)'
38+
url.body = `access_token=${cookieVal}`
39+
chavy.post(url, (error, response, data) => {
40+
const result = JSON.parse(data)
41+
const title = `${cookieName}`
42+
let subTitle = ``
43+
let detail = ``
44+
if (signresult.result == 0) {
45+
subTitle = `签到结果: 成功`
46+
} else if (signresult.result == 122) {
47+
subTitle = `签到结果: 成功 (重复签到)`
48+
}
49+
detail = `共签: ${result.cumulativeDays}次, 连签: ${result.continuousDays}次, 说明: ${signresult.msg}`
50+
chavy.msg(title, subTitle, detail)
51+
chavy.log(`${cookieName}, data: ${data}`)
52+
})
53+
}
54+
55+
function init() {
56+
isSurge = () => {
57+
return undefined === this.$httpClient ? false : true
58+
}
59+
isQuanX = () => {
60+
return undefined === this.$task ? false : true
61+
}
62+
getdata = (key) => {
63+
if (isSurge()) return $persistentStore.read(key)
64+
if (isQuanX()) return $prefs.valueForKey(key)
65+
}
66+
setdata = (key, val) => {
67+
if (isSurge()) return $persistentStore.write(key, val)
68+
if (isQuanX()) return $prefs.setValueForKey(key, val)
69+
}
70+
msg = (title, subtitle, body) => {
71+
if (isSurge()) $notification.post(title, subtitle, body)
72+
if (isQuanX()) $notify(title, subtitle, body)
73+
}
74+
log = (message) => console.log(message)
75+
get = (url, cb) => {
76+
if (isSurge()) {
77+
$httpClient.get(url, cb)
78+
}
79+
if (isQuanX()) {
80+
url.method = 'GET'
81+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
82+
}
83+
}
84+
post = (url, cb) => {
85+
if (isSurge()) {
86+
$httpClient.post(url, cb)
87+
}
88+
if (isQuanX()) {
89+
url.method = 'POST'
90+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
91+
}
92+
}
93+
done = (value = {}) => {
94+
$done(value)
95+
}
96+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
97+
}

0 commit comments

Comments
 (0)