|
| 1 | +const cookieName = '蔚来' |
| 2 | +const signurlKey = 'signurl_nextevcar' |
| 3 | +const signheaderKey = 'signheader_nextevcar' |
| 4 | +const nextevcar = init() |
| 5 | +const signurlVal = nextevcar.getdata(signurlKey) |
| 6 | +const signheaderVal = nextevcar.getdata(signheaderKey) |
| 7 | + |
| 8 | +sign() |
| 9 | + |
| 10 | +function sign() { |
| 11 | + const url = { url: signurlVal, headers: JSON.parse(signheaderVal) } |
| 12 | + nextevcar.post(url, (error, response, data) => { |
| 13 | + nextevcar.log(`${cookieName}, data: ${data}`) |
| 14 | + const title = `${cookieName}` |
| 15 | + let subTitle = '' |
| 16 | + let detail = '' |
| 17 | + const result = JSON.parse(data) |
| 18 | + if (result.result_code == "success") { |
| 19 | + subTitle = `签到结果: 成功` |
| 20 | + detail = `签到积分: ${result.data.stats.credit_amount}, 连签: ${result.data.stats.continuous_checkin_days}天` |
| 21 | + } else if (result.result_code == "credit_limit_reached") { |
| 22 | + subTitle = `签到结果: 成功 (重复签到)` |
| 23 | + } else { |
| 24 | + subTitle = `签到结果: 失败` |
| 25 | + detail = `说明: ${result.debug_msg}, 请重新获取` |
| 26 | + } |
| 27 | + nextevcar.msg(title, subTitle, detail) |
| 28 | + nextevcar.done() |
| 29 | + }) |
| 30 | +} |
| 31 | + |
| 32 | +function init() { |
| 33 | + isSurge = () => { |
| 34 | + return undefined === this.$httpClient ? false : true |
| 35 | + } |
| 36 | + isQuanX = () => { |
| 37 | + return undefined === this.$task ? false : true |
| 38 | + } |
| 39 | + getdata = (key) => { |
| 40 | + if (isSurge()) return $persistentStore.read(key) |
| 41 | + if (isQuanX()) return $prefs.valueForKey(key) |
| 42 | + } |
| 43 | + setdata = (key, val) => { |
| 44 | + if (isSurge()) return $persistentStore.write(key, val) |
| 45 | + if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 46 | + } |
| 47 | + msg = (title, subtitle, body) => { |
| 48 | + if (isSurge()) $notification.post(title, subtitle, body) |
| 49 | + if (isQuanX()) $notify(title, subtitle, body) |
| 50 | + } |
| 51 | + log = (message) => console.log(message) |
| 52 | + get = (url, cb) => { |
| 53 | + if (isSurge()) { |
| 54 | + $httpClient.get(url, cb) |
| 55 | + } |
| 56 | + if (isQuanX()) { |
| 57 | + url.method = 'GET' |
| 58 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 59 | + } |
| 60 | + } |
| 61 | + post = (url, cb) => { |
| 62 | + if (isSurge()) { |
| 63 | + $httpClient.post(url, cb) |
| 64 | + } |
| 65 | + if (isQuanX()) { |
| 66 | + url.method = 'POST' |
| 67 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 68 | + } |
| 69 | + } |
| 70 | + put = (url, cb) => { |
| 71 | + if (isSurge()) { |
| 72 | + $httpClient.put(url, cb) |
| 73 | + } |
| 74 | + if (isQuanX()) { |
| 75 | + url.method = 'PUT' |
| 76 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 77 | + } |
| 78 | + } |
| 79 | + done = (value = {}) => { |
| 80 | + $done(value) |
| 81 | + } |
| 82 | + return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, put, done } |
| 83 | +} |
0 commit comments