|
1 | | -const cookieName = '字幕组' |
2 | | -const cookieKey = 'chavy_cookie_zimuzu' |
3 | | -const cookieAppKey = 'chavy_cookie_zimuzu_app' |
4 | | -const authUrlAppKey = 'chavy_auth_url_zimuzu_app' |
5 | | -const chavy = init() |
6 | | -const cookieVal = chavy.getdata(cookieKey) |
7 | | -let cookieAppVal = chavy.getdata(cookieAppKey) |
8 | | -const authUrlAppVal = chavy.getdata(authUrlAppKey) |
9 | | -const signinfo = {} |
| 1 | +const $ = new Env('字幕组') |
| 2 | +$.VAL_cookie = $.getdata('chavy_cookie_zimuzu') |
| 3 | +$.VAL_appurl = $.getdata('chavy_auth_url_zimuzu_app') |
10 | 4 |
|
11 | | -sign() |
| 5 | +!(async () => { |
| 6 | + $.log('', `🔔 ${$.name}, 开始!`, '') |
| 7 | + await web() |
| 8 | + await app() |
| 9 | + await showmsg() |
| 10 | +})() |
| 11 | + .catch((e) => { |
| 12 | + $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') |
| 13 | + }) |
| 14 | + .finally(() => { |
| 15 | + $.msg($.name, $.subt, $.desc), $.log('', `🔔 ${$.name}, 结束!`, ''), $.done() |
| 16 | + }) |
12 | 17 |
|
13 | | -function sign() { |
14 | | - signweb() |
15 | | - signapp() |
16 | | - check() |
| 18 | +function web() { |
| 19 | + return new Promise((resove) => { |
| 20 | + const url = { url: `http://www.rrys2019.com/user/login/getCurUserTopInfo`, headers: {} } |
| 21 | + url.headers['Cookie'] = $.VAL_cookie |
| 22 | + 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' |
| 23 | + $.get(url, (error, response, data) => ($.web = JSON.parse(data, resove()))) |
| 24 | + }) |
17 | 25 | } |
18 | 26 |
|
19 | | -function signweb() { |
20 | | - let url = { url: `http://www.rrys2019.com/user/login/getCurUserTopInfo`, headers: { Cookie: cookieVal } } |
21 | | - 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' |
22 | | - |
23 | | - chavy.get(url, (error, response, data) => { |
24 | | - chavy.log(`${cookieName}, signweb - data: ${data}`) |
25 | | - signinfo.web = JSON.parse(data) |
26 | | - }) |
| 27 | +async function app() { |
| 28 | + await loginapp() |
| 29 | + await refreshapp() |
| 30 | + await signapp() |
27 | 31 | } |
28 | 32 |
|
29 | | -function loginapp(cb) { |
30 | | - if (authUrlAppVal) { |
31 | | - const url = { url: authUrlAppVal, headers: {} } |
| 33 | +function loginapp() { |
| 34 | + return new Promise((resove) => { |
| 35 | + const url = { url: $.VAL_appurl, headers: {} } |
32 | 36 | url.headers['Accept'] = `*/*` |
33 | 37 | url.headers['Accept-Encoding'] = `gzip;q=1.0, compress;q=0.5` |
34 | 38 | url.headers['Accept-Language'] = `zh-Hans-CN;q=1.0, en-US;q=0.9` |
35 | 39 | url.headers['Connection'] = `close` |
36 | 40 | url.headers['Host'] = `ios.zmzapi.com` |
37 | 41 | url.headers['Referer'] = `http://h5.rrhuodong.com/mobile/mission/pages/task.html` |
38 | 42 | url.headers['User-Agent'] = `YYets_swift/2.5.7 (com.yyets.ZiMuZu; build:29; iOS 13.3.1) Alamofire/4.9.1` |
39 | | - chavy.get(url, (error, response, data) => { |
40 | | - const result = JSON.parse(data) |
41 | | - if (result.status == 1) refreshapp(result, cb) |
42 | | - else signinfo.app = result |
43 | | - }) |
44 | | - } else { |
45 | | - cb() |
46 | | - } |
| 43 | + $.get(url, (error, response, data) => (($.loginapp = JSON.parse(data)), resove())) |
| 44 | + }) |
47 | 45 | } |
48 | 46 |
|
49 | | -function refreshapp(logininfo, cb) { |
50 | | - const url = { url: `http://h5.rrhuodong.com/index.php?g=api/mission&m=index&a=login&uid=${logininfo.data.uid}&token=${logininfo.data.token}`, headers: {} } |
51 | | - url.headers['Accept'] = `application/json, text/plain, */*` |
52 | | - url.headers['Accept-Encoding'] = `gzip, deflate` |
53 | | - url.headers['Accept-Language'] = `zh-cn` |
54 | | - url.headers['Connection'] = `close` |
55 | | - url.headers['Host'] = `h5.rrhuodong.com` |
56 | | - url.headers['Referer'] = `http://h5.rrhuodong.com/mobile/mission/pages/task.html` |
57 | | - url.headers['User-Agent'] = `Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148` |
58 | | - chavy.get(url, (error, response, data) => { |
59 | | - const respcookie = response.headers['Set-Cookie'] |
60 | | - if (respcookie && respcookie.indexOf('PHPSESSID=') >= 0) { |
61 | | - cookieAppVal = response.headers['Set-Cookie'].match(/PHPSESSID=([^;]*)/)[0] |
62 | | - if (cookieAppVal) chavy.setdata(cookieAppVal, cookieAppKey) |
63 | | - } |
64 | | - cb() |
| 47 | +function refreshapp() { |
| 48 | + return new Promise((resove) => { |
| 49 | + const uid = $.loginapp && $.loginapp.data && $.loginapp.data.uid |
| 50 | + const token = $.loginapp && $.loginapp.data && $.loginapp.data.token |
| 51 | + const url = { url: `http://h5.rrhuodong.com/index.php?g=api/mission&m=index&a=login&uid=${uid}&token=${token}`, headers: {} } |
| 52 | + url.headers['Accept'] = `application/json, text/plain, */*` |
| 53 | + url.headers['Accept-Encoding'] = `gzip, deflate` |
| 54 | + url.headers['Accept-Language'] = `zh-cn` |
| 55 | + url.headers['Connection'] = `close` |
| 56 | + url.headers['Host'] = `h5.rrhuodong.com` |
| 57 | + url.headers['Referer'] = `http://h5.rrhuodong.com/mobile/mission/pages/task.html` |
| 58 | + url.headers['User-Agent'] = `Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148` |
| 59 | + $.get(url, (error, response, data) => resove()) |
65 | 60 | }) |
66 | 61 | } |
67 | 62 |
|
68 | 63 | function signapp() { |
69 | | - loginapp(() => { |
70 | | - let url = { url: `http://h5.rrhuodong.com/index.php?g=api/mission&m=clock&a=store&id=2`, headers: { Cookie: cookieAppVal } } |
| 64 | + return new Promise((resove) => { |
| 65 | + const url = { url: `http://h5.rrhuodong.com/index.php?g=api/mission&m=clock&a=store&id=2`, headers: {} } |
71 | 66 | url.headers['Accept'] = `application/json, text/plain, */*` |
72 | 67 | url.headers['Accept-Encoding'] = `gzip, deflate` |
73 | 68 | url.headers['Accept-Language'] = `zh-cn` |
74 | 69 | url.headers['Connection'] = `close` |
75 | 70 | url.headers['Host'] = `h5.rrhuodong.com` |
76 | 71 | url.headers['Referer'] = `http://h5.rrhuodong.com/mobile/mission/pages/task.html` |
77 | 72 | url.headers['User-Agent'] = `Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148` |
78 | | - |
79 | | - chavy.get(url, (error, response, data) => { |
80 | | - chavy.log(`${cookieName}, signapp - data: ${data}`) |
81 | | - signinfo.app = JSON.parse(data) |
82 | | - }) |
| 73 | + $.get(url, (error, response, data) => (($.app = JSON.parse(data)), resove())) |
83 | 74 | }) |
84 | 75 | } |
85 | 76 |
|
86 | | -function getinfo() { |
87 | | - const title = `${cookieName}` |
88 | | - let subTitle = `网页: ` |
89 | | - let detail = '' |
90 | | - |
91 | | - // web |
92 | | - if (signinfo.web.status == 1) { |
93 | | - if (signinfo.web.data.new_login) subTitle += '成功' |
94 | | - else subTitle += '成功 (重复)' |
95 | | - detail = `人人钻: ${signinfo.web.data.userinfo.point}, 登录天数: ${signinfo.web.data.usercount.cont_login}` |
96 | | - } else if (signinfo.web.status == 4001) { |
97 | | - subTitle += '未登录' |
98 | | - } else { |
99 | | - subTitle += '失败' |
100 | | - } |
101 | | - |
102 | | - // app |
103 | | - subTitle += `; APP: ` |
104 | | - if (signinfo.app.status == 1) subTitle += '成功' |
105 | | - else if (signinfo.app.status == 4005) subTitle += '成功 (重复)' |
106 | | - else if (signinfo.app.status == 1021) subTitle += '未登录' |
107 | | - else subTitle += '失败' |
108 | | - |
109 | | - chavy.msg(title, subTitle, detail) |
110 | | - chavy.done() |
111 | | -} |
112 | | - |
113 | | -function check(checkms = 0) { |
114 | | - if (signinfo.web && signinfo.app) { |
115 | | - getinfo() |
116 | | - } else { |
117 | | - if (checkms > 5000) { |
118 | | - chavy.msg(`${cookieName}`, `签到失败: 超时退出`, ``) |
119 | | - chavy.done() |
| 77 | +function showmsg() { |
| 78 | + return new Promise((resove) => { |
| 79 | + $.subt = '' |
| 80 | + $.desc = '' |
| 81 | + // web |
| 82 | + if ($.web.status == 1) { |
| 83 | + if ($.web.data.new_login) $.subt += '成功' |
| 84 | + else $.subt += '成功 (重复)' |
| 85 | + $.desc = `人人钻: ${$.web.data.userinfo.point}, 登录天数: ${$.web.data.usercount.cont_login}` |
| 86 | + } else if ($.web.status == 4001) { |
| 87 | + $.subt += '未登录' |
120 | 88 | } else { |
121 | | - setTimeout(() => check(checkms + 100), 100) |
| 89 | + $.subt += '失败' |
122 | 90 | } |
123 | | - } |
124 | | -} |
125 | 91 |
|
126 | | -function init() { |
127 | | - isSurge = () => { |
128 | | - return undefined === this.$httpClient ? false : true |
129 | | - } |
130 | | - isQuanX = () => { |
131 | | - return undefined === this.$task ? false : true |
132 | | - } |
133 | | - getdata = (key) => { |
134 | | - if (isSurge()) return $persistentStore.read(key) |
135 | | - if (isQuanX()) return $prefs.valueForKey(key) |
136 | | - } |
137 | | - setdata = (key, val) => { |
138 | | - if (isSurge()) return $persistentStore.write(key, val) |
139 | | - if (isQuanX()) return $prefs.setValueForKey(key, val) |
140 | | - } |
141 | | - msg = (title, subtitle, body) => { |
142 | | - if (isSurge()) $notification.post(title, subtitle, body) |
143 | | - if (isQuanX()) $notify(title, subtitle, body) |
144 | | - } |
145 | | - log = (message) => console.log(message) |
146 | | - get = (url, cb) => { |
147 | | - if (isSurge()) { |
148 | | - $httpClient.get(url, cb) |
149 | | - } |
150 | | - if (isQuanX()) { |
151 | | - url.method = 'GET' |
152 | | - $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
153 | | - } |
154 | | - } |
155 | | - post = (url, cb) => { |
156 | | - if (isSurge()) { |
157 | | - $httpClient.post(url, cb) |
158 | | - } |
159 | | - if (isQuanX()) { |
160 | | - url.method = 'POST' |
161 | | - $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
162 | | - } |
163 | | - } |
164 | | - done = (value = {}) => { |
165 | | - $done(value) |
166 | | - } |
167 | | - return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 92 | + // app |
| 93 | + $.subt += `; APP: ` |
| 94 | + if ($.app.status == 1) $.subt += '成功' |
| 95 | + else if ($.app.status == 4005) $.subt += '成功 (重复)' |
| 96 | + else if ($.app.status == 1021) $.subt += '未登录' |
| 97 | + else $.subt += '失败' |
| 98 | + resove() |
| 99 | + }) |
168 | 100 | } |
| 101 | + |
| 102 | +// prettier-ignore |
| 103 | +function Env(t){this.name=t,this.logs=[],this.isSurge=(()=>"undefined"!=typeof $httpClient),this.isQuanX=(()=>"undefined"!=typeof $task),this.log=((...t)=>{this.logs=[...this.logs,...t],t?console.log(t.join("\n")):console.log(this.logs.join("\n"))}),this.msg=((t=this.name,s="",i="")=>{this.isSurge()&&$notification.post(t,s,i),this.isQuanX()&&$notify(t,s,i),this.log("==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="),t&&this.log(t),s&&this.log(s),i&&this.log(i)}),this.getdata=(t=>this.isSurge()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):void 0),this.setdata=((t,s)=>this.isSurge()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):void 0),this.get=((t,s)=>this.send(t,"GET",s)),this.wait=((t,s=t)=>i=>setTimeout(()=>i(),Math.floor(Math.random()*(s-t+1)+t))),this.post=((t,s)=>this.send(t,"POST",s)),this.send=((t,s,i)=>{if(this.isSurge()){const e="POST"==s?$httpClient.post:$httpClient.get;e(t,(t,s,e)=>{s.body=e,s.statusCode=s.status,i(t,s,e)})}this.isQuanX()&&(t.method=s,$task.fetch(t).then(t=>{t.status=t.statusCode,i(null,t,t.body)},t=>i(t.error,t,t)))}),this.done=((t={})=>$done(t))} |
0 commit comments