Skip to content

Commit 7c8b239

Browse files
committed
更新[ApkTw]: 调整获取会话方式
1 parent a32fdfc commit 7c8b239

7 files changed

+124
-174
lines changed

QuantumultX_AppStore_Local_Cookie.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning
1010
^https:\/\/api\-new\.app\.acfun\.cn\/rest\/app\/user\/personalInfo url script-request-header chavyleung/acfun/acfun.cookie.js
1111

1212
# APK.TW
13-
^https:\/\/apk\.tw\/?.? url script-request-header chavyleung/apktw/apktw.cookie.js
13+
^https://apk.tw\/member.php(.*?)action=login url script-request-body chavyleung/apktw/apktw.cookie.js
1414

1515
# bilibili
1616
^https:\/\/(www|live)\.bilibili\.com\/?.? url script-request-header chavyleung/bilibili/bilibili.cookie.js

QuantumultX_Local_Cookie.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning
1010
^https:\/\/api\-new\.app\.acfun\.cn\/rest\/app\/user\/personalInfo url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/acfun/acfun.cookie.js
1111

1212
# APK.TW
13-
^https:\/\/apk\.tw\/?.? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.cookie.js
13+
^https://apk.tw\/member.php(.*?)action=login url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.cookie.js
1414

1515
# bilibili
1616
^https:\/\/(www|live)\.bilibili\.com\/?.? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.cookie.js

apktw/README.md

+6-33
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
# APK.TW
22

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 环境下, 请保证本脚本在路由或网关级翻墙环境下运行!
3+
> 调整获取会话正则 (使用账号密码登录获取)
204
215
## 配置 (Surge)
226

@@ -25,7 +9,7 @@
259
apk.tw
2610

2711
[Script]
28-
http-request ^https:\/\/apk\.tw\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.cookie.js
12+
http-request ^https://apk.tw\/member.php(.*?)action=login script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.cookie.js,requires-body=true
2913
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.js
3014
```
3115

@@ -36,28 +20,17 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr
3620
apk.tw
3721

3822
[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
23+
^https://apk.tw\/member.php(.*?)action=login url script-request-body apktw.cookie.js
4324

4425
[task_local]
4526
1 0 * * * apktw.js
4627
```
4728

4829
## 说明
4930

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 条脚本注释掉了
31+
1. 访问: `https://apk.tw/` (如果你已经登录, 请先注销)
32+
2. 使用账号密码登录
33+
3. 系统提示: `获取会话: 成功` (以登录成功后弹出的通知为准!)
6134

6235
> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
6336

apktw/apktw.cookie.js

