|
| 1 | +const cookieName = '去哪儿' |
| 2 | +const cookieKey = 'chavy_cookie_qunar' |
| 3 | +const chavy = init() |
| 4 | +const cookieVal = JSON.parse(chavy.getdata(cookieKey)) |
| 5 | + |
| 6 | +sign() |
| 7 | + |
| 8 | +function sign() { |
| 9 | + let url = { url: `https://user.qunar.com/webapi/member/signNewIndex.htm`, headers: cookieVal } |
| 10 | + url.body = `channel=app&platform=ios` |
| 11 | + chavy.post(url, (error, response, data) => { |
| 12 | + chavy.log(`${cookieName}, data: ${data}`) |
| 13 | + let result = JSON.parse(data) |
| 14 | + const title = `${cookieName}` |
| 15 | + let subTitle = `` |
| 16 | + let detail = `` |
| 17 | + if (result.errcode == 200) { |
| 18 | + if (result.data.modalInfo.title) { |
| 19 | + subTitle = '签到结果: 成功' |
| 20 | + detail = `${result.data.unit}: ${result.data.total}个, 连签: ${result.data.continuous}天, 说明: ${result.data.modalInfo.title}` |
| 21 | + } else { |
| 22 | + subTitle = '签到结果: 成功 (重复签到)' |
| 23 | + detail = `${result.data.unit}: ${result.data.total}个, 连签: ${result.data.continuous}天` |
| 24 | + } |
| 25 | + } else { |
| 26 | + subTitle = '签到结果: 失败' |
| 27 | + detail = `编码: ${result.errcode}, 说明: ${result.errmsg}` |
| 28 | + } |
| 29 | + chavy.msg(title, subTitle, detail) |
| 30 | + }) |
| 31 | + |
| 32 | + chavy.done() |
| 33 | +} |
| 34 | + |
| 35 | +function init() { |
| 36 | + isSurge = () => { |
| 37 | + return undefined === this.$httpClient ? false : true |
| 38 | + } |
| 39 | + isQuanX = () => { |
| 40 | + return undefined === this.$task ? false : true |
| 41 | + } |
| 42 | + getdata = (key) => { |
| 43 | + if (isSurge()) return $persistentStore.read(key) |
| 44 | + if (isQuanX()) return $prefs.valueForKey(key) |
| 45 | + } |
| 46 | + setdata = (key, val) => { |
| 47 | + if (isSurge()) return $persistentStore.write(key, val) |
| 48 | + if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 49 | + } |
| 50 | + msg = (title, subtitle, body) => { |
| 51 | + if (isSurge()) $notification.post(title, subtitle, body) |
| 52 | + if (isQuanX()) $notify(title, subtitle, body) |
| 53 | + } |
| 54 | + log = (message) => console.log(message) |
| 55 | + get = (url, cb) => { |
| 56 | + if (isSurge()) { |
| 57 | + $httpClient.get(url, cb) |
| 58 | + } |
| 59 | + if (isQuanX()) { |
| 60 | + url.method = 'GET' |
| 61 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 62 | + } |
| 63 | + } |
| 64 | + post = (url, cb) => { |
| 65 | + if (isSurge()) { |
| 66 | + $httpClient.post(url, cb) |
| 67 | + } |
| 68 | + if (isQuanX()) { |
| 69 | + url.method = 'POST' |
| 70 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 71 | + } |
| 72 | + } |
| 73 | + done = (value = {}) => { |
| 74 | + $done(value) |
| 75 | + } |
| 76 | + return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 77 | +} |
0 commit comments