Skip to content

Commit 8b991a5

Browse files
committed
添加[网易严选]签到脚本
1 parent d9427f6 commit 8b991a5

3 files changed

Lines changed: 257 additions & 0 deletions

File tree

‎yanxuan/README.md‎

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

‎yanxuan/yanxuan.cookie.js‎

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

‎yanxuan/yanxuan.js‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const cookieName = '网易严选'
2+
const cookieKey = 'chavy_cookie_yanxuan'
3+
const tokenKey = 'chavy_token_yanxuan'
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://m.you.163.com/xhr/points/sign.json?csrf_token=${token.csrf_token}`, headers: { Cookie: cookieVal } }
13+
url.headers['Accept'] = `application/json, text/javascript, */*; q=0.01`
14+
url.headers['Accept-Encoding'] = `gzip, deflate, br`
15+
url.headers['Origin'] = `https://m.you.163.com`
16+
url.headers['Connection'] = `keep-alive`
17+
url.headers['Host'] = `m.you.163.com`
18+
url.headers['Content-Length'] = `0`
19+
url.headers['User-Agent'] = `Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 yanxuan/5.1.2 device-id/d7af0a77d9d88bd33a8ae5b35e6219ad app-chan-id/AppStore trustId/ios_trustid_3353a5577f9c4677bddec1ca7ac490fb`
20+
url.headers['Referer'] = `https://m.you.163.com/points/index`
21+
url.headers['Accept-Language'] = `zh-cn`
22+
url.headers['X-Requested-With'] = `XMLHttpRequest`
23+
24+
chavy.post(url, (error, response, data) => {
25+
chavy.log(`${cookieName}, data: ${data}`)
26+
const result = JSON.parse(data)
27+
const title = `${cookieName}`
28+
let subTitle = ``
29+
let detail = ``
30+
if (result.code == '200') {
31+
subTitle = `签到结果: 成功`
32+
detail = `积分: ${result.data.point}`
33+
} else if (result.code == '400') {
34+
subTitle = `签到结果: 成功 (重复签到)`
35+
detail = `说明: ${result.errorCode}`
36+
} else {
37+
subTitle = `签到失败: 未知`
38+
detail = `编码: ${result.code}, 说明: ${result.errorCode}`
39+
}
40+
chavy.msg(title, subTitle, detail)
41+
})
42+
chavy.done()
43+
}
44+
45+
function init() {
46+
isSurge = () => {
47+
return undefined === this.$httpClient ? false : true
48+
}
49+
isQuanX = () => {
50+
return undefined === this.$task ? false : true
51+
}
52+
getdata = (key) => {
53+
if (isSurge()) return $persistentStore.read(key)
54+
if (isQuanX()) return $prefs.valueForKey(key)
55+
}
56+
setdata = (key, val) => {
57+
if (isSurge()) return $persistentStore.write(key, val)
58+
if (isQuanX()) return $prefs.setValueForKey(key, val)
59+
}
60+
msg = (title, subtitle, body) => {
61+
if (isSurge()) $notification.post(title, subtitle, body)
62+
if (isQuanX()) $notify(title, subtitle, body)
63+
}
64+
log = (message) => console.log(message)
65+
get = (url, cb) => {
66+
if (isSurge()) {
67+
$httpClient.get(url, cb)
68+
}
69+
if (isQuanX()) {
70+
url.method = 'GET'
71+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
72+
}
73+
}
74+
post = (url, cb) => {
75+
if (isSurge()) {
76+
$httpClient.post(url, cb)
77+
}
78+
if (isQuanX()) {
79+
url.method = 'POST'
80+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
81+
}
82+
}
83+
done = (value = {}) => {
84+
$done(value)
85+
}
86+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
87+
}

0 commit comments

Comments
 (0)