|
| 1 | +const cookieName = '美团' |
| 2 | +const tokenurlKey = 'chavy_tokenurl_meituan' |
| 3 | +const tokenheaderKey = 'chavy_tokenheader_meituan' |
| 4 | +const signurlKey = 'chavy_signurl_meituan' |
| 5 | +const signheaderKey = 'chavy_signheader_meituan' |
| 6 | +const signbodyKey = 'chavy_signbody_meituan' |
| 7 | +const chavy = init() |
| 8 | +const tokenurlVal = chavy.getdata(tokenurlKey) |
| 9 | +const tokenheaderVal = chavy.getdata(tokenheaderKey) |
| 10 | +const signurlVal = chavy.getdata(signurlKey) |
| 11 | +const signheaderVal = chavy.getdata(signheaderKey) |
| 12 | +const signBodyVal = chavy.getdata(signbodyKey) |
| 13 | + |
| 14 | +sign() |
| 15 | + |
| 16 | +function sign() { |
| 17 | + const url = { url: signurlVal, headers: JSON.parse(signheaderVal), body: signBodyVal } |
| 18 | + chavy.post(url, (error, response, data) => { |
| 19 | + chavy.log(`${cookieName}, data: ${data}`) |
| 20 | + const result = JSON.parse( |
| 21 | + `{\"code\":0,\"msg\":\"操作成功\",\"data\":[{\"activityId\":100219,\"errorCode\":0,\"signInAwardRecords\":[{\"type\":4,\"info\":\"{\\\"amount\\\":206,\\\"id\\\":137735,\\\"manual\\\":false,\\\"type\\\":\\\"cash\\\"}\"},{\"type\":1,\"info\":\"{\\\"amount\\\":25.0,\\\"condition\\\":\\\"满200元可用\\\",\\\"name\\\":\\\"签到酒店首单券\\\",\\\"isMoney\\\":false,\\\"id\\\":137742,\\\"type\\\":\\\"coupon\\\",\\\"manual\\\":true,\\\"couponId\\\":\\\"0c7a0ebe5a\\\",\\\"personaId\\\":980}\"},{\"type\":1,\"info\":\"{\\\"amount\\\":4.0,\\\"condition\\\":\\\"满49元可用\\\",\\\"name\\\":\\\"签到美食券\\\",\\\"isMoney\\\":false,\\\"id\\\":137743,\\\"type\\\":\\\"coupon\\\",\\\"manual\\\":true,\\\"couponId\\\":\\\"6afa6cc079\\\",\\\"personaId\\\":110509}\"}],\"circleSignTimes\":1,\"circleSize\":7,\"firstSignDay\":true,\"success\":true,\"lastDayInCircle\":false}]}` |
| 22 | + ) |
| 23 | + let subTitle = `` |
| 24 | + let detail = `` |
| 25 | + if (result.code == 0) { |
| 26 | + subTitle = `签到结果: 成功` |
| 27 | + detail = `本周连签: ${result.data[0].circleSignTimes}天` |
| 28 | + for (r of result.data[0].signInAwardRecords) { |
| 29 | + const rinfo = JSON.parse(r.info) |
| 30 | + if (rinfo.type == `cash`) detail += `, 奖励金: ${rinfo.amount / 100}元` |
| 31 | + else if (rinfo.type == `coupon`) detail += `\n优惠券: ${rinfo.name}: ${rinfo.amount}元 (${rinfo.condition})` |
| 32 | + else detail += `\n未知奖励!` |
| 33 | + } |
| 34 | + } else if (result.code == 2002) { |
| 35 | + subTitle = `签到结果: 成功 (重复签到)` |
| 36 | + detail = `说明: ${result.msg}` |
| 37 | + } else { |
| 38 | + subTitle = `签到结果: 失败` |
| 39 | + detail = `编码: ${result.code}, 说明: ${result.msg}` |
| 40 | + } |
| 41 | + chavy.msg(cookieName, subTitle, detail) |
| 42 | + chavy.done() |
| 43 | + }) |
| 44 | +} |
| 45 | + |
| 46 | +function init() { |
| 47 | + isSurge = () => { |
| 48 | + return undefined === this.$httpClient ? false : true |
| 49 | + } |
| 50 | + isQuanX = () => { |
| 51 | + return undefined === this.$task ? false : true |
| 52 | + } |
| 53 | + getdata = (key) => { |
| 54 | + if (isSurge()) return $persistentStore.read(key) |
| 55 | + if (isQuanX()) return $prefs.valueForKey(key) |
| 56 | + } |
| 57 | + setdata = (key, val) => { |
| 58 | + if (isSurge()) return $persistentStore.write(key, val) |
| 59 | + if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 60 | + } |
| 61 | + msg = (title, subtitle, body) => { |
| 62 | + if (isSurge()) $notification.post(title, subtitle, body) |
| 63 | + if (isQuanX()) $notify(title, subtitle, body) |
| 64 | + } |
| 65 | + log = (message) => console.log(message) |
| 66 | + get = (url, cb) => { |
| 67 | + if (isSurge()) { |
| 68 | + $httpClient.get(url, cb) |
| 69 | + } |
| 70 | + if (isQuanX()) { |
| 71 | + url.method = 'GET' |
| 72 | + $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
| 73 | + } |
| 74 | + } |
| 75 | + post = (url, cb) => { |
| 76 | + if (isSurge()) { |
| 77 | + $httpClient.post(url, cb) |
| 78 | + } |
| 79 | + if (isQuanX()) { |
| 80 | + url.method = 'POST' |
| 81 | + $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
| 82 | + } |
| 83 | + } |
| 84 | + done = (value = {}) => { |
| 85 | + $done(value) |
| 86 | + } |
| 87 | + return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 88 | +} |
0 commit comments