ios_rule_script/script/obsolete/eleme/eleme_daily.js

384 lines
43 KiB
JavaScript
Raw Normal View History

2021-04-09 19:34:05 +08:00
const scriptName = '饿了么';
const getCoordinateRegex1 = /^https?:\/\/air\.tb\.ele\.me\/app\/conch-page\/svip-home-tasklist-new\/home\?.*longitude=([^&]*).*latitude=([^&]*)/;
const getCoordinateRegex2 = /^https?:\/\/tb\.ele\.me\/wow\/alsc\/mod\/.*longitude=([^&]*).*latitude=([^&]*)/;
const getCoordinateRegex3 = /^https?:\/\/h5\.ele\.me\/restapi\/biz\.svip_scene\/svip\/engine\/queryTrafficSupply\?.*longitude=([^&]*).*latitude=([^&]*)/;
const getCookiesRegex = /^https?:\/\/air\.tb\.ele\.me\/app\/conch-page\/svip-foodie-card\/home/;
const elemeCookieKey = 'eleme_cookies';
const elemeCoordinateKey = 'eleme_coordinate';
const elemeMissionKey = 'eleme_mission';
const elemeSyncQinglongKey = 'eleme_sync_qinglong';
const elemeTaskKey = "eleme_task_keywords";
let currentUserId = "";
let currentCookies = "";
let currentCoordinate = null;
2021-04-09 19:34:05 +08:00
const $ = MagicJS(scriptName, "INFO");
2021-04-09 19:34:05 +08:00
function getUserId(cookies) {
if (!!cookies) {
let userId = /USERID=(\d*)/.exec(cookies)[1];
$.logger.info(`当前UserId${userId}`);
return userId;
}
}
async function getCoordinate() {
try {
$.logger.debug(`当前获取的header\n${$.request.headers}`);
currentUserId = getUserId($.request.headers.Cookie);
let hisCoordinate = $.data.read(elemeCoordinateKey, "", currentUserId);
arr = $.request.url.match(getCoordinateRegex1);
if (arr && arr.length < 2) {
arr = $.request.url.match(getCoordinateRegex2);
}
if (arr && arr.length < 2) {
arr = $.request.url.match(getCoordinateRegex3);
}
const longitude = arr[1];
const latitude = arr[2];
if (!hisCoordinate || (!!hisCoordinate && (hisCoordinate.longitude !== longitude || hisCoordinate.latitude !== latitude))) {
$.data.write(elemeCoordinateKey, { longitude, latitude }, currentUserId);
$.notification.post("更新坐标成功");
}
const syncQinglong = $.data.read(elemeSyncQinglongKey, false);
if (syncQinglong === true) {
// 获取青龙面板存储的坐标
hisCoordinate = await $.qinglong.read(elemeCoordinateKey, "", currentUserId);
if (!hisCoordinate || (!!hisCoordinate && (hisCoordinate.longitude !== longitude || hisCoordinate.latitude !== latitude))) {
await $.qinglong.write(elemeCoordinateKey, { longitude, latitude }, currentUserId);
$.notification.post("同步坐标至青龙面板成功");
}
2021-04-09 19:34:05 +08:00
}
}
catch (err) {
$.notify('获取坐标出现异常,请查阅日志。');
$.logError(`获取坐标出现执行异常,异常信息:${err}`);
}
}
async function getCookies() {
try {
const cookie = $.request.headers.Cookie;
$.logger.info(`本次运行获取的新Cookies\n${cookie}`);
currentUserId = getUserId(cookie);
const compareCookie2 = !!cookie ? /cookie2=([a-zA-Z0-9]*)/.exec(cookie)[1] : null;
// 获取存储池中的旧Cookie
let hisCookie = $.data.read(elemeCookieKey, "", currentUserId);
$.logger.info(`存储池中旧的Cookies\n${hisCookie}`);
if (!!cookie) {
if (!hisCookie) {
$.data.write(elemeCookieKey, cookie, currentUserId);
$.notification.post("Cookie获取成功");
}
else {
const compareHisCookie2 = !!hisCookie ? /cookie2=([a-zA-Z0-9]*)/.exec(hisCookie)[1] : null;
$.logger.info(`用于比较Cookie变化\n新:${compareCookie2}\n旧:${compareHisCookie2}`);
if (compareCookie2 !== compareHisCookie2) {
$.data.write(elemeCookieKey, cookie, currentUserId);
$.notification.post("Cookie更新成功");
}
}
if ($.data.read(elemeSyncQinglongKey, false) === true) {
hisCookie = await $.qinglong.read(elemeCookieKey, "", currentUserId);
$.logger.info(`青龙面板中旧的Cookies\n${hisCookie}`);
if (!hisCookie) {
await $.qinglong.write(elemeCookieKey, cookie, currentUserId);
$.notification.post("Cookie同步至青龙面板成功");
}
else {
const compareHisCookie2 = !!hisCookie ? /cookie2=([a-zA-Z0-9]*)/.exec(hisCookie)[1] : null;
$.logger.info(`用于比较Cookie变化\n新:${compareCookie2}\n旧:${compareHisCookie2}`);
if (compareCookie2 !== compareHisCookie2) {
await $.qinglong.write(elemeCookieKey, cookie, currentUserId);
$.notification.post("Cookie同步至青龙面板成功");
}
}
}
}
else {
$.logger.warning('没有获取到有效的CookiesSurge请关闭MITM over HTTP/2')
}
}
catch (err) {
$.logger.error(`获取Cookies出现异常\n${err}`);
2021-04-09 19:34:05 +08:00
}
}
function addConfig(config) {
currentCoordinate = currentCoordinate || $.data.read(elemeCoordinateKey, "", currentUserId);
config.headers.Cookie = currentCookies;
config.headers["x-shard"] = `loc=${currentCoordinate.longitude},${currentCoordinate.latitude}`;
return config;
}
$.http.interceptors.request.use(addConfig);
2021-04-09 19:34:05 +08:00
// 获取待领取的吃货豆列表
function getPeaList() {
return new Promise((resolve, reject) => {
currentCoordinate = currentCoordinate || $.data.read(elemeCoordinateKey, "", currentUserId);
$.http.get({
url: `https://h5.ele.me/restapi/biz.svip_core/v1/foodie/homepage?longitude=${currentCoordinate.longitude}&latitude=${currentCoordinate.latitude}`,
2021-04-09 19:34:05 +08:00
headers: {
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Host": "h5.ele.me",
"Referer": "https://h5.ele.me/svip/home?entryStat=profile",
"User-Agent": "Rajax/1 Apple/iPhone10,3 iOS/14.2 Eleme/9.3.8",
"f-pTraceId": "WVNet_WV_2-3-74",
"f-refer": "wv_h5"
2021-04-09 19:34:05 +08:00
}
}).then(resp => {
const obj = resp.body;
if (obj.success === true) {
let peaList = [];
obj.foodiePeaBlock.peaList.forEach(element => {
peaList.push({ 'id': element.id, 'count': element.count, 'description': element.description });
});
$.logger.info(`获取待领取的吃货豆成功:${JSON.stringify(peaList)}`);
resolve(peaList);
2021-04-09 19:34:05 +08:00
}
else {
const msg = `获取待领取的吃货豆失败\n${JSON.stringify(obj)}`;
$.logger.warning(msg);
reject(msg);
2021-04-09 19:34:05 +08:00
}
}).catch(err => {
const msg = `获取待领取的吃货豆出现异常\n${err}`;
$.logger.error(msg);
reject(msg);
2021-04-09 19:34:05 +08:00
})
})
}
// 领取吃货豆
function drawPea(peaId) {
return new Promise((resolve, reject) => {
currentCoordinate = currentCoordinate || $.data.read(elemeCoordinateKey, "", currentUserId);
$.http.post({
2021-04-09 19:34:05 +08:00
url: `https://h5.ele.me/restapi/biz.svip_bonus/v1/users/supervip/pea/draw?peaId=${peaId}`,
headers: {
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Content-Type": "application/json;charset=utf-8",
"Host": "h5.ele.me",
"Origin": "https://h5.ele.me",
"Referer": "https://h5.ele.me/svip/home?entryStat=profile",
"User-Agent": "Rajax/1 Apple/iPhone10,3 iOS/14.2 Eleme/9.3.8",
"f-pTraceId": "WVNet_WV_2-3-73",
"f-refer": "wv_h5"
2021-04-09 19:34:05 +08:00
},
body: JSON.stringify(currentCoordinate)
}).then(resp => {
const obj = resp.body;
if (obj.success === true) {
$.logger.info(`领取吃货豆成功\n${JSON.stringify(obj)}`);
resolve(true);
2021-04-09 19:34:05 +08:00
}
else {
const msg = `领取吃货豆失败\n${JSON.stringify(obj)}`;
$.logger.warning(msg);
reject(msg)
}
}).catch(err => {
const msg = `领取吃货豆异常\n${err}`;
$.logger.error(msg);
reject(msg)
})
})
}
// 获取超级会员任务列表
function getSuperVipMissions() {
return new Promise((resolve, reject) => {
// 获取配置的任务关键词
let taskKeywords = $.data.read(elemeTaskKey, "美食外卖");
$.logger.info(`只获取含有以下关键词的任务:${taskKeywords}`);
taskKeywords = taskKeywords.split(';');
// 获取坐标
currentCoordinate = currentCoordinate || $.data.read(elemeCoordinateKey, "", currentUserId);
$.http.get({
url: `https://h5.ele.me/restapi/svip_biz/v1/supervip/query_mission_list?longitude=${currentCoordinate.longitude}&latitude=${currentCoordinate.latitude}`,
headers: {
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Host": "h5.ele.me",
"Referer": "https://h5.ele.me/svip/home?entryStat=profile",
"User-Agent": "Rajax/1 Apple/iPhone10,3 iOS/14.2 Eleme/9.3.8",
"f-pTraceId": "WVNet_WV_2-3-30",
"f-refer": "wv_h5"
},
}).then(resp => {
const obj = resp.body;
if (obj && obj.missions) {
let result = [];
obj.missions.forEach((element) => {
let missionInfo = JSON.stringify(element);
let flag = false;
for (keyword of taskKeywords) {
if (missionInfo.indexOf(keyword) >= 0) {
flag = true;
break;
}
2021-04-09 19:34:05 +08:00
}
if (flag === true) {
result.push(element.mission_id);
2021-04-09 19:34:05 +08:00
}
});
resolve(result);
2021-04-09 19:34:05 +08:00
}
else {
const msg = `获取待领取的会员任务失败\n${JSON.stringify(obj)}`;
$.logger.warning(msg);
reject(msg);
}
}).catch(err => {
const msg = `获取待领取的会员任务异常\n${JSON.stringify(err)}`;
$.logger.error(msg);
reject(msg);
2021-04-09 19:34:05 +08:00
})
});
2021-04-09 19:34:05 +08:00
}
// 接受超级会员任务列表中的任务
function acceptMission(missionId) {
return new Promise((resolve, reject) => {
const _mission_id = encodeURIComponent(missionId);
// 获取坐标
currentCoordinate = currentCoordinate || $.data.read(elemeCoordinateKey, "", currentUserId);
$.http.post({
url: `https://h5.ele.me/restapi/svip_biz/v1/supervip/accept_mission?type=0&receiveType=1&mission_id=${_mission_id}`,
headers: {
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Content-Type": "application/json;charset=utf-8",
"Host": "h5.ele.me",
"Origin": "https://h5.ele.me",
"Referer": "https://h5.ele.me/svip/home?entryStat=profile",
"User-Agent": "Rajax/1 Apple/iPhone10,3 iOS/14.5.1 Eleme/9.8.5",
"f-pTraceId": "WVNet_WV_1-1-40",
"f-refer": "wv_h5"
},
body: currentCoordinate,
}).then(resp => {
const obj = resp.body;
if (obj.success === true) {
$.logger.info(`领取会员任务成功任务Id${missionId},任务描述:${obj.mission.checkout_description}`);
resolve(obj.mission.checkout_description);
} else {
const msg = `领取会员任务失败任务Id${missionId}\n${JSON.stringify(obj)}`;
$.logger.warning(msg);
reject(msg);
}
}).catch(err => {
const msg = `领取会员任务异常任务Id${missionId}\n${err}`;
$.logger.error(msg);
reject(msg);
})
});
}
; (async () => {
if ($.isRequest) {
if ((
getCoordinateRegex1.test($.request.url) ||
getCoordinateRegex2.test($.request.url) ||
getCoordinateRegex3.test($.request.url)
) && $.request.method == "GET") {
await getCoordinate();
}
else if (getCookiesRegex.test($.request.url)) {
await getCookies();
2021-04-09 19:34:05 +08:00
}
}
else {
const allSessions = $.data.allSessions(elemeCookieKey);
if (!allSessions) {
const msg = "没有读取到需要执行的Cookies请先打开饿了么获取!";
$.logger.warning(msg);
$.notification.post(msg);
2021-04-09 19:34:05 +08:00
}
else {
$.logger.info(`${allSessions.length}个Cookies需要执行`);
for (let [index, session] of allSessions.entries()) {
$.logger.info(`正在执行第 ${index + 1} 个Cookie的任务`);
let content = "";
currentUserId = session;
currentCookies = $.data.read(elemeCookieKey, "", session);
// 获取待领取的吃货豆
$.logger.info("开始领取吃货豆")
2021-04-09 19:34:05 +08:00
let peaCount = 0;
let drawPeaContent = '';
const peaList = await getPeaList();
if (!!peaList && peaList.length > 0) {
let tasks = [];
peaList.forEach(pea => {
tasks.push($.utils.retry(drawPea, 3, 500)(pea.id).then(() => {
peaCount += pea.count;
drawPeaContent += `\n${pea.description}-${pea.count}吃货豆-领取成功`;
}).catch(() => {
drawPeaContent += `\n${pea.description}-${pea.count}吃货豆-领取失败`;
}));
});
await Promise.all(tasks).then(() => {
content = `本次共领取吃货豆${peaCount}`;
$.logger.info(drawPeaContent);
})
}
else {
const msg = "没发现待领取的吃货豆";
content = msg;
$.logger.info(msg);
}
// 根据关键词领取任务
if ($.data.read(elemeMissionKey, true) === true) {
const missionIds = await $.utils.retry(getSuperVipMissions, 3, 1000)().catch(err => {
$.notification.post(err);
});
if (!!missionIds && missionIds.length > 0) {
$.logger.info(`匹配关键词的任务Id:\n${JSON.stringify(missionIds)}`);
content += !!content? "\n": "";
content += "会员任务领取结果:\n";
for (let missionId of missionIds) {
await $.utils.retry(acceptMission, 3, 1000)(missionId).then((desc) => {
content += desc;
}).catch(err => {
$.notification.post(err);
})
}
2021-04-09 19:34:05 +08:00
}
}
$.notification.post(`${scriptName} - ${currentUserId}`, "", content);
$.logger.info(`${index + 1} 个Cookie任务执行完毕`);
2021-04-09 19:34:05 +08:00
}
}
}
$.done();
2021-04-09 19:34:05 +08:00
})();
/**
*
* $$\ $$\ $$\ $$$$$\ $$$$$$\ $$$$$$\
* $$$\ $$$ | \__| \__$$ |$$ __$$\ $$ ___$$\
* $$$$\ $$$$ | $$$$$$\ $$$$$$\ $$\ $$$$$$$\ $$ |$$ / \__| \_/ $$ |
* $$\$$\$$ $$ | \____$$\ $$ __$$\ $$ |$$ _____| $$ |\$$$$$$\ $$$$$ /
* $$ \$$$ $$ | $$$$$$$ |$$ / $$ |$$ |$$ / $$\ $$ | \____$$\ \___$$\
* $$ |\$ /$$ |$$ __$$ |$$ | $$ |$$ |$$ | $$ | $$ |$$\ $$ | $$\ $$ |
* $$ | \_/ $$ |\$$$$$$$ |\$$$$$$$ |$$ |\$$$$$$$\\$$$$$$ |\$$$$$$ | \$$$$$$ |
* \__| \__| \_______| \____$$ |\__| \_______|\______/ \______/ \______/
* $$\ $$ |
* \$$$$$$ |
* \______/
*
*/
function MagicJS(e = "MagicJS", t = "INFO") { const r = () => { const e = typeof $loon !== "undefined"; const t = typeof $task !== "undefined"; const n = typeof module !== "undefined"; const r = typeof $httpClient !== "undefined" && !e; const i = typeof $storm !== "undefined"; const o = typeof $environment !== "undefined" && typeof $environment["stash-build"] !== "undefined"; const s = r || e || i || o; const a = typeof importModule !== "undefined"; return { isLoon: e, isQuanX: t, isNode: n, isSurge: r, isStorm: i, isStash: o, isSurgeLike: s, isScriptable: a, get name() { if (e) { return "Loon" } else if (t) { return "QuantumultX" } else if (n) { return "NodeJS" } else if (r) { return "Surge" } else if (a) { return "Scriptable" } else { return "unknown" } }, get build() { if (r) { return $environment["surge-build"] } else if (o) { return $environment["stash-build"] } else if (i) { return $storm.buildVersion } }, get language() { if (r || o) { return $environment["language"] } }, get version() { if (r) { return $environment["surge-version"] } else if (o) { return $environment["stash-version"] } else if (i) { return $storm.appVersion } else if (n) { return process.version } }, get system() { if (r) { return $environment["system"] } else if (n) { return process.platform } }, get systemVersion() { if (i) { return $storm.systemVersion } }, get deviceName() { if (i) { return $storm.deviceName } } } }; const i = (n, e = "INFO") => { let r = e; const i = { SNIFFER: 6, DEBUG: 5, INFO: 4, NOTIFY: 3, WARNING: 2, ERROR: 1, CRITICAL: 0, NONE: -1 }; const o = { SNIFFER: "", DEBUG: "", INFO: "", NOTIFY: "", WARNING: "❗ ", ERROR: "❌ ", CRITICAL: "❌ ", NONE: "" }; const t = (e, t = "INFO") => { if (!(i[r] < i[t.toUpperCase()])) console.log(`[${t}] [${n}]\n${o[t.toUpperCase()]}${e}\n`) }; const s = e => { r = e }; return { setLevel: s, sniffer: e => { t(e, "SNIFFER") }, debug: e => { t(e, "DEBUG") }, info: e => { t(e, "INFO") }, notify: e => { t(e, "NOTIFY") }, warning: e => { t(e, "WARNING") }, error: e => { t(e, "ERROR") }, retry: e => { t(e, "RETRY") } } }; return new class { constructor(e, t) { this._startTime = Date.now(); this.version = "3.0.0"; this.scriptName = e; this.env = r(); this.logger = i(e, t); this.http = typeof MagicHttp === "function" ? MagicHttp(this.env, this.logger) : undefined; this.data = typeof MagicData === "function" ? MagicData(this.env, this.logger) : undefined; this.notification = typeof MagicNotification === "function" ? MagicNotification(this.scriptName, this.env, this.logger, this.http) : undefined; this.utils = typeof MagicUtils === "function" ? MagicUtils(this.env, this.logger) : undefined; this.qinglong = typeof MagicQingLong === "function" ? MagicQingLong(this.env, this.data, this.logger) : undefined; if (typeof this.data !== "undefined") { let e = this.data.read("magic_loglevel"); const n = this.data.read("magic_bark_url"); if (e) { this.logger.setLevel(e.toUpperCase()) } if (n) { this.notification.setBark(n) } } } get isRequest() { return typeof $request !== "undefined" && typeof $response === "undefined" } get isResponse() { return typeof $response !== "undefined" } get isDebug() { return this.logger.level === "DEBUG" } get request() { return typeof $request !== "undefined" ? $request : undefined } get response() { if (typeof $response !== "undefined") { if ($response.hasOwnProperty("status")) $response["statusCode"] = $response["status"]; if ($response.hasOwnProperty("statusCode")) $response["status"] = $response["statusCode"]; return $response } else { return undefined } } done = (e = {}) => { this._endTime = Date.now(); let t = (this._endTime - this._startTime) / 1e3; this.logger.info(`SCRIPT COMPLETED: ${t} S.`); if (typeof $done !== "undefined") { $done(e) } } }(e, t) } function MagicHttp(u, c) { const t = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1"; const n = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.59"