|
| 1 | +const cookieName = '中国联通' |
| 2 | +const tokenurlKey = 'chavy_tokenurl_10010' |
| 3 | +const tokenheaderKey = 'chavy_tokenheader_10010' |
| 4 | +const signurlKey = 'chavy_signurl_10010' |
| 5 | +const signheaderKey = 'chavy_signheader_10010' |
| 6 | +const chavy = init() |
| 7 | +const tokenurlVal = chavy.getdata(tokenurlKey) |
| 8 | +const tokenheaderVal = chavy.getdata(tokenheaderKey) |
| 9 | +const signurlVal = chavy.getdata(signurlKey) |
| 10 | +let signheaderVal = chavy.getdata(signheaderKey) |
| 11 | +const signinfo = {} |
| 12 | + |
| 13 | +sign() |
| 14 | + |
| 15 | +function sign() { |
| 16 | + signapp() |
| 17 | + getinfo() |
| 18 | + // getdetail() |
| 19 | + check() |
| 20 | +} |
| 21 | + |
| 22 | +function gettel() { |
| 23 | + const reqheaders = JSON.parse(signheaderVal) |
| 24 | + const reqreferer = reqheaders.Referer |
| 25 | + return reqreferer.match(/desmobile=(.*?)(&|$)/)[1] |
| 26 | +} |
| 27 | + |
| 28 | +function loginapp(cb) { |
| 29 | + const url = { url: tokenurlVal, headers: JSON.parse(tokenheaderVal) } |
| 30 | + chavy.get(url, (error, response, data) => { |
| 31 | + const respcookie = response.headers['Set-Cookie'] |
| 32 | + const signheaderObj = JSON.parse(signheaderVal) |
| 33 | + let signcookie = signheaderObj['Cookie'] |
| 34 | + signcookie = signcookie.replace(/route5=([^;]*)/, respcookie.match(/route5=([^;]*)/)[0]) |
| 35 | + signcookie = signcookie.replace(/JSESSIONID=([^;]*)/, respcookie.match(/JSESSIONID=([^;]*)/)[0]) |
| 36 | + signheaderObj['Cookie'] = signcookie |
| 37 | + signheaderVal = JSON.stringify(signheaderObj) |
| 38 | + cb() |
| 39 | + }) |
| 40 | +} |
| 41 | + |
| 42 | +function signapp() { |
| 43 | + loginapp(() => { |
| 44 | + chavy.log(`${cookieName}, signapp - signheaderVal: ${signheaderVal}`) |
| 45 | + const url = { url: signurlVal, headers: JSON.parse(signheaderVal) } |
| 46 | + url.body = `className=signinIndex` |
| 47 | + chavy.post(url, (error, response, data) => (signinfo.signapp = data)) |
| 48 | + }) |
| 49 | +} |
| 50 | + |
| 51 | +function getinfo() { |
| 52 | + const url = { url: `https://mina.10010.com/wxapplet/bind/getIndexData/alipay/alipaymini?user_id=${gettel()}` } |
| 53 | + chavy.get(url, (error, response, data) => (signinfo.info = data)) |
| 54 | +} |
| 55 | + |
| 56 | +function getdetail() { |
| 57 | + const url = { url: `https://mina.10010.com/wxapplet/bind/getCombospare/alipay/alipaymini?stoken=&user_id=${gettel()}` } |
| 58 | + chavy.get(url, (error, response, data) => (signinfo.detail = data)) |
| 59 | +} |
| 60 | + |
| 61 | +function check(checkms = 0) { |
| 62 | + if (signinfo.signapp && signinfo.info) { |
| 63 | + chavy.log(`${cookieName}, signapp: ${signinfo.signapp}`) |
| 64 | + chavy.log(`${cookieName}, info: ${signinfo.info}`) |
| 65 | + // chavy.log(`${cookieName}, detail: ${signinfo.detail}`) |
| 66 | + signinfo.signapp = JSON.parse(signinfo.signapp) |
| 67 | + signinfo.info = JSON.parse(signinfo.info) |
| 68 | + // signinfo.detail = JSON.parse(signinfo.detail) |
| 69 | + showmsg() |
| 70 | + } else { |
| 71 | + if (checkms > 5000) { |
| 72 | + chavy.log(`${cookieName}, signapp: ${signinfo.signapp}`) |
| 73 | + chavy.log(`${cookieName}, info: ${signinfo.info}`) |
| 74 | + // chavy.log(`${cookieName}, detail: ${signinfo.detail}`) |
| 75 | + chavy.msg(`${cookieName}`, `签到失败: 超时退出`, ``) |
| 76 | + chavy.done() |
| 77 | + } else { |
| 78 | + setTimeout(() => check(checkms + 100), 100) |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +function showmsg() { |
| 84 | + let subTitle = '' |
| 85 | + let detail = '' |
| 86 | + let signday = '' |
| 87 | + |
| 88 | + // 签到结果 |
| 89 | + if (signinfo.signapp.msgCode == '0000') { |
| 90 | + subTitle = `签到结果: 成功` |
| 91 | + signday = ` (连签${signinfo.signapp.continuCount}天)` |
| 92 | + detail = `连签: ${signinfo.signapp.continuCount}天, 积分: +${signinfo.signapp.prizeCount}` |
| 93 | + } else if (signinfo.signapp.msgCode == '0008') { |
| 94 | + subTitle = `签到结果: 成功 (重复签到)` |
| 95 | + } else { |
| 96 | + subTitle = `签到结果: 失败` |
| 97 | + } |
| 98 | + |
| 99 | + // 基本信息 |
| 100 | + if (signinfo.info.code == '0000') { |
| 101 | + subTitle += signday |
| 102 | + detail = detail ? `${detail}\n` : `` |
| 103 | + const free = signinfo.info.dataList[0] |
| 104 | + const flow = signinfo.info.dataList[1] |
| 105 | + const voice = signinfo.info.dataList[2] |
| 106 | + detail = `话费: ${free.number}${free.unit}, 已用: ${flow.number}${flow.unit}, 剩余: ${voice.number}${voice.unit}` |
| 107 | + } |
| 108 | + |
| 109 | + // 详细信息 |
| 110 | + // if (signinfo.detail.code == '0000') { |
| 111 | + // } |
| 112 | + |
| 113 | + chavy.msg(cookieName, subTitle, detail) |
| 114 | + chavy.done() |
| 115 | +} |
| 116 | + |
| 117 | +function init() { |
| 118 | + isSurge = () => { |
| 119 | + return undefined === this.$httpClient ? false : true |
| 120 | + } |
| 121 | + isQuanX = () => { |
| 122 | + return undefined === this.$task ? false : true |
| 123 | + } |
| 124 | + getdata = (key) => { |
| 125 | + if (isSurge()) return $persistentStore.read(key) |
| 126 | + if (isQuanX()) return $prefs.valueForKey(key) |
| 127 | + } |
| 128 | + setdata = (key, val) => { |
| 129 | + if (isSurge()) return $persistentStore.write(key, val) |
| 130 | + if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 131 | + } |
| 132 | + msg = (title, subtitle, body) => { |
| 133 | + if (isSurge()) $notification.post(title, subtitle, body) |
| 134 | + if (isQuanX()) $notify(title, subtitle, body) |
| 135 | + } |
| 136 | + log = (message) => console.log(message) |
| 137 | + get = (url, cb) => { |
| 138 | + if (isSurge()) { |
| 139 | + $httpClient.get(url, cb) |
| 140 | + } |
| 141 | + if (isQuanX()) { |
| 142 | + url.method = 'GET' |
| 143 | + $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
| 144 | + } |
| 145 | + } |
| 146 | + post = (url, cb) => { |
| 147 | + if (isSurge()) { |
| 148 | + $httpClient.post(url, cb) |
| 149 | + } |
| 150 | + if (isQuanX()) { |
| 151 | + url.method = 'POST' |
| 152 | + $task.fetch(url).then((resp) => cb(null, resp, resp.body)) |
| 153 | + } |
| 154 | + } |
| 155 | + done = (value = {}) => { |
| 156 | + $done(value) |
| 157 | + } |
| 158 | + return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 159 | +} |
0 commit comments