jhsh_checkIn.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /**
  2. * 脚本名称:建行生活
  3. * 活动入口:建行生活APP -> 首页 -> 会员有礼 -> 签到
  4. * 脚本说明:连续签到领优惠券礼包(打车、外卖优惠券),配置重写手动签到一次即可获取签到数据,默认领取外卖券,可在 BoxJS 配置奖品。兼容 Node.js 环境,变量名称 JHSH_BODY、JHSH_GIFT、JHSH_LOGIN_INFO,多账号分割符 "|"。
  5. * 仓库地址:https://github.com/FoKit/Scripts
  6. * 更新时间:2023-10-31 修复多账号 Set-Cookie 参数的串号问题
  7. * 更新时间:2023-10-30 修复 Cokie 失效问题,增加骑行券类型参数,感谢 Sliverkiss、𝘠𝘶𝘩𝘦𝘯𝘨、苍井灰灰 大佬提供帮助。
  8. /*
  9. https://raw.githubusercontent.com/FoKit/Scripts/main/boxjs/fokit.boxjs.json
  10. https://raw.githubusercontent.com/FoKit/Scripts/main/rewrite/get_jhsh_cookie.sgmodule
  11. ------------------ Surge 配置 -----------------
  12. [MITM]
  13. hostname = yunbusiness.ccb.com
  14. [Script]
  15. 建行数据 = type=http-request,pattern=^https:\/\/yunbusiness\.ccb\.com\/(clp_coupon|clp_service)\/txCtrl\?txcode=(A3341A038|autoLogin),requires-body=1,max-size=0,script-path=https://raw.githubusercontent.com/FoKit/Scripts/main/scripts/jhsh_checkIn.js
  16. 建行生活 = type=cron,cronexp=17 7 * * *,timeout=60,script-path=https://raw.githubusercontent.com/FoKit/Scripts/main/scripts/jhsh_checkIn.js,script-update-interval=0
  17. ------------------ Loon 配置 ------------------
  18. [MITM]
  19. hostname = yunbusiness.ccb.com
  20. [Script]
  21. http-request ^https:\/\/yunbusiness\.ccb\.com\/(clp_coupon|clp_service)\/txCtrl\?txcode=(A3341A038|autoLogin) tag=建行数据, script-path=https://raw.githubusercontent.com/FoKit/Scripts/main/scripts/jhsh_checkIn.js,requires-body=1
  22. cron "17 7 * * *" script-path=https://raw.githubusercontent.com/FoKit/Scripts/main/scripts/jhsh_checkIn.js,tag = 建行生活,enable=true
  23. -------------- Quantumult X 配置 --------------
  24. [MITM]
  25. hostname = yunbusiness.ccb.com
  26. [rewrite_local]
  27. ^https:\/\/yunbusiness\.ccb\.com\/(clp_coupon|clp_service)\/txCtrl\?txcode=(A3341A038|autoLogin) url script-request-body https://raw.githubusercontent.com/FoKit/Scripts/main/scripts/jhsh_checkIn.js
  28. [task_local]
  29. 17 7 * * * https://raw.githubusercontent.com/FoKit/Scripts/main/scripts/jhsh_checkIn.js, tag=建行生活, enabled=true
  30. ------------------ Stash 配置 -----------------
  31. cron:
  32. script:
  33. - name: 建行生活
  34. cron: '17 7 * * *'
  35. timeout: 10
  36. http:
  37. mitm:
  38. - "yunbusiness.ccb.com"
  39. script:
  40. - match: ^https:\/\/yunbusiness\.ccb\.com\/(clp_coupon|clp_service)\/txCtrl\?txcode=(A3341A038|autoLogin)
  41. name: 建行生活
  42. type: request
  43. require-body: true
  44. script-providers:
  45. 建行生活:
  46. url: https://raw.githubusercontent.com/FoKit/Scripts/main/scripts/jhsh_checkIn.js
  47. interval: 86400
  48. */
  49. const $ = new Env('建行生活');
  50. const notify = $.isNode() ? require('./sendNotify') : '';
  51. let AppId = '1472477795',
  52. giftMap = { "1": "打车", "2": "外卖", "3": "骑行" },
  53. message = '';
  54. let giftType = ($.isNode() ? process.env.JHSH_GIFT : $.getdata('JHSH_GIFT')) || '2'; // 奖励类型,默认领取'外卖'券
  55. let bodyStr = ($.isNode() ? process.env.JHSH_BODY : $.getdata('JHSH_BODY')) || ''; // 签到所需的 body
  56. let autoLoginInfo = ($.isNode() ? process.env.JHSH_LOGIN_INFO : $.getdata('JHSH_LOGIN_INFO')) || ''; // 刷新 session 所需的数据
  57. let AppVersion = ($.isNode() ? process.env.JHSH_VERSION : $.getdata('JHSH_VERSION')) || '2.1.5.002'; // 最新版本号,获取失败时使用
  58. let bodyArr = bodyStr ? bodyStr.split("|") : [];
  59. let bodyArr2 = autoLoginInfo ? autoLoginInfo.split("|") : [];
  60. $.is_debug = ($.isNode() ? process.env.IS_DEDUG : $.getdata('is_debug')) || 'false';
  61. if (isGetCookie = typeof $request !== `undefined`) {
  62. GetCookie();
  63. $.done();
  64. } else {
  65. !(async () => {
  66. if (!autoLoginInfo || !bodyStr) {
  67. $.msg($.name, '❌ 请先获取建行生活Cookie。');
  68. return;
  69. }
  70. console.log(`\n共有[${bodyArr.length}]个建行生活账号\n`);
  71. await getLatestVersion(); // 获取版本信息
  72. for (let i = 0; i < bodyArr.length; i++) {
  73. if (bodyArr[i]) {
  74. $.index = i + 1;
  75. $.token = '';
  76. $.info = JSON.parse(bodyArr[i]);
  77. $.info2 = JSON.parse(bodyArr2[i]);
  78. $.giftList = [];
  79. $.giftList2 = [];
  80. $.getGiftMsg = "";
  81. $.isGetGift = false;
  82. $.DeviceId = $.info2['DeviceId'];
  83. $.MBCUserAgent = $.info2['MBCUserAgent'];
  84. $.ALBody = $.info2['Body'];
  85. console.log(`\n===== 账号[${$.info?.USR_TEL || $.index}]开始签到 =====\n`);
  86. if (!$.info?.MID || !$.DeviceId || !$.MBCUserAgent || !$.ALBody) {
  87. message += `🎉 账号 [${$.info?.USR_TEL ? hideSensitiveData($.info?.USR_TEL, 3, 4) : $.index}] 缺少参数,请重新获取Cookie。\n`;
  88. continue;
  89. }
  90. await autoLogin(); // 刷新 session
  91. if (!$.token) continue;
  92. await main(); // 签到主函数
  93. if ($.giftList.length > 0) {
  94. for (let j = 0; j < $.giftList.length; j++) {
  95. if ($.isGetGift) break;
  96. let item = $.giftList[j]
  97. $.couponId = item?.couponId;
  98. $.nodeDay = item?.nodeDay;
  99. $.couponType = item?.couponType;
  100. $.dccpBscInfSn = item?.dccpBscInfSn;
  101. $.continue = false;
  102. console.log(`尝试领取[${giftMap[giftType]}]券`);
  103. for (let k = 1; k <= 3; k++) {
  104. if (!$.continue) {
  105. if (k >= 2) console.log(`领取失败,重试一次`);
  106. await $.wait(1000 * 5);
  107. await getGift(); // 领取奖励
  108. if ($.isGetGift) break;
  109. }
  110. }
  111. };
  112. if (!$.isGetGift) {
  113. $.getGiftMsg = `请打开app查看优惠券到账情况。\n`;
  114. }
  115. message += "," + $.getGiftMsg;
  116. }
  117. await $.wait(1000 * 3);
  118. }
  119. }
  120. if (message) {
  121. message = message.replace(/\n+$/, '');
  122. if ($.isNode()) {
  123. await notify.sendNotify($.name, message);
  124. } else {
  125. $.msg($.name, '', message);
  126. }
  127. }
  128. })()
  129. .catch((e) => {
  130. $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
  131. })
  132. .finally(() => {
  133. $.done();
  134. })
  135. }
  136. // 获取签到数据
  137. function GetCookie() {
  138. console.log($request.headers);
  139. console.log($request.body);
  140. if (/A3341A038/.test($request.url)) {
  141. $.body = JSON.parse($request.body);
  142. // if (bodyStr.indexOf('MID') == -1) {
  143. // bodyStr = '';
  144. // $.setdata(bodyStr, 'JHSH_BODY');
  145. // console.log(`用户数据缺失字段,已清空用户数据,请重新获取Cookie。`);
  146. // }
  147. // if (bodyStr.indexOf($.body?.MEB_ID) == -1) {
  148. $.body['MID'] = $request.headers['MID'] || $request.headers['Mid'] || $request.headers['mid'];
  149. $.body = JSON.stringify($.body);
  150. console.log(`开始新增用户数据 ${$.body}`);
  151. // bodyArr.push($.body);
  152. // $.setdata(bodyArr.join('|'), 'JHSH_BODY');
  153. $.setdata($.body, 'JHSH_BODY');
  154. // } else {
  155. // console.log('数据已存在,不再写入。');
  156. // }
  157. $.msg($.name, ``, `🎉 建行生活签到数据获取成功。`);
  158. } else if (/autoLogin/.test($request.url)) {
  159. $.DeviceId = $request.headers['DeviceId'] || $request.headers['Deviceid'] || $request.headers['deviceid'];
  160. $.MBCUserAgent = $request.headers['MBC-User-Agent'] || $request.headers['Mbc-user-agent'] || $request.headers['mbc-user-agent'];
  161. if ($.DeviceId && $.MBCUserAgent && $request.body) {
  162. autoLoginInfo = {
  163. "DeviceId": $.DeviceId,
  164. "MBCUserAgent": $.MBCUserAgent,
  165. "Body": $request.body
  166. }
  167. $.setdata(JSON.stringify(autoLoginInfo), 'JHSH_LOGIN_INFO');
  168. console.log(JSON.stringify(autoLoginInfo) + "写入成功");
  169. }
  170. }
  171. }
  172. // 刷新 session
  173. async function autoLogin() {
  174. let opt = {
  175. url: `https://yunbusiness.ccb.com/clp_service/txCtrl?txcode=autoLogin`,
  176. headers: {
  177. 'AppVersion': AppVersion,
  178. 'Content-Type': `application/json`,
  179. 'DeviceId': $.DeviceId,
  180. 'Accept': `application/json`,
  181. 'MBC-User-Agent': $.MBCUserAgent,
  182. 'Cookie': ''
  183. },
  184. body: $.ALBody
  185. }
  186. debug(opt)
  187. return new Promise(resolve => {
  188. $.post(opt, async (error, response, data) => {
  189. try {
  190. let result = $.toObj(data) || response.body;
  191. // 如果数据未加密,则 session 未过期
  192. if (result?.errCode) {
  193. // {"newErrMsg":"未能处理您的请求。如有疑问,请咨询在线客服或致电95533","data":"","reqFlowNo":"","errCode":"0","errMsg":"session未失效,勿重复登录"}
  194. // $.token = $.getdata('JHSH_TOKEN');
  195. console.log(`${result?.errMsg}`);
  196. } else {
  197. const set_cookie = response.headers['set-cookie'] || response.headers['Set-cookie'] || response.headers['Set-Cookie'];
  198. // !$.isNode() ? $.setdata($.token, 'JHSH_TOKEN') : ''; // 数据持久化
  199. let new_cookie = $.toStr(set_cookie).match(/SESSION=([a-f0-9-]+);/);
  200. if (new_cookie) {
  201. $.token = new_cookie[0];
  202. console.log(`✅ 刷新 session 成功!`);
  203. debug(new_cookie);
  204. } else {
  205. message += `❌ 账号 [${$.info?.USR_TEL ? hideSensitiveData($.info?.USR_TEL, 3, 4) : $.index}] 刷新 session 失败,请重新获取Cookie。\n`;
  206. console.log(`⛔️ 刷新 session 失败`);
  207. debug(set_cookie);
  208. }
  209. }
  210. } catch (error) {
  211. $.log(error);
  212. } finally {
  213. resolve()
  214. }
  215. });
  216. })
  217. }
  218. // 签到主函数
  219. async function main() {
  220. let opt = {
  221. url: `https://yunbusiness.ccb.com/clp_coupon/txCtrl?txcode=A3341A115`,
  222. headers: {
  223. "MID": $.info?.MID,
  224. "Content-Type": "application/json;charset=utf-8",
  225. "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148/CloudMercWebView/UnionPay/1.0 CCBLoongPay",
  226. "Accept": "application/json,text/javascript,*/*",
  227. "content-type": "application/json",
  228. "Cookie": $.token
  229. },
  230. // body: `{"ACT_ID":"${$.info.ACT_ID}","MEB_ID":"${$.info.MEB_ID}","USR_TEL":"${$.info.USR_TEL}","REGION_CODE":"${$.info.REGION_CODE}","chnlType":"${$.info.chnlType}","regionCode":"${$.info.regionCode}"}`,
  231. body: `{"ACT_ID":"${$.info.ACT_ID}","REGION_CODE":"${$.info.REGION_CODE}","chnlType":"${$.info.chnlType}","regionCode":"${$.info.regionCode}"}`
  232. }
  233. debug(opt)
  234. return new Promise(resolve => {
  235. $.post(opt, async (err, resp, data) => {
  236. try {
  237. err && $.log(err);
  238. if (data) {
  239. debug(data);
  240. data = JSON.parse(data);
  241. let text = '';
  242. if (data.errCode == 0) {
  243. text = `🎉 账号 [${$.info?.USR_TEL ? hideSensitiveData($.info?.USR_TEL, 3, 4) : $.index}] 签到成功`;
  244. console.log(text);
  245. message += text;
  246. if (data?.data?.IS_AWARD == 1) {
  247. $.GIFT_BAG = data?.data?.GIFT_BAG;
  248. $.GIFT_BAG.forEach(item => {
  249. let body = { "couponId": item.couponId, "nodeDay": item.nodeDay, "couponType": item.couponType, "dccpBscInfSn": item.dccpBscInfSn };
  250. if (new RegExp(`${giftMap[giftType]}`).test(item?.couponName)) {
  251. if (/信用卡/.test(item?.couponName)) {
  252. $.giftList.unshift(body);
  253. } else {
  254. $.giftList.push(body);
  255. }
  256. } else {
  257. $.giftList2.push(body);
  258. }
  259. })
  260. $.giftList = [...$.giftList, ...$.giftList2];
  261. } else if (data?.data?.NEST_AWARD_DAY >= 1) {
  262. text = `继续签到${data.data.NEST_AWARD_DAY}天可领取${giftMap[giftType]}券`;
  263. message += `,${text}\n`;
  264. console.log(text);
  265. } else {
  266. console.log(`暂无可领取的奖励`);
  267. message += "\n";
  268. }
  269. } else {
  270. console.log(JSON.stringify(data));
  271. text = `❌ 账号 [${$.info?.USR_TEL ? hideSensitiveData($.info?.USR_TEL, 3, 4) : $.index}] 签到失败,${data.errMsg}\n`;
  272. console.log(text);
  273. message += text;
  274. }
  275. } else {
  276. $.log("服务器返回了空数据");
  277. }
  278. } catch (error) {
  279. $.log(error);
  280. } finally {
  281. resolve();
  282. }
  283. })
  284. })
  285. }
  286. // 领取奖励
  287. async function getGift() {
  288. let opt = {
  289. url: `https://yunbusiness.ccb.com/clp_coupon/txCtrl?txcode=A3341C082`,
  290. headers: {
  291. "MID": $.info?.MID,
  292. "Content-Type": "application/json;charset=utf-8",
  293. "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148/CloudMercWebView/UnionPay/1.0 CCBLoongPay",
  294. "Accept": "application/json,text/javascript,*/*"
  295. },
  296. body: `{"mebId":"${$.info.MEB_ID}","actId":"${$.info.ACT_ID}","nodeDay":${$.nodeDay},"couponType":${$.couponType},"nodeCouponId":"${$.couponId}","dccpBscInfSn":"${$.dccpBscInfSn}","chnlType":"${$.info.chnlType}","regionCode":"${$.info.regionCode}"}`
  297. }
  298. debug(opt);
  299. return new Promise(resolve => {
  300. $.post(opt, async (err, resp, data) => {
  301. try {
  302. err && $.log(err);
  303. if (data) {
  304. debug(data);
  305. data = JSON.parse(data);
  306. if (data.errCode == 0) {
  307. $.isGetGift = true;
  308. $.getGiftMsg = `获得签到奖励:${data?.data?.title}(${data?.data?.subTitle})\n`;
  309. console.log($.getGiftMsg);
  310. } else {
  311. $.continue = true;
  312. console.log(JSON.stringify(data));
  313. }
  314. } else {
  315. $.log("服务器返回了空数据");
  316. }
  317. } catch (error) {
  318. $.log(error);
  319. } finally {
  320. resolve();
  321. }
  322. })
  323. })
  324. }
  325. // 获取最新版本
  326. async function getLatestVersion() {
  327. let opt = {
  328. url: `https://itunes.apple.com/cn/lookup?id=${AppId}`,
  329. headers: { "Content-Type": "application/x-www-form-urlencoded" }
  330. }
  331. return new Promise(resolve => {
  332. $.get(opt, async (err, resp, data) => {
  333. try {
  334. err && $.log(err);
  335. if (data) {
  336. try {
  337. let result = JSON.parse(data);
  338. const { trackName, bundleId, version, currentVersionReleaseDate, } = result.results[0];
  339. AppVersion = version;
  340. !$.isNode() ? $.setdata(AppVersion, 'JHSH_VERSION') : ''; // 数据持久化
  341. console.log(`版本信息: ${trackName} ${version}\nBundleId: ${bundleId} \n更新时间: ${currentVersionReleaseDate}`);
  342. } catch (e) {
  343. $.log(e);
  344. };
  345. } else {
  346. console.log(`版本信息获取失败\n`);
  347. }
  348. } catch (error) {
  349. $.log(error);
  350. } finally {
  351. resolve();
  352. }
  353. })
  354. })
  355. }
  356. // 数据脱敏
  357. function hideSensitiveData(string, head_length = 2, foot_length = 2) {
  358. let star = '';
  359. try {
  360. for (var i = 0; i < string.length - head_length - foot_length; i++) {
  361. star += '*';
  362. }
  363. return string.substring(0, head_length) + star + string.substring(string.length - foot_length);
  364. } catch (e) {
  365. console.log(e);
  366. return string;
  367. }
  368. }
  369. // DEBUG
  370. function debug(content, title = "debug") {
  371. let start = `\n----- ${title} -----\n`;
  372. let end = `\n----- ${$.time('HH:mm:ss')} -----\n`;
  373. if ($.is_debug === 'true') {
  374. if (typeof content == "string") {
  375. console.log(start + content + end);
  376. } else if (typeof content == "object") {
  377. console.log(start + $.toStr(content) + end);
  378. }
  379. }
  380. }
  381. // prettier-ignore
  382. function Env(t, e) { class s { constructor(t) { this.env = t } send(t, e = "GET") { t = "string" == typeof t ? { url: t } : t; let s = this.get; return "POST" === e && (s = this.post), new Promise((e, i) => { s.call(this, t, (t, s, r) => { t ? i(t) : e(s) }) }) } get(t) { return this.send.call(this.env, t) } post(t) { return this.send.call(this.env, t, "POST") } } return new class { constructor(t, e) { this.name = t, this.http = new s(this), this.data = null, this.dataFile = "box.dat", this.logs = [], this.isMute = !1, this.isNeedRewrite = !1, this.logSeparator = "\n", this.encoding = "utf-8", this.startTime = (new Date).getTime(), Object.assign(this, e), this.log("", `\ud83d\udd14${this.name}, \u5f00\u59cb!`) } isNode() { return "undefined" != typeof module && !!module.exports } isQuanX() { return "undefined" != typeof $task } isSurge() { return "undefined" != typeof $httpClient && "undefined" == typeof $loon } isLoon() { return "undefined" != typeof $loon } isShadowrocket() { return "undefined" != typeof $rocket } isStash() { return "undefined" != typeof $environment && $environment["stash-version"] } toObj(t, e = null) { try { return JSON.parse(t) } catch { return e } } toStr(t, e = null) { try { return JSON.stringify(t) } catch { return e } } getjson(t, e) { let s = e; const i = this.getdata(t); if (i) try { s = JSON.parse(this.getdata(t)) } catch { } return s } setjson(t, e) { try { return this.setdata(JSON.stringify(t), e) } catch { return !1 } } getScript(t) { return new Promise(e => { this.get({ url: t }, (t, s, i) => e(i)) }) } runScript(t, e) { return new Promise(s => { let i = this.getdata("@chavy_boxjs_userCfgs.httpapi"); i = i ? i.replace(/\n/g, "").trim() : i; let r = this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout"); r = r ? 1 * r : 20, r = e && e.timeout ? e.timeout : r; const [o, a] = i.split("@"), n = { url: `http://${a}/v1/scripting/evaluate`, body: { script_text: t, mock_type: "cron", timeout: r }, headers: { "X-Key": o, Accept: "*/*" } }; this.post(n, (t, e, i) => s(i)) }).catch(t => this.logErr(t)) } loaddata() { if (!this.isNode()) return {}; { this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path"); const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e); if (!s && !i) return {}; { const i = s ? t : e; try { return JSON.parse(this.fs.readFileSync(i)) } catch (t) { return {} } } } } writedata() { if (this.isNode()) { this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path"); const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e), r = JSON.stringify(this.data); s ? this.fs.writeFileSync(t, r) : i ? this.fs.writeFileSync(e, r) : this.fs.writeFileSync(t, r) } } lodash_get(t, e, s) { const i = e.replace(/\[(\d+)\]/g, ".$1").split("."); let r = t; for (const t of i) if (r = Object(r)[t], void 0 === r) return s; return r } lodash_set(t, e, s) { return Object(t) !== t ? t : (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), e.slice(0, -1).reduce((t, s, i) => Object(t[s]) === t[s] ? t[s] : t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}, t)[e[e.length - 1]] = s, t) } getdata(t) { let e = this.getval(t); if (/^@/.test(t)) { const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t), r = s ? this.getval(s) : ""; if (r) try { const t = JSON.parse(r); e = t ? this.lodash_get(t, i, "") : e } catch (t) { e = "" } } return e } setdata(t, e) { let s = !1; if (/^@/.test(e)) { const [, i, r] = /^@(.*?)\.(.*?)$/.exec(e), o = this.getval(i), a = i ? "null" === o ? null : o || "{}" : "{}"; try { const e = JSON.parse(a); this.lodash_set(e, r, t), s = this.setval(JSON.stringify(e), i) } catch (e) { const o = {}; this.lodash_set(o, r, t), s = this.setval(JSON.stringify(o), i) } } else s = this.setval(t, e); return s } getval(t) { return this.isSurge() || this.isLoon() ? $persistentStore.read(t) : this.isQuanX() ? $prefs.valueForKey(t) : this.isNode() ? (this.data = this.loaddata(), this.data[t]) : this.data && this.data[t] || null } setval(t, e) { return this.isSurge() || this.isLoon() ? $persistentStore.write(t, e) : this.isQuanX() ? $prefs.setValueForKey(t, e) : this.isNode() ? (this.data = this.loaddata(), this.data[e] = t, this.writedata(), !0) : this.data && this.data[e] || null } initGotEnv(t) { this.got = this.got ? this.got : require("got"), this.cktough = this.cktough ? this.cktough : require("tough-cookie"), this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar, t && (t.headers = t.headers ? t.headers : {}, void 0 === t.headers.Cookie && void 0 === t.cookieJar && (t.cookieJar = this.ckjar)) } get(t, e = (() => { })) { if (t.headers && (delete t.headers["Content-Type"], delete t.headers["Content-Length"]), this.isSurge() || this.isLoon()) this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, { "X-Surge-Skip-Scripting": !1 })), $httpClient.get(t, (t, s, i) => { !t && s && (s.body = i, s.statusCode = s.status ? s.status : s.statusCode, s.status = s.statusCode), e(t, s, i) }); else if (this.isQuanX()) this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, { hints: !1 })), $task.fetch(t).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => e(t && t.error || "UndefinedError")); else if (this.isNode()) { let s = require("iconv-lite"); this.initGotEnv(t), this.got(t).on("redirect", (t, e) => { try { if (t.headers["set-cookie"]) { const s = t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString(); s && this.ckjar.setCookieSync(s, null), e.cookieJar = this.ckjar } } catch (t) { this.logErr(t) } }).then(t => { const { statusCode: i, statusCode: r, headers: o, rawBody: a } = t, n = s.decode(a, this.encoding); e(null, { status: i, statusCode: r, headers: o, rawBody: a, body: n }, n) }, t => { const { message: i, response: r } = t; e(i, r, r && s.decode(r.rawBody, this.encoding)) }) } } post(t, e = (() => { })) { const s = t.method ? t.method.toLocaleLowerCase() : "post"; if (t.body && t.headers && !t.headers["Content-Type"] && (t.headers["Content-Type"] = "application/x-www-form-urlencoded"), t.headers && delete t.headers["Content-Length"], this.isSurge() || this.isLoon()) this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, { "X-Surge-Skip-Scripting": !1 })), $httpClient[s](t, (t, s, i) => { !t && s && (s.body = i, s.statusCode = s.status ? s.status : s.statusCode, s.status = s.statusCode), e(t, s, i) }); else if (this.isQuanX()) t.method = s, this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, { hints: !1 })), $task.fetch(t).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => e(t && t.error || "UndefinedError")); else if (this.isNode()) { let i = require("iconv-lite"); this.initGotEnv(t); const { url: r, ...o } = t; this.got[s](r, o).then(t => { const { statusCode: s, statusCode: r, headers: o, rawBody: a } = t, n = i.decode(a, this.encoding); e(null, { status: s, statusCode: r, headers: o, rawBody: a, body: n }, n) }, t => { const { message: s, response: r } = t; e(s, r, r && i.decode(r.rawBody, this.encoding)) }) } } time(t, e = null) { const s = e ? new Date(e) : new Date; let i = { "M+": s.getMonth() + 1, "d+": s.getDate(), "H+": s.getHours(), "m+": s.getMinutes(), "s+": s.getSeconds(), "q+": Math.floor((s.getMonth() + 3) / 3), S: s.getMilliseconds() }; /(y+)/.test(t) && (t = t.replace(RegExp.$1, (s.getFullYear() + "").substr(4 - RegExp.$1.length))); for (let e in i) new RegExp("(" + e + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? i[e] : ("00" + i[e]).substr(("" + i[e]).length))); return t } msg(e = t, s = "", i = "", r) { const o = t => { if (!t) return t; if ("string" == typeof t) return this.isLoon() ? t : this.isQuanX() ? { "open-url": t } : this.isSurge() ? { url: t } : void 0; if ("object" == typeof t) { if (this.isLoon()) { let e = t.openUrl || t.url || t["open-url"], s = t.mediaUrl || t["media-url"]; return { openUrl: e, mediaUrl: s } } if (this.isQuanX()) { let e = t["open-url"] || t.url || t.openUrl, s = t["media-url"] || t.mediaUrl, i = t["update-pasteboard"] || t.updatePasteboard; return { "open-url": e, "media-url": s, "update-pasteboard": i } } if (this.isSurge()) { let e = t.url || t.openUrl || t["open-url"]; return { url: e } } } }; if (this.isMute || (this.isSurge() || this.isLoon() ? $notification.post(e, s, i, o(r)) : this.isQuanX() && $notify(e, s, i, o(r))), !this.isMuteLog) { let t = ["", "==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="]; t.push(e), s && t.push(s), i && t.push(i), console.log(t.join("\n")), this.logs = this.logs.concat(t) } } log(...t) { t.length > 0 && (this.logs = [...this.logs, ...t]), console.log(t.join(this.logSeparator)) } logErr(t, e) { const s = !this.isSurge() && !this.isQuanX() && !this.isLoon(); s ? this.log("", `\u2757\ufe0f${this.name}, \u9519\u8bef!`, t.stack) : this.log("", `\u2757\ufe0f${this.name}, \u9519\u8bef!`, t) } wait(t) { return new Promise(e => setTimeout(e, t)) } done(t = {}) { const e = (new Date).getTime(), s = (e - this.startTime) / 1e3; this.log("", `\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`), this.log(), this.isSurge() || this.isQuanX() || this.isLoon() ? $done(t) : this.isNode() && process.exit(1) } }(t, e) }