Skip to content

Commit 9a47cca

Browse files
committed
添加[威锋网]签到脚本
1 parent 1b8b261 commit 9a47cca

3 files changed

Lines changed: 291 additions & 0 deletions

File tree

‎feng/README.md‎

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

‎feng/feng.cookie.js‎

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

‎feng/feng.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_feng'
3+
const chavy = init()
4+
const cookieVal = chavy.getdata(cookieKey)
5+
6+
sign()
7+
8+
function sign() {
9+
let url = { url: `https://beta-api.feng.com/v1/attendance/userSignIn`, headers: {}, body: {} }
10+
url.headers['Host'] = 'beta-api.feng.com'
11+
url.headers['Origin'] = 'https://www.feng.com'
12+
url.headers['Referer'] = 'https://www.feng.com/'
13+
url.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
14+
url.headers['Accept'] = 'application/json, text/plain, */*'
15+
url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'
16+
url.headers['X-Access-Token'] = getToken()
17+
chavy.post(url, (error, response, data) => {
18+
let result = JSON.parse(data)
19+
let title = `${cookieName}`
20+
// 签到成功 || 签到重复
21+
if (result.status && (result.status.code == 0 || result.status.code == 1021)) {
22+
if (chavy.isQuanX()) getexp(result)
23+
if (chavy.isSurge()) showSurgeMsg(result)
24+
}
25+
// 签到失败
26+
else {
27+
let subTitle = `签到结果: 失败`
28+
let detail = `说明: ${result.status.message}`
29+
chavy.msg(title, subTitle, detail)
30+
chavy.log(`${cookieName}, cookieKey: ${cookieVal}`)
31+
chavy.log(`${cookieName}, token: ${getToken()}`)
32+
}
33+
chavy.log(`${cookieName}, data: ${data}`)
34+
})
35+
chavy.done()
36+
}
37+
38+
function getexp(signResult) {
39+
let url = { url: `https://beta-api.feng.com/v1/user/experience`, headers: {}, body: {} }
40+
url.headers['Host'] = 'beta-api.feng.com'
41+
url.headers['Origin'] = 'https://www.feng.com'
42+
url.headers['Referer'] = 'https://www.feng.com/'
43+
url.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
44+
url.headers['Accept'] = 'application/json, text/plain, */*'
45+
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
46+
url.headers['Accept-Language'] = 'zh-cn'
47+
url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'
48+
url.headers['X-Access-Token'] = getToken()
49+
chavy.get(url, (error, response, data) => {
50+
let result = JSON.parse(data)
51+
let title = `${cookieName}`
52+
let subTitle = ''
53+
let detail = `累计: ${result.data.signInCount}次, 等级: ${result.data.level} (${result.data.levelTitle}), 经验: ${result.data.currentExperience}/${result.data.creditsLower}`
54+
chavy.log(signResult.status.code + ', ' + signResult.status.code == 0)
55+
// 签到成功
56+
if (signResult.status.code == 0) {
57+
subTitle = `签到结果: 成功`
58+
chavy.msg(title, subTitle, detail)
59+
}
60+
// 签到重复
61+
else if (signResult.status.code == 1021) {
62+
subTitle = `签到结果: 成功 (重复签到)`
63+
chavy.msg(title, subTitle, detail)
64+
}
65+
chavy.log(`${cookieName}, data: ${data}`)
66+
})
67+
}
68+
69+
function showSurgeMsg(signResult) {
70+
let title = `${cookieName}`
71+
let detail = `详情: Surge环境下无法获取 (目测是Bug)`
72+
// 签到成功
73+
if (signResult.status.code == 0) {
74+
subTitle = `签到结果: 成功`
75+
chavy.msg(title, subTitle, detail)
76+
}
77+
// 签到重复
78+
else if (signResult.status.code == 1021) {
79+
subTitle = `签到结果: 成功 (重复签到)`
80+
chavy.msg(title, subTitle, detail)
81+
}
82+
}
83+
84+
function getToken() {
85+
const userInfo = decodeURIComponent(decodeURIComponent([...cookieVal.matchAll(/userInfo=(\{[^;]*)/g)][0][1]))
86+
return JSON.parse(userInfo).accessToken
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)