jhshRobber.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. [task_local]
  3. # 建行生活抢券-并发
  4. 5 29,59 * * * * jhsh_coupon.js, tag=建行生活抢券-并发, enabled=true
  5. 只能圈×抓包,搜yunbusiness.ccb.com,请求体中的USER_ID,设置JHSH_COUPON_CKS 手机号&USER_ID 多账号@分割
  6. https://github.com/a65101855/zyk/blob/77822527079cf4a5a0fad264f0229aae781ad413/APP/jhsh_bf.js
  7. */
  8. const $ = new Env('建行生活抢券');
  9. now_ts = new Date().getTime();
  10. today = $.time('YYYY-MM-DD', now_ts);
  11. todayWDayNum = new Date(now_ts).getDay();
  12. todayWDayNum = todayWDayNum == 0? 7: todayWDayNum;
  13. sevenOclock_ts = new Date(`${today} 07:00:00`).getTime();
  14. eightOclock_ts = new Date(`${today} 08:00:00`).getTime();
  15. eightHalfOclock_ts = new Date(`${today} 08:30:00`).getTime();
  16. tenOclock_ts = new Date(`${today} 10:00:00`).getTime();
  17. tenHalfOclock_ts = new Date(`${today} 10:30:00`).getTime();
  18. elevenOclock_ts = new Date(`${today} 11:00:00`).getTime();
  19. elevenHALFOclock_ts = new Date(`${today} 11:30:00`).getTime();
  20. pmTwoHalfOclock_ts = new Date(`${today} 14:30:00`).getTime();
  21. pmThreeHalfOclock_ts = new Date(`${today} 15:30:00`).getTime();
  22. // test_ts = now_ts + 3000
  23. couponIds = ''
  24. couponMapList = [
  25. {
  26. "id": "239987",
  27. "name": "周一7点 满2-1券",
  28. "time": "7_1",
  29. "getTimes": "2",
  30. "period": "Week",
  31. "zoneId": "370200"
  32. },
  33. {
  34. "id": "239961",
  35. "name": "周二7点 满3-2券",
  36. "time": "7_2",
  37. "getTimes": "2",
  38. "period": "Week",
  39. "zoneId": "370200"
  40. },
  41. {
  42. "id": "239968",
  43. "name": "周三7点 满4-3券",
  44. "time": "7_3",
  45. "getTimes": "2",
  46. "period": "Week",
  47. "zoneId": "370200"
  48. },
  49. {
  50. "id": "239973",
  51. "name": "周四7点 满5-4券",
  52. "time": "7_4",
  53. "getTimes": "2",
  54. "period": "Week",
  55. "zoneId": "370200"
  56. },
  57. {
  58. "id": "239979",
  59. "name": "周五7点 满6-5券",
  60. "time": "7_5",
  61. "getTimes": "2",
  62. "period": "Week",
  63. "zoneId": "370200"
  64. },
  65. {
  66. "id": "239980",
  67. "name": "周六7点 满7-6券",
  68. "time": "7_6",
  69. "getTimes": "2",
  70. "period": "Week",
  71. "zoneId": "370200"
  72. },
  73. {
  74. "id": "239984",
  75. "name": "周日7点 满8-7券",
  76. "time": "7_7",
  77. "getTimes": "2",
  78. "period": "Week",
  79. "zoneId": "370200"
  80. },
  81. {
  82. "id": "243175",
  83. "name": "【数币支付5折起】商超/轻餐满30元减15元券(数字人民币专属)",
  84. "time": "8"
  85. },
  86. {
  87. "id": "243159",
  88. "name": "【数币支付5折起】正餐满100元减50元券(数字人民币专属)",
  89. "time": "8"
  90. },
  91. {
  92. "id": "234460",
  93. "name": "【每日好券】青岛轻食满12元减6元券",
  94. "time": "10",
  95. "getTimes": "4",
  96. "period": "Week",
  97. "zoneId": "370200"
  98. },
  99. {
  100. "id": "241434",
  101. "name": "每日好券外卖满20元减6元券(龙卡信用卡专享)",
  102. "time": "10",
  103. "getTimes": "4",
  104. "period": "Week",
  105. "zoneId": "370200"
  106. },
  107. {
  108. "id": "246994",
  109. "name": "崂山矿泉水,周二11点",
  110. "time": "11_2",
  111. "getTimes": "1",
  112. "period": "Forever",
  113. "zoneId": "370200"
  114. },
  115. {
  116. "id": "252156",
  117. "name": "崂山零售满300-100优惠券2(数字人民币专享)",
  118. "time": "10_5"
  119. },
  120. {
  121. "id": "252152",
  122. "name": "崂山零售满50-20优惠券2(数字人民币专享)",
  123. "time": "10_5"
  124. },
  125. {
  126. "id": "143780",
  127. "name": "周四5折胖哥俩满100减50元券-青岛(数币专享)",
  128. "time": "10:30_4",
  129. "getTimes": "4",
  130. "period": "Week",
  131. "zoneId": "370200"
  132. },
  133. {
  134. "id": "143754",
  135. "name": "周四5折西村叔叔满50减25元券-青岛(数币专享)",
  136. "time": "10:30_4",
  137. "getTimes": "4",
  138. "period": "Week",
  139. "zoneId": "370200"
  140. },
  141. {
  142. "id": "198662",
  143. "name": "周四5折笑蕾满50减25元券-青岛(数币专享)",
  144. "time": "10:30_4",
  145. "getTimes": "4",
  146. "period": "Week",
  147. "zoneId": "370200"
  148. },
  149. {
  150. "id": "164187",
  151. "name": "周四5折皇家美孚满50减25元券-青岛(数币专享)",
  152. "time": "10:30_4",
  153. "getTimes": "4",
  154. "period": "Week",
  155. "zoneId": "370200"
  156. },
  157. {
  158. "id": "164194",
  159. "name": "周四5折那些年满100减50元券-青岛(数币专享)",
  160. "time": "10:30_4",
  161. "getTimes": "4",
  162. "period": "Week",
  163. "zoneId": "370200"
  164. },
  165. {
  166. "id": "253297",
  167. "name": "周五话费50-40券",
  168. "time": "8:30_5",
  169. "getTimes": "1",
  170. "period": "Week",
  171. "zoneId": "370200"
  172. },
  173. {
  174. "id": "253297",
  175. "name": "周五话费50-40券",
  176. "time": "14:30_5",
  177. "getTimes": "1",
  178. "period": "Week",
  179. "zoneId": "370200"
  180. },
  181. {
  182. "id": "251869",
  183. "name": "周五外卖30-20券",
  184. "time": "11:30_5",
  185. "getTimes": "1",
  186. "period": "Week",
  187. "zoneId": "370200"
  188. },
  189. {
  190. "id": "251869",
  191. "name": "周五外卖30-20券",
  192. "time": "15:30_5",
  193. "getTimes": "1",
  194. "period": "Week",
  195. "zoneId": "370200"
  196. }
  197. ]
  198. diff = -1
  199. if (sevenOclock_ts - now_ts <= 60 * 1000 && sevenOclock_ts - now_ts > 0) {
  200. diff = sevenOclock_ts - now_ts
  201. couponIds = process.env.SEVEN_OCLOCK_COUPON_IDS ? SEVEN_OCLOCK_COUPON_IDS : "239984&239980&239979&239973&239968&239961&239987"
  202. }
  203. if (eightOclock_ts - now_ts <= 60 * 1000 && eightOclock_ts - now_ts > 0) {
  204. diff = eightOclock_ts - now_ts
  205. couponIds = process.env.EIGHT_OCLOCK_COUPON_IDS ? EIGHT_OCLOCK_COUPON_IDS : "243175&243159"
  206. }
  207. if (eightHalfOclock_ts - now_ts <= 60 * 1000 && eightHalfOclock_ts - now_ts > 0) {
  208. diff = eightHalfOclock_ts - now_ts
  209. couponIds = process.env.EIGHT_HALF_OCLOCK_COUPON_IDS ? EIGHT_HALF_OCLOCK_COUPON_IDS : "253297"
  210. }
  211. if (tenOclock_ts - now_ts <= 60 * 1000 && tenOclock_ts - now_ts > 0) {
  212. diff = tenOclock_ts - now_ts
  213. couponIds = process.env.TEN_OCLOCK_COUPON_IDS ? TEN_OCLOCK_COUPON_IDS : "254554&246314"
  214. }
  215. if (tenHalfOclock_ts - now_ts <= 60 * 1000 && tenHalfOclock_ts - now_ts > 0) {
  216. diff = tenHalfOclock_ts - now_ts
  217. couponIds = process.env.TEN_HALF_OCLOCK_COUPON_IDS ? TEN_HALF_OCLOCK_COUPON_IDS : "164194&143780"
  218. }
  219. if (elevenOclock_ts - now_ts <= 60 * 1000 && elevenOclock_ts - now_ts > 0) {
  220. diff = elevenOclock_ts - now_ts
  221. couponIds = process.env.ELEVEN_OCLOCK_COUPON_IDS ? ELEVEN_OCLOCK_COUPON_IDS : ""
  222. }
  223. if (elevenHALFOclock_ts - now_ts <= 60 * 1000 && elevenHALFOclock_ts - now_ts > 0) {
  224. diff = elevenHALFOclock_ts - now_ts
  225. couponIds = process.env.ELEVEN_HALF_OCLOCK_COUPON_IDS ? ELEVEN_HALF_OCLOCK_COUPON_IDS : "251869"
  226. }
  227. if (pmTwoHalfOclock_ts - now_ts <= 60 * 1000 && pmTwoHalfOclock_ts - now_ts > 0) {
  228. diff = pmTwoHalfOclock_ts - now_ts
  229. couponIds = process.env.PM_TWO_HALF_OCLOCK_COUPON_IDS ? PM_TWO_HALF_OCLOCK_COUPON_IDS : "253297"
  230. }
  231. if (pmThreeHalfOclock_ts - now_ts <= 60 * 1000 && pmThreeHalfOclock_ts - now_ts > 0) {
  232. diff = pmThreeHalfOclock_ts - now_ts
  233. couponIds = process.env.PM_THREE_HALF_OCLOCK_COUPON_IDS ? PM_THREE_HALF_OCLOCK_COUPON_IDS : "251869"
  234. }
  235. // if (test_ts - now_ts <= 60 * 1000) {
  236. // couponIds = process.env.ELEVEN_OCLOCK_COUPON_IDS ? ELEVEN_OCLOCK_COUPON_IDS : "241434"
  237. // }
  238. // couponIds = '241434'
  239. if (couponIds == '' || diff == -1) {
  240. console.log('当前时间段没有可抢券!')
  241. return
  242. }
  243. couponIdArr = couponIds.split('&')
  244. $.url = 'https://yunbusiness.ccb.com/clp_coupon/txCtrl?txcode=A3341C040'
  245. cookies = process.env.JHSH_COUPON_CKS ? process.env.JHSH_COUPON_CKS : ''
  246. if (cookies == '') {
  247. console.log('未填写建行生活抢券Cookie!')
  248. return
  249. }
  250. cookieArr = cookies.split('@')
  251. console.log(`\n==========共发现${cookieArr.length}个账号==========\n`)
  252. $.weekDayNum = 0
  253. $.couponTime = 0
  254. $.message = ''
  255. $.promiseList = []
  256. !(async () => {
  257. await $.wait(diff)
  258. a: for (let couponId of couponIdArr) {
  259. for (couponInfo of couponMapList) {
  260. if (couponInfo.id == couponId) {
  261. $.couponName = couponInfo.name
  262. $.couponTime = couponInfo.time
  263. if ($.couponTime.indexOf("_") > -1) {
  264. $.weekDayNum = $.couponTime.split("_")[1]
  265. $.couponTime = $.couponTime.split("_")[0]
  266. } else {
  267. $.weekDayNum = 0
  268. }
  269. console.log($.weekDayNum)
  270. if ($.weekDayNum != 0 && $.weekDayNum != todayWDayNum) {
  271. console.log(`\n${$.couponName} 非抢券时间`)
  272. continue a
  273. }
  274. }
  275. }
  276. for (cookie of cookieArr) {
  277. $.promiseList.push(main(cookie, couponId, $.couponName))
  278. }
  279. }
  280. $.message = await Promise.all($.promiseList)
  281. if ($.message != '') {
  282. await $.msg($.name, `建行生活抢券通知`, `${$.message}`);
  283. }
  284. })()
  285. .catch((e) => {
  286. $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
  287. })
  288. .finally(() => {
  289. $.done();
  290. })
  291. function main(cookie, couponId, couponName) {
  292. return new Promise(async resolve => {
  293. let phone = cookie.split(';')[0]
  294. let userId = cookie.split(';')[1]
  295. console.log(`${time()} 账号【${phone}】开抢【${couponName}】`)
  296. let ua = `jdapp;iPhone;10.2.2;13.1.2;${uuid()};M/5.0;network/wifi;ADID/;model/iPhone8,1;addressid/2308460611;appBuild/167863;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1;`
  297. let dict = {}
  298. dict.hotFlag = true
  299. dict.needWait = false
  300. dict.isSuccess = false
  301. dict.errMsg = ''
  302. dict.phone = phone
  303. dict.userId = userId
  304. dict.ua = ua
  305. dict.couponId = couponId
  306. dict.couponName = couponName
  307. for (let count = 0; count < 20; count++) {
  308. if (dict.hotFlag == true) {
  309. console.log(`${time()} 账号【${phone}】开始尝试第${count + 1}次抢券~`)
  310. await getCoupon(dict)
  311. await $.wait(300)
  312. if (dict.needWait == true) {
  313. await $.wait(500)
  314. }
  315. } else {
  316. break
  317. }
  318. }
  319. console.log(`${time()} 账号【${phone}】抢券结果 ${dict.errMsg}`)
  320. resolve(`账号[${phone}] ${couponName} ${dict.errMsg}\n`)
  321. })
  322. }
  323. function getCoupon(dict) {
  324. let myRequest = getPostRequest(dict);
  325. // console.log(type + '-->'+ JSON.stringify(myRequest))
  326. return new Promise(async resolve => {
  327. $.post(myRequest, (err, resp, data) => {
  328. try {
  329. dict.hotFlag = false
  330. dict.needWait = false
  331. dict.isSuccess = false
  332. dataObj = JSON.parse(data)
  333. if (err) {
  334. dict.errMsg = `抢券失败:${dataObj.errMsg}`
  335. console.log(dict.errMsg)
  336. if (dict.errMsg.indexOf('拥挤') > -1) {
  337. dict.hotFlag = true
  338. }
  339. if (dict.errMsg.indexOf('流控检查') > -1) {
  340. dict.needWait = true
  341. dict.hotFlag = true
  342. }
  343. } else {
  344. dict.isSuccess = true
  345. if (data.indexOf('LIST') > -1) {
  346. console.log(`${time()}【${dict.phone}】抢券成功,获得 ${dict.couponName}`)
  347. dict.errMsg = `抢券成功!`
  348. }
  349. if (data.indexOf('coupMap') > -1) {
  350. console.log(`${time()}【${dict.phone}】已经抢过 ${dict.couponName}`)
  351. dict.errMsg = `已经抢过优惠券 `
  352. }
  353. }
  354. } catch (e) {
  355. // console.log(data);
  356. console.log(e, resp)
  357. } finally {
  358. resolve();
  359. }
  360. })
  361. })
  362. }
  363. function time() {
  364. return moment().format('YYYY-MM-DD HH:mm:ss.SSSSS')
  365. }
  366. function getPostRequest(dict, method = "POST") {
  367. let headers = {
  368. "Accept": "application/json,text/javascript,*/*",
  369. // "Accept-Encoding": "gzip, deflate, br",
  370. "Connection": "keep-alive",
  371. "User-Agent": dict.ua,
  372. "Content-Type": "application/json",
  373. // "X-Requested-With": "XMLHttpRequest",
  374. "Host": "yunbusiness.ccb.com"
  375. }
  376. body = getRequestBody(dict)
  377. // console.log(JSON.stringify(body))
  378. return { url: $.url, method: method, headers: headers, body: JSON.stringify(body), timeout: 30000 };
  379. }
  380. function getRequestBody(dict) {
  381. // return `{"req_channel_type": "1","PlatForm_Code": "MCP", "coupon_ID": ${$.couponId},"Mrch_ID": "","Mblph_No": ${$.phone},"Channel_User_ID": ${$.userId},"CLD_SOURCE_CHNL": "01","DtSrc": "MCP","MctGetCoupon_Type": "20","MS_FLAG": "0","CLD_REQ_CHANNEL": "01","MCT_CTMS": {},"COUPON_ID": ${$.couponId},"MEB_ID": ${$.userId},"USR_TEL": ${$.phone},"COUP_CHNL": "01","MSPS_ENTITY": {"PlatForm_Code": "MCP","coupon_ID": ${$.couponId},"Channel_User_ID": ${$.userId},"Mblph_No": ${$.phone},"DtSrc": "MCP"},"chnlType": "1","regionCode": "370200"}`
  382. return {
  383. "req_channel_type": "1",
  384. "PlatForm_Code": "MCP",
  385. "coupon_ID": dict.couponId,
  386. "Mrch_ID": "",
  387. "Mblph_No": dict.phone,
  388. "Channel_User_ID": dict.userId,
  389. "CLD_SOURCE_CHNL": "01",
  390. "DtSrc": "MCP",
  391. "MctGetCoupon_Type": "20",
  392. "MS_FLAG": "0",
  393. "CLD_REQ_CHANNEL": "01",
  394. "MCT_CTMS": {},
  395. "COUPON_ID": dict.couponId,
  396. "MEB_ID": dict.userId,
  397. "USR_TEL": dict.phone,
  398. "COUP_CHNL": "01",
  399. "MSPS_ENTITY": {
  400. "PlatForm_Code": "MCP",
  401. "coupon_ID": dict.couponId,
  402. "Channel_User_ID": dict.userId,
  403. "Mblph_No": dict.phone,
  404. "DtSrc": "MCP"
  405. },
  406. "chnlType": "1",
  407. "regionCode": "370200"
  408. }
  409. }
  410. function uuid(x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") {
  411. return x.replace(/[xy]/g, function (x) {
  412. const r = 16 * Math.random() | 0, n = "x" === x ? r : 3 & r | 8;
  413. return n.toString(36)
  414. })
  415. }
  416. //---SyncByPyScript---Env-start
  417. function Env(t, e) { "undefined" != typeof process && JSON.stringify(process.env).indexOf("GITHUB") > -1 && process.exit(0); 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.startTime = (new Date).getTime(), Object.assign(this, e), this.log("", `🔔${this.name}, 开始!`) } 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 } 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, h] = i.split("@"), n = { url: `http://${h}/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), h = i ? "null" === o ? null : o || "{}" : "{}"; try { const e = JSON.parse(h); 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 = (() => { })) { 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), e(t, s, i) })) : 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))) : this.isNode() && (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: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => { const { message: s, response: i } = t; e(s, i, i && i.body) })) } post(t, e = (() => { })) { 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.post(t, (t, s, i) => { !t && s && (s.body = i, s.statusCode = s.status), e(t, s, i) }); else if (this.isQuanX()) t.method = "POST", 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)); else if (this.isNode()) { this.initGotEnv(t); const { url: s, ...i } = t; this.got.post(s, i).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => { const { message: s, response: i } = t; e(s, i, i && i.body) }) } } 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; return { "open-url": e, "media-url": s } } 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 = ["", "==============📣系统通知📣=============="]; 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("", `❗️${this.name}, 错误!`, t.stack) : this.log("", `❗️${this.name}, 错误!`, t) } wait(t) { return new Promise(e => setTimeout(e, t)) } done(t = {}) { const e = (new Date).getTime(), s = (e - this.startTime) / 1e3; this.log("", `🔔${this.name}, 结束! 🕛 ${s} 秒`), this.log(), (this.isSurge() || this.isQuanX() || this.isLoon()) && $done(t) } }(t, e) }
  418. //---SyncByPyScript---Env-end