+27-53
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,28 @@
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}`);
1+
const $ = new Env('ApkTw')
2+
3+
!(async () => {
4+
$.log('', `🔔 ${$.name}, 获取会话: 开始!`, '')
5+
const session = {}
6+
session.url = $request.url
7+
session.body = $request.body
8+
session.headers = $request.headers
9+
delete session.headers['Content-Length']
10+
delete session.headers['Cookie']
11+
$.log('', `url: ${session.url}`, `body: ${session.body}`, `headers: ${JSON.stringify(session.headers)}`)
12+
if ($.setdata(JSON.stringify(session), 'chavy_cookie_apktw')) {
13+
$.subt = '获取会话: 成功!'
14+
} else {
15+
$.subt = '获取会话: 失败!'
916
}
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();
17+
})()
18+
.catch((e) => {
19+
$.subt = '获取会话: 失败!'
20+
$.desc = `原因: ${e}`
21+
$.log(`❌ ${$.name}, 获取会话: 失败! 原因: ${e}!`)
22+
})
23+
.finally(() => {
24+
$.msg($.name, $.subt, $.desc), $.log('', `🔔 ${$.name}, 获取会话: 结束!`, ''), $.done()
25+
})
26+
27+
// prettier-ignore
28+
function Env(t){this.name=t,this.logs=[],this.isSurge=(()=>"undefined"!=typeof $httpClient),this.isQuanX=(()=>"undefined"!=typeof $task),this.log=((...t)=>{this.logs=[...this.logs,...t],t?console.log(t.join("\n")):console.log(this.logs.join("\n"))}),this.msg=((t=this.name,s="",i="")=>{this.isSurge()&&$notification.post(t,s,i),this.isQuanX()&&$notify(t,s,i);const e=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t&&e.push(t),s&&e.push(s),i&&e.push(i),console.log(e.join("\n"))}),this.getdata=(t=>this.isSurge()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):void 0),this.setdata=((t,s)=>this.isSurge()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):void 0),this.get=((t,s)=>this.send(t,"GET",s)),this.wait=((t,s=t)=>i=>setTimeout(()=>i(),Math.floor(Math.random()*(s-t+1)+t))),this.post=((t,s)=>this.send(t,"POST",s)),this.send=((t,s,i)=>{if(this.isSurge()){const e="POST"==s?$httpClient.post:$httpClient.get;e(t,(t,s,e)=>{s&&(s.body=e,s.statusCode=s.status),i(t,s,e)})}this.isQuanX()&&(t.method=s,$task.fetch(t).then(t=>{t.status=t.statusCode,i(null,t,t.body)},t=>i(t.error,t,t)))}),this.done=((t={})=>$done(t))}

apktw/apktw.js

+86-83
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,96 @@
1-
const cookieName = 'APK.TW'
2-
const cookieKey = 'chavy_cookie_apktw'
3-
const chavy = init()
4-
const cookieVal = chavy.getdata(cookieKey)
1+
const $ = new Env('ApkTw')
2+
$.VAL_login = $.getdata('chavy_cookie_apktw')
53

6-
sign()
4+
!(async () => {
5+
$.log('', `🔔 ${$.name}, 开始!`, '')
6+
await login()
7+
await getHash()
8+
await sign()
9+
await showmsg()
10+
})()
11+
.catch((e) => {
12+
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
13+
})
14+
.finally(() => {
15+
$.msg($.name, $.subt, ''), $.log('', `🔔 ${$.name}, 结束!`, ''), $.done()
16+
})
717

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)
18+
// 登录
19+
function login() {
20+
const url = JSON.parse($.VAL_login)
21+
return new Promise((resove) => $.post(url, (error, response, data) => resove()))
22+
}
23+
24+
function getHash() {
25+
return new Promise((resove) => {
26+
const url = { url: 'https://apk.tw/', headers: {} }
27+
url.headers['Host'] = 'apk.tw'
28+
url.headers['Referer'] = 'https://apk.tw/forum.php'
29+
url.headers['Accept'] = '*/*'
30+
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'
31+
$.get(url, (error, response, data) => {
32+
try {
33+
if (error) throw new Error(error)
34+
if (/\/source\/plugin\/dsu_amupper\/images\/wb\.gif/.test(data)) {
35+
$.isSigned = true
36+
$.isSignSuc = true
37+
} else {
38+
$.isSigned = false
39+
const [hash] = /plugin.php\?id=dsu_amupper:pper([^('|")]*)/.exec(data)
40+
if (hash) {
41+
$.hash = hash
42+
} else {
43+
$.isSignSuc = false
44+
}
45+
}
46+
} catch (e) {
47+
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, '')
48+
} finally {
49+
resove()
50+
}
51+
})
1652
})
17-
chavy.done()
1853
}
1954

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 = `签到结果: 成功`
55+
function sign() {
56+
if ($.isSigned && !$.hash) return
57+
return new Promise((resove) => {
58+
const url = { url: `https://apk.tw/${$.hash}&inajax=1&ajaxtarget=my_amupper`, headers: {} }
59+
$.log(`❕ ${url.url}!`)
60+
url.headers['Host'] = 'apk.tw'
61+
url.headers['Referer'] = 'https://apk.tw/forum.php'
62+
url.headers['Accept'] = '*/*'
63+
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'
64+
$.get(url, (error, response, data) => {
65+
try {
66+
if (error) throw new Error(error)
67+
if (/\/source\/plugin\/dsu_amupper\/images\/wb\.gif/.test(data)) {
68+
$.isSignSuc = true
3969
} else {
40-
subTitle = `签到结果: 失败 (未知)`
70+
$.isSignSuc = false
4171
}
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-
}
72+
} catch (e) {
73+
$.isSignSuc = false
74+
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, '')
75+
} finally {
76+
resove()
77+
}
78+
})
79+
})
5080
}
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))
81+
82+
function showmsg() {
83+
return new Promise((resove) => {
84+
if ($.isSigned) {
85+
$.subt = '签到: 重复'
86+
} else if (!$.isSigned && $.isSignSuc) {
87+
$.subt = '签到: 成功'
88+
} else {
89+
$.subt = '签到: 失败'
8790
}
88-
}
89-
done = (value = {}) => {
90-
$done(value)
91-
}
92-
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
91+
resove()
92+
})
9393
}
94+
95+
// prettier-ignore
96+
function Env(t){this.name=t,this.logs=[],this.isSurge=(()=>"undefined"!=typeof $httpClient),this.isQuanX=(()=>"undefined"!=typeof $task),this.log=((...t)=>{this.logs=[...this.logs,...t],t?console.log(t.join("\n")):console.log(this.logs.join("\n"))}),this.msg=((t=this.name,s="",i="")=>{this.isSurge()&&$notification.post(t,s,i),this.isQuanX()&&$notify(t,s,i);const e=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t&&e.push(t),s&&e.push(s),i&&e.push(i),console.log(e.join("\n"))}),this.getdata=(t=>this.isSurge()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):void 0),this.setdata=((t,s)=>this.isSurge()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):void 0),this.get=((t,s)=>this.send(t,"GET",s)),this.wait=((t,s=t)=>i=>setTimeout(()=>i(),Math.floor(Math.random()*(s-t+1)+t))),this.post=((t,s)=>this.send(t,"POST",s)),this.send=((t,s,i)=>{if(this.isSurge()){const e="POST"==s?$httpClient.post:$httpClient.get;e(t,(t,s,e)=>{s&&(s.body=e,s.statusCode=s.status),i(t,s,e)})}this.isQuanX()&&(t.method=s,$task.fetch(t).then(t=>{t.status=t.statusCode,i(null,t,t.body)},t=>i(t.error,t,t)))}),this.done=((t={})=>$done(t))}

chavy.box.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ function getSystemApps() {
9191
repo: 'https://github.com/chavyleung/scripts/tree/master/apktw',
9292
url: 'https://apk.tw/',
9393
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/apktw.png',
94-
tasks: [{ cron: '3 0 * * *', script: 'noteyoudao.js' }],
95-
rewrites: [{ type: 'request', pattern: '^https://note.youdao.com/yws/mapi/user?method=checkin', script: 'noteyoudao.cookie.js', body: true }]
94+
tasks: [{ cron: '3 0 * * *', script: 'apktw.js' }],
95+
rewrites: [{ type: 'request', pattern: '^https://apk.tw/member.php(.*?)action=login', script: 'apktw.cookie.js', body: true }]
9696
},
9797
{
9898
id: 'BAIDU',

surge.cookies.sgmodule

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Rewrite: 10010 = type=http-request,pattern=^https:\/\/m.client.10010.com\/dailyl
99
Rewrite: 10086 = type=http-request,pattern=^http:\/\/wx.10086.cn\/website\/taskCenter\/index\?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js
1010
Rewrite: 10086 = type=http-request,pattern=^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js
1111
Rewrite: AcFun = type=http-request,pattern=^https:\/\/api\-new\.app\.acfun\.cn\/rest\/app\/user\/personalInfo,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/acfun/acfun.cookie.js
12-
Rewrite: ApkTw = type=http-request,pattern=^https:\/\/apk\.tw\/?.?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.cookie.js
12+
Rewrite: ApkTw = type=http-request,pattern=^https://apk.tw\/member.php(.*?)action=login,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.cookie.js,requires-body=true
1313
Rewrite: BiliBili = type=http-request,pattern=^https:\/\/(www|live)\.bilibili\.com\/?.?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.cookie.js
1414
Rewrite: CSDN = type=http-request,pattern=^https:\/\/gw.csdn.net\/mini-app\/v2\/lucky_draw\/login\/sign_in\?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/csdn/csdn.cookie.js
1515
Rewrite: CSDN = type=http-request,pattern=^https:\/\/passport.csdn.net\/v2\/api\/app\/login\/checkAndRefreshToken,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/csdn/csdn.cookie.js

0 commit comments

Comments
 (0)