"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// ../../packages/utils-pure/index.ts function getXmlElement(xml, tag) { if (!xml.match) return ""; let m = xml.match(`<${tag}>(.*)`); return m ? m[1] : ""; } function isPlainObject(obj) { return Array.isArray(obj) || Object.prototype.toString.call(obj) === "[object Object]"; } function sortStringify(obj) { return Object.entries(obj).sort().map(([key, value]) => `${key}=${value}`).join("&"); } function getBeijingTime(timestamp) { let time = timestamp ? new Date(timestamp) : /* @__PURE__ */ new Date(), [year, monthStr, dayStr] = time.toLocaleDateString("zh-CN").split(/[/:-]/); return { year: parseInt(year, 10), month: parseInt(monthStr, 10), day: parseInt(dayStr, 10) }; } function getInToday(timestamp) { let today = getBeijingTime(), time = getBeijingTime(timestamp); return today.day === time.day && today.month === time.month && today.year === time.year; } // ../../core/ecloud/constant.ts var Appkey = "600100422"; // ../../core/ecloud/api.ts function createApi(http) { let logboxUrl = "https://open.e.189.cn/api/logbox", oauth2Url = logboxUrl + "/oauth2"; return { loginSubmit({ username, password, returnUrl, paramId, pre = "{NRP}" }) { return http.post(oauth2Url + "/loginSubmit.do", { version: "v2.0", appKey: "cloud", apToken: "", accountType: "01", userName: `${pre}${username}`, epd: `${pre}${password}`, validateCode: "", captchaToken: "", captchaType: "", dynamicCheck: "FALSE", clientType: 1, returnUrl, mailSuffix: "@189.cn", paramId, cb_SaveName: 3 }); }, async loginRedirect() { let loginUrl = (await http.get("https://cloud.189.cn/api/portal/loginUrl.action", { native: !0, followRedirect: !1 })).headers.location; if (!loginUrl) throw new Error("获取登录链接loginUrl失败"); let htmlUrl = (await http.get(loginUrl, { native: !0, followRedirect: !1 })).headers.location; if (!htmlUrl) throw new Error("获取登录链接htmlUrl失败"); return htmlUrl.split(".html?")[1].split("&").reduce((acc, cur) => { let [key, value] = cur.split("="); return acc[key] = value, acc; }, {}); }, appConf() { return http.post(oauth2Url + "/appConf.do", { appKey: "cloud" }); }, encryptConf() { return http.post(logboxUrl + "/config/encryptConf.do", "appId=cloud"); }, loginCallback(toUrl) { return http.get(toUrl); }, drawPrizeMarket(taskId) { return http.get( `https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=${taskId}&activityId=ACT_SIGNIN&noCache=${Math.random()}` ); }, userSign(version = "10.1.4", model = "iPhone14") { return http.get( `https://api.cloud.189.cn/mkt/userSign.action?rand=${(/* @__PURE__ */ new Date()).getTime()}&clientType=TELEANDROID&version=${version}&model=${model}`, { headers: { HOST: "m.cloud.189.cn" } } ); }, getUserBriefInfo() { return http.get( "https://cloud.189.cn/api/portal/v2/getUserBriefInfo.action" ); }, getAccessTokenBySsKey(sessionKey, headers) { return http.get( `https://cloud.189.cn/api/open/oauth2/getAccessTokenBySsKey.action?sessionKey=${sessionKey}`, { headers } ); }, getFamilyList(headers) { return http.get("https://api.cloud.189.cn/open/family/manage/getFamilyList.action", { headers }); }, familySign(familyId, headers) { return http.get( `https://api.cloud.189.cn/open/family/manage/exeFamilyUserSign.action?familyId=${familyId}`, { headers } ); }, getListGrow() { return http.get( `https://cloud.189.cn/api/portal/listGrow.action?noCache=${Math.random()}` ); }, getUserSizeInfo() { return http.get(`https://cloud.189.cn/api/portal/getUserSizeInfo.action?noCache=${Math.random()}`, { headers: { referrer: "https://cloud.189.cn/web/main/file/folder/-11" } }); }, http }; } // ../../core/ecloud/index.ts async function signIn($) { try { let { isSign, netdiskBonus } = await $.api.userSign(); if (!netdiskBonus) { $.logger.fatal("签到失败,请手动签到"); return; } if (isSign) { $.logger.info("今日已签到,获得", netdiskBonus, "MB"); return; } $.logger.success("签到成功,获得", netdiskBonus, "MB"); } catch (error) { $.logger.error("签到异常", error); } } async function drawPrizeMarket($, taskId) { try { let data = await $.api.drawPrizeMarket(taskId), { errorCode, prizeName, errorMsg } = data; if (errorCode) return errorCode === "User_Not_Chance" ? $.logger.info(`${taskId}无抽奖次数`) : $.logger.fail("抽奖失败", errorCode, errorMsg); if (prizeName) return $.logger.info("抽奖成功,获得", prizeName); $.logger.fail("抽奖失败", JSON.stringify(data)); } catch (error) { $.logger.error("抽奖异常", error); } } async function getEncryptConf($) { try { let encryptConf = await $.api.encryptConf(); if (encryptConf.data.pubKey) return encryptConf.data; } catch (error) { $.logger.debug("获取加密配置异常", error); } return { pubKey: "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZLyV4gHNDUGJMZoOcYauxmNEsKrc0TlLeBEVVIIQNzG4WqjimceOj5R9ETwDeeSN3yejAKLGHgx83lyy2wBjvnbfm/nLObyWwQD/09CmpZdxoFYCH6rdDjRpwZOZ2nXSZpgkZXoOBkfNXNxnN74aXtho2dqBynTw3NFTWyQl8BQIDAQAB", pre: "{NRP}" }; } async function login($) { let { lt, reqId } = await $.api.loginRedirect(); $.api.http.setHeader("Lt", lt).setHeader("reqId", reqId); let appConfig = await $.api.appConf(), username = $.config.username, password = $.config.password, pre; if ($.rsaEncrypt) { let encryptCon = await getEncryptConf($), publicKey = `-----BEGIN PUBLIC KEY----- ${encryptCon.pubKey} -----END PUBLIC KEY-----`; ({ username, password } = $.rsaEncrypt(publicKey, $.config.username, $.config.password)), pre = encryptCon.pre; } let { result, toUrl, msg } = await $.api.loginSubmit({ username, password, paramId: appConfig.data.paramId, returnUrl: appConfig.data.returnUrl, pre }); if (result !== 0) throw $.logger.error("登录失败", result, msg), new Error(msg); await $.api.loginCallback(toUrl); } async function drawPrizeTask($) { $.logger.debug("开始执行抽奖任务"); try { await drawPrizeMarket($, "TASK_SIGNIN"), await $.sleep(6e3), await drawPrizeMarket($, "TASK_SIGNIN_PHOTOS"), await $.sleep(6e3), await drawPrizeMarket($, "TASK_2022_FLDFS_KJ"); } catch (error) { $.logger.error("抽奖任务异常", error); } } async function getSessionKey($) { try { let { res_code, res_message, sessionKey } = await $.api.getUserBriefInfo(); if (res_code === 0) return sessionKey; $.logger.error("获取 sessionKey 失败", res_code, res_message); } catch (error) { $.logger.error("获取 sessionKey 异常", error); } } async function getAccessToken($, sessionKey) { try { let data = await $.api.getAccessTokenBySsKey(sessionKey, { Appkey, ...getSignature($.md5, { Appkey, sessionKey }) }); if (data.errorCode) { $.logger.error("获取 accessToken 失败", data.errorCode, data.errorMsg); return; } return data; } catch (error) { $.logger.error("获取 sessionKey 异常", error); } } async function getFamilyId($, AccessToken) { try { let xml = await $.api.getFamilyList({ ...getSignature($.md5, { AccessToken }) }); if (isPlainObject(xml)) { $.logger.fail("获取家庭出错", JSON.stringify(xml)); return; } return getXmlElement(xml, "familyId"); } catch (error) { $.logger.error("获取家庭信息异常", error); } } async function signInFamily($, AccessToken) { if (!AccessToken) return $.logger.fail("请提供 AccessToken"); try { let familyId = await getFamilyId($, AccessToken); if (!familyId) return $.logger.fail("签到失败"); let xml = await $.api.familySign(familyId, { ...getSignature($.md5, { AccessToken, familyId }) }); if (isPlainObject(xml)) { $.logger.fail("签到异常", JSON.stringify(xml)); return; } let bonusSpace = getXmlElement(xml, "bonusSpace"); $.logger.success(`签到成功,获得${bonusSpace}M家庭空间`); } catch (error) { $.logger.error("家庭签到异常", error); } } async function getTaskProgress($, times) { let returnWarp = (sign = 0, draw = !1) => ({ sign, draw }); try { let data = await $.api.getListGrow(); if (data.errorCode) return $.logger.fail("获取空间记录失败", data.errorCode, data.errorMsg), returnWarp(); let todayList = data.growList.filter( (item) => getInToday(item.changeTime) && (item.taskName === "每日签到送空间" || item.taskName === "天翼云盘50M空间") ); if (todayList.length === 0) return returnWarp(); let todaySign = todayList.find((item) => item.taskName === "每日签到送空间"); if (todaySign) return todayList.length >= 3 ? returnWarp(todaySign.changeValue, !0) : returnWarp(todaySign.changeValue, !1); if (todayList.length >= 2) return returnWarp(0, !0); } catch (error) { $.logger.error("获取空间记录异常", error); } return returnWarp(); } async function appLogin($) { try { let sessionKey = await getSessionKey($); if (!sessionKey) return; let data = await getAccessToken($, sessionKey); return data ? data.accessToken : void 0; } catch (error) { $.logger.error("appLogin 异常", error); } } async function init($) { return await login($), $.store = { AccessToken: await appLogin($) }, await getTaskProgress($, 1); } function convertSizeToGigaMega(size) { console.log(size); let gigabytes = Math.floor(size / 1073741824), megabytes = (size - 1073741824 * gigabytes) / 1048576; return megabytes ? `${gigabytes}G ${megabytes}M` : `${gigabytes}G`; } async function printSize($) { try { let xml = await $.api.getUserSizeInfo(); if (typeof xml != "string") { $.logger.info("获取空间大小异常", JSON.stringify(xml)); return; } let cloudCapacityInfo = getXmlElement(xml, "cloudCapacityInfo"), familyCapacityInfo = getXmlElement(xml, "familyCapacityInfo"), cloudSize = +getXmlElement(cloudCapacityInfo, "totalSize"), familySize = +getXmlElement(familyCapacityInfo, "totalSize"); $.logger.info( `云盘空间:${convertSizeToGigaMega(cloudSize)}`, `家庭空间:${convertSizeToGigaMega(familySize)}` ); } catch (error) { $.logger.debug("获取空间大小异常", error.message); } } async function run($) { $.logger.info("开始签到", $.config.username); try { let { draw, sign } = await init($); await printSize($), sign ? $.logger.info(`今日已签到,获得${sign}M空间`) : (await $.sleep(2e3), await signIn($)), draw ? $.logger.info("今日已无抽奖次数") : (await $.sleep(5e3), await drawPrizeTask($)), await $.sleep(5e3), await signInFamily($, $.store && $.store.AccessToken), await printSize($); } catch (error) { $.logger.error("运行异常", error); } } function getSignature(md52, data) { let Timestamp = String(Date.now()), d = {}; return data.AccessToken && (d.AccessToken = data.AccessToken), { signature: md52(sortStringify({ Timestamp, ...data })), Timestamp, "Sign-Type": "1", ...d }; } // index.ts var _conf = require('@asunajs/conf'); var _http = require('@asunajs/http'); var _push = require('@asunajs/push'); // ../../packages/utils/index.ts var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto); function sleep(time) { return new Promise((res) => setTimeout(() => res(time), time)); } async function createLogger(options) { let { createConsola, consola } = await Promise.resolve().then(() => _interopRequireWildcard(require("./dist-WNKMRARM.cjs"))); return consola.options.level = 5, createConsola({ level: 5, reporters: [ { log: ({ type, args, level, date }) => { if (options && options.pushData) { let msg = args.reduce((str, cur) => `${str} ${cur}`, "").substring(1); options.pushData.push({ msg, type, level, date }); } consola[type].apply(consola, args); } } ] }); } function _hash(algorithm, input) { return _crypto2.default.createHash(algorithm).update(input).digest("hex"); } function md5(input) { return _hash("md5", input); } async function pushMessage({ pushData, message, sendNotify: sendNotify2, createRequest: createRequest2 }) { if (pushData.length && message) { if (message.onlyError && !pushData.some((el) => el.type === "error")) return; let msg = pushData.filter((el) => el.level < 4).map((m) => `[${m.type} ${m.date.toLocaleTimeString()}]${m.msg}`).join(` `); msg && await sendNotify2( { logger: await createLogger(), http: { fetch: (op) => createRequest2().request(op) } }, message, message.title || "asign 运行推送", msg ); } } // index.ts function rsaEncrypt(publicKey, text) { return _crypto.publicEncrypt.call(void 0, { key: publicKey, padding: _crypto.constants.RSA_PKCS1_PADDING }, Buffer.from(text, "utf8") ).toString("hex"); } async function main(config, option) { let logger = await createLogger({ pushData: option == null ? void 0 : option.pushData }), $ = { api: createApi( _http.createRequest.call(void 0, { headers: { "content-type": "application/x-www-form-urlencoded", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/123.0", Referer: "https://open.e.189.cn/", accept: "application/json" } }) ), logger, sleep, rsaEncrypt: (publicKey, username, password) => ({ username: rsaEncrypt(publicKey, username), password: rsaEncrypt(publicKey, password) }), config, md5 }; $.logger.start("-------------"), await run($); } async function run2(inputPath) { let { config } = await _conf.loadConfig.call(void 0, inputPath), logger = await createLogger(), ecloud = config.ecloud; if (!ecloud || !ecloud.length) return logger.error("未找到配置文件/变量"); let pushData = []; for (let index = 0; index < ecloud.length; index++) { let c = ecloud[index]; if (c.password) try { await main(c, { pushData }); } catch (error) { logger.error(error); } } await pushMessage({ pushData, message: config.message, sendNotify: _push.sendNotify, createRequest: _http.createRequest }); } exports.main = main; exports.run = run2;