Update WPS Script.

Powered By @chavyleung
This commit is contained in:
sve1r 2020-07-02 10:56:26 +08:00
parent 23663d47b0
commit f4f5514ca3
3 changed files with 551 additions and 0 deletions

101
Scripts/WPS/Readme.md Normal file
View File

@ -0,0 +1,101 @@
# WPS
# 此 Readme Copied From [@chavyleung](https://github.com/chavyleung/scripts/blob/master/wps/README.md)
> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
> 2020.3.15 增加小程序签到
> 2020.6.10 1.小程序打卡可以自动答题; 2.自动做满邀请 10 个用户任务 (次日打卡送 10 天会员). 感谢 @Wenmoux 提供的邀请人列表
> 注意 1: 获取 Cookie 的正则有变动, 但不用重取 Cookie
> 注意 2: 把签到时间调整为 06:00 - 13:00 之间
> 2020.6.11 不需要单独从小程序获取 Cookie, 添加自动报名脚本
## 配置 (Surge)
```properties
[MITM]
hostname = zt.wps.cn
[Script]
http-request ^https:\/\/zt.wps.cn\/2018\/docer_check_in\/api\/act_list script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wps/wps.cookie.js
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wps/wps.js
```
## 配置 (QuanX)
```properties
[MITM]
hostname = 110.43.90.61, zt.wps.cn
[rewrite_local]
^https:\/\/zt.wps.cn\/2018\/docer_check_in\/api\/act_list url script-request-header wps.cookie.js
[task_local]
1 0 * * * wps.js
```
## 说明
1. 配置`[MITM]`
- Surge: zt.wps.cn
- QuanX: 110.43.90.61, zt.wps.cn
2. 再配置重写规则:
- Surge: 把两条远程脚本放到`[Script]`
- QuanX: 把`wps.cookie.js`和`wps.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
3. 打开 APP , 进入签到页面, 系统提示: `获取会话: 成功 (签到)` (不用手动签到)
4. 最后就可以把两条获取 Cookie 的脚本注释掉了
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)

394
Scripts/WPS/WPS.js Normal file
View File

@ -0,0 +1,394 @@
const $ = new Env('WPS')
$.VAL_signhomeurl = $.getdata('chavy_signhomeurl_wps')
$.VAL_signhomeheader = $.getdata('chavy_signhomeheader_wps')
!(async () => {
$.log('', `🔔 ${$.name}, 开始!`, '')
await loginapp()
await signapp()
await getquestion()
await answerwx()
await signwx()
await signupwx()
await getUserInfo()
await invite()
await getSigninfo()
await getSignreward()
await showmsg()
})()
.catch((e) => {
$.log('', `${$.name}, 失败! 原因: ${e}!`, '')
})
.finally(() => {
$.msg($.name, $.subt, $.desc.join('\n')), $.log('', `🔔 ${$.name}, 结束!`, ''), $.done()
})
// 登录 App
function loginapp() {
return new Promise((resove) =>
$.get({url: $.VAL_signhomeurl, headers: JSON.parse($.VAL_signhomeheader)}, (error, response, data) => {
try {
if (error) throw new Error(error)
$.homeinfo = JSON.parse(data)
if ($.homeinfo.result === 'ok') {
const headers = JSON.parse($.VAL_signhomeheader)
const [, sid] = /wps_sid=(.*?)(;|,|$)/.exec(headers.Cookie)
$.sid = sid
}
} catch (e) {
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
} finally {
resove()
}
})
)
}
// 签到 App
function signapp() {
return new Promise((resove) => {
const url = {
url: 'https://zt.wps.cn/2018/docer_check_in/api/checkin_today',
headers: JSON.parse($.VAL_signhomeheader)
}
url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01'
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
url.headers['Origin'] = 'https://zt.wps.cn'
url.headers['Connection'] = 'keep-alive'
url.headers['Host'] = 'zt.wps.cn'
url.headers['Referer'] = 'https://zt.wps.cn/static/2019/docer_check_in_ios/dist/?position=member_ios'
url.headers['Accept-Language'] = 'zh-cn'
url.headers['X-Requested-With'] = 'XMLHttpRequest'
$.post(url, (error, response, data) => {
try {
if (error) throw new Error(error)
$.signapp = JSON.parse(data)
} catch (e) {
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
} finally {
resove()
}
})
})
}
// 获取并回答问题
async function answerwx() {
const answers = ['WPS会员全文检索', '100G', 'WPS会员数据恢复', 'WPS会员PDF转doc', 'WPS会员PDF转图片', 'WPS图片转PDF插件', '金山PDF转WORD', 'WPS会员拍照转文字', '使用WPS会员修复', 'WPS全文检索功能', '有,且无限次', '文档修复']
// 尝试最多 10 次回答问题
for (let idx = 0; idx < 10; idx++) {
$.log(`问题: ${$.question.title}`)
if ($.question.multi_select === 0) {
const optionIdx = $.question.options.findIndex((option) => answers.includes(option))
if (optionIdx === -1) {
$.log(`选项: ${$.question.options.join(', ')}`)
$.log('跳过! 原因: 找不到答案.', '')
await getquestion()
} else {
$.log(`选项: ${$.question.options.join(', ')}`)
$.log(`答案: ${optionIdx + 1}.${$.question.options[optionIdx]}`, '')
await answerquestion(optionIdx + 1)
if ($.answer.right) {
$.answer.optionIdx = optionIdx
$.log('回答正确!')
break
} else {
$.log(`回答错误! 详情: ${$.answer._raw.msg}`)
await getquestion()
continue
}
}
} else {
$.log(`选项: ${$.question.options.join(', ')}`)
$.log('跳过! 原因: 不做多选.', '')
await getquestion()
}
}
}
// 获取问题
function getquestion() {
return new Promise((resove) => {
const url = {url: 'https://zt.wps.cn/2018/clock_in/api/get_question?award=wps', headers: {sid: $.sid}}
$.get(url, (error, response, data) => {
try {
if (error) throw new Error(error)
$.question = JSON.parse(data).data
} catch (e) {
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
} finally {
resove()
}
})
})
}
// 回答问题
function answerquestion(optIdx) {
return new Promise((resove) => {
const body = `answer=${optIdx}`
const url = {url: 'https://zt.wps.cn/2018/clock_in/api/answer?member=wps', body, headers: {sid: $.sid}}
$.post(url, (error, response, data) => {
try {
if (error) throw new Error(error)
const _data = JSON.parse(data)
$.answer = {_raw: _data, right: _data.result === 'ok'}
} catch (e) {
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
} finally {
resove()
}
})
})
}
function signwx() {
return new Promise((resove) => {
const url = {url: 'https://zt.wps.cn/2018/clock_in/api/clock_in?award=wps', headers: {sid: $.sid}}
$.get(url, (error, response, data) => {
try {
if (error) throw new Error(error)
const _data = JSON.parse(data)
$.signwx = {
_raw: _data,
isSuc: _data.result === 'ok' || (_data.result === 'error' && '已打卡' === _data.msg),
isRepeat: _data.result === 'error' && _data.msg === '已打卡',
isSignupNeed: _data.result === 'error' && _data.msg === '前一天未报名',
msg: _data.msg
}
} catch (e) {
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
} finally {
resove()
}
})
})
}
function signupwx() {
if (!$.signwx.isSignupNeed) return null
return new Promise((resove) => {
const url = {url: 'http://zt.wps.cn/2018/clock_in/api/sign_up', headers: {sid: $.sid}}
$.get(url, (error, response, data) => {
try {
if (error) throw new Error(error)
const _data = JSON.parse(data)
$.signupwx = {
_raw: _data,
isSuc: _data.result === 'ok',
msg: _data.msg
}
} catch (e) {
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
} finally {
resove()
}
})
})
}
// 获取签到详情
function getSigninfo() {
return new Promise((resove) => {
const url = {
url: 'https://zt.wps.cn/2018/docer_check_in/api/checkin_record',
headers: JSON.parse($.VAL_signhomeheader)
}
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
url.headers['Connection'] = 'keep-alive'
url.headers['Referer'] = 'https://zt.wps.cn/static/2019/docer_check_in_ios/dist/?position=member_ios'
url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01'
url.headers['Host'] = 'zt.wps.cn'
url.headers['Accept-Language'] = 'zh-cn'
url.headers['X-Requested-With'] = 'XMLHttpRequest'
$.get(url, (error, response, data) => {
try {
if (error) throw new Error(error)
$.signinfo = JSON.parse(data)
} catch (e) {
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
} finally {
resove()
}
})
})
}
// 获取签到奖励
function getSignreward() {
return new Promise((resove) => {
const url = {
url: 'https://zt.wps.cn/2018/docer_check_in/api/reward_record',
headers: JSON.parse($.VAL_signhomeheader)
}
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
url.headers['Connection'] = 'keep-alive'
url.headers['Referer'] = 'https://zt.wps.cn/static/2019/docer_check_in_ios/dist/?position=member_ios'
url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01'
url.headers['Host'] = 'zt.wps.cn'
url.headers['Accept-Language'] = 'zh-cn'
url.headers['X-Requested-With'] = 'XMLHttpRequest'
$.get(url, (error, response, data) => {
try {
if (error) throw new Error(error)
$.signreward = JSON.parse(data)
} catch (e) {
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
} finally {
resove()
}
})
})
}
// 获取用户信息
function getUserInfo() {
return new Promise((resove) => {
const url = {url: 'https://vip.wps.cn/userinfo', headers: {sid: $.sid}}
$.get(url, (error, response, data) => {
try {
if (error) throw new Error(error)
$.userinfo = JSON.parse(data)
} catch (e) {
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
} finally {
resove()
}
})
})
}
function invite() {
const sids = [
'V02S2UBSfNlvEprMOn70qP3jHPDqiZU00a7ef4a800341c7c3b',
'V02StVuaNcoKrZ3BuvJQ1FcFS_xnG2k00af250d4002664c02f',
'V02SWIvKWYijG6Rggo4m0xvDKj1m7ew00a8e26d3002508b828',
'V02Sr3nJ9IicoHWfeyQLiXgvrRpje6E00a240b890023270f97',
'V02SBsNOf4sJZNFo4jOHdgHg7-2Tn1s00a338776000b669579',
'V02ScVbtm2pQD49ArcgGLv360iqQFLs014c8062e000b6c37b6',
'V02S2oI49T-Jp0_zJKZ5U38dIUSIl8Q00aa679530026780e96',
'V02ShotJqqiWyubCX0VWTlcbgcHqtSQ00a45564e002678124c',
'V02SFiqdXRGnH5oAV2FmDDulZyGDL3M00a61660c0026781be1',
'V02S7tldy5ltYcikCzJ8PJQDSy_ElEs00a327c3c0026782526',
'V02SPoOluAnWda0dTBYTXpdetS97tyI00a16135e002684bb5c',
'V02Sb8gxW2inr6IDYrdHK_ywJnayd6s00ab7472b0026849b17',
'V02SwV15KQ_8n6brU98_2kLnnFUDUOw00adf3fda0026934a7f',
'V02SC1mOHS0RiUBxeoA8NTliH2h2NGc00a803c35002693584d'
]
$.invites = []
const inviteActs = []
$.log('', '开始邀请: ')
for (let sidIdx = 0; sidIdx < sids.length; sidIdx++) {
inviteActs.push(
new Promise((resove) => {
const body = `invite_userid=${$.userinfo.data.userid}`
const url = {url: 'http://zt.wps.cn/2018/clock_in/api/invite', body, headers: {sid: sids[sidIdx]}}
$.post(url, (error, response, data) => {
try {
if (error) throw new Error(error)
const _data = JSON.parse(data)
const _invite = {_raw: _data, inviteIdx: sidIdx, isSuc: _data.result === 'ok'}
$.invites.push(_invite)
$.log(` 邀请第 ${_invite.inviteIdx + 1} 个用户: ${_invite.isSuc ? '成功!' : '失败!'}`)
} catch (e) {
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
} finally {
resove()
}
})
})
)
}
return Promise.all(inviteActs)
}
function showmsg() {
return new Promise((resove) => {
$.subt = ''
$.desc = []
if (/ok/.test($.signapp.result)) {
$.subt = '签到: 成功'
} else if (/error/.test($.signapp.result) && /recheckin/.test($.signapp.msg)) {
$.subt = '签到: 重复'
} else {
$.subt = '签到: 失败'
}
if ($.signinfo && $.homeinfo.data[0]) {
const current = $.homeinfo.data[0]
$.desc.push(`连签: ${$.signinfo.data.max_days}天, 本期: ${current.end_date} (第${current.id}期)`)
$.desc.push('查看签到详情', '')
}
if ($.signwx) {
$.subt += ', '
if ($.signwx.isSuc && !$.signwx.isRepeat) $.subt += `打卡: 成功`
else if ($.signwx.isSuc && $.signwx.isRepeat) $.subt += `打卡: 重复`
else if (!$.signwx.isSuc && $.signwx.isSignupNeed && $.signupwx.isSuc) $.subt += `打卡: 报名成功`
else if (!$.signwx.isSuc && $.signwx.isSignupNeed && !$.signupwx.isSuc) $.subt += `打卡: 报名失败`
else $.subt += `打卡: 失败`
$.desc.push(`打卡: ${$.signwx.msg}`)
if ($.signwx.isSignupNeed) {
$.desc.push(`报名: ${$.signupwx.isSuc ? '成功' : `失败! 原因: ${$.signupwx.msg}`}`)
}
$.desc.push(`问题: ${$.question.title}`)
$.desc.push(`答案: ${$.answer.optionIdx + 1}.${$.question.options[$.answer.optionIdx]}`)
}
if ($.invites) {
const invitedCnt = $.invites.filter((invite) => invite.isSuc).length
const inviteCnt = $.invites.length
$.subt += ', 邀请: '
$.subt += `${invitedCnt}/${inviteCnt}`
}
if ($.signreward && $.signreward.data) {
const maxdays = $.signinfo.data.max_days
let curDays = 0
$.signreward.data.forEach((r) => {
const rstatus = r.status == 'unreceived' ? '[未领]' : '[已领]'
const limit_days = parseInt(r.limit_days)
const daysstatus = maxdays >= limit_days ? '✅' : '❕'
if (curDays < limit_days) {
curDays = limit_days
$.desc.push('', `${daysstatus} 连签${limit_days}天: `)
}
$.desc.push(` ${rstatus} ${r.reward_name}`)
})
}
resove()
})
}
// prettier-ignore
function Env(s) {
this.name = s, this.data = null, this.logs = [], this.isSurge = (() => "undefined" != typeof $httpClient), this.isQuanX = (() => "undefined" != typeof $task), this.isNode = (() => "undefined" != typeof module && !!module.exports), this.log = ((...s) => {
this.logs = [...this.logs, ...s], s ? console.log(s.join("\n")) : console.log(this.logs.join("\n"))
}), this.msg = ((s = this.name, t = "", i = "") => {
this.isSurge() && $notification.post(s, t, i), this.isQuanX() && $notify(s, t, i);
const e = ["", "==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];
s && e.push(s), t && e.push(t), i && e.push(i), console.log(e.join("\n"))
}), this.getdata = (s => {
if (this.isSurge()) return $persistentStore.read(s);
if (this.isQuanX()) return $prefs.valueForKey(s);
if (this.isNode()) {
const t = "box.dat";
return this.fs = this.fs ? this.fs : require("fs"), this.fs.existsSync(t) ? (this.data = JSON.parse(this.fs.readFileSync(t)), this.data[s]) : null
}
}), this.setdata = ((s, t) => {
if (this.isSurge()) return $persistentStore.write(s, t);
if (this.isQuanX()) return $prefs.setValueForKey(s, t);
if (this.isNode()) {
const i = "box.dat";
return this.fs = this.fs ? this.fs : require("fs"), !!this.fs.existsSync(i) && (this.data = JSON.parse(this.fs.readFileSync(i)), this.data[t] = s, this.fs.writeFileSync(i, JSON.stringify(this.data)), !0)
}
}), this.wait = ((s, t = s) => i => setTimeout(() => i(), Math.floor(Math.random() * (t - s + 1) + s))), this.get = ((s, t) => this.send(s, "GET", t)), this.post = ((s, t) => this.send(s, "POST", t)), this.send = ((s, t, i) => {
if (this.isSurge()) {
const e = "POST" == t ? $httpClient.post : $httpClient.get;
e(s, (s, t, e) => {
t && (t.body = e, t.statusCode = t.status), i(s, t, e)
})
}
this.isQuanX() && (s.method = t, $task.fetch(s).then(s => {
s.status = s.statusCode, i(null, s, s.body)
}, s => i(s.error, s, s))), this.isNode() && (this.request = this.request ? this.request : require("request"), s.method = t, s.gzip = !0, this.request(s, (s, t, e) => {
t && (t.status = t.statusCode), i(null, t, e)
}))
}), this.done = ((s = {}) => this.isNode() ? null : $done(s))
}

56
Scripts/WPS/wps.cookie.js Normal file
View File

@ -0,0 +1,56 @@
const $ = new Env('WPS')
!(async () => {
$.log('', `🔔 ${$.name}, 获取会话: 开始!`, '')
const VAL_url = $request.url
const VAL_headers = JSON.stringify($request.headers)
$.log('', `${$.name}`, `url: ${$request.url}`, `headers: ${JSON.stringify($request.headers)}`, '')
$.setdata(VAL_url, 'chavy_signhomeurl_wps')
$.setdata(VAL_headers, 'chavy_signhomeheader_wps')
$.subt = '获取会话: 成功!'
})()
.catch((e) => {
$.subt = '获取会话: 失败!'
$.desc = `原因: ${e}`
$.log(`${$.name}, 获取会话: 失败! 原因: ${e}!`)
})
.finally(() => {
$.msg($.name, $.subt, $.desc), $.log('', `🔔 ${$.name}, 获取会话: 结束!`, ''), $.done()
})
// prettier-ignore
function Env(s) {
this.name = s, this.data = null, this.logs = [], this.isSurge = (() => "undefined" != typeof $httpClient), this.isQuanX = (() => "undefined" != typeof $task), this.isNode = (() => "undefined" != typeof module && !!module.exports), this.log = ((...s) => {
this.logs = [...this.logs, ...s], s ? console.log(s.join("\n")) : console.log(this.logs.join("\n"))
}), this.msg = ((s = this.name, t = "", i = "") => {
this.isSurge() && $notification.post(s, t, i), this.isQuanX() && $notify(s, t, i);
const e = ["", "==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];
s && e.push(s), t && e.push(t), i && e.push(i), console.log(e.join("\n"))
}), this.getdata = (s => {
if (this.isSurge()) return $persistentStore.read(s);
if (this.isQuanX()) return $prefs.valueForKey(s);
if (this.isNode()) {
const t = "box.dat";
return this.fs = this.fs ? this.fs : require("fs"), this.fs.existsSync(t) ? (this.data = JSON.parse(this.fs.readFileSync(t)), this.data[s]) : null
}
}), this.setdata = ((s, t) => {
if (this.isSurge()) return $persistentStore.write(s, t);
if (this.isQuanX()) return $prefs.setValueForKey(s, t);
if (this.isNode()) {
const i = "box.dat";
return this.fs = this.fs ? this.fs : require("fs"), !!this.fs.existsSync(i) && (this.data = JSON.parse(this.fs.readFileSync(i)), this.data[t] = s, this.fs.writeFileSync(i, JSON.stringify(this.data)), !0)
}
}), this.wait = ((s, t = s) => i => setTimeout(() => i(), Math.floor(Math.random() * (t - s + 1) + s))), this.get = ((s, t) => this.send(s, "GET", t)), this.post = ((s, t) => this.send(s, "POST", t)), this.send = ((s, t, i) => {
if (this.isSurge()) {
const e = "POST" == t ? $httpClient.post : $httpClient.get;
e(s, (s, t, e) => {
t && (t.body = e, t.statusCode = t.status), i(s, t, e)
})
}
this.isQuanX() && (s.method = t, $task.fetch(s).then(s => {
s.status = s.statusCode, i(null, s, s.body)
}, s => i(s.error, s, s))), this.isNode() && (this.request = this.request ? this.request : require("request"), s.method = t, s.gzip = !0, this.request(s, (s, t, e) => {
t && (t.status = t.statusCode), i(null, t, e)
}))
}), this.done = ((s = {}) => this.isNode() ? null : $done(s))
}