|
| 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