Skip to content

Commit 2c5d852

Browse files
committed
更新[顺丰速运]: 修复 QuanX 环境自动运行报错问题, 感谢 QuanX 作者提供的解决姿势
1 parent dd9c6d3 commit 2c5d852

1 file changed

Lines changed: 47 additions & 208 deletions

File tree

‎sfexpress/sfexpress.js‎

Lines changed: 47 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,60 @@
1-
const chavy = init()
2-
const cookieName = '顺丰速运'
3-
const KEY_loginurl = 'chavy_loginurl_sfexpress'
4-
const KEY_loginheader = 'chavy_loginheader_sfexpress'
5-
const KEY_login27url = 'chavy_login27url_sfexpress'
6-
const KEY_login27header = 'chavy_login27header_sfexpress'
1+
const $ = new Env('顺丰速运')
2+
$.VAL_loginurl = $.getdata('chavy_loginurl_sfexpress')
3+
$.VAL_loginheader = $.getdata('chavy_loginheader_sfexpress')
74

8-
const signinfo = {}
9-
let VAL_loginurl = chavy.getdata(KEY_loginurl)
10-
let VAL_loginheader = chavy.getdata(KEY_loginheader)
11-
let VAL_login27url = chavy.getdata(KEY_login27url)
12-
let VAL_login27header = chavy.getdata(KEY_login27header)
13-
14-
;(sign = async () => {
15-
chavy.log(`🔔 ${cookieName}`)
5+
!(async () => {
6+
await refresh()
167
await loginapp()
178
await signapp()
18-
// if (VAL_login27url && VAL_login27header) {
19-
// await loginapp27()
20-
// await signapp27()
21-
// await getinfo27()
22-
// }
239
await getinfo()
24-
showmsg()
25-
chavy.done()
26-
})().catch((e) => chavy.log(`❌ ${cookieName} 签到失败: ${e}`), chavy.done())
10+
await showmsg()
11+
})()
12+
.catch((e) => $.logErr(e))
13+
.finally(() => $.done())
2714

