Skip to content

Commit

Permalink
添加[米游社]签到
Browse files Browse the repository at this point in the history
  • Loading branch information
chavyleung committed Feb 14, 2020
1 parent aaa1452 commit 9283028
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 2 deletions.
5 changes: 4 additions & 1 deletion QuantumultX_Local_Cookie.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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
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

# 电信营业厅
# 190及以后版本
Expand Down Expand Up @@ -127,4 +127,7 @@ hostname = gdws.nsenz.com, credits.bz.mgtv.com, *.csdn.net, wapside.189.cn, *.ac
# 芒果TV
^https:\/\/credits.bz.mgtv.com\/user\/creditsTake url script-request-header chavyleung/mgtv/mgtv.cookie.js

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


4 changes: 3 additions & 1 deletion QuantumultX_Local_Task.conf
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@
# 加油广东
1 7 * * * chavyleung/gdoil/gdoil.js
# 芒果TV
2 0 * * * chavyleung/mgtv/mgtv.js
2 0 * * * chavyleung/mgtv/mgtv.js
# 米游社
2 0 * * * chavyleung/mihoyo/mihoyo.js
91 changes: 91 additions & 0 deletions mihoyo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 米游社

> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
## 配置 (Surge)

```properties
[MITM]
*.mihoyo.com

[Script]
http-request ^https:\/\/api-takumi.mihoyo.com\/apihub\/api\/getGameList script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mihoyo/mihoyo.cookie.js
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mihoyo/mihoyo.js
```

## 配置 (QuanX)

```properties
[MITM]
*.mihoyo.com

[rewrite_local]
^https:\/\/api-takumi.mihoyo.com\/apihub\/api\/getGameList url script-request-header mihoyo.cookie.js

[task_local]
1 0 * * * mihoyo.js
```

## 说明

1. 先把`*.mihoyo.com`加到`[MITM]`
2. 再配置重写规则:
- Surge: 把两条远程脚本放到`[Script]`
- QuanX: 把`mihoyo.cookie.js``mihoyo.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
3. 打开 APP , 系统提示: `获取Cookie: 成功`
4. 最后就可以把第 1 条脚本注释掉了
5. 运行一次脚本, 如果提示重复签到, 那就算成功了!

> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次.
## 常见问题

1. 无法写入 Cookie

- 检查 Surge 系统通知权限放开了没
- 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴)

2. 写入 Cookie 成功, 但签到不成功

- 看看是不是在登录前就写入 Cookie 了
- 如果是,请确保在登录成功后,再尝试写入 Cookie

3. 为什么有时成功有时失败

- 很正常,网络问题,哪怕你是手工签到也可能失败(凌晨签到容易拥堵就容易失败)
- 暂时不考虑代码级的重试机制,但咱有配置级的(暴力美学):

- `Surge`配置:

```properties
# 没有什么是一顿饭解决不了的:
cron "10 0 0 * * *" script-path=xxx.js # 每天00:00:10执行一次
# 如果有,那就两顿:
cron "20 0 0 * * *" script-path=xxx.js # 每天00:00:20执行一次
# 实在不行,三顿也能接受:
cron "30 0 0 * * *" script-path=xxx.js # 每天00:00:30执行一次

# 再粗暴点,直接:
cron "* */60 * * * *" script-path=xxx.js # 每60分执行一次
```

- `QuanX`配置:

```properties
[task_local]
1 0 * * * xxx.js # 每天00:01执行一次
2 0 * * * xxx.js # 每天00:02执行一次
3 0 * * * xxx.js # 每天00:03执行一次

*/60 * * * * xxx.js # 每60分执行一次
```

## 感谢

[@NobyDa](https://github.com/NobyDa)

[@lhie1](https://github.com/lhie1)

[@ConnersHua](https://github.com/ConnersHua)
57 changes: 57 additions & 0 deletions mihoyo/mihoyo.cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const cookieName = '米游社'
const signurlKey = 'chavy_signurl_mihoyo'
const signheaderKey = 'chavy_signheader_mihoyo'
const chavy = init()

if ($request && $request.method != 'OPTIONS') {
const signurlVal = $request.url
const signheaderVal = JSON.stringify($request.headers)
if (signurlVal) chavy.setdata(signurlVal, signurlKey)
if (signheaderVal) chavy.setdata(signheaderVal, signheaderKey)
chavy.msg(cookieName, `获取Cookie: 成功`, ``)
}

function init() {
isSurge = () => {
return undefined === this.$httpClient ? false : true
}
isQuanX = () => {
return undefined === this.$task ? false : true
}
getdata = (key) => {
if (isSurge()) return $persistentStore.read(key)
if (isQuanX()) return $prefs.valueForKey(key)
}
setdata = (key, val) => {
if (isSurge()) return $persistentStore.write(key, val)
if (isQuanX()) return $prefs.setValueForKey(key, val)
}
msg = (title, subtitle, body) => {
if (isSurge()) $notification.post(title, subtitle, body)
if (isQuanX()) $notify(title, subtitle, body)
}
log = (message) => console.log(message)
get = (url, cb) => {
if (isSurge()) {
$httpClient.get(url, cb)
}
if (isQuanX()) {
url.method = 'GET'
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
}
}
post = (url, cb) => {
if (isSurge()) {
$httpClient.post(url, cb)
}
if (isQuanX()) {
url.method = 'POST'
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
}
}
done = (value = {}) => {
$done(value)
}
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
}
chavy.done()
101 changes: 101 additions & 0 deletions mihoyo/mihoyo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const cookieName = '米游社'
const signurlKey = 'chavy_signurl_mihoyo'
const signheaderKey = 'chavy_signheader_mihoyo'
const chavy = init()
const signurlVal = chavy.getdata(signurlKey)
const signheaderVal = chavy.getdata(signheaderKey)
const signinfo = []
let bbslist = []

sign()

function sign() {
const url = { url: `https://api-takumi.mihoyo.com/apihub/api/getGameList`, headers: JSON.parse(signheaderVal) }
chavy.get(url, (error, response, data) => {
const result = JSON.parse(data)
bbslist = result.data.list
for (bbs of bbslist) signbbs(bbs)
check()
})
}

function signbbs(bbs) {
const url = { url: `https://api-takumi.mihoyo.com/apihub/sapi/signIn?gids=${bbs.id}`, headers: JSON.parse(signheaderVal) }
chavy.post(url, (error, response, data) => signinfo.push(data))
}

function check(checkms = 0) {
if (bbslist.length == signinfo.length) {
showmsg()
} else {
if (checkms > 5000) {
chavy.msg(`${cookieName}`, `签到失败: 超时退出`, ``)
chavy.done()
} else {
setTimeout(() => check(checkms + 100), 100)
}
}
}

function showmsg() {
const totalcnt = bbslist.length
let signed = 0
let skiped = 0
let succnt = 0
let failcnt = 0
for (info of signinfo) {
const i = JSON.parse(info)
if (i.retcode == 0) (signed += 1), (succnt += 1)
else if (i.retcode == 1008) (signed += 1), (skiped += 1)
else failcnt += 1
}
let subtitle = totalcnt == signed ? '签到结果: 全部成功' : '签到结果: 部分成功'
subtitle = 0 == signed ? '签到结果: 全部失败' : subtitle
const detail = `共签: ${signed}/${totalcnt}, 本次成功: ${succnt}, 失败: ${failcnt}, 重签: ${skiped}`
chavy.msg(cookieName, subtitle, detail)
chavy.done()
}

function init() {
isSurge = () => {
return undefined === this.$httpClient ? false : true
}
isQuanX = () => {
return undefined === this.$task ? false : true
}
getdata = (key) => {
if (isSurge()) return $persistentStore.read(key)
if (isQuanX()) return $prefs.valueForKey(key)
}
setdata = (key, val) => {
if (isSurge()) return $persistentStore.write(key, val)
if (isQuanX()) return $prefs.setValueForKey(key, val)
}
msg = (title, subtitle, body) => {
if (isSurge()) $notification.post(title, subtitle, body)
if (isQuanX()) $notify(title, subtitle, body)
}
log = (message) => console.log(message)
get = (url, cb) => {
if (isSurge()) {
$httpClient.get(url, cb)
}
if (isQuanX()) {
url.method = 'GET'
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
}
}
post = (url, cb) => {
if (isSurge()) {
$httpClient.post(url, cb)
}
if (isQuanX()) {
url.method = 'POST'
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
}
}
done = (value = {}) => {
$done(value)
}
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
}

0 comments on commit 9283028

Please sign in to comment.