Skip to content

Commit c45e4bf

Browse files
committed
添加[飞客茶馆]签到脚本
1 parent bd02470 commit c45e4bf

3 files changed

Lines changed: 245 additions & 0 deletions

File tree

‎flyertea/README.md‎

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

‎flyertea/flyertea.cookie.js‎

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

‎flyertea/flyertea.js‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const cookieName = '飞客茶馆'
2+
const cookieKey = 'chavy_cookie_flyertea'
3+
const tokenKey = 'chavy_token_flyertea'
4+
const chavy = init()
5+
let cookieVal = chavy.getdata(cookieKey)
6+
let tokenVal = chavy.getdata(tokenKey)
7+
8+
sign()
9+
10+
function sign() {
11+
const token = JSON.parse(tokenVal)
12+
let url = { url: `https://www.flyertea.com/plugin.php?id=k_misign:sign&operation=qiandao&from=insign&version=${token.version}&appcan=appcan&appkey=${token.appkey}&appversion=${token.appversion}&formhash=${token.formhash}&token=${token.token}`, headers: { Cookie: cookieVal } }
13+
url.headers['Accept'] = `*/*`
14+
url.headers['Accept-Language'] = `zh-Hans-CN;q=1, en-US;q=0.9`
15+
url.headers['Host'] = `www.flyertea.com`
16+
url.headers['User-Agent'] = `FKForum/7.14.0 (iPhone10,1; iOS 13.3; Scale/2.00)`
17+
url.headers['Referer'] = `https://www.flyertea.com/home.php`
18+
url.headers['Accept-Encoding'] = `gzip, deflate, br`
19+
url.headers['Connection'] = `keep-alive`
20+
chavy.get(url, (error, response, data) => {
21+
chavy.log(`${cookieName}, data: ${data}`)
22+
const result = JSON.parse(data)
23+
const title = `${cookieName}`
24+
let subTitle = ``
25+
let detail = ``
26+
if (result.Variables && result.Variables.Message.messageval == 'success') {
27+
subTitle = `签到结果: 成功`
28+
detail = `说明: ${result.Variables.Message.messagestr}`
29+
chavy.msg(title, subTitle, detail)
30+
} else {
31+
if (result.Message.messageval == 'error' && result.Message.messagestr.indexOf('只能签到一次') >= 0) {
32+
subTitle = `签到结果: 成功 (重复签到)`
33+
} else {
34+
subTitle = `签到结果: 失败`
35+
}
36+
detail = `说明: ${result.Message.messagestr}`
37+
chavy.msg(title, subTitle, detail)
38+
}
39+
})
40+
chavy.done()
41+
}
42+
43+
function init() {
44+
isSurge = () => {
45+
return undefined === this.$httpClient ? false : true
46+
}
47+
isQuanX = () => {
48+
return undefined === this.$task ? false : true
49+
}
50+
getdata = (key) => {
51+
if (isSurge()) return $persistentStore.read(key)
52+
if (isQuanX()) return $prefs.valueForKey(key)
53+
}
54+
setdata = (key, val) => {
55+
if (isSurge()) return $persistentStore.write(key, val)
56+
if (isQuanX()) return $prefs.setValueForKey(key, val)
57+
}
58+
msg = (title, subtitle, body) => {
59+
if (isSurge()) $notification.post(title, subtitle, body)
60+
if (isQuanX()) $notify(title, subtitle, body)
61+
}
62+
log = (message) => console.log(message)
63+
get = (url, cb) => {
64+
if (isSurge()) {
65+
$httpClient.get(url, cb)
66+
}
67+
if (isQuanX()) {
68+
url.method = 'GET'
69+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
70+
}
71+
}
72+
post = (url, cb) => {
73+
if (isSurge()) {
74+
$httpClient.post(url, cb)
75+
}
76+
if (isQuanX()) {
77+
url.method = 'POST'
78+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
79+
}
80+
}
81+
done = (value = {}) => {
82+
$done(value)
83+
}
84+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
85+
}

0 commit comments

Comments
 (0)