28-
function loginapp() {
29-
return new Promise((resolve, reject) => {
30-
const url = { url: VAL_loginurl, headers: { Cookie: '' } }
31-
chavy.get(url, (error, response, data) => {
32-
try {
33-
resolve()
34-
} catch (e) {
35-
chavy.msg(cookieName, `登录结果: 失败`, `说明: ${e}`)
36-
chavy.log(`❌ ${cookieName} loginapp - 登录失败: ${e}`)
37-
chavy.log(`❌ ${cookieName} loginapp - response: ${JSON.stringify(response)}`)
38-
resolve()
39-
}
40-
})
15+
function refresh() {
16+
if (!$.isQuanX()) return
17+
return new Promise((resolve) => {
18+
const url = { url: `https://sf-integral-sign-in.weixinjia.net/app/signin`, headers: { Cookie: '' } }
19+
url.body = `date=${new Date().getFullYear()}-${new Date().getMonth() + 1}-${new Date().getDate()}`
20+
$.post(url, () => resolve())
4121
})
4222
}
4323

44-
function loginapp27() {
45-
return new Promise((resolve, reject) => {
46-
const url = { url: VAL_login27url, headers: JSON.parse(VAL_login27header) }
47-
chavy.get(url, (error, response, data) => {
48-
try {
49-
resolve()
50-
} catch (e) {
51-
chavy.msg(cookieName, `登录结果: 失败 (27周年)`, `说明: ${e}`)
52-
chavy.log(`❌ ${cookieName} loginapp27 - 登录失败: ${e}`)
53-
chavy.log(`❌ ${cookieName} loginapp27 - response: ${JSON.stringify(response)}`)
54-
resolve()
55-
}
56-
})
24+
function loginapp() {
25+
return new Promise((resolve) => {
26+
const url = { url: $.VAL_loginurl }
27+
$.get(url, () => resolve())
5728
})
5829
}
5930

6031
function signapp() {
61-
return new Promise((resolve, reject) => {
62-
let url = { url: `https://sf-integral-sign-in.weixinjia.net/app/signin`, headers: JSON.parse(VAL_loginheader) }
32+
return new Promise((resolve) => {
33+
const url = { url: `https://sf-integral-sign-in.weixinjia.net/app/signin`, headers: JSON.parse($.VAL_loginheader) }
6334
delete url.headers['Cookie']
6435
url.headers['Origin'] = 'https://sf-integral-sign-in.weixinjia.net'
6536
url.headers['Connection'] = 'keep-alive'
6637
url.headers['Content-Type'] = 'application/x-www-form-urlencoded'
6738
url.headers['Accept'] = 'application/json, text/plain, */*'
6839
url.headers['Host'] = 'sf-integral-sign-in.weixinjia.net'
69-
url.headers['Content-Length'] = '15'
7040
url.headers['Accept-Language'] = 'zh-cn'
7141
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
7242
url.body = `date=${new Date().getFullYear()}-${new Date().getMonth() + 1}-${new Date().getDate()}`
73-
chavy.post(url, (error, response, data) => {
43+
$.post(url, (err, resp, data) => {
7444
try {
75-
chavy.log(`❕ ${cookieName} signapp - response: ${JSON.stringify(response)}`)
76-
signinfo.signapp = JSON.parse(data)
77-
resolve()
45+
$.signapp = JSON.parse(data)
7846
} catch (e) {
79-
chavy.msg(cookieName, `签到结果: 失败`, `说明: ${e}`)
80-
chavy.log(`❌ ${cookieName} signapp - 签到失败: ${e}`)
81-
chavy.log(`❌ ${cookieName} signapp - response: ${JSON.stringify(response)}`)
82-
resolve()
83-
}
84-
})
85-
})
86-
}
87-
88-
function signapp27() {
89-
return new Promise((resolve, reject) => {
90-
let url = { url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/activity/sign`, headers: {} }
91-
delete url.headers['Cookie']
92-
url.headers['Accept'] = 'application/json, text/plain, */*'
93-
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
94-
url.headers['Accept-Language'] = 'zh-cn'
95-
url.headers['Connection'] = 'keep-alive'
96-
url.headers['Content-Type'] = 'application/json;charset=utf-8'
97-
url.headers['Host'] = 'mcs-mimp-web.sf-express.com'
98-
url.headers['Origin'] = 'https://mcs-mimp-web.sf-express.com'
99-
url.headers['Referer'] = 'https://mcs-mimp-web.sf-express.com/sfAnniversary'
100-
url.headers['User-Agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 mediaCode=SFEXPRESSAPP-iOS-ML'
101-
url.body = '{"channel": "SFAPP","secondChannel": "APP_HOME_ENTRY"}'
102-
chavy.post(url, (error, response, data) => {
103-
try {
104-
chavy.log(`❕ ${cookieName} signapp27 - response: ${JSON.stringify(response)}`)
105-
signinfo.signapp27 = JSON.parse(data)
106-
resolve()
107-
} catch (e) {
108-
chavy.msg(cookieName, `签到结果: 失败 (27周年)`, `说明: ${e}`)
109-
chavy.log(`❌ ${cookieName} signapp27 - 签到失败: ${e}`)
110-
chavy.log(`❌ ${cookieName} signapp27 - response: ${JSON.stringify(response)}`)
111-
resolve()
112-
}
113-
})
114-
})
115-
}
116-
117-
function getinfo27() {
118-
return new Promise((resolve, reject) => {
119-
let url = { url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/activity/sign/days`, headers: JSON.parse(VAL_loginheader) }
120-
delete url.headers['Cookie']
121-
url.headers['Accept'] = 'application/json, text/plain, */*'
122-
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
123-
url.headers['Accept-Language'] = 'zh-cn'
124-
url.headers['Connection'] = 'keep-alive'
125-
url.headers['Content-Length'] = '2'
126-
url.headers['Content-Type'] = 'application/json;charset=utf-8'
127-
url.headers['Host'] = 'mcs-mimp-web.sf-express.com'
128-
url.headers['Origin'] = 'https://mcs-mimp-web.sf-express.com'
129-
url.headers['Referer'] = 'https://mcs-mimp-web.sf-express.com/sfAnniversary'
130-
url.headers['User-Agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 mediaCode=SFEXPRESSAPP-iOS-ML'
131-
url.body = '{}'
132-
chavy.post(url, (error, response, data) => {
133-
try {
134-
chavy.log(`❕ ${cookieName} getinfo27 - response: ${JSON.stringify(response)}`)
135-
signinfo.getinfo27 = JSON.parse(data)
136-
resolve()
137-
} catch (e) {
138-
chavy.msg(cookieName, `获取信息: 失败 (27周年)`, `说明: ${e}`)
139-
chavy.log(`❌ ${cookieName} getinfo27 - 获取信息: ${e}`)
140-
chavy.log(`❌ ${cookieName} getinfo27 - response: ${JSON.stringify(response)}`)
47+
$.logErr(e, resp)
48+
} finally {
14149
resolve()
14250
}
14351
})
14452
})
14553
}
14654

14755
function getinfo() {
148-
return new Promise((resolve, reject) => {
149-
let url = { url: `https://sf-integral-sign-in.weixinjia.net/app/init`, headers: JSON.parse(VAL_loginheader) }
56+
return new Promise((resolve) => {
57+
const url = { url: `https://sf-integral-sign-in.weixinjia.net/app/init`, headers: JSON.parse($.VAL_loginheader) }
15058
delete url.headers['Cookie']
15159
url.headers['Origin'] = 'https://sf-integral-sign-in.weixinjia.net'
15260
url.headers['Connection'] = 'keep-alive'
@@ -155,108 +63,39 @@ function getinfo() {
15563
url.headers['Host'] = 'sf-integral-sign-in.weixinjia.net'
15664
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
15765
url.headers['Accept-Language'] = 'zh-cn'
158-
url.headers['Content-Length'] = '0'
159-
160-
chavy.post(url, (error, response, data) => {
66+
$.post(url, (err, resp, data) => {
16167
try {
162-
chavy.log(`❕ ${cookieName} getinfo - response: ${JSON.stringify(response)}`)
163-
signinfo.info = JSON.parse(data)
164-
resolve()
68+
$.info = JSON.parse(data)
16569
} catch (e) {
166-
chavy.msg(cookieName, `获取信息: 失败`, `说明: ${e}`)
167-
chavy.log(`❌ ${cookieName} getinfo - 获取信息失败: ${e}`)
168-
chavy.log(`❌ ${cookieName} getinfo - response: ${JSON.stringify(response)}`)
70+
$.logErr(e, resp)
71+
} finally {
16972
resolve()
17073
}
17174
})
17275
})
17376
}
17477

17578
function showmsg() {
176-
let subTitle = ''
177-
let detail = ''
178-
if (signinfo.signapp.code == 0 && signinfo.signapp.msg == 'success') {
179-
subTitle = `签到: 成功`
180-
} else if (signinfo.signapp.code == -1) {
181-
if (signinfo.signapp.msg == 'ALREADY_CHECK') {
182-
subTitle = `签到: 重复`
183-
} else {
184-
subTitle = `签到: 失败`
185-
}
186-
} else {
187-
subTitle = `签到: 未知`
188-
detail = `说明: ${signinfo.signapp.msg}`
189-
}
190-
191-
if (signinfo.info && signinfo.info.code == 0) {
192-
detail = `积分: ${signinfo.info.data.member_info.integral}, 本周连签: ${signinfo.info.data.check_count}天`
193-
}
194-
195-
if (signinfo.signapp27) {
196-
subTitle += subTitle == '' ? '' : '; '
197-
if (signinfo.signapp27.success == true) {
198-
subTitle += `周年: 成功 (+${signinfo.signapp27.obj}积分)`
199-
} else if (signinfo.signapp27.success == false) {
200-
if (signinfo.signapp27.errorCode == '200010') {
201-
subTitle += `签到: 重复`
202-
} else if (signinfo.signapp27.errorCode == '100111') {
203-
subTitle += `签到: 未登录`
79+
return new Promise((resolve) => {
80+
if ($.signapp.code == 0 && $.signapp.msg == 'success') {
81+
$.subt = `签到: 成功`
82+
} else if ($.signapp.code == -1) {
83+
if ($.signapp.msg == 'ALREADY_CHECK') {
84+
$.subt = `签到: 重复`
20485
} else {
205-
subTitle += `签到: 失败`
86+
$.subt = `签到: 失败`
20687
}
20788
} else {
208-
subTitle += `周年: 未知`
209-
detail += `说明: ${signinfo.signapp.msg}`
89+
$.subt = `签到: 未知`
90+
$.desc = `说明: ${$.signapp.msg}`
21091
}
211-
212-
if (signinfo.getinfo27 && signinfo.getinfo27.success == true) {
213-
detail += `, 周年连签: ${signinfo.getinfo27.obj.length}天`
92+
if ($.info && $.info.code == 0) {
93+
$.desc = `积分: ${$.info.data.member_info.integral}, 本周连签: ${$.info.data.check_count}天`
21494
}
215-
}
216-
217-
chavy.msg(cookieName, subTitle, detail)
95+
$.msg($.name, $.subt, $.desc)
96+
resolve()
97+
})
21898
}
21999

220-
function init() {
221-
isSurge = () => {
222-
return undefined === this.$httpClient ? false : true
223-
}
224-
isQuanX = () => {
225-
return undefined === this.$task ? false : true
226-
}
227-
getdata = (key) => {
228-
if (isSurge()) return $persistentStore.read(key)
229-
if (isQuanX()) return $prefs.valueForKey(key)
230-
}
231-
setdata = (key, val) => {
232-
if (isSurge()) return $persistentStore.write(key, val)
233-
if (isQuanX()) return $prefs.setValueForKey(key, val)
234-
}
235-
msg = (title, subtitle, body) => {
236-
if (isSurge()) $notification.post(title, subtitle, body)
237-
if (isQuanX()) $notify(title, subtitle, body)
238-
}
239-
log = (message) => console.log(message)
240-
get = (url, cb) => {
241-
if (isSurge()) {
242-
$httpClient.get(url, cb)
243-
}
244-
if (isQuanX()) {
245-
url.method = 'GET'
246-
$task.fetch(url).then((resp) => cb(null, resp, resp.body))
247-
}
248-
}
249-
post = (url, cb) => {
250-
if (isSurge()) {
251-
$httpClient.post(url, cb)
252-
}
253-
if (isQuanX()) {
254-
url.method = 'POST'
255-
$task.fetch(url).then((resp) => cb(null, resp, resp.body))
256-
}
257-
}
258-
done = (value = {}) => {
259-
$done(value)
260-
}
261-
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
262-
}
100+
// prettier-ignore
101+
function Env(t,s){return new class{constructor(t,s){this.name=t,this.data=null,this.dataFile="box.dat",this.logs=[],this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient}isLoon(){return"undefined"!=typeof $loon}loaddata(){if(!this.isNode)return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch{return{}}}}}writedata(){if(this.isNode){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),h=JSON.stringify(this.data);e?this.fs.writeFileSync(t,h):i?this.fs.writeFileSync(s,h):this.fs.writeFileSync(t,h)}}getdata(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setdata(t,s){return this.isSurge()||this.isLoon()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}get(t,s=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))}):this.isQuanX()?$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t)):this.isNode()&&(this.got=this.got?this.got:require("got"),this.got(t).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t)))}post(t,s=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),delete t.headers["Content-Length"],this.isSurge()||this.isLoon())$httpClient.post(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))});else if(this.isQuanX())t.method="POST",$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t));else if(this.isNode()){this.got=this.got?this.got:require("got");const{url:e,...i}=t;this.got.post(e,i).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t))}}msg(s=t,e="",i="",h){this.isSurge()||this.isLoon()?$notification.post(s,e,i):this.isQuanX()&&$notify(s,e,i),this.logs.push("","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="),this.logs.push(s),e&&this.logs.push(e),i&&this.logs.push(i)}log(...t){t.length>0?this.logs=[...this.logs,...t]:console.log(this.logs.join(this.logSeparator))}logErr(t,s){const e=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();e?$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.message)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t=null){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,s)}

0 commit comments

Comments
 (0)