Skip to content

Commit

Permalink
添加[去哪儿]签到脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
chavyleung committed Feb 4, 2020
1 parent c430536 commit 86b8630
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 0 deletions.
6 changes: 6 additions & 0 deletions QuantumultX_Local_Cookie.conf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ hostname = wapside.189.cn, *.acfun.cn, apk.tw, *.bilibili.com, api.dongqiudi.com
# 195及以后版本
^https:\/\/c\.m\.163\.com\/uc\/api\/sign\/v2\/commit url script-request-body chavyleung/neteasenews/neteasenews.cookie.js

# 去哪儿
# 189及以前版本
# ^https:\/\/user.qunar.com\/webapi\/member\/signNewIndex.htm url script-response-body chavyleung/qunar/qunar.cookie.js
# 190及以后版本
^https:\/\/user.qunar.com\/webapi\/member\/signNewIndex.htm url script-request-header chavyleung/qunar/qunar.cookie.js

# 人人视频
# 189及以前版本
# ^https:\/\/api\.rr\.tv\/user\/profile url script-response-body chavyleung/rrtv/rrtv.cookie.js
Expand Down
2 changes: 2 additions & 0 deletions QuantumultX_Local_Task.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
10 0 * * * chavyleung/neteasemusic/quanx/neteasemusic.js
# 网易新闻
10 0 * * * chavyleung/neteasenews/neteasenews.js
# 去哪儿
10 0 * * * chavyleung/qunar/qunar.jsnews
# 人人视频
10 0 * * * chavyleung/rrtv/rrtv.js
# 顺丰速运
Expand Down
95 changes: 95 additions & 0 deletions qunar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# 去哪儿

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

```properties
[MITM]
user.qunar.com

[Script]
http-request ^https:\/\/user.qunar.com\/webapi\/member\/signNewIndex.htm script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qunar/qunar.cookie.js
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qunar/qunar.js
```

## 配置 (QuanX)

```properties
[MITM]
user.qunar.com

[rewrite_local]
# 189及以前版本
^https:\/\/user.qunar.com\/webapi\/member\/signNewIndex.htm url script-response-body qunar.cookie.js
# 190及以后版本
^https:\/\/user.qunar.com\/webapi\/member\/signNewIndex.htm url script-request-header qunar.cookie.js

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

## 说明

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

> 第 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)
58 changes: 58 additions & 0 deletions qunar/qunar.cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const cookieName = '去哪儿'
const cookieKey = 'chavy_cookie_qunar'
const chavy = init()
const cookieVal = JSON.stringify($request.headers)

if (cookieVal) {
chavy.setdata(cookieVal, cookieKey)
chavy.msg(`${cookieName}`, '获取Cookie: 成功', '')
chavy.log(`[${cookieName}] 获取Cookie: 成功, cookie: ${cookieVal}`)
} else {
chavy.msg(`${cookieName}`, '获取Cookie: 失败', '说明: 未知')
chavy.log(`[${cookieName}] 获取Cookie: 失败, cookie: ${cookieVal}`)
}

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()
77 changes: 77 additions & 0 deletions qunar/qunar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const cookieName = '去哪儿'
const cookieKey = 'chavy_cookie_qunar'
const chavy = init()
const cookieVal = JSON.parse(chavy.getdata(cookieKey))

sign()

function sign() {
let url = { url: `https://user.qunar.com/webapi/member/signNewIndex.htm`, headers: cookieVal }
url.body = `channel=app&platform=ios`
chavy.post(url, (error, response, data) => {
chavy.log(`${cookieName}, data: ${data}`)
let result = JSON.parse(data)
const title = `${cookieName}`
let subTitle = ``
let detail = ``
if (result.errcode == 200) {
if (result.data.modalInfo.title) {
subTitle = '签到结果: 成功'
detail = `${result.data.unit}: ${result.data.total}个, 连签: ${result.data.continuous}天, 说明: ${result.data.modalInfo.title}`
} else {
subTitle = '签到结果: 成功 (重复签到)'
detail = `${result.data.unit}: ${result.data.total}个, 连签: ${result.data.continuous}天`
}
} else {
subTitle = '签到结果: 失败'
detail = `编码: ${result.errcode}, 说明: ${result.errmsg}`
}
chavy.msg(title, 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 86b8630

Please sign in to comment.