Skip to content

Commit 9283028

Browse files
committed
添加[米游社]签到
1 parent aaa1452 commit 9283028

5 files changed

Lines changed: 256 additions & 2 deletions

File tree

‎QuantumultX_Local_Cookie.conf‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
hostname = gdws.nsenz.com, credits.bz.mgtv.com, *.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
1+
hostname = *.mihoyo.com, gdws.nsenz.com, credits.bz.mgtv.com, *.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及以后版本
@@ -127,4 +127,7 @@ hostname = gdws.nsenz.com, credits.bz.mgtv.com, *.csdn.net, wapside.189.cn, *.ac
127127
# 芒果TV
128128
^https:\/\/credits.bz.mgtv.com\/user\/creditsTake url script-request-header chavyleung/mgtv/mgtv.cookie.js
129129

130+
# 米游社
131+
^https:\/\/api-takumi.mihoyo.com\/apihub\/api\/getGameList url script-request-header chavyleung/mihoyo/mihoyo.cookie.js
132+
130133

‎QuantumultX_Local_Task.conf‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@
4343
# 加油广东
4444
1 7 * * * chavyleung/gdoil/gdoil.js
4545
# 芒果TV
46-
2 0 * * * chavyleung/mgtv/mgtv.js
46+
2 0 * * * chavyleung/mgtv/mgtv.js
47+
# 米游社
48+
2 0 * * * chavyleung/mihoyo/mihoyo.js

‎mihoyo/README.md‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# 米游社
2+
3+
> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
4+
5+
## 配置 (Surge)
6+
7+
```properties
8+
[MITM]
9+
*.mihoyo.com
10+
11+
[Script]
12+
http-request ^https:\/\/api-takumi.mihoyo.com\/apihub\/api\/getGameList script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mihoyo/mihoyo.cookie.js
13+
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mihoyo/mihoyo.js
14+
```
15+
16+
## 配置 (QuanX)
17+
18+
```properties
19+
[MITM]
20+
*.mihoyo.com
21+
22+
[rewrite_local]
23+
^https:\/\/api-takumi.mihoyo.com\/apihub\/api\/getGameList url script-request-header mihoyo.cookie.js
24+
25+
[task_local]
26+
1 0 * * * mihoyo.js
27+
```
28+
29+
## 说明
30+
31+
1. 先把`*.mihoyo.com`加到`[MITM]`
32+
2. 再配置重写规则:
33+
- Surge: 把两条远程脚本放到`[Script]`
34+
- QuanX: 把`mihoyo.cookie.js`和`mihoyo.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
35+
3. 打开 APP , 系统提示: `获取Cookie: 成功`
36+
4. 最后就可以把第 1 条脚本注释掉了
37+
5. 运行一次脚本, 如果提示重复签到, 那就算成功了!
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)

‎mihoyo/mihoyo.cookie.js‎

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

‎mihoyo/mihoyo.js‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
const cookieName = '米游社'
2+
const signurlKey = 'chavy_signurl_mihoyo'
3+
const signheaderKey = 'chavy_signheader_mihoyo'
4+
const chavy = init()
5+
const signurlVal = chavy.getdata(signurlKey)
6+
const signheaderVal = chavy.getdata(signheaderKey)
7+
const signinfo = []
8+
let bbslist = []
9+
10+
sign()
11+
12+
function sign() {
13+
const url = { url: `https://api-takumi.mihoyo.com/apihub/api/getGameList`, headers: JSON.parse(signheaderVal) }
14+
chavy.get(url, (error, response, data) => {
15+
const result = JSON.parse(data)
16+
bbslist = result.data.list
17+
for (bbs of bbslist) signbbs(bbs)
18+
check()
19+
})
20+
}
21+
22+
function signbbs(bbs) {
23+
const url = { url: `https://api-takumi.mihoyo.com/apihub/sapi/signIn?gids=${bbs.id}`, headers: JSON.parse(signheaderVal) }
24+
chavy.post(url, (error, response, data) => signinfo.push(data))
25+
}
26+
27+
function check(checkms = 0) {
28+
if (bbslist.length == signinfo.length) {
29+
showmsg()
30+
} else {
31+
if (checkms > 5000) {
32+
chavy.msg(`${cookieName}`, `签到失败: 超时退出`, ``)
33+
chavy.done()
34+
} else {
35+
setTimeout(() => check(checkms + 100), 100)
36+
}
37+
}
38+
}
39+
40+
function showmsg() {
41+
const totalcnt = bbslist.length
42+
let signed = 0
43+
let skiped = 0
44+
let succnt = 0
45+
let failcnt = 0
46+
for (info of signinfo) {
47+
const i = JSON.parse(info)
48+
if (i.retcode == 0) (signed += 1), (succnt += 1)
49+
else if (i.retcode == 1008) (signed += 1), (skiped += 1)
50+
else failcnt += 1
51+
}
52+
let subtitle = totalcnt == signed ? '签到结果: 全部成功' : '签到结果: 部分成功'
53+
subtitle = 0 == signed ? '签到结果: 全部失败' : subtitle
54+
const detail = `共签: ${signed}/${totalcnt}, 本次成功: ${succnt}, 失败: ${failcnt}, 重签: ${skiped}`
55+
chavy.msg(cookieName, subtitle, detail)
56+
chavy.done()
57+
}
58+
59+
function init() {
60+
isSurge = () => {
61+
return undefined === this.$httpClient ? false : true
62+
}
63+
isQuanX = () => {
64+
return undefined === this.$task ? false : true
65+
}
66+
getdata = (key) => {
67+
if (isSurge()) return $persistentStore.read(key)
68+
if (isQuanX()) return $prefs.valueForKey(key)
69+
}
70+
setdata = (key, val) => {
71+
if (isSurge()) return $persistentStore.write(key, val)
72+
if (isQuanX()) return $prefs.setValueForKey(key, val)
73+
}
74+
msg = (title, subtitle, body) => {
75+
if (isSurge()) $notification.post(title, subtitle, body)
76+
if (isQuanX()) $notify(title, subtitle, body)
77+
}
78+
log = (message) => console.log(message)
79+
get = (url, cb) => {
80+
if (isSurge()) {
81+
$httpClient.get(url, cb)
82+
}
83+
if (isQuanX()) {
84+
url.method = 'GET'
85+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
86+
}
87+
}
88+
post = (url, cb) => {
89+
if (isSurge()) {
90+
$httpClient.post(url, cb)
91+
}
92+
if (isQuanX()) {
93+
url.method = 'POST'
94+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
95+
}
96+
}
97+
done = (value = {}) => {
98+
$done(value)
99+
}
100+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
101+
}

0 commit comments

Comments
 (0)