mirror of
https://github.com/shufflewzc/faker2.git
synced 2025-04-23 02:48:44 +08:00
update
This commit is contained in:
parent
9e2e725afe
commit
0661f71099
10
jd_618phone.js
Normal file
10
jd_618phone.js
Normal file
File diff suppressed because one or more lines are too long
@ -18,6 +18,7 @@ apk add g++ make --no-cache
|
||||
pnpm config set registry https://registry.npmmirror.com
|
||||
pnpm install -g
|
||||
pnpm install -g ds
|
||||
pnpm install -g adler-32
|
||||
pnpm install -g png-js
|
||||
pnpm install -g date-fns
|
||||
pnpm install -g axios@1.6.7
|
||||
@ -28,12 +29,15 @@ pnpm install -g global-agent
|
||||
pnpm install -g @types/node
|
||||
pnpm install -g request
|
||||
pnpm install -g jsdom
|
||||
pnpm install -g crc
|
||||
pnpm install -g qs
|
||||
pnpm install -g moment
|
||||
pnpm install -g cheerio
|
||||
pnpm install -g dotenv
|
||||
pnpm install -g got@11.8.6
|
||||
pnpm install -g tough-cookie
|
||||
pnpm install -g https-proxy-agent@7.0.2
|
||||
pnpm install -g http-cookie-agent
|
||||
pnpm install -g console-table-printer@2.12.0
|
||||
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ jieba
|
||||
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ requests
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
910
jd_try.js
Normal file
910
jd_try.js
Normal file
@ -0,0 +1,910 @@
|
||||
/**
|
||||
* 京东试用, 只是一个DEMO
|
||||
|
||||
0 18 * * * jd_try.js
|
||||
|
||||
*/
|
||||
const qs = require('qs');
|
||||
const axios = require("axios");
|
||||
const common = require('./utils/Rebels_jdCommon')
|
||||
const {H5st} = require("./utils/h5st4.4.0_lite");
|
||||
const {SmashUtils} = require("./utils/smashUtils");
|
||||
const $ = new Env("京东试用");
|
||||
const URL = "https://api.m.jd.com/client.action";
|
||||
let trialActivityIdList = [];
|
||||
let trialActivityTitleList = [];
|
||||
let notifyMsg = "";
|
||||
let size = 1;
|
||||
$.isPush = true;
|
||||
$.isLimit = false;
|
||||
$.isForbidden = false;
|
||||
$.wrong = false;
|
||||
$.giveupNum = 0;
|
||||
$.successNum = 0;
|
||||
$.completeNum = 0;
|
||||
$.getNum = 0;
|
||||
$.try = true;
|
||||
$.sentNum = 0;
|
||||
$.cookiesArr = [];
|
||||
//默认的过滤关键词
|
||||
$.innerKeyWords = ["幼儿园", "教程", "英语", "辅导", "培训", "孩子", "小学", "成人用品", "套套", "情趣", "自慰", "阳具", "飞机杯", "男士用品", "女士用品", "内衣", "高潮", "避孕", "乳腺", "肛塞", "肛门", "宝宝", "芭比", "娃娃", "男用", "女用", "神油", "足力健", "老年", "老人", "宠物", "饲料", "丝袜", "黑丝", "磨脚", "脚皮", "除臭", "性感", "内裤", "跳蛋", "安全套", "龟头", "阴道", "阴部", "手机卡", "电话卡", "流量卡", "习题", "试卷",];
|
||||
//下面很重要,遇到问题请把下面注释看一遍再来问
|
||||
let args_xh = {
|
||||
/*
|
||||
* 控制一次最多跑几个号,默认10个
|
||||
*/
|
||||
try_num: process.env.JD_TRY_NUM * 1 || 10, /*
|
||||
* 控制是否输出当前环境变量设置,默认为false
|
||||
* 环境变量名称:XH_TRY_ENV
|
||||
*/
|
||||
env: process.env.XH_TRY_ENV === "true" || false, /*
|
||||
* 跳过某个指定账号,默认为全部账号清空
|
||||
* 填写规则:例如当前Cookie1为pt_key=key; pt_pin=pin1;则环境变量填写pin1即可,此时pin1的购物车将不会被清空
|
||||
* 若有更多,则按照pin1@pin2@pin3进行填写
|
||||
* 环境变量名称:XH_TRY_EXCEPT
|
||||
*/
|
||||
except: (process.env.XH_TRY_EXCEPT && process.env.XH_TRY_EXCEPT.split("@")) || [], //以上环境变量新增于2022.01.30
|
||||
/*
|
||||
* 由于每个账号每次获取的试用产品都不一样,所以为了保证每个账号都能试用到不同的商品,之前的脚本都不支持采用统一试用组的
|
||||
* 以下环境变量是用于指定是否采用统一试用组的
|
||||
* 例如当 JD_TRY_UNIFIED 为 true时,有3个账号,第一个账号跑脚本的时候,试用组是空的
|
||||
* 而当第一个账号跑完试用组后,第二个,第三个账号所采用的试用组默认采用的第一个账号的试用组
|
||||
* 优点:减少除第一个账号外的所有账号遍历,以减少每个账号的遍历时间
|
||||
* 缺点:A账号能申请的东西,B账号不一定有
|
||||
* 提示:想每个账号独立不同的试用产品的,请设置为false,想减少脚本运行时间的,请设置为true
|
||||
* 默认为false
|
||||
*/
|
||||
unified: process.env.JD_TRY_UNIFIED === "true" || false, //以上环境变量新增于2022.01.25
|
||||
/*
|
||||
* 商品原价,低于这个价格都不会试用,意思是
|
||||
* A商品原价49元,试用价1元,如果下面设置为50,那么A商品不会被加入到待提交的试用组
|
||||
* B商品原价99元,试用价0元,如果下面设置为50,那么B商品将会被加入到待提交的试用组
|
||||
* C商品原价99元,试用价1元,如果下面设置为50,那么C商品将会被加入到待提交的试用组
|
||||
* 默认为0
|
||||
* */
|
||||
jdPrice: process.env.JD_TRY_PRICE * 1 || 20, /*
|
||||
* 下面有一个function是可以获取tabId列表,名为try_tabList
|
||||
* 可设置环境变量:JD_TRY_TABID,用@进行分隔
|
||||
* tabId不定期会变,获取不到商品,自行获取并修改tabId
|
||||
* */
|
||||
tabId: (process.env.JD_TRY_TABID && process.env.JD_TRY_TABID.split("@").map(Number)) || [212, 221, 222, 223, 229, 225, 224, 226, 234, 227, 228], /*
|
||||
* 试用商品标题过滤,黑名单,当标题存在关键词时,则不加入试用组
|
||||
* 当白名单和黑名单共存时,黑名单会自动失效,优先匹配白名单,匹配完白名单后不会再匹配黑名单,望周知
|
||||
* 例如A商品的名称为『旺仔牛奶48瓶特价』,设置了匹配白名单,白名单关键词为『牛奶』,但黑名单关键词存在『旺仔』
|
||||
* 这时,A商品还是会被添加到待提交试用组,白名单优先于黑名单
|
||||
* 已内置对应的 成人类 幼儿类 宠物 老年人类关键词,请勿重复添加
|
||||
* 可设置环境变量:JD_TRY_TITLEFILTERS,关键词与关键词之间用@分隔
|
||||
* */
|
||||
titleFilters: (process.env.JD_TRY_TITLEFILTERS && process.env.JD_TRY_TITLEFILTERS.split("@")) || [], /*
|
||||
* 试用价格(中了要花多少钱),高于这个价格都不会试用,小于等于才会试用,意思就是
|
||||
* A商品原价49元,现在试用价1元,如果下面设置为10,那A商品将会被添加到待提交试用组,因为1 < 10
|
||||
* B商品原价49元,现在试用价2元,如果下面设置为1,那B商品将不会被添加到待提交试用组,因为2 > 1
|
||||
* C商品原价49元,现在试用价1元,如果下面设置为1,那C商品也会被添加到带提交试用组,因为1 = 1
|
||||
* 可设置环境变量:JD_TRY_TRIALPRICE,默认为0
|
||||
* */
|
||||
trialPrice: process.env.JD_TRY_TRIALPRICE * 1 || 0, /*
|
||||
* 最小提供数量,例如试用商品只提供2份试用资格,当前设置为1,则会进行申请
|
||||
* 若只提供5分试用资格,当前设置为10,则不会申请
|
||||
* 可设置环境变量:JD_TRY_MINSUPPLYNUM
|
||||
* */
|
||||
minSupplyNum: process.env.JD_TRY_MINSUPPLYNUM * 1 || 1, /*
|
||||
* 过滤大于设定值的已申请人数,例如下面设置的10000,A商品已经有10001人申请了,则A商品不会进行申请,会被跳过
|
||||
* 可设置环境变量:JD_TRY_APPLYNUMFILTER
|
||||
* */
|
||||
applyNumFilter: process.env.JD_TRY_APPLYNUMFILTER * 1 || 10000, /*
|
||||
* 商品数组的最大长度,通俗来说就是即将申请的商品队列长度
|
||||
* 例如设置为20,当第一次获取后获得12件,过滤后剩下5件,将会进行第二次获取,过滤后加上第一次剩余件数
|
||||
* 例如是18件,将会进行第三次获取,直到过滤完毕后为20件才会停止,不建议设置太大
|
||||
* 可设置环境变量:JD_TRY_MAXLENGTH
|
||||
* */
|
||||
maxLength: process.env.JD_TRY_MAXLENGTH * 1 || 5, /*
|
||||
* 过滤种草官类试用,某些试用商品是专属官专属,考虑到部分账号不是种草官账号
|
||||
* 例如A商品是种草官专属试用商品,下面设置为true,而你又不是种草官账号,那A商品将不会被添加到待提交试用组
|
||||
* 例如B商品是种草官专属试用商品,下面设置为false,而你是种草官账号,那A商品将会被添加到待提交试用组
|
||||
* 例如B商品是种草官专属试用商品,下面设置为true,即使你是种草官账号,A商品也不会被添加到待提交试用组
|
||||
* 可设置环境变量:JD_TRY_PASSZC,默认为true
|
||||
* */
|
||||
passZhongCao: process.env.JD_TRY_PASSZC !== "false", /*
|
||||
* 是否打印输出到日志,考虑到如果试用组长度过大,例如100以上,如果每个商品检测都打印一遍,日志长度会非常长
|
||||
* 打印的优点:清晰知道每个商品为什么会被过滤,哪个商品被添加到了待提交试用组
|
||||
* 打印的缺点:会使日志变得很长
|
||||
*
|
||||
* 不打印的优点:简短日志长度
|
||||
* 不打印的缺点:无法清晰知道每个商品为什么会被过滤,哪个商品被添加到了待提交试用组
|
||||
* 可设置环境变量:JD_TRY_PLOG,默认为true
|
||||
* */
|
||||
printLog: process.env.JD_TRY_PLOG !== "false", /*
|
||||
* 白名单,是否打开,如果下面为true,那么黑名单会自动失效
|
||||
* 白名单和黑名单无法共存,白名单永远优先于黑名单
|
||||
* 可通过环境变量控制:JD_TRY_WHITELIST,默认为false
|
||||
* */
|
||||
whiteList: process.env.JD_TRY_WHITELIST === "true" || false, /*
|
||||
* 白名单关键词,当标题存在关键词时,加入到试用组
|
||||
* 例如A商品的名字为『旺仔牛奶48瓶特价』,白名单其中一个关键词是『牛奶』,那么A将会直接被添加到待提交试用组,不再进行另外判断
|
||||
* 就算设置了黑名单也不会判断,希望这种写得那么清楚的脑瘫问题就别提issues了
|
||||
* 可通过环境变量控制:JD_TRY_WHITELIST,用@分隔
|
||||
* */
|
||||
whiteListKeywords: (process.env.JD_TRY_WHITELISTKEYWORDS && process.env.JD_TRY_WHITELISTKEYWORDS.split("@")) || [], /*
|
||||
* 每多少个账号发送一次通知,默认为4
|
||||
* 可通过环境变量控制 JD_TRY_SENDNUM
|
||||
* */
|
||||
sendNum: process.env.JD_TRY_SENDNUM * 1 || 4,
|
||||
};
|
||||
|
||||
!(async () => {
|
||||
await $.wait(500);
|
||||
$.log("\n第一次运行请务必运行一次【依赖安装(jd_indeps.sh)】脚本\n避免出现一些奇怪的问题,遇到问题请先看脚本内注释\n频道:https://t.me/zhouya47\n");
|
||||
await requireConfig();
|
||||
if (!$.cookiesArr[0]) {
|
||||
$.msg($.name, "【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取", "https://bean.m.jd.com/", {
|
||||
"open-url": "https://bean.m.jd.com/",
|
||||
});
|
||||
return;
|
||||
}
|
||||
args_xh.tabId = args_xh.tabId.sort(() => 0.5 - Math.random());
|
||||
for (let i = 0; i < args_xh.try_num; i++) {
|
||||
if ($.cookiesArr[i]) {
|
||||
$.cookie = $.cookiesArr[i];
|
||||
$.UserName = decodeURIComponent($.cookie.match(/pt_pin=(.+?);/) && $.cookie.match(/pt_pin=(.+?);/)[1]);
|
||||
$.index = i + 1;
|
||||
$.isLogin = true;
|
||||
$.nickName = "";
|
||||
$.userAgent = common.genUA($.UserName);
|
||||
// await totalBean();
|
||||
console.log(`\n开始【京东账号${$.index}】${$.nickName || $.UserName}\n`);
|
||||
$.except = false;
|
||||
if (args_xh.except.includes($.UserName)) {
|
||||
console.log(`跳过账号:${$.nickName || $.UserName}`);
|
||||
$.except = true;
|
||||
continue;
|
||||
}
|
||||
if (!$.isLogin) {
|
||||
$.msg($.name, `【提示】cookie已失效`, `京东账号${$.index} ${$.nickName || $.UserName}\n请重新登录获取\nhttps://bean.m.jd.com/bean/signIndex.action`, {
|
||||
"open-url": "https://bean.m.jd.com/bean/signIndex.action",
|
||||
});
|
||||
await $.notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`);
|
||||
continue;
|
||||
}
|
||||
$.ParamsSignLite = new H5st("https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html?ids=501730512%2C501676150&navh=49&stath=37&tttparams=wUQ86eyJhZGRyZXNzSWQiOjAsImRMYXQiOjAsImRMbmciOjAsImdMYXQiOiIzOS45NDQwOTMiLCJnTG5nIjoiMTE2LjQ4MjI3NiIsImdwc19hcmVhIjoiMF8wXzBfMCIsImxhdCI6MCwibG5nIjowLCJtb2RlbCI6IlJlZG1pIE5vdGUgMTJUIFBybyIsInBvc0xhdCI6IjM5Ljk0NDA5MyIsInBvc0xuZyI6IjExNi40ODIyNzYiLCJwcnN0YXRlIjoiMCIsInVlbXBzIjoiMC0wLTAiLCJ1bl9hcmVhIjoiMV83Ml81NTY3NF8wIn50%3D&preventPV=1&forceCurrentView=1",
|
||||
$.cookie,
|
||||
$.userAgent, {
|
||||
debug: false,
|
||||
appId: "35fa0",
|
||||
});
|
||||
$.smashUtils = new SmashUtils(
|
||||
'https://prodev.m.jd.com/mall/active/3mpGVQDhvLsMvKfZZumWPQyWt83L/index.html?activityId=501742184&sku=10097544183544',
|
||||
$.cookie,
|
||||
$.userAgent
|
||||
);
|
||||
try {
|
||||
$.smashUtils["getLocalData"]();
|
||||
$.smashUtils["getAppOs"]();
|
||||
$.smashUtils.getBlog();
|
||||
$.smashUtils["getFpv"]();
|
||||
await $.smashUtils.getInfo();
|
||||
$.smashUtils.setjoyyaCookie("init");
|
||||
$.smashUtils.getJrInfo();
|
||||
} catch (e) {
|
||||
$.smashUtils.getInterfaceData({
|
||||
funcName: "other",
|
||||
real_msg: "initial",
|
||||
error_msg: e && e.message
|
||||
})
|
||||
}
|
||||
await $.smashUtils.initial({
|
||||
appId: "50170_", debug: !1, preRequest: !0, onSign: function (e) {
|
||||
e.code, e.message, e.data
|
||||
}, onRequestTokenRemotely: function (e) {
|
||||
e.code, e.message
|
||||
}, onRequestToken: function (e) {
|
||||
e.code, e.message
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
$.totalTry = 0;
|
||||
$.totalSuccess = 0;
|
||||
$.nowTabIdIndex = 0;
|
||||
$.nowPage = 1;
|
||||
$.nowItem = 1;
|
||||
$.retrynum = 0;
|
||||
if (!args_xh.unified) {
|
||||
trialActivityIdList = [];
|
||||
trialActivityTitleList = [];
|
||||
}
|
||||
$.isLimit = false;
|
||||
$.isForbidden = false;
|
||||
$.wrong = false;
|
||||
size = 1;
|
||||
|
||||
while (trialActivityIdList.length < args_xh.maxLength && $.retrynum < 3) {
|
||||
if ($.nowTabIdIndex === args_xh.tabId.length) {
|
||||
console.log(`tabId组已遍历完毕,不在获取商品\n`);
|
||||
break;
|
||||
} else {
|
||||
await try_feedsList(args_xh.tabId[$.nowTabIdIndex], $.nowPage); //获取对应tabId的试用页面
|
||||
}
|
||||
if (trialActivityIdList.length < args_xh.maxLength) {
|
||||
console.log(`间隔等待中,请等待5秒 \n`);
|
||||
await $.wait(5000);
|
||||
}
|
||||
}
|
||||
if ($.isForbidden === false && $.isLimit === false) {
|
||||
console.log(`稍后将执行试用申请,请等待 5 秒\n`);
|
||||
await $.wait(5000);
|
||||
for (let i = 0; i < trialActivityIdList.length && $.isLimit === false; i++) {
|
||||
if ($.isLimit) {
|
||||
console.log("试用上限");
|
||||
break;
|
||||
}
|
||||
if ($.isForbidden) {
|
||||
console.log("403了,跳出");
|
||||
break;
|
||||
}
|
||||
await try_apply(trialActivityTitleList[i], trialActivityIdList[i]);
|
||||
console.log(`间隔等待中,请等待15秒 \n`);
|
||||
await $.wait(15000);
|
||||
}
|
||||
console.log("试用申请执行完毕...");
|
||||
$.giveupNum = 0;
|
||||
$.successNum = 0;
|
||||
$.getNum = 0;
|
||||
$.completeNum = 0;
|
||||
// await try_MyTrials(1, 2); //申请成功的商品
|
||||
await showMsg();
|
||||
}
|
||||
}
|
||||
if ($.isNode()) {
|
||||
if ($.index % args_xh.sendNum === 0) {
|
||||
$.sentNum++;
|
||||
console.log(`正在进行第 ${$.sentNum} 次发送通知,发送数量:${args_xh.sendNum}`);
|
||||
await $.notify.sendNotify(`${$.name}`, `${notifyMsg}`);
|
||||
notifyMsg = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($.isNode() && $.except === false) {
|
||||
if ($.cookiesArr.length - $.sentNum * args_xh.sendNum < args_xh.sendNum && notifyMsg.length != 0) {
|
||||
console.log(`正在进行最后一次发送通知,发送数量:${$.cookiesArr.length - $.sentNum * args_xh.sendNum}`);
|
||||
await $.notify.sendNotify(`${$.name}`, `${notifyMsg}`);
|
||||
notifyMsg = "";
|
||||
}
|
||||
}
|
||||
})()
|
||||
.catch((e) => {
|
||||
console.error(`❗️ ${$.name} 运行错误!\n${e}`);
|
||||
})
|
||||
.finally(() => $.done());
|
||||
|
||||
function requireConfig() {
|
||||
return new Promise((resolve) => {
|
||||
$.notify = $.isNode() ? require("./sendNotify") : {
|
||||
sendNotify: async () => {
|
||||
}
|
||||
};
|
||||
//获取 Cookies
|
||||
$.cookiesArr = [];
|
||||
if ($.isNode()) {
|
||||
//Node.js用户请在jdCookie.js处填写京东ck;
|
||||
const jdCookieNode = require("./jdCookie.js");
|
||||
Object.keys(jdCookieNode).forEach((item) => {
|
||||
if (jdCookieNode[item]) $.cookiesArr.push(jdCookieNode[item]);
|
||||
});
|
||||
if (process.env.JD_DEBUG && process.env.JD_DEBUG === "false") console.log = () => {
|
||||
};
|
||||
} else {
|
||||
//IOS等用户直接用NobyDa的jd $.cookie
|
||||
$.cookiesArr = [$.getdata("CookieJD"), $.getdata("CookieJD2"), ...jsonParse($.getdata("CookiesJD") || "[]").map((item) => item.cookie)].filter((item) => !!item);
|
||||
}
|
||||
for (let keyWord of $.innerKeyWords) args_xh.titleFilters.push(keyWord);
|
||||
console.log(`共${$.cookiesArr.length}个京东账号\n`);
|
||||
if (args_xh.env) {
|
||||
console.log("=========环境变量配置如下=========");
|
||||
console.log(`env: ${typeof args_xh.env}, ${args_xh.env}`);
|
||||
console.log(`try_num: ${typeof args_xh.try_num}, ${args_xh.try_num}`);
|
||||
console.log(`except: ${typeof args_xh.except}, ${args_xh.except}`);
|
||||
console.log(`unified: ${typeof args_xh.unified}, ${args_xh.unified}`);
|
||||
console.log(`jdPrice: ${typeof args_xh.jdPrice}, ${args_xh.jdPrice}`);
|
||||
console.log(`tabId: ${typeof args_xh.tabId}, ${args_xh.tabId}`);
|
||||
console.log(`titleFilters: ${typeof args_xh.titleFilters}, ${args_xh.titleFilters}`);
|
||||
console.log(`trialPrice: ${typeof args_xh.trialPrice}, ${args_xh.trialPrice}`);
|
||||
console.log(`minSupplyNum: ${typeof args_xh.minSupplyNum}, ${args_xh.minSupplyNum}`);
|
||||
console.log(`applyNumFilter: ${typeof args_xh.applyNumFilter}, ${args_xh.applyNumFilter}`);
|
||||
console.log(`maxLength: ${typeof args_xh.maxLength}, ${args_xh.maxLength}`);
|
||||
console.log(`passZhongCao: ${typeof args_xh.passZhongCao}, ${args_xh.passZhongCao}`);
|
||||
console.log(`printLog: ${typeof args_xh.printLog}, ${args_xh.printLog}`);
|
||||
console.log(`whiteList: ${typeof args_xh.whiteList}, ${args_xh.whiteList}`);
|
||||
console.log(`whiteListKeywords: ${typeof args_xh.whiteListKeywords}, ${args_xh.whiteListKeywords}`);
|
||||
console.log("===============================");
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
//获取商品列表并且过滤
|
||||
async function try_feedsList(tabId, page) {
|
||||
const body = {
|
||||
functionId: "try_SpecFeedList",
|
||||
appid: "newtry",
|
||||
body: JSON.stringify({
|
||||
tabId: tabId + "",
|
||||
page: page,
|
||||
version: 2,
|
||||
source: "default",
|
||||
client: "outer",
|
||||
})
|
||||
}
|
||||
|
||||
const h5st = await $.ParamsSignLite.sign(body)
|
||||
|
||||
try {
|
||||
const {data} = await api({
|
||||
method: "POST",
|
||||
url: `https://api.m.jd.com/client.action`,
|
||||
headers: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
origin: "https://prodev.m.jd.com",
|
||||
Referer: "https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html?ids=501730512%2C501676150&navh=49&stath=37&tttparams=wUQ86eyJhZGRyZXNzSWQiOjAsImRMYXQiOjAsImRMbmciOjAsImdMYXQiOiIzOS45NDQwOTMiLCJnTG5nIjoiMTE2LjQ4MjI3NiIsImdwc19hcmVhIjoiMF8wXzBfMCIsImxhdCI6MCwibG5nIjowLCJtb2RlbCI6IlJlZG1pIE5vdGUgMTJUIFBybyIsInBvc0xhdCI6IjM5Ljk0NDA5MyIsInBvc0xuZyI6IjExNi40ODIyNzYiLCJwcnN0YXRlIjoiMCIsInVlbXBzIjoiMC0wLTAiLCJ1bl9hcmVhIjoiMV83Ml81NTY3NF8wIn50%3D&preventPV=1&forceCurrentView=1",
|
||||
"User-Agent": $.userAgent,
|
||||
"x-referer-page": "https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html"
|
||||
},
|
||||
data: qs.stringify({
|
||||
...body,
|
||||
h5st: h5st.h5st
|
||||
})
|
||||
});
|
||||
|
||||
let tempKeyword = ``;
|
||||
if (data.data) {
|
||||
console.log(`第 ${size++} 次获取试用商品成功,tabId:${args_xh.tabId[$.nowTabIdIndex]} 的 第 ${page} 页`);
|
||||
console.log(`获取到商品 ${data.data.feedList.length} 条`);
|
||||
for (let item of data.data.feedList) {
|
||||
if (item.applyNum === null) {
|
||||
args_xh.printLog ? console.log(`商品未到申请时间:${item.skuTitle}\n`) : "";
|
||||
continue;
|
||||
}
|
||||
if (trialActivityIdList.length >= args_xh.maxLength) {
|
||||
console.log("商品列表长度已满.结束获取");
|
||||
break;
|
||||
}
|
||||
if (item.applyState === 1) {
|
||||
args_xh.printLog ? console.log(`商品已申请试用:${item.skuTitle}\n`) : "";
|
||||
continue;
|
||||
}
|
||||
if (item.applyState !== null) {
|
||||
args_xh.printLog ? console.log(`商品状态异常,未找到skuTitle\n`) : "";
|
||||
continue;
|
||||
}
|
||||
if (args_xh.passZhongCao) {
|
||||
$.isPush = true;
|
||||
if (item.tagList.length !== 0) {
|
||||
for (let itemTag of item.tagList) {
|
||||
if (itemTag.tagType === 3) {
|
||||
args_xh.printLog ? console.log("商品被过滤,该商品是种草官专属") : "";
|
||||
$.isPush = false;
|
||||
break;
|
||||
} else if (itemTag.tagType === 5) {
|
||||
args_xh.printLog ? console.log("商品被跳过,该商品是付费试用!") : "";
|
||||
$.isPush = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item.skuTitle && $.isPush) {
|
||||
args_xh.printLog ? console.log(`检测 tabId:${args_xh.tabId[$.nowTabIdIndex]} 的 第 ${page} 页 第 ${$.nowItem++ + 1} 个商品\n${item.skuTitle}`) : "";
|
||||
if (args_xh.whiteList) {
|
||||
if (args_xh.whiteListKeywords.some((fileter_word) => item.skuTitle.includes(fileter_word))) {
|
||||
args_xh.printLog ? console.log(`商品白名单通过,将加入试用组,trialActivityId为${item.trialActivityId}\n`) : "";
|
||||
trialActivityIdList.push(item.trialActivityId);
|
||||
trialActivityTitleList.push(item.skuTitle);
|
||||
}
|
||||
} else {
|
||||
tempKeyword = ``;
|
||||
if (parseFloat(item.jdPrice) <= args_xh.jdPrice) {
|
||||
args_xh.printLog ? console.log(`商品被过滤,商品价格 ${item.jdPrice} < ${args_xh.jdPrice} \n`) : "";
|
||||
} else if (parseFloat(item.supplyNum) < args_xh.minSupplyNum && item.supplyNum !== null) {
|
||||
args_xh.printLog ? console.log(`商品被过滤,提供申请的份数小于预设申请的份数 \n`) : "";
|
||||
} else if (parseFloat(item.applyNum) > args_xh.applyNumFilter && item.applyNum !== null) {
|
||||
args_xh.printLog ? console.log(`商品被过滤,已申请人数大于预设的${args_xh.applyNumFilter}人 \n`) : "";
|
||||
} else if (item.jdPrice === null) {
|
||||
args_xh.printLog ? console.log(`商品被过滤,商品无价,不能申请 \n`) : "";
|
||||
} else if (parseFloat(item.trialPrice) > args_xh.trialPrice) {
|
||||
args_xh.printLog ? console.log(`商品被过滤,商品试用价大于预设试用价 \n`) : "";
|
||||
} else if (args_xh.titleFilters.some((fileter_word) => (item.skuTitle.includes(fileter_word) ? (tempKeyword = fileter_word) : ""))) {
|
||||
args_xh.printLog ? console.log(`商品被过滤,含有关键词 ${tempKeyword}\n`) : "";
|
||||
} else {
|
||||
args_xh.printLog ? console.log(`商品通过,加入试用组,trialActivityId为${item.trialActivityId}\n`) : "";
|
||||
if (trialActivityIdList.indexOf(item.trialActivityId) === -1) {
|
||||
trialActivityIdList.push(item.trialActivityId);
|
||||
trialActivityTitleList.push(item.skuTitle);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ($.isPush !== false) {
|
||||
console.error("skuTitle解析异常");
|
||||
return;
|
||||
}
|
||||
}
|
||||
console.log(`当前试用组长度为:${trialActivityIdList.length}`);
|
||||
console.log(`下一页状态:${data.data.hasNext}`);
|
||||
if (data.data.hasNext === false) {
|
||||
if ($.nowTabIdIndex < args_xh.tabId.length) {
|
||||
$.nowTabIdIndex++;
|
||||
$.nowPage = 1;
|
||||
$.nowItem = 1;
|
||||
$.retrynum = 0;
|
||||
} else {
|
||||
// 这下是真的没了
|
||||
$.retrynum = 999
|
||||
}
|
||||
} else {
|
||||
$.nowPage++;
|
||||
$.retrynum = 0;
|
||||
}
|
||||
} else {
|
||||
console.log(`💩 获得试用列表失败: ${data.message}`);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.message === `Request failed with status code 403`) {
|
||||
$.retrynum++;
|
||||
if ($.retrynum === 4) {
|
||||
$.isForbidden = true;
|
||||
$.log("多次尝试失败,换个时间再试!");
|
||||
} else {
|
||||
console.log(`请求失败,第 ${$.retrynum} 次重试`);
|
||||
}
|
||||
} else {
|
||||
console.log(e.message);
|
||||
console.log(`${$.name} API请求失败,请检查网路重试`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function try_apply(title, activityId) {
|
||||
console.log(`申请试用商品提交中...`);
|
||||
args_xh.printLog ? console.log(`商品:${title}`) : "";
|
||||
args_xh.printLog ? console.log(`id为:${activityId}`) : "";
|
||||
|
||||
const body = {
|
||||
functionId: "try_apply",
|
||||
appid: "newtry",
|
||||
body: JSON.stringify({
|
||||
"activityId": activityId * 1,
|
||||
})
|
||||
}
|
||||
|
||||
const h5st = await $.ParamsSignLite.sign(body)
|
||||
const joylog = await $.smashUtils.sign({
|
||||
...body,
|
||||
h5st: h5st.h5st
|
||||
}, true);
|
||||
|
||||
try {
|
||||
const {data} = await api({
|
||||
method: "POST",
|
||||
url: `https://api.m.jd.com/client.action`,
|
||||
headers: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
origin: "https://pro.m.jd.com",
|
||||
Referer: "https://pro.m.jd.com/mall/active/3mpGVQDhvLsMvKfZZumWPQyWt83L/index.html?activityId=501834423&sku=65263095978",
|
||||
"User-Agent": $.userAgent,
|
||||
"x-referer-page": "https://pro.m.jd.com/mall/active/3mpGVQDhvLsMvKfZZumWPQyWt83L/index.html"
|
||||
},
|
||||
data: qs.stringify(joylog)
|
||||
});
|
||||
|
||||
$.totalTry++;
|
||||
if (data.success && data.code === "1") {
|
||||
// 申请成功
|
||||
console.log("申请提交成功");
|
||||
$.totalSuccess++;
|
||||
} else if (data.code === "-106") {
|
||||
console.log(data.message); // 未在申请时间内!
|
||||
} else if (data.code === "-110") {
|
||||
console.log(data.message); // 您的申请已成功提交,请勿重复申请…
|
||||
} else if (data.code === "-120") {
|
||||
console.log(data.message); // 您还不是会员,本品只限会员申请试用,请注册会员后申请!
|
||||
} else if (data.code === "-167") {
|
||||
console.log(data.message); // 抱歉,此试用需为种草官才能申请。查看下方详情了解更多。
|
||||
} else if (data.code === "-131") {
|
||||
console.log(data.message); // 申请次数上限。
|
||||
$.isLimit = true;
|
||||
} else if (data.code === "-113") {
|
||||
console.log(data.message); // 操作不要太快哦!
|
||||
} else {
|
||||
console.log("申请失败", data);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.message === `Request failed with status code 403`) {
|
||||
$.isForbidden = true;
|
||||
console.log("账号被京东服务器风控,不再请求该帐号");
|
||||
} else {
|
||||
console.log(e.message);
|
||||
console.log(`${$.name} API请求失败,请检查网路重试`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function try_MyTrials(page, selected) {
|
||||
return new Promise((resolve, reject) => {
|
||||
switch (selected) {
|
||||
case 1:
|
||||
console.log("正在获取已申请的商品...");
|
||||
break;
|
||||
case 2:
|
||||
console.log("正在获取申请成功的商品...");
|
||||
break;
|
||||
case 3:
|
||||
console.log("正在获取申请失败的商品...");
|
||||
break;
|
||||
default:
|
||||
console.log("selected错误");
|
||||
}
|
||||
let options = {
|
||||
url: URL,
|
||||
data: `appid=newtry&functionId=try_MyTrials&clientVersion=10.3.4&client=wh5&body=%7B%22page%22%3A${page}%2C%22selected%22%3A${selected}%2C%22previewTime%22%3A%22%22%7D`,
|
||||
headers: {
|
||||
origin: "https://prodev.m.jd.com",
|
||||
"User-Agent": $.userAgent,
|
||||
referer: "https://prodev.m.jd.com/",
|
||||
cookie: $.cookie,
|
||||
},
|
||||
};
|
||||
$.restApi(options, (err, resp, data) => {
|
||||
try {
|
||||
if (err) {
|
||||
console.log(`🚫 ${arguments.callee.name.toString()} API请求失败,请检查网路\n${JSON.stringify(err)}`);
|
||||
} else {
|
||||
if (data.success) {
|
||||
//temp adjustment
|
||||
if (selected === 2) {
|
||||
if (data.success && data.data) {
|
||||
for (let item of data.data.list) {
|
||||
item.status === 4 || item.text.text.includes("试用资格已过期") ? ($.giveupNum += 1) : "";
|
||||
item.status === 2 && item.text.text.includes("试用资格将保留") ? ($.successNum += 1) : "";
|
||||
item.status === 2 && item.text.text.includes("请收货后尽快提交报告") ? ($.getNum += 1) : "";
|
||||
item.status === 2 && item.text.text.includes("试用已完成") ? ($.completeNum += 1) : "";
|
||||
}
|
||||
console.log(`待领取 | 已领取 | 已完成 | 已放弃:${$.successNum} | ${$.getNum} | ${$.completeNum} | ${$.giveupNum}`);
|
||||
} else {
|
||||
console.log(`获得成功列表失败: ${data.message}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.error(`ERROR:try_MyTrials`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
reject(`⚠️ ${arguments.callee.name.toString()} API返回结果解析出错\n${e}\n${JSON.stringify(data)}`);
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function showMsg() {
|
||||
let message = ``;
|
||||
message += `👤 京东账号${$.index} ${$.nickName || $.UserName}\n`;
|
||||
if ($.totalSuccess !== 0 && $.totalTry !== 0) {
|
||||
message += `🎉 本次提交申请:${$.totalSuccess}/${$.totalTry}个商品🛒\n`;
|
||||
message += `🎉 ${$.successNum}个商品待领取\n`;
|
||||
message += `🎉 ${$.getNum}个商品已领取\n`;
|
||||
message += `🎉 ${$.completeNum}个商品已完成\n`;
|
||||
message += `🗑 ${$.giveupNum}个商品已放弃\n\n`;
|
||||
} else {
|
||||
message += `⚠️ 本次执行没有申请试用商品\n`;
|
||||
message += `🎉 ${$.successNum}个商品待领取\n`;
|
||||
message += `🎉 ${$.getNum}个商品已领取\n`;
|
||||
message += `🎉 ${$.completeNum}个商品已完成\n`;
|
||||
message += `🗑 ${$.giveupNum}个商品已放弃\n\n`;
|
||||
}
|
||||
if (!args_xh.jdNotify || args_xh.jdNotify === "false") {
|
||||
$.msg($.name, ``, message, {
|
||||
"open-url": "https://try.m.jd.com/user",
|
||||
});
|
||||
if ($.isNode()) notifyMsg += `${message}`;
|
||||
} else {
|
||||
console.log(message);
|
||||
}
|
||||
}
|
||||
|
||||
function totalBean() {
|
||||
return new Promise(async (resolve) => {
|
||||
const options = {
|
||||
url: `https://wq.jd.com/user/info/QueryJDUserInfo?sceneval=2`, headers: {
|
||||
Accept: "application/json,text/plain, */*",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Accept-Encoding": "gzip, deflate, br",
|
||||
"Accept-Language": "zh-cn",
|
||||
Connection: "keep-alive",
|
||||
Cookie: $.cookie,
|
||||
Referer: "https://wqs.jd.com/my/jingdou/my.shtml?sceneval=2",
|
||||
"User-Agent": $.userAgent,
|
||||
}, timeout: 10000,
|
||||
};
|
||||
$.restApi(options, (err, resp, data) => {
|
||||
try {
|
||||
if (err) {
|
||||
console.log(`${JSON.stringify(err)}`);
|
||||
console.log(`${$.name} API请求失败,请检查网路重试`);
|
||||
} else {
|
||||
if (data) {
|
||||
if (data["retcode"] === 13) {
|
||||
$.isLogin = false; //cookie过期
|
||||
return;
|
||||
}
|
||||
if (data["retcode"] === 0) {
|
||||
$.nickName = (data["base"] && data["base"].nickname) || $.UserName;
|
||||
} else {
|
||||
$.nickName = $.UserName;
|
||||
}
|
||||
} else {
|
||||
console.log(`京东服务器返回空数据`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
$.logErr(e, resp);
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function jsonParse(str) {
|
||||
if (typeof str == "string") {
|
||||
try {
|
||||
return JSON.parse(str);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
$.msg($.name, "", "请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Env(name, opts) {
|
||||
class Http {
|
||||
constructor(env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
send(opts, method = "GET") {
|
||||
opts = typeof opts === "string" ? {
|
||||
url: opts,
|
||||
} : opts;
|
||||
let sender = this.get;
|
||||
if (method === "POST") {
|
||||
sender = this.post;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
sender.call(this, opts, (err, resp, body) => {
|
||||
if (err) reject(err); else resolve(resp);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
get(opts) {
|
||||
return this.send.call(this.env, opts);
|
||||
}
|
||||
|
||||
post(opts) {
|
||||
return this.send.call(this.env, opts, "POST");
|
||||
}
|
||||
}
|
||||
|
||||
return new (class {
|
||||
constructor(name, opts) {
|
||||
this.name = name;
|
||||
this.http = new Http(this);
|
||||
this.data = null;
|
||||
this.dataFile = "box.dat";
|
||||
this.logs = [];
|
||||
this.isMute = false;
|
||||
this.isNeedRewrite = false;
|
||||
this.logSeparator = "\n";
|
||||
this.startTime = new Date().getTime();
|
||||
Object.assign(this, opts);
|
||||
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;
|
||||
}
|
||||
|
||||
loaddata() {
|
||||
if (this.isNode()) {
|
||||
this.fs = this.fs ? this.fs : require("fs");
|
||||
this.path = this.path ? this.path : require("path");
|
||||
const curDirDataFilePath = this.path.resolve(this.dataFile);
|
||||
const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile);
|
||||
const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath);
|
||||
const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath);
|
||||
if (isCurDirDataFile || isRootDirDataFile) {
|
||||
const datPath = isCurDirDataFile ? curDirDataFilePath : rootDirDataFilePath;
|
||||
try {
|
||||
return JSON.parse(this.fs.readFileSync(datPath));
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
} else return {};
|
||||
} else return {};
|
||||
}
|
||||
|
||||
lodash_get(source, path, defaultValue = undefined) {
|
||||
const paths = path.replace(/\[(\d+)\]/g, ".$1").split(".");
|
||||
let result = source;
|
||||
for (const p of paths) {
|
||||
result = Object(result)[p];
|
||||
if (result === undefined) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
getdata(key) {
|
||||
let val = this.getval(key);
|
||||
// 如果以 @
|
||||
if (/^@/.test(key)) {
|
||||
const [, objkey, paths] = /^@(.*?)\.(.*?)$/.exec(key);
|
||||
const objval = objkey ? this.getval(objkey) : "";
|
||||
if (objval) {
|
||||
try {
|
||||
const objedval = JSON.parse(objval);
|
||||
val = objedval ? this.lodash_get(objedval, paths, "") : val;
|
||||
} catch (e) {
|
||||
val = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
getval(key) {
|
||||
if (this.isSurge() || this.isLoon()) {
|
||||
return $persistentStore.read(key);
|
||||
} else if (this.isQuanX()) {
|
||||
return $prefs.valueForKey(key);
|
||||
} else if (this.isNode()) {
|
||||
this.data = this.loaddata();
|
||||
return this.data[key];
|
||||
} else {
|
||||
return (this.data && this.data[key]) || null;
|
||||
}
|
||||
}
|
||||
|
||||
initAxios() {
|
||||
if (!this.axios) {
|
||||
this.axios = axios.create();
|
||||
}
|
||||
}
|
||||
|
||||
restApi(opts, callback = () => {
|
||||
}) {
|
||||
this.initAxios();
|
||||
this.axios(opts)
|
||||
.then(resp => {
|
||||
const {status, headers, data} = resp;
|
||||
callback(null, {
|
||||
status, headers, data,
|
||||
}, data);
|
||||
}, (err) => {
|
||||
const {message: error, response: resp} = err;
|
||||
callback(error, resp, resp && resp.data);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统通知
|
||||
*
|
||||
* > 通知参数: 同时支持 QuanX 和 Loon 两种格式, EnvJs根据运行环境自动转换, Surge 环境不支持多媒体通知
|
||||
*
|
||||
* 示例:
|
||||
* $.msg(title, subt, desc, 'twitter://')
|
||||
* $.msg(title, subt, desc, { 'open-url': 'twitter://', 'media-url': 'https://github.githubassets.com/images/modules/open_graph/github-mark.png' })
|
||||
* $.msg(title, subt, desc, { 'open-url': 'https://bing.com', 'media-url': 'https://github.githubassets.com/images/modules/open_graph/github-mark.png' })
|
||||
*
|
||||
* @param {*} title 标题
|
||||
* @param {*} subt 副标题
|
||||
* @param {*} desc 通知详情
|
||||
* @param {*} opts 通知参数
|
||||
*
|
||||
*/
|
||||
msg(title = name, subt = "", desc = "", opts) {
|
||||
const toEnvOpts = (rawopts) => {
|
||||
if (!rawopts) return rawopts;
|
||||
if (typeof rawopts === "string") {
|
||||
if (this.isLoon()) return rawopts; else if (this.isQuanX()) return {
|
||||
"open-url": rawopts,
|
||||
}; else if (this.isSurge()) return {
|
||||
url: rawopts,
|
||||
}; else return undefined;
|
||||
} else if (typeof rawopts === "object") {
|
||||
if (this.isLoon()) {
|
||||
let openUrl = rawopts.openUrl || rawopts.url || rawopts["open-url"];
|
||||
let mediaUrl = rawopts.mediaUrl || rawopts["media-url"];
|
||||
return {
|
||||
openUrl, mediaUrl,
|
||||
};
|
||||
} else if (this.isQuanX()) {
|
||||
let openUrl = rawopts["open-url"] || rawopts.url || rawopts.openUrl;
|
||||
let mediaUrl = rawopts["media-url"] || rawopts.mediaUrl;
|
||||
return {
|
||||
"open-url": openUrl, "media-url": mediaUrl,
|
||||
};
|
||||
} else if (this.isSurge()) {
|
||||
let openUrl = rawopts.url || rawopts.openUrl || rawopts["open-url"];
|
||||
return {
|
||||
url: openUrl,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
if (!this.isMute) {
|
||||
if (this.isSurge() || this.isLoon()) {
|
||||
$notification.post(title, subt, desc, toEnvOpts(opts));
|
||||
} else if (this.isQuanX()) {
|
||||
$notify(title, subt, desc, toEnvOpts(opts));
|
||||
}
|
||||
}
|
||||
if (!this.isMuteLog) {
|
||||
let logs = ["", "==============📣系统通知📣=============="];
|
||||
logs.push(title);
|
||||
subt ? logs.push(subt) : "";
|
||||
desc ? logs.push(desc) : "";
|
||||
console.log(logs.join("\n"));
|
||||
this.logs = this.logs.concat(logs);
|
||||
}
|
||||
}
|
||||
|
||||
log(...logs) {
|
||||
if (logs.length > 0) {
|
||||
this.logs = [...this.logs, ...logs];
|
||||
}
|
||||
console.log(logs.join(this.logSeparator));
|
||||
}
|
||||
|
||||
logErr(err, msg) {
|
||||
const isPrintSack = !this.isSurge() && !this.isQuanX() && !this.isLoon();
|
||||
if (!isPrintSack) {
|
||||
this.log("", `❗️${this.name}, 错误!`, err);
|
||||
} else {
|
||||
this.log("", `❗️${this.name}, 错误!`, err.stack);
|
||||
}
|
||||
}
|
||||
|
||||
wait(time) {
|
||||
return new Promise((resolve) => setTimeout(resolve, time));
|
||||
}
|
||||
|
||||
done(val = {}) {
|
||||
const endTime = new Date().getTime();
|
||||
const costTime = (endTime - this.startTime) / 1000;
|
||||
this.log("", `🔔${this.name}, 结束! 🕛 ${costTime} 秒`);
|
||||
this.log();
|
||||
if (this.isSurge() || this.isQuanX() || this.isLoon()) {
|
||||
$done(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
)
|
||||
(name, opts);
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
49
utils/baseCookie.js
Normal file
49
utils/baseCookie.js
Normal file
@ -0,0 +1,49 @@
|
||||
function getBaseCookie(userAgent, url) {
|
||||
var cookie = "";
|
||||
|
||||
function genUuid() {
|
||||
return new Date().getTime() + "" + parseInt(2147483647 * Math.random());
|
||||
}
|
||||
|
||||
function setCookie(e, t) {
|
||||
if (e) {
|
||||
cookie += " " + e + "=" + t + ";";
|
||||
}
|
||||
}
|
||||
|
||||
function setJdv(e, t) {
|
||||
var i = isPrey(10) && (!e || e.length > 400) ? t + "|direct|-|none|-|" + new Date().getTime() : e;
|
||||
setCookie("__jdv", i);
|
||||
}
|
||||
|
||||
function isPrey(e) {
|
||||
if (e >= 100) return !0;
|
||||
var t = uuid, r = t.substr(t.length - 2);
|
||||
return !!r && 1 * r < e;
|
||||
}
|
||||
|
||||
function isEmbedded() {
|
||||
var e = userAgent || "";
|
||||
return /^(jdapp|jdltapp|jdpingou|jdmini|yhdapp);/.test(e) || isJdLog();
|
||||
}
|
||||
|
||||
function isJdLog() {
|
||||
return (userAgent || "").indexOf(";jdlog;") > -1;
|
||||
}
|
||||
|
||||
var r = 122270672, i = genUuid(), s = parseInt(new Date().getTime() / 1e3);
|
||||
uuid = i;
|
||||
|
||||
var C, P = url && url.split("/")[2], A = !1;
|
||||
|
||||
setCookie("__jda", [r, i, s, s, s, 1].join("."));
|
||||
setCookie("__jdb", [r, 1, i + "|" + 1, s].join("."));
|
||||
var j = encodeURIComponent([r, "direct", "-", "none", "-", new Date().getTime()].join("|"));
|
||||
setJdv(j, r);
|
||||
setCookie("__jdc", r);
|
||||
setCookie("mba_muid", encodeURI(uuid));
|
||||
|
||||
return cookie;
|
||||
}
|
||||
|
||||
module.exports.getBaseCookie = getBaseCookie
|
337
utils/baseH5st.js
Normal file
337
utils/baseH5st.js
Normal file
@ -0,0 +1,337 @@
|
||||
const CryptoJS = require("crypto-js");
|
||||
const {BaseUtils} = require("./baseUtils");
|
||||
const os = require('os');
|
||||
|
||||
class BaseH5st {
|
||||
|
||||
constructor(url, cookieStr, userAgent) {
|
||||
global.baseUtils || new BaseUtils();
|
||||
baseUtils.changeEnv(url, cookieStr, userAgent);
|
||||
|
||||
this.ErrCodes = {
|
||||
UNSIGNABLE_PARAMS: 1, APPID_ABSENT: 2, TOKEN_EMPTY: 3, GENERATE_SIGNATURE_FAILED: 4, UNHANDLED_ERROR: -1
|
||||
};
|
||||
|
||||
this._defaultAlgorithm = {};
|
||||
this._debug = false;
|
||||
|
||||
this.settings = {
|
||||
debug: !1, preRequest: !1, timeout: 2,
|
||||
};
|
||||
}
|
||||
|
||||
_log(log) {
|
||||
if (this._debug) {
|
||||
console.log('[sign]', log)
|
||||
}
|
||||
}
|
||||
|
||||
getSync(t) {
|
||||
let item = window.localStorage.getItem(t);
|
||||
if (item) {
|
||||
let r = JSON.parse(item);
|
||||
if (!r || !r.t || !r.e || 0 === r.e || new Date - r.t >= 1e3 * r.e) {
|
||||
this.removeSync(t);
|
||||
return "";
|
||||
}
|
||||
return r.v
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
setSync(t, r, n, e) {
|
||||
let i = {
|
||||
v: r,
|
||||
t: (new Date).getTime(),
|
||||
e: "number" != typeof n.expire ? 0 : n.expire
|
||||
}
|
||||
window.localStorage.setItem(t, JSON.stringify(i));
|
||||
}
|
||||
|
||||
removeSync(t) {
|
||||
window.localStorage.removeItem(t)
|
||||
}
|
||||
|
||||
__genDefaultKey(t, z) {
|
||||
let A = "";
|
||||
let S = CryptoJS.enc.Utf8.stringify(CryptoJS.enc.Base64.parse(baseUtils.decodeBase64URL(this.__parseToken(t, 16, 28)))),
|
||||
B = S.match(/^[123]([x+][123])+/);
|
||||
if (B) {
|
||||
var j = B[0]["split"](""),
|
||||
M = "";
|
||||
j.forEach((r) => {
|
||||
if (isNaN(r)) {
|
||||
if (["+", "x"].includes(r)) M = r;
|
||||
} else {
|
||||
var a = `local_key_${r}`;
|
||||
if (this._defaultAlgorithm[a]) {
|
||||
switch (M) {
|
||||
case "+":
|
||||
A = `${A}${this.__algorithm(a, z, t)}`;
|
||||
break;
|
||||
case "x":
|
||||
A = this.__algorithm(a, A, t);
|
||||
break;
|
||||
default:
|
||||
A = this.__algorithm(a, z, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
this._log(`__genDefaultKey input=${z},express=${S},key=${A}`)
|
||||
return A;
|
||||
}
|
||||
|
||||
__algorithm(t, r, n) {
|
||||
return t === "local_key_3" ? this._defaultAlgorithm[t](r, n).toString(CryptoJS.enc.Hex) : this._defaultAlgorithm[t](r).toString(CryptoJS.enc.Hex);
|
||||
}
|
||||
|
||||
__parseToken(t, r, n) {
|
||||
if (t) return baseUtils.getDefaultMethod(t, 'slice').call(t, r, n);
|
||||
return "";
|
||||
}
|
||||
|
||||
__parseAlgorithm(t, r) {
|
||||
this["_token"] = t || "";
|
||||
this.__genKey = r && new Function(`return ${r}`)() || null;
|
||||
return !(!this["_token"] || !this.__genKey);
|
||||
}
|
||||
|
||||
__genSign(t, r) {
|
||||
var y = baseUtils.getDefaultMethod(r, 'map')["call"](r, function (t) {
|
||||
return t["key"] + ":" + t.value;
|
||||
})["join"]("&");
|
||||
var d = CryptoJS.HmacSHA256(y, t).toString(CryptoJS.enc.Hex);
|
||||
this._log(`__genSign, paramsStr:${y}, signedStr:${d}`);
|
||||
return d;
|
||||
}
|
||||
|
||||
async __requestAlgorithmOnce() {
|
||||
await this.__requestAlgorithm();
|
||||
}
|
||||
|
||||
async __requestAlgorithm() {
|
||||
this._log("__requestAlgorithm start.");
|
||||
var r = this.envCollect(0);
|
||||
r.ai = this._appId;
|
||||
r.fp = this._fingerprint;
|
||||
var n = JSON.stringify(r, null, 2);
|
||||
this._log(`__requestAlgorithm envCollect=${n}`);
|
||||
var e = this.aes(n , 'wm0!@w-s#ll1flo(', "0102030405060708");
|
||||
var dt = {
|
||||
fingerprint: this._fingerprint, appId: this._appId, version: this._version, env: e, debug: this._debug,
|
||||
};
|
||||
|
||||
try {
|
||||
var {data} = await api({
|
||||
url: "https://cactus.jd.com/request_algo",
|
||||
method: "post",
|
||||
data: {
|
||||
version: dt.version,
|
||||
fp: dt.fingerprint,
|
||||
appId: dt.appId,
|
||||
timestamp: Date.now(),
|
||||
platform: "web",
|
||||
expandParams: dt.env,
|
||||
fv: this.v,
|
||||
},
|
||||
headers: {
|
||||
"Content-Type": "application/json;charset=utf-8",
|
||||
Origin: "https://cactus.jd.com",
|
||||
Host: "cactus.jd.com",
|
||||
accept: "*/*",
|
||||
"User-Agent": navigation.userAgent,
|
||||
},
|
||||
});
|
||||
|
||||
if (data && data.status === 200 && data.data && data.data.result) {
|
||||
var c = data.data.result;
|
||||
if (c.algo && c.tk && c.fp) {
|
||||
var l = c.fp === this._fingerprint,
|
||||
p = l ? this.getSync(this._storageFpKey, 1) : "",
|
||||
d = p && c.fp === p;
|
||||
if (d) {
|
||||
var z = this.__parseToken(c.tk, 13, 15);
|
||||
var x = parseInt(z, 16);
|
||||
var w = x * 60 * 60;
|
||||
this.setSync(this._storagetokenKey, CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(c.tk)), {
|
||||
expire: w,
|
||||
});
|
||||
this.setSync(this._storageAlgnKey, CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(c.algo)), {
|
||||
expire: w,
|
||||
});
|
||||
}
|
||||
this._log(`__requestAlgorithm request success!, check memory fp:${l}, check storage fp:${d}, token:${c.tk}, storageFp:${p}, fp:${c.fp}`);
|
||||
} else {
|
||||
throw new Error("data.result format error.");
|
||||
}
|
||||
} else {
|
||||
throw new Error("request params error.");
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(`request error, ${error.code}, ${error.message}`);
|
||||
}
|
||||
this._log(this._debug, "__requestAlgorithm end.");
|
||||
}
|
||||
|
||||
__checkParams(t) {
|
||||
let u = null;
|
||||
if (!this._appId) {
|
||||
u = {
|
||||
code: this.ErrCodes.APPID_ABSENT, message: "appId is required"
|
||||
}
|
||||
}
|
||||
if (!baseUtils.isPlainObject(t)) {
|
||||
u = {
|
||||
code: this.ErrCodes.UNSIGNABLE_PARAMS, message: 'params is not a plain object'
|
||||
}
|
||||
}
|
||||
if (baseUtils.isEmpty(t)) {
|
||||
u = {
|
||||
code: this.ErrCodes.UNSIGNABLE_PARAMS, message: 'params is empty'
|
||||
}
|
||||
}
|
||||
if (baseUtils.containsReservedParamName(t)) {
|
||||
u = {
|
||||
code: this.ErrCodes.UNSIGNABLE_PARAMS, message: 'params contains reserved param name.'
|
||||
}
|
||||
}
|
||||
if (u) {
|
||||
this._onSign(u);
|
||||
return null;
|
||||
}
|
||||
let o, e, r, n;
|
||||
o = baseUtils.getDefaultMethod(e = baseUtils.getDefaultMethod(r = baseUtils.getDefaultMethod(n = Object.keys(t), 'sort').call(n), 'map').call(r, (function (e) {
|
||||
return {key: e, value: t[e]}
|
||||
})), 'filter').call(e, (function (t) {
|
||||
return baseUtils.isSafeParamValue(t.value)
|
||||
}))
|
||||
|
||||
if (o.length === 0) {
|
||||
this._onSign({
|
||||
code: this.ErrCodes.UNSIGNABLE_PARAMS, message: 'params is empty after excluding "unsafe" params',
|
||||
});
|
||||
return null;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
__collect() {
|
||||
var n = this.envCollect(1);
|
||||
n.fp = this._fingerprint;
|
||||
var e = JSON.stringify(n, null, 2);
|
||||
this._log(`__collect envCollect=${e}`);
|
||||
return this.aes(e, this.collectSecret, "0102030405060708");
|
||||
}
|
||||
|
||||
async sign(params) {
|
||||
try {
|
||||
var Ot = Date.now();
|
||||
var e = ["functionId", "appid", "client", "body", "clientVersion", "sign", "t", "jsonp"].reduce((function (e, r) {
|
||||
var n = params[r];
|
||||
return n && ("body" === r && (n = CryptoJS.SHA256(n).toString()), e[r] = n), e
|
||||
}), {});
|
||||
|
||||
var o = this.__checkParams(e);
|
||||
if (o == null) {
|
||||
return e;
|
||||
}
|
||||
await this.__requestDeps();
|
||||
let i = this.__collect();
|
||||
let a = this.__makeSign(o, i);
|
||||
this._log(`sign elapsed time!${Date.now() - Ot}ms`);
|
||||
return Object.assign({}, e, a);
|
||||
} catch (error) {
|
||||
this._onSign({
|
||||
code: this.ErrCodes.UNHANDLED_ERROR, message: 'unknown error'
|
||||
})
|
||||
this._log(`unknown error!${error.message}`);
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
||||
envCollect(e) {
|
||||
let info = {
|
||||
pp: (() => {
|
||||
let ptPin = baseUtils.extractPtPin(document.cookie);
|
||||
if (ptPin) {
|
||||
return {
|
||||
"p1": ptPin,
|
||||
"p2": ptPin
|
||||
}
|
||||
}
|
||||
return {}
|
||||
})(),
|
||||
extend: {
|
||||
bu1: this.bu1,
|
||||
bu2: 0,
|
||||
bu3: document.head.childElementCount,
|
||||
bu4: 0,
|
||||
bu5: 0,
|
||||
l: 0,
|
||||
ls: 0,
|
||||
wd: 0,
|
||||
wk: 0,
|
||||
},
|
||||
random: baseUtils.getRandomIDPro({size: 12, dictType: 'max', customDict: null}),
|
||||
sua: (() => {
|
||||
var regex = new RegExp("Mozilla/5.0 \\((.*?)\\)");
|
||||
var matches = window.navigator.userAgent.match(regex);
|
||||
return matches && matches[1] ? matches[1] : "";
|
||||
})()
|
||||
}
|
||||
|
||||
if (this.v) {
|
||||
info.v = this.v
|
||||
}
|
||||
|
||||
if (e == 0) {
|
||||
Object.assign(info, {
|
||||
"wc": /Chrome/.test(window.navigator.userAgent) && !window.chrome ? 1 : 0,
|
||||
"wd": 0,
|
||||
"l": navigator.language,
|
||||
"ls": navigator.languages.join(","),
|
||||
"ml": navigator.mimeTypes.length,
|
||||
"pl": navigator.plugins.length,
|
||||
"av": (() => {
|
||||
let av = window.navigator.userAgent.match(/(?<=\/)[0-9]\.0[^'"\n]+/g);
|
||||
return av.length > 0 ? av[0] : "";
|
||||
})(),
|
||||
"ua": window.navigator.userAgent,
|
||||
"w": window.screen.width,
|
||||
"h": window.screen.height,
|
||||
"ow": window.outerWidth,
|
||||
"oh": window.outerHeight,
|
||||
"url": location.href,
|
||||
"og": location.origin,
|
||||
// "pf": os.platform(),
|
||||
// "bu2": " at https://storage.360buyimg.com/webcontainer/js_security_v3_0.1.5.js:3833:21",
|
||||
// "canvas": "07d433e77178ffb3c4358a1a92f3233f",
|
||||
// "webglFp": "d714752d3e7330bcd7e2b332e7cbcb56",
|
||||
"ccn": navigator.hardwareConcurrency,
|
||||
"ai": this._appId,
|
||||
"pr": 1,
|
||||
"re": document.referrer,
|
||||
"referer": (() => {
|
||||
var i = new RegExp("[^?]*"),
|
||||
u = document.referrer.match(i);
|
||||
if (!u || !u[0]) return "";
|
||||
return u[0];
|
||||
})(),
|
||||
"pp1": {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
aes(message, key, iv) {
|
||||
return CryptoJS.AES.encrypt(message, CryptoJS.enc.Utf8.parse(key), {
|
||||
iv: CryptoJS.enc.Utf8.parse(iv),
|
||||
}).ciphertext.toString();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.BaseH5st = BaseH5st
|
1539
utils/baseUtils.js
Normal file
1539
utils/baseUtils.js
Normal file
File diff suppressed because it is too large
Load Diff
408
utils/h5st4.4.0_lite.js
Normal file
408
utils/h5st4.4.0_lite.js
Normal file
@ -0,0 +1,408 @@
|
||||
const CryptoJS = require("crypto-js");
|
||||
const ADLER32 = require("adler-32");
|
||||
const {BaseH5st} = require("./baseH5st");
|
||||
const qs = require("qs");
|
||||
|
||||
class H5st extends BaseH5st {
|
||||
constructor(url, cookieStr, userAgent, config) {
|
||||
super(url, cookieStr, userAgent);
|
||||
|
||||
if (url) {
|
||||
try {
|
||||
this.url = url;
|
||||
} catch (e) {
|
||||
console.log('url传递错误')
|
||||
}
|
||||
}
|
||||
|
||||
if (url) {
|
||||
try {
|
||||
this.url = url;
|
||||
} catch (e) {
|
||||
console.log("url传递错误");
|
||||
}
|
||||
}
|
||||
|
||||
this.childElementCount = 0;
|
||||
this.v = "v_lite_f_4.4.0"
|
||||
|
||||
this._storageFpKey = 'WQ_lite_vk1';
|
||||
this._defaultToken = "";
|
||||
this._appId = "";
|
||||
this._defaultAlgorithm = {
|
||||
local_key_1: CryptoJS.MD5, local_key_2: CryptoJS.SHA256, local_key_3: CryptoJS.HmacSHA256
|
||||
};
|
||||
this._version = '4.4';
|
||||
this._fingerprint = "";
|
||||
this.settings = {
|
||||
debug: !1
|
||||
};
|
||||
this.ErrCodes = {
|
||||
UNSIGNABLE_PARAMS: 1, APPID_ABSENT: 2, TOKEN_EMPTY: 3, GENERATE_SIGNATURE_FAILED: 4, UNHANDLED_ERROR: -1
|
||||
};
|
||||
this.__iniConfig(Object.assign({}, this.settings, config));
|
||||
}
|
||||
|
||||
__iniConfig(t) {
|
||||
if (!("string" === typeof t.appId && t.appId)) {
|
||||
console.error('settings.appId must be a non-empty string')
|
||||
}
|
||||
this._appId = t.appId || "";
|
||||
if (this._appId) {
|
||||
this._storageFpKey = this._storageFpKey + "_" + this._appId + "_" + this._version
|
||||
}
|
||||
this._debug = Boolean(t.debug);
|
||||
this._onSign = "function" === typeof t.onSign ? t.onSign : function () {
|
||||
};
|
||||
this._log(`create instance with appId=${this._appId}`)
|
||||
}
|
||||
|
||||
__genDefaultKey(t, r, n, e) {
|
||||
return super.__genDefaultKey(t, `${t}${r}${n}${e}qV!+A!`);
|
||||
}
|
||||
|
||||
__genSignParams(t, e, r, n) {
|
||||
return ["" + r, "" + this._fingerprint, "" + this._appId, "" + this._defaultToken, "" + t, "" + this._version, "" + e, "" + n].join(";")
|
||||
}
|
||||
|
||||
__genSign(t, e) {
|
||||
const i = baseUtils.getDefaultMethod(e, 'map').call(e, (function (t) {
|
||||
return t.key + ":" + t.value
|
||||
})).join("&");
|
||||
const a = CryptoJS.MD5(t + i + t).toString(CryptoJS.enc.Hex);
|
||||
this._log(`__genSign, paramsStr:${i}, signedStr:${a}`)
|
||||
return a
|
||||
}
|
||||
|
||||
async __requestDeps() {
|
||||
this._fingerprint = this.getSync(this._storageFpKey);
|
||||
if (!this._fingerprint) {
|
||||
this._fingerprint = this.generateVisitKey();
|
||||
this.setSync(this._storageFpKey, this._fingerprint, {expire: 3600 * 24 * 365});
|
||||
}
|
||||
this._log('__requestDeps, fp:' + this._fingerprint);
|
||||
}
|
||||
|
||||
__makeSign(t, e) {
|
||||
function format() {
|
||||
let t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : Date.now(),
|
||||
e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "yyyy-MM-dd", n = new Date(t),
|
||||
r = e, o = {
|
||||
"M+": n.getMonth() + 1,
|
||||
"d+": n.getDate(),
|
||||
"D+": n.getDate(),
|
||||
"h+": n.getHours(),
|
||||
"H+": n.getHours(),
|
||||
"m+": n.getMinutes(),
|
||||
"s+": n.getSeconds(),
|
||||
"w+": n.getDay(),
|
||||
"q+": Math.floor((n.getMonth() + 3) / 3),
|
||||
"S+": n.getMilliseconds(),
|
||||
};
|
||||
return (/(y+)/i.test(r) && (r = r.replace(RegExp.$1, "".concat(n.getFullYear()).substr(4 - RegExp.$1.length))), Object.keys(o).forEach(function (t) {
|
||||
if (new RegExp("(".concat(t, ")")).test(r)) {
|
||||
var e = "S+" === t ? "000" : "00";
|
||||
r = r.replace(RegExp.$1, 1 == RegExp.$1.length ? o[t] : "".concat(e).concat(o[t]).substr("".concat(o[t]).length));
|
||||
}
|
||||
}), r);
|
||||
}
|
||||
|
||||
let i = Date.now(), a = format(i, 'yyyyMMddhhmmssSSS'), u = a + "88";
|
||||
this._defaultToken = this.genLocalTK(this._fingerprint);
|
||||
let o = this.__genDefaultKey(this._defaultToken, this._fingerprint, u, this._appId)
|
||||
if (!o) {
|
||||
if (this._defaultToken) {
|
||||
this._onSign({code: this.ErrCodes.GENERATE_SIGNATURE_FAILED, message: 'generate key failed'})
|
||||
} else {
|
||||
this._onSign({code: this.ErrCodes.TOKEN_EMPTY, message: 'token is empty'})
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
const f = this.__genSign(o, t);
|
||||
const l = baseUtils.getDefaultMethod(t, 'map').call(t, (function (t) {
|
||||
return t.key
|
||||
})).join(",");
|
||||
const h = 1;
|
||||
const p = this.__genSignParams(f, i, a, e);
|
||||
this._log(`__makeSign, result:${JSON.stringify({
|
||||
key: o, signStr: f, _stk: l, _ste: h, h5st: p
|
||||
})}`)
|
||||
this._onSign({code: 0, message: 'success'})
|
||||
return {_stk: l, _ste: h, h5st: p};
|
||||
}
|
||||
|
||||
__collect() {
|
||||
let n = this.envCollect(1);
|
||||
n.fp = this._fingerprint;
|
||||
if (0 === n['extend']['bu2']) {
|
||||
n['extend']['bu2'] = -1
|
||||
}
|
||||
let o = JSON.stringify(n, null, 2)
|
||||
this._log(`__collect envCollect=${o}`)
|
||||
let i = CryptoJS.AES.encrypt(o, CryptoJS.enc.Utf8.parse('r1T.6Vinpb.k+/a)'), {iv: CryptoJS.enc.Utf8.parse("0102030405060708")});
|
||||
return i.ciphertext.toString()
|
||||
}
|
||||
|
||||
genLocalTK(t) {
|
||||
const that = this;
|
||||
|
||||
function b(t) {
|
||||
function w(t) {
|
||||
return baseUtils.getDefaultMethod(Array.prototype, 'map').call(t, (function (t) {
|
||||
var e;
|
||||
return baseUtils.getDefaultMethod(e = "00" + (255 & t).toString(16), 'slice').call(e, -2)
|
||||
})).join("")
|
||||
}
|
||||
|
||||
function _(t) {
|
||||
var e = new Uint8Array(t.length);
|
||||
return baseUtils.getDefaultMethod(Array.prototype, 'forEach').call(e, (function (e, r, n) {
|
||||
n[r] = t.charCodeAt(r)
|
||||
})), w(e)
|
||||
}
|
||||
|
||||
function x(t) {
|
||||
var o = function () {
|
||||
var t = new ArrayBuffer(2);
|
||||
new DataView(t).setInt16(0, 256, !0);
|
||||
return 256 === new Int16Array(t)[0];
|
||||
}();
|
||||
var i = Math.floor(t / Math.pow(2, 32));
|
||||
var a = t % Math.pow(2, 32);
|
||||
var u = new ArrayBuffer(8);
|
||||
var c = new DataView(u);
|
||||
o ? (c.setUint32(0, a, o), c.setUint32(4, i, o)) : (c.setUint32(0, i, o), c.setUint32(4, a, o))
|
||||
return new Uint8Array(u)
|
||||
}
|
||||
|
||||
var n = "", o = Date.now(), u = 'HiO81-Ei89DH', v = function (t, e, r, n) {
|
||||
var i = new Uint8Array(16);
|
||||
baseUtils.getDefaultMethod(Array.prototype, 'forEach').call(i, (function (e, r, n) {
|
||||
n[r] = t.charCodeAt(r)
|
||||
}));
|
||||
var u = x(e), c = new Uint8Array(2);
|
||||
baseUtils.getDefaultMethod(Array.prototype, 'forEach').call(c, (function (t, e, n) {
|
||||
n[e] = r.charCodeAt(e)
|
||||
}));
|
||||
var f = new Uint8Array(12);
|
||||
baseUtils.getDefaultMethod(Array.prototype, 'forEach').call(f, (function (t, e, r) {
|
||||
r[e] = n.charCodeAt(e)
|
||||
}));
|
||||
var s = new Uint8Array(38);
|
||||
s.set(c), s.set(f, 2), s.set(u, 14), s.set(i, 22);
|
||||
var l = ADLER32.buf(s);
|
||||
l >>>= 0;
|
||||
var h = '00000000' + l.toString(16);
|
||||
return h.substr(h.length - 8)
|
||||
}(t, o, "(>", u);
|
||||
n += _(v), n += _("(>"), n += _(u), n += function (t) {
|
||||
return w(x(t))
|
||||
}(o), n += _(t);
|
||||
var g = CryptoJS.enc.Hex.parse(n), b = CryptoJS.AES.encrypt(g, CryptoJS.enc.Utf8.parse('eHL4|FW#Chc3#q?0'), {iv: CryptoJS.enc.Utf8.parse('0102030405060708')});
|
||||
return that.fromBase64(CryptoJS.enc.Base64.stringify(b.ciphertext))
|
||||
}
|
||||
|
||||
var r = {magic: "tk", version: "02", platform: "w", expires: "41", producer: "l"};
|
||||
r.expr = function () {
|
||||
for (var r = that.getRandomIDPro({
|
||||
size: 32, dictType: 'max', customDict: null
|
||||
}), n = ["1", "2", "3"], o = ["+", "x"], i = (2 + Math.floor(4 * Math.random())), a = "", u = 0; u < i; u++) a += n[Math.floor((Math.random() * 3))], (u < i - 1) && (a += o[Math.floor((Math.random() * 2))]);
|
||||
(a.length < 9) && (a += r.substr(0, (9 - a.length)));
|
||||
var f = CryptoJS.enc.Utf8.parse(a), s = CryptoJS.enc.Base64.stringify(f);
|
||||
return that.fromBase64(s)
|
||||
}();
|
||||
r.cipher = b(t);
|
||||
r.adler32 = function (t) {
|
||||
var r = ADLER32.str(t);
|
||||
r >>>= 0;
|
||||
var n = '00000000' + r.toString(16);
|
||||
return n.substr(n.length - 8)
|
||||
}(r.magic + r.version + r.platform + r.expires + r.producer + r.expr + r.cipher);
|
||||
return r.magic + r.version + r.platform + r.adler32 + r.expires + r.producer + r.expr + r.cipher
|
||||
}
|
||||
|
||||
getRandomIDPro() {
|
||||
var t, e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, r = e.size,
|
||||
n = void 0 === r ? 10 : r, o = e.dictType, i = void 0 === o ? "number" : o, a = e.customDict, u = "";
|
||||
if (a && "string" == typeof a) t = a; else switch (i) {
|
||||
case"alphabet":
|
||||
t = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
break;
|
||||
case"max":
|
||||
t = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
|
||||
break;
|
||||
default:
|
||||
t = "0123456789"
|
||||
}
|
||||
for (; n--;) u += t[Math.random() * t.length | 0];
|
||||
return u
|
||||
}
|
||||
|
||||
fromBase64(t) {
|
||||
return t.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")
|
||||
}
|
||||
|
||||
generateVisitKey() {
|
||||
const that = this;
|
||||
|
||||
function d(t, e) {
|
||||
var r, f = [], s = t.length, l = hh(t);
|
||||
try {
|
||||
for (l.s(); !(r = l.n()).done;) {
|
||||
var p = r.value;
|
||||
if (Math.random() * s < e && (f.push(p), 0 == --e)) {
|
||||
break;
|
||||
}
|
||||
s--
|
||||
}
|
||||
} catch (t) {
|
||||
l.e(t)
|
||||
} finally {
|
||||
l.f()
|
||||
}
|
||||
for (var d = "", g = 0; g < f.length; g++) {
|
||||
var y = (Math.random() * (f.length - g) | 0);
|
||||
d += f[y], f[y] = f[((f.length - g) - 1)]
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
function hh(t, u) {
|
||||
function p(t, e) {
|
||||
(null == e || e > t.length) && (e = t.length);
|
||||
for (var r = 0, n = new Array(e); r < e; r++) n[r] = t[r];
|
||||
return n
|
||||
}
|
||||
|
||||
var c = void 0 !== o && i(t) || t["@@iterator"];
|
||||
if (!c) {
|
||||
if (Array.isArray(t) || (c = function (t, e) {
|
||||
var o;
|
||||
if (!t) return;
|
||||
if ("string" == typeof t) return p(t, e);
|
||||
var i = baseUtils.getDefaultMethod(o = Object.prototype.toString.call(t), 'slice').call(o, 8, -1);
|
||||
"Object" === i && t.constructor && (i = t.constructor.name);
|
||||
if ("Map" === i || "Set" === i) return n(t);
|
||||
if ("Arguments" === i || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)) return p(t, e)
|
||||
}(t)) || u && t && "number" == typeof t.length) {
|
||||
c && (t = c);
|
||||
var f = 0, s = function () {
|
||||
};
|
||||
return {
|
||||
s: s, n: function () {
|
||||
return f >= t.length ? {done: !0} : {done: !1, value: t[f++]}
|
||||
}, e: function (t) {
|
||||
throw t
|
||||
}, f: s
|
||||
}
|
||||
}
|
||||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
|
||||
}
|
||||
var l, h = !0, d = !1;
|
||||
return {
|
||||
s: function () {
|
||||
c = c.call(t)
|
||||
}, n: function () {
|
||||
var t = c.next();
|
||||
return h = t.done, t
|
||||
}, e: function (t) {
|
||||
for (var r = e, n = [], o = 0; ;) switch (r[o++]) {
|
||||
case 11:
|
||||
n.push(!0);
|
||||
break;
|
||||
case 18:
|
||||
l = n[n.length - 1];
|
||||
break;
|
||||
case 33:
|
||||
n.push(t);
|
||||
break;
|
||||
case 74:
|
||||
d = n[n.length - 1];
|
||||
break;
|
||||
case 95:
|
||||
return;
|
||||
case 99:
|
||||
n.pop()
|
||||
}
|
||||
}, f: function () {
|
||||
try {
|
||||
h || null == c.return || c.return()
|
||||
} finally {
|
||||
if (d) throw l
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function y(t, e) {
|
||||
for (var r = 0; r < e.length; r++) {
|
||||
-1 !== baseUtils.getDefaultMethod(t, 'indexOf').call(t, e[r]) && (t = t.replace(e[r], ""))
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
function g(t) {
|
||||
for (var e = t.size, n = t.num, o = ""; e--;) o += n[0 | (Math.random() * n.length)];
|
||||
return o
|
||||
}
|
||||
|
||||
var r = '1uct6d0jhq';
|
||||
var n = d(r, 4);
|
||||
var o = 10 * Math.random() | 0;
|
||||
var i = y(r, n);
|
||||
var a = ((g({size: o, num: i}) + n + g({size: 12 - o - 1, num: i})) + o).split("");
|
||||
var u = baseUtils.getDefaultMethod(a, 'slice').call(a, 0, 8);
|
||||
var l = baseUtils.getDefaultMethod(a, 'slice').call(a, 8);
|
||||
var h = [];
|
||||
for (; u.length > 0;) {
|
||||
h.push((35 - parseInt(u.pop(), 36)).toString(36))
|
||||
}
|
||||
return (h = baseUtils.getDefaultMethod(h, 'concat').call(h, l)).join("")
|
||||
}
|
||||
}
|
||||
|
||||
async function test(cookieStr, userAgent) {
|
||||
var h5stObj = new H5st("https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html?ids=501730512%2C501676150&navh=49&stath=37&tttparams=wUQ86eyJhZGRyZXNzSWQiOjAsImRMYXQiOjAsImRMbmciOjAsImdMYXQiOiIzOS45NDQwOTMiLCJnTG5nIjoiMTE2LjQ4MjI3NiIsImdwc19hcmVhIjoiMF8wXzBfMCIsImxhdCI6MCwibG5nIjowLCJtb2RlbCI6IlJlZG1pIE5vdGUgMTJUIFBybyIsInBvc0xhdCI6IjM5Ljk0NDA5MyIsInBvc0xuZyI6IjExNi40ODIyNzYiLCJwcnN0YXRlIjoiMCIsInVlbXBzIjoiMC0wLTAiLCJ1bl9hcmVhIjoiMV83Ml81NTY3NF8wIn50%3D&preventPV=1&forceCurrentView=1", cookieStr, userAgent, {
|
||||
debug: true,
|
||||
appId: "35fa0",
|
||||
});
|
||||
|
||||
var a = await h5stObj.sign({
|
||||
functionId: "try_SpecFeedList",
|
||||
appid: "newtry",
|
||||
body: JSON.stringify({"tabId":"212","page":1,"version":2,"source":"default","client":"outer","tryIds":["501730512","501676150"]})
|
||||
});
|
||||
console.log(a);
|
||||
|
||||
let params = qs.stringify({
|
||||
functionId: "try_SpecFeedList",
|
||||
appid: "newtry",
|
||||
body: JSON.stringify({"tabId":"212","page":1,"version":2,"source":"default","client":"outer","tryIds":["501730512","501676150"]}),
|
||||
'h5st': a.h5st
|
||||
});
|
||||
console.log(params);
|
||||
|
||||
try {
|
||||
const {data} = await api({
|
||||
method: "POST",
|
||||
url: `https://api.m.jd.com/client.action`,
|
||||
headers: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
origin: "https://prodev.m.jd.com",
|
||||
Referer: "https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html?ids=501730512%2C501676150&navh=49&stath=37&tttparams=wUQ86eyJhZGRyZXNzSWQiOjAsImRMYXQiOjAsImRMbmciOjAsImdMYXQiOiIzOS45NDQwOTMiLCJnTG5nIjoiMTE2LjQ4MjI3NiIsImdwc19hcmVhIjoiMF8wXzBfMCIsImxhdCI6MCwibG5nIjowLCJtb2RlbCI6IlJlZG1pIE5vdGUgMTJUIFBybyIsInBvc0xhdCI6IjM5Ljk0NDA5MyIsInBvc0xuZyI6IjExNi40ODIyNzYiLCJwcnN0YXRlIjoiMCIsInVlbXBzIjoiMC0wLTAiLCJ1bl9hcmVhIjoiMV83Ml81NTY3NF8wIn50%3D&preventPV=1&forceCurrentView=1",
|
||||
"User-Agent": userAgent,
|
||||
"x-referer-page": "https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html"
|
||||
},
|
||||
data: params
|
||||
});
|
||||
console.log(data);
|
||||
} catch (e) {
|
||||
console.log(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
H5st,
|
||||
test
|
||||
}
|
1473
utils/smashUtils.js
Normal file
1473
utils/smashUtils.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user