Skip to content

Commit 81c7be3

Browse files
committed
添加[APK.TW]签到脚本
1 parent b6ac7ef commit 81c7be3

3 files changed

Lines changed: 279 additions & 0 deletions

File tree

‎apktw/README.md‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# APK.TW
2+
3+
> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
4+
5+
> iOS 需要网关级翻墙!
6+
7+
> iOS 需要网关级翻墙!
8+
9+
> iOS 需要网关级翻墙!
10+
11+
> surge mac 环节下无需网关级翻墙, 可直接运行 (可能需要打开增强模式)!
12+
13+
> 目前尚不清楚 Cookie 有效期如何
14+
15+
> 如果你看到这里还没放弃, 请仔细下面的操作说明 (需要点骚操作)
16+
17+
解释:
18+
19+
由于 apk.tw 需要翻墙, 又由于 iOS 的限制, Surge & QuanX 在脚本内的请求都无法走代理, 所以 iOS 环境下, 请保证本脚本在路由或网关级翻墙环境下运行!
20+
21+
## 配置 (Surge)
22+
23+
```properties
24+
[MITM]
25+
apk.tw
26+
27+
[Script]
28+
http-request ^https:\/\/apk\.tw\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.cookie.js
29+
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.js
30+
```
31+
32+
## 配置 (QuanX)
33+
34+
```properties
35+
[MITM]
36+
apk.tw
37+
38+
[rewrite_local]
39+
# 189及以前版本
40+
^https:\/\/apk\.tw\/?.? url script-response-body apktw.cookie.js
41+
# 190及以后版本
42+
^https:\/\/apk\.tw\/?.? url script-request-header apktw.cookie.js
43+
44+
[task_local]
45+
1 0 * * * apktw.js
46+
```
47+
48+
## 说明
49+
50+
> 先在登录成功后, 再打开获取 Cookie 的脚本
51+
52+
1. 先在浏览器登录 `(先登录! 先登录! 先登录!)`, https://apk.tw/
53+
2. 滑到页面底部, 点击`电脑版`, 把页面切换为电脑版, 确认登录成功后再执行下面步骤
54+
3. 先把`apk.tw`加到`[MITM]`
55+
4. 再配置重写规则:
56+
- Surge: 把两条远程脚本放到`[Script]`
57+
- QuanX: 把`apktw.cookie.js`和`apktw.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
58+
5. 打开浏览器访问: https://apk.tw
59+
6. 系统提示: `获取Cookie: 成功`
60+
7. 最后就可以把第 1 条脚本注释掉了
61+
62+
> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
63+
64+
> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次.
65+
66+
## 常见问题
67+
68+
1. 无法写入 Cookie
69+
70+
- 检查 Surge 系统通知权限放开了没
71+
- 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴)
72+
73+
2. 写入 Cookie 成功, 但签到不成功
74+
75+
- 看看是不是在登录前就写入 Cookie 了
76+
- 如果是,请确保在登录成功后,再尝试写入 Cookie
77+
78+
3. 为什么有时成功有时失败
79+
80+
- 很正常,网络问题,哪怕你是手工签到也可能失败(凌晨签到容易拥堵就容易失败)
81+
- 暂时不考虑代码级的重试机制,但咱有配置级的(暴力美学):
82+
83+
- `Surge`配置:
84+
85+
```properties
86+
# 没有什么是一顿饭解决不了的:
87+
cron "10 0 0 * * *" script-path=xxx.js # 每天00:00:10执行一次
88+
# 如果有,那就两顿:
89+
cron "20 0 0 * * *" script-path=xxx.js # 每天00:00:20执行一次
90+
# 实在不行,三顿也能接受:
91+
cron "30 0 0 * * *" script-path=xxx.js # 每天00:00:30执行一次
92+
93+
# 再粗暴点,直接:
94+
cron "* */60 * * * *" script-path=xxx.js # 每60分执行一次
95+
```
96+
97+
- `QuanX`配置:
98+
99+
```properties
100+
[task_local]
101+
1 0 * * * xxx.js # 每天00:01执行一次
102+
2 0 * * * xxx.js # 每天00:02执行一次
103+
3 0 * * * xxx.js # 每天00:03执行一次
104+
105+
*/60 * * * * xxx.js # 每60分执行一次
106+
```
107+
108+
## 感谢
109+
110+
[@NobyDa](https://github.com/NobyDa)
111+
112+
[@lhie1](https://github.com/lhie1)
113+
114+
[@ConnersHua](https://github.com/ConnersHua)
115+
116+
```
117+
<img src="./source/plugin/dsu_amupper/images/dk.gif" style="margin-bottom:-6px;">
118+
https://apk.tw/plugin.php?id=dsu_amupper:pper&ajax=1&formhash=9894bd20&zjtesttimes=1577779673&inajax=1&ajaxtarget=my_amupper
119+
:method: GET
120+
:scheme: https
121+
:authority: apk.tw
122+
:path: /plugin.php?id=dsu_amupper:pper&ajax=1&formhash=9894bd20&zjtesttimes=1577779673&inajax=1&ajaxtarget=my_amupper
123+
Accept: */*
124+
Cookie: xfhP_2132_dsu_amupper_header=PHNwYW4gY2xhc3M9InBpcGUiPnw8L3NwYW4%2BPGEgaWQ9Im15X2FtdXBwZXIiIGhyZWY9ImphdmFzY3JpcHQ6OyIgb25jbGljaz0iYWpheGdldCgncGx1Z2luLnBocD9pZD1kc3VfYW11cHBlcjpwcGVyJmFqYXg9MSZmb3JtaGFzaD05ODk0YmQyMCZ6anRlc3R0aW1lcz0xNTc3Nzc5Njc0JywgJ215X2FtdXBwZXInLCAnbXlfYW11cHBlcicsICfnsL3liLDkuK0nLCAnJyxmdW5jdGlvbiAoKSB7dG9uZXBsYXllcigwKTt9KTsiPjxpbWcgc3JjPSIuL3NvdXJjZS9wbHVnaW4vZHN1X2FtdXBwZXIvaW1hZ2VzL2RrLmdpZiIgc3R5bGU9Im1hcmdpbi1ib3R0b206LTZweDsiPjwvYT4%3D; xfhP_2132_lastact=1577779674%09home.php%09spacecp; __asc=b3c0cc6c16f5afd676092d4eda8; __auc=dce799f516f59f067237a2febb9; _ga=GA1.2.1608429304.1577761929; _gid=GA1.2.1688629439.1577761939; xfhP_2132_noticeTitle=1; xfhP_2132_nofavfid=1; xfhP_2132_sid=J87Vc1; xfhP_2132_auth=7ac24btCR%2BdI6b4lefpECmxYWj0Wn9yVqWWBGEcJbcrJJQ%2Fict%2F6dtRYiEbwRqBBA9KS0YQBQ5gi4yXDAIRIiGR8WIxb; xfhP_2132_ulastactivity=915f6BAyOWJu5e6W%2FFDdReWOBJY9iCFtYx%2BtJZFz36l7rpWBZnyF; xfhP_2132_secqaa=26426276.be83416687a9ef3d73; xfhP_2132_sendmail=1; xfhP_2132_lastvisit=1577758319; xfhP_2132_saltkey=sy5ICtnI; __cfduid=d070a2409b8f31d15ce3354ce3514c78e1577761919
125+
Accept-Language: zh-cn
126+
Host: apk.tw
127+
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15
128+
Referer: https://apk.tw/forum.php
129+
Accept-Encoding: gzip, deflate, br
130+
Connection: keep-alive
131+
X-Requested-With: XMLHttpRequest
132+
```

‎apktw/apktw.cookie.js‎

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

‎apktw/apktw.js‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const cookieName = 'APK.TW'
2+
const cookieKey = 'chavy_cookie_apktw'
3+
const chavy = init()
4+
const cookieVal = chavy.getdata(cookieKey)
5+
6+
sign()
7+
8+
function sign() {
9+
let url = { url: `https://apk.tw/`, headers: { Cookie: cookieVal } }
10+
url.headers['Host'] = 'apk.tw'
11+
url.headers['Referer'] = 'https://apk.tw/forum.php'
12+
url.headers['Accept'] = '*/*'
13+
url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'
14+
chavy.get(url, (error, response, data) => {
15+
signbbs(data.match(/\/source\/plugin\/dsu_amupper\/images\/wb\.gif/), data)
16+
})
17+
chavy.done()
18+
}
19+
20+
function signbbs(signedmatch, homedata) {
21+
const title = `${cookieName}`
22+
let subTitle = ``
23+
let detail = ``
24+
if (signedmatch) {
25+
subTitle = `签到结果: 成功 (重复签到)`
26+
chavy.msg(title, subTitle, detail)
27+
} else {
28+
const signmatch = homedata.match(/plugin.php\?id=dsu_amupper:pper([^\']*)/)
29+
if (signmatch) {
30+
let url = { url: `https://apk.tw/${signmatch[0]}&inajax=1&ajaxtarget=my_amupper`, headers: { Cookie: cookieVal } }
31+
url.headers['Host'] = 'apk.tw'
32+
url.headers['Referer'] = 'https://apk.tw/forum.php'
33+
url.headers['Accept'] = '*/*'
34+
url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'
35+
chavy.get(url, (error, response, data) => {
36+
chavy.log(`${cookieName}, data: ${data}`)
37+
if (data.match(/\/source\/plugin\/dsu_amupper\/images\/wb\.gif/)) {
38+
subTitle = `签到结果: 成功`
39+
} else {
40+
subTitle = `签到结果: 失败 (未知)`
41+
}
42+
chavy.msg(title, subTitle, detail)
43+
})
44+
} else {
45+
subTitle = `签到结果: 失败 (未知)`
46+
chavy.log(`${cookieName}, homedata: ${homedata}`)
47+
chavy.msg(title, subTitle, detail)
48+
}
49+
}
50+
}
51+
function init() {
52+
isSurge = () => {
53+
return undefined === this.$httpClient ? false : true
54+
}
55+
isQuanX = () => {
56+
return undefined === this.$task ? false : true
57+
}
58+
getdata = (key) => {
59+
if (isSurge()) return $persistentStore.read(key)
60+
if (isQuanX()) return $prefs.valueForKey(key)
61+
}
62+
setdata = (key, val) => {
63+
if (isSurge()) return $persistentStore.write(key, val)
64+
if (isQuanX()) return $prefs.setValueForKey(key, val)
65+
}
66+
msg = (title, subtitle, body) => {
67+
if (isSurge()) $notification.post(title, subtitle, body)
68+
if (isQuanX()) $notify(title, subtitle, body)
69+
}
70+
log = (message) => console.log(message)
71+
get = (url, cb) => {
72+
if (isSurge()) {
73+
$httpClient.get(url, cb)
74+
}
75+
if (isQuanX()) {
76+
url.method = 'GET'
77+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
78+
}
79+
}
80+
post = (url, cb) => {
81+
if (isSurge()) {
82+
$httpClient.post(url, cb)
83+
}
84+
if (isQuanX()) {
85+
url.method = 'POST'
86+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
87+
}
88+
}
89+
done = (value = {}) => {
90+
$done(value)
91+
}
92+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
93+
}

0 commit comments

Comments
 (0)