Skip to content

Commit f3cfc42

Browse files
committed
添加[喜马拉雅]签到脚本
1 parent 4fbc5a5 commit f3cfc42

3 files changed

Lines changed: 277 additions & 0 deletions

File tree

‎ximalaya/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+
mobwsa.ximalaya.com
10+
11+
[Script]
12+
http-request ^https?:\/\/mobwsa\.ximalaya\.com\/mobile\-user\/homePage\/.* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/ximalaya/ximalaya.cookie.js
13+
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/ximalaya/ximalaya.js
14+
```
15+
16+
## 配置 (QuanX)
17+
18+
```properties
19+
[MITM]
20+
mobwsa.ximalaya.com
21+
22+
[rewrite_local]
23+
^https?:\/\/mobwsa\.ximalaya\.com\/mobile\-user\/homePage\/.* url script-response-body ximalaya.cookie.js
24+
25+
[task_local]
26+
1 0 * * * ximalaya.js
27+
```
28+
29+
## 说明
30+
31+
1. 先把`mobwsa.ximalaya.com`加到`[MITM]`
32+
2. 再配置重写规则:
33+
- Surge: 把两条远程脚本放到`[Script]`
34+
- QuanX: 把`ximalaya.cookie.js`和`ximalaya.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
35+
3. 打开 APP, 访问下`我的`
36+
4. 系统提示: `获取Cookie: 成功` & `获取Token: 成功`(如果不提示获取成功, 尝试杀进程再进我的)
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)

‎ximalaya/ximalaya.cookie.js‎

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

‎ximalaya/ximalaya.js‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
const cookieName = '喜马拉雅'
2+
const cookieKey = 'chavy_cookie_ximalaya'
3+
const chavy = init()
4+
const cookieVal = chavy.getdata(cookieKey)
5+
6+
sign()
7+
8+
function sign() {
9+
getinfo((signinfo) => {
10+
if (signinfo.isTickedToday == false) {
11+
let url = { url: `https://m.ximalaya.com/starwar/lottery/check-in/check/action`, headers: { Cookie: cookieVal } }
12+
url.headers['Accept'] = `application/json, text/plain, */*`
13+
url.headers['Accept-Encoding'] = `gzip, deflate, br`
14+
url.headers['Accept-Language'] = `zh-cn`
15+
url.headers['Connection'] = `keep-alive`
16+
url.headers['Host'] = `m.ximalaya.com`
17+
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 iting/6.6.45 kdtunion_iting/1.0 iting(main)/6.6.45/ios_1'
18+
chavy.post(url, (error, response, data) => {
19+
const title = `${cookieName}`
20+
let subTitle = ``
21+
let detail = ``
22+
if (data == 'true') {
23+
getacc((accinfo) => {
24+
subTitle = `签到结果: 成功`
25+
detail = `共签: ${signinfo.totalCheckedCounts + 1}天, 积分: ${accinfo.data.score}(+${signinfo.awardAmount})`
26+
chavy.msg(title, subTitle, detail)
27+
chavy.log(`${cookieName}, sign: ${data}`)
28+
})
29+
} else {
30+
subTitle = `签到结果: 失败`
31+
detail = `说明: ${data}`
32+
chavy.msg(title, subTitle, detail)
33+
chavy.log(`${cookieName}, sign: ${data}`)
34+
}
35+
})
36+
chavy.done()
37+
}
38+
})
39+
}
40+
41+
function getinfo(cb) {
42+
let url = { url: `https://m.ximalaya.com/starwar/lottery/check-in/record`, headers: { Cookie: cookieVal } }
43+
url.headers['Accept'] = `application/json, text/plain, */*`
44+
url.headers['Accept-Encoding'] = `gzip, deflate, br`
45+
url.headers['Accept-Language'] = `zh-cn`
46+
url.headers['Connection'] = `keep-alive`
47+
url.headers['Content-Type'] = `application/json;charset=utf-8`
48+
url.headers['Host'] = `m.ximalaya.com`
49+
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 iting/6.6.45 kdtunion_iting/1.0 iting(main)/6.6.45/ios_1'
50+
chavy.get(url, (error, response, data) => {
51+
chavy.log(`${cookieName}, signinfo: ${data}`)
52+
if (data) {
53+
const signinfo = JSON.parse(data)
54+
if (signinfo.isTickedToday == true) {
55+
getacc((accinfo) => {
56+
const title = `${cookieName}`
57+
let subTitle = `签到结果: 成功 (重复签到)`
58+
let detail = `共签: ${signinfo.totalCheckedCounts}天, 积分: ${accinfo.data.score}(+${signinfo.awardAmount})`
59+
chavy.msg(title, subTitle, detail)
60+
chavy.log(`${cookieName}, data: ${data}`)
61+
})
62+
} else {
63+
cb(signinfo)
64+
}
65+
} else {
66+
const title = `${cookieName}`
67+
let subTitle = `签到结果: 失败`
68+
let detail = `说明: 请选登录`
69+
chavy.msg(title, subTitle, detail)
70+
}
71+
})
72+
}
73+
74+
function getacc(cb) {
75+
let url = { url: `https://m.ximalaya.com/starwar/task/listen/account`, headers: { Cookie: cookieVal } }
76+
url.headers['Accept'] = `application/json, text/plain, */*`
77+
url.headers['Accept-Encoding'] = `gzip, deflate, br`
78+
url.headers['Accept-Language'] = `zh-cn`
79+
url.headers['Connection'] = `keep-alive`
80+
url.headers['Content-Type'] = `application/json;charset=utf-8`
81+
url.headers['Host'] = `m.ximalaya.com`
82+
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 iting/6.6.45 kdtunion_iting/1.0 iting(main)/6.6.45/ios_1'
83+
chavy.get(url, (error, response, data) => {
84+
cb(JSON.parse(data))
85+
chavy.log(`${cookieName}, acc: ${data}`)
86+
})
87+
}
88+
89+
function init() {
90+
isSurge = () => {
91+
return undefined === this.$httpClient ? false : true
92+
}
93+
isQuanX = () => {
94+
return undefined === this.$task ? false : true
95+
}
96+
getdata = (key) => {
97+
if (isSurge()) return $persistentStore.read(key)
98+
if (isQuanX()) return $prefs.valueForKey(key)
99+
}
100+
setdata = (key, val) => {
101+
if (isSurge()) return $persistentStore.write(key, val)
102+
if (isQuanX()) return $prefs.setValueForKey(key, val)
103+
}
104+
msg = (title, subtitle, body) => {
105+
if (isSurge()) $notification.post(title, subtitle, body)
106+
if (isQuanX()) $notify(title, subtitle, body)
107+
}
108+
log = (message) => console.log(message)
109+
get = (url, cb) => {
110+
if (isSurge()) {
111+
$httpClient.get(url, cb)
112+
}
113+
if (isQuanX()) {
114+
url.method = 'GET'
115+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
116+
}
117+
}
118+
post = (url, cb) => {
119+
if (isSurge()) {
120+
$httpClient.post(url, cb)
121+
}
122+
if (isQuanX()) {
123+
url.method = 'POST'
124+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
125+
}
126+
}
127+
done = (value = {}) => {
128+
$done(value)
129+
}
130+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
131+
}

0 commit comments

Comments
 (0)