This commit is contained in:
Faker 2024-10-21 16:07:49 +08:00
parent 5c5604ce27
commit abb1a9794c
11 changed files with 4090 additions and 3522 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

18
jd_dplh1020.js Normal file

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

523
jd_try.js
View File

@ -1,17 +1,21 @@
/**
* 京东试用 只是一个DEMO
*/
const fs = require('fs').promises;
const path = require('path');
const qs = require('qs');
const axios = require("axios");
const common = require('./utils/Rebels_jdCommon')
const {SmashUtils} = require("./utils/smashUtils");
const {setBaseCookie} = require("./utils/baseCookie");
const axios = require('axios');
const { SmashUtils } = require('./utils/smashUtils');
const { setBaseCookie } = require('./utils/baseCookie');
const { getJsToken } = require('./utils/jsToken.js');
const $ = new Env("京东试用");
const URL = "https://api.m.jd.com/client.action";
const cacheFilePath = path.join(__dirname, 'tokenCache.json');
const $ = new Env('京东试用');
const URL = 'https://api.m.jd.com/client.action';
let trialActivityIdList = [];
let trialActivityTitleList = [];
let notifyMsg = "";
let notifyMsg = '';
let size = 1;
$.isPush = true;
$.isLimit = false;
@ -25,24 +29,76 @@ $.try = true;
$.sentNum = 0;
$.cookiesArr = [];
//默认的过滤关键词
$.innerKeyWords = ["幼儿园", "教程", "英语", "辅导", "培训", "孩子", "小学", "成人用品", "套套", "情趣", "自慰", "阳具", "飞机杯", "男士用品", "女士用品", "内衣", "高潮", "避孕", "乳腺", "肛塞", "肛门", "宝宝", "芭比", "娃娃", "男用", "女用", "神油", "足力健", "老年", "老人", "宠物", "饲料", "丝袜", "黑丝", "磨脚", "脚皮", "除臭", "性感", "内裤", "跳蛋", "安全套", "龟头", "阴道", "阴部", "手机卡", "电话卡", "流量卡", "习题", "试卷",];
$.innerKeyWords = [
'幼儿园',
'教程',
'英语',
'辅导',
'培训',
'孩子',
'小学',
'成人用品',
'套套',
'情趣',
'自慰',
'阳具',
'飞机杯',
'男士用品',
'女士用品',
'内衣',
'高潮',
'避孕',
'乳腺',
'肛塞',
'肛门',
'宝宝',
'芭比',
'娃娃',
'男用',
'女用',
'神油',
'足力健',
'老年',
'老人',
'宠物',
'饲料',
'丝袜',
'黑丝',
'磨脚',
'脚皮',
'除臭',
'性感',
'内裤',
'跳蛋',
'安全套',
'龟头',
'阴道',
'阴部',
'手机卡',
'电话卡',
'流量卡',
'习题',
'试卷',
];
//下面很重要,遇到问题请把下面注释看一遍再来问
let args_xh = {
h5st_server: process.env.H5ST_SERVER || 'https://jd1.zhx47.xyz',
/*
* 控制一次最多跑几个号默认10个
*/
try_num: process.env.JD_TRY_NUM * 1 || 10000, /*
try_num: process.env.JD_TRY_NUM * 1 || 10,
/*
* 控制是否输出当前环境变量设置默认为false
* 环境变量名称XH_TRY_ENV
*/
env: process.env.XH_TRY_ENV === "true" || false, /*
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
except: (process.env.XH_TRY_EXCEPT && process.env.XH_TRY_EXCEPT.split('@')) || [],
/*
* 由于每个账号每次获取的试用产品都不一样所以为了保证每个账号都能试用到不同的商品之前的脚本都不支持采用统一试用组的
* 以下环境变量是用于指定是否采用统一试用组的
@ -53,7 +109,7 @@ let args_xh = {
* 提示想每个账号独立不同的试用产品的请设置为false想减少脚本运行时间的请设置为true
* 默认为false
*/
unified: process.env.JD_TRY_UNIFIED === "true" || false, //以上环境变量新增于2022.01.25
unified: process.env.JD_TRY_UNIFIED === 'true' || false,
/*
* 商品原价低于这个价格都不会试用意思是
* A商品原价49元试用价1元如果下面设置为50那么A商品不会被加入到待提交的试用组
@ -61,12 +117,14 @@ let args_xh = {
* C商品原价99元试用价1元如果下面设置为50那么C商品将会被加入到待提交的试用组
* 默认为0
* */
jdPrice: process.env.JD_TRY_PRICE * 1 || 20, /*
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], /*
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瓶特价设置了匹配白名单白名单关键词为牛奶但黑名单关键词存在旺仔
@ -74,36 +132,42 @@ let args_xh = {
* 已内置对应的 成人类 幼儿类 宠物 老年人类关键词请勿重复添加
* 可设置环境变量JD_TRY_TITLEFILTERS关键词与关键词之间用@分隔
* */
titleFilters: (process.env.JD_TRY_TITLEFILTERS && process.env.JD_TRY_TITLEFILTERS.split("@")) || [], /*
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, /*
trialPrice: process.env.JD_TRY_TRIALPRICE * 1 || 0,
/*
* 最小提供数量例如试用商品只提供2份试用资格当前设置为1则会进行申请
* 若只提供5分试用资格当前设置为10则不会申请
* 可设置环境变量JD_TRY_MINSUPPLYNUM
* */
minSupplyNum: process.env.JD_TRY_MINSUPPLYNUM * 1 || 1, /*
minSupplyNum: process.env.JD_TRY_MINSUPPLYNUM * 1 || 1,
/*
* 过滤大于设定值的已申请人数例如下面设置的10000A商品已经有10001人申请了则A商品不会进行申请会被跳过
* 可设置环境变量JD_TRY_APPLYNUMFILTER
* */
applyNumFilter: process.env.JD_TRY_APPLYNUMFILTER * 1 || 10000, /*
applyNumFilter: process.env.JD_TRY_APPLYNUMFILTER * 1 || 10000,
/*
* 商品数组的最大长度通俗来说就是即将申请的商品队列长度
* 例如设置为20当第一次获取后获得12件过滤后剩下5件将会进行第二次获取过滤后加上第一次剩余件数
* 例如是18件将会进行第三次获取直到过滤完毕后为20件才会停止不建议设置太大
* 可设置环境变量JD_TRY_MAXLENGTH
* */
maxLength: process.env.JD_TRY_MAXLENGTH * 1 || 5, /*
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", /*
passZhongCao: process.env.JD_TRY_PASSZC !== 'false',
/*
* 是否打印输出到日志考虑到如果试用组长度过大例如100以上如果每个商品检测都打印一遍日志长度会非常长
* 打印的优点清晰知道每个商品为什么会被过滤哪个商品被添加到了待提交试用组
* 打印的缺点会使日志变得很长
@ -112,18 +176,21 @@ let args_xh = {
* 不打印的缺点无法清晰知道每个商品为什么会被过滤哪个商品被添加到了待提交试用组
* 可设置环境变量JD_TRY_PLOG默认为true
* */
printLog: process.env.JD_TRY_PLOG !== "false", /*
printLog: process.env.JD_TRY_PLOG !== 'false',
/*
* 白名单是否打开如果下面为true那么黑名单会自动失效
* 白名单和黑名单无法共存白名单永远优先于黑名单
* 可通过环境变量控制JD_TRY_WHITELIST默认为false
* */
whiteList: process.env.JD_TRY_WHITELIST === "true" || 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("@")) || [], /*
whiteListKeywords: (process.env.JD_TRY_WHITELISTKEYWORDS && process.env.JD_TRY_WHITELISTKEYWORDS.split('@')) || [],
/*
* 每多少个账号发送一次通知默认为4
* 可通过环境变量控制 JD_TRY_SENDNUM
* */
@ -132,12 +199,13 @@ let args_xh = {
!(async () => {
await $.wait(500);
$.log("\n第一次运行请务必运行一次【依赖安装(jd_indeps.sh)】脚本\n避免出现一些奇怪的问题遇到问题请先看脚本内注释\n频道https://t.me/zhouya47\n");
$.log('\n遇到问题请先看脚本内注释解决不了可联系https://t.me/zhouya47\n');
await requireConfig();
if (!$.cookiesArr[0]) {
console.log($.name, "【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取", "https://bean.m.jd.com/");
console.log($.name, '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/');
return;
}
$.cache = await readCache();
args_xh.tabId = args_xh.tabId.sort(() => 0.5 - Math.random());
for (let i = 0; i < args_xh.try_num; i++) {
if ($.cookiesArr[i]) {
@ -145,11 +213,13 @@ let args_xh = {
$.UserName = decodeURIComponent($.cookie.match(/pt_pin=(.+?);/) && $.cookie.match(/pt_pin=(.+?);/)[1]);
$.index = i + 1;
$.isLogin = true;
$.userAgent = common.genUA($.UserName);
$.userAgent = process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : 'Mozilla/5.0 (Linux; Android 13; 23054RA19C Build/TP1A.220624.014; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/122.0.6261.119 Mobile Safari/537.36',
console.log(`\n开始【京东账号${$.index}${$.UserName}\n`);
await try_rafflecount();
$.except = false;
if (args_xh.except.includes($.UserName)) {
// await try_MyTrials(1, 2); //申请成功的商品
console.log(`跳过账号:${$.UserName}`);
$.except = true;
continue;
@ -161,6 +231,7 @@ let args_xh = {
}
await initSmashUtils();
await initJsToken();
$.totalTry = 0;
$.totalSuccess = 0;
@ -194,18 +265,18 @@ let args_xh = {
await $.wait(5000);
for (let i = 0; i < trialActivityIdList.length && $.isLimit === false; i++) {
if ($.isLimit) {
console.log("试用上限");
console.log('试用上限');
break;
}
if ($.isForbidden) {
console.log("403了跳出");
console.log('403了跳出');
break;
}
await try_apply(trialActivityTitleList[i], trialActivityIdList[i]);
console.log(`间隔等待中请等待15秒 \n`);
await $.wait(15000);
}
console.log("试用申请执行完毕...");
console.log('试用申请执行完毕...');
$.giveupNum = 0;
$.successNum = 0;
$.getNum = 0;
@ -214,20 +285,20 @@ let args_xh = {
await showMsg();
}
}
// if ($.index % args_xh.sendNum === 0) {
// $.sentNum++;
// console.log(`正在进行第 ${$.sentNum} 次发送通知,发送数量:${args_xh.sendNum}`);
// await $.notify.sendNotify(`${$.name}`, `${notifyMsg}`);
// notifyMsg = "";
// }
if ($.index % args_xh.sendNum === 0) {
$.sentNum++;
console.log(`正在进行第 ${$.sentNum} 次发送通知,发送数量:${args_xh.sendNum}`);
await $.notify.sendNotify(`${$.name}`, `${notifyMsg}`);
notifyMsg = '';
}
}
if ($.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 = '';
}
}
// if ($.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}`);
@ -236,21 +307,20 @@ let args_xh = {
function requireConfig() {
return new Promise((resolve) => {
$.notify = require("./sendNotify");
$.notify = require('./sendNotify');
//获取 Cookies
$.cookiesArr = [];
//Node.js用户请在jdCookie.js处填写京东ck;
const jdCookieNode = require("./jdCookie.js");
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 = () => {
};
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => {};
for (let keyWord of $.innerKeyWords) args_xh.titleFilters.push(keyWord);
console.log(`${$.cookiesArr.length}个京东账号\n`);
if (args_xh.env) {
console.log("=========环境变量配置如下=========");
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}`);
@ -266,70 +336,76 @@ function requireConfig() {
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("===============================");
console.log('===============================');
}
resolve();
});
}
async function try_apply(title, activityId) {
console.log(`申请试用商品提交中...`);
args_xh.printLog ? console.log(`商品:${title}`) : "";
args_xh.printLog ? console.log(`id为${activityId}`) : "";
args_xh.printLog ? console.log(`商品:${title}`) : '';
args_xh.printLog ? console.log(`id为${activityId}`) : '';
const sign = await h5stSign({
functionId: "try_apply",
appid: "newtry",
const sign = await h5stSign(
{
functionId: 'try_apply',
appid: 'newtry',
body: {
"activityId": Number(activityId),
}
}, '20240830232408557;5mztiyg695z5tnm6;35fa0;tk03w9b6e1c4318nMQIE17rhyLkcTB-PhrO8maY4_RSFx_6guFXoBgeXI5Q-pgu5iYVqY7DEIqs3bafgK11fvFYpImgx;cf229d6282c8034badeed93959755103;4.7;1725031448557;UO2O1eGHgZxHt05fbSMrWvUOu1PbhSTSZXp1azqJ7fMHhEK13A77ZoJ724J8DSzpZ9uzLpnSVPxqwCJFi_q-ZwH6yKHQBoB9MYxqe7f3r0o8VsqWKarWlBbrnRW-D7AxITRFcUYuG1-4CsL0Gv8R4NY7sRBegv_2GGO5XGqFAtxWe6vfNHZwnpdmCGAhMTxShK03QzvlawNfPeWXjEuEGSOoqDg8-o9lV8b64XK1YS2ATcbPlAXI8aKiOBFJam3P-jckGZ07hQDJgDXut8xEuFLOuBuLaKBUA4wgE0SFuGW_BcTdXJ5eLa5q_4KSBlqg7qv-fxuo63VFJWVMwnXf7W-0OgheXs4j9DQNh27xJR2bNu-pLfvjbNpzfP8IA_rvoMuy-jzbU65EWLHBTDwFyKjKwRf8UpVqDlbAn9w0P6u9q6qLhyM7an-PhlwdrLeHyCtqGGrxPldbz2Ljo4j6iBSYEKV_kjHxZ6Ae0pfqutW7Aq0UPOuc5bhxfQ3EgG7unVUiRJVoUHW0b5Eg-tiymJxRPe7ZKTkRBMp99Ke-YgzrnelJvloLcMBx_SFuiGwdcHL8fY_p5xIpUsrVxOLCu7nZggE7nDk8PeheJO0dl8zjLad9Prk3hGJ0DQIeqffFGvzEemLTD52YgeDqWQHLXbk3;b49e1f80adb86f588174db9e7128196b')
activityId: Number(activityId),
},
'x-api-eid-token': $.jsToken,
},
'20241020185421353;1o2o2rcsbkd2oob3;35fa0;tk03wa89a1cc518n9ZP1SOIb8Pc1YYoGhRS77lgzvyvQJ2UgI7sI61yIMnWsVSbzlrknsxqwCUFtLWlyUGX9IwK4uCHZ;fbadddbc42bb81b641a319315b6e78dd;4.8;1729421661353;TKmWZt2OjOg7nNT9rNg6zNvKnNj7lOUOcOU6wNUO2uWLkSTOcO07zJwO2W0UqO0JhOg_0JgJxNjKjOwKx5T9zNQKjKjJxJT9kCjJiSjJyNUOcOU6Qlg90Bg50WUOMm0Oh2TJ0FD9zJQKdOA9z1jKwBA_kGTJyJDIdSwJdWjJ0BzO2uzOjRw5oRg_0WUOMm0OkeUIoGz53BQ7t9g-h2wO2uzOgNUO2uWL0Cf9MxDE09TIDRgF0W0I0ig7ydA_kNUO2uWL0OjKoxgB0W0I0_Q60WUOMmE32W0UmW0I02D50NUO2WUOMm0O0W0I06D50NUO2WUOMmEJkW0I0_D50NUO2WUOMmUK2uzOhCv_0WUO2W0UqWTOcOUJhNwO2WUO2uWLm6TOcOkKhNwO2WUO2uWLliUOcO0KhNwO2WUO2uWL0CzLleUK3BQ5tlwO2uzOlCv_0WUO2W0UqWTOcOk8fNUO2WUOMmEJ2uzOjlwO2WUO2uWLmW0I0mwO2WUO2uWLmW0I0Gg50WUO2W0UbV0I0Gw7xFP4xNUO2uWLZVUOMO09hGAKeOzJhCg_eKjJ3Fw80W0I0ST60WUO2W0UbV0I0WP60WUOMm0Oi_T42qTJgeA8-VkImeUKlWUBIVk6fZQ9oxgB0W0I0SA5jNUO2um4;8ca0bcf93cae914dfdd88b7cc3a6f4e4',
);
setBaseCookie();
const joylog = await $.smashUtils.sign({
...sign.body
}, true);
const joylog = await $.smashUtils.sign(
{
...sign.body,
},
true,
);
try {
const {data} = await api({
method: "POST",
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",
"User-Agent": $.userAgent,
"x-referer-page": "https://pro.m.jd.com/mall/active/3mpGVQDhvLsMvKfZZumWPQyWt83L/index.html"
'content-type': 'application/x-www-form-urlencoded',
origin: 'https://pro.m.jd.com',
Referer: 'https://pro.m.jd.com/mall/active/3mpGVQDhvLsMvKfZZumWPQyWt83L/index.html',
'User-Agent': $.userAgent,
'x-referer-page': 'https://pro.m.jd.com/mall/active/3mpGVQDhvLsMvKfZZumWPQyWt83L/index.html',
},
data: qs.stringify(joylog)
data: qs.stringify(joylog),
});
$.totalTry++;
if (data.success && data.code === "1") {
if (data.success && data.code === '1') {
// 申请成功
console.log("申请提交成功");
console.log('申请提交成功');
$.totalSuccess++;
} else if (data.code === "-106") {
} else if (data.code === '-106') {
console.log(data.message); // 未在申请时间内!
} else if (data.code === "-110") {
} else if (data.code === '-110') {
console.log(data.message); // 您的申请已成功提交,请勿重复申请…
} else if (data.code === "-120") {
} else if (data.code === '-120') {
console.log(data.message); // 您还不是会员,本品只限会员申请试用,请注册会员后申请!
} else if (data.code === "-167") {
} else if (data.code === '-167') {
console.log(data.message); // 抱歉,此试用需为种草官才能申请。查看下方详情了解更多。
} else if (data.code === "-131") {
} else if (data.code === '-131') {
console.log(data.message); // 申请次数上限。
$.isLimit = true;
} else if (data.code === "-113") {
} else if (data.code === '-113') {
console.log(data.message); // 操作不要太快哦!
} else {
console.log("申请失败", data);
console.log('申请失败', data);
}
} catch (e) {
if (e.message === `Request failed with status code 403`) {
$.isForbidden = true;
console.log("账号被京东服务器风控,不再请求该帐号");
console.log('账号被京东服务器风控,不再请求该帐号');
} else {
console.log(e.message);
console.log(`${$.name} API请求失败请检查网路重试`);
@ -337,45 +413,56 @@ async function try_apply(title, activityId) {
}
}
function try_MyTrials(page, selected) {
return new Promise((resolve, reject) => {
async function try_MyTrials(page, selected) {
switch (selected) {
case 1:
console.log("正在获取已申请的商品...");
console.log('正在获取已申请的商品...');
break;
case 2:
console.log("正在获取申请成功的商品...");
console.log('正在获取申请成功的商品...');
break;
case 3:
console.log("正在获取申请失败的商品...");
console.log('正在获取申请失败的商品...');
break;
default:
console.log("selected错误");
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,
const sign = await h5stSign(
{
functionId: 'try_MyTrials',
appid: 'newtry',
clientVersion: '13.6.1',
client: 'wh5',
body: { page: page, selected: selected, previewTime: '' },
},
'20241020190915983;agi39zmtagmaaap8;6d63a;tk02wc1d11c3f41lMisxeDIrM3F5zw3TlpVl9lTWqno08Vqtiq4GkXuDVANat5P5-_e_KEjjFRW7OrmT7wCN7nkBO0Eh;c86014a641551242004b4f25c80b56b3efd4405d6bf9899da355593a8710e73e;4.2;1729422555983;e9f6ec1bab0ebf8ad0759c5c9ae319e1e6e561685fd3cb857e7337eff91b61f556bf8a7d02fa529215a3be23a58fcfe0128cabd647573f2a59044ccdd081cca3b1b9334614e6d42db8e32b5c2a8dfe46c4fea05d438740136f73aba5a8b1673c119835af2c1f0459d5b259773ab0312e6aa38abdbe32772a6256aaa4674f4e2beee112716c526703a1e93306c7771b610617a98f88165f08f00444938cd695d29a2df1ac2ffa476c9505cd78864ba430ce5081edadba67198b13ca3fafc9739c053460325939c1342afae5b7963d4005dcc643d32e8f36bb97585d5a6e3210fbbb86eb075b3f9493926e7cefd59d542e06b0bbfbeb78d764025f6a2c1d51dc7cdc806118aa9ef83ee8a5992ba4945c0b6a541385d17bd302ea99572bd1999f7f8ec143e2f59287e8aa14b362eb36ef8a',
'4.2.0',
);
const options = {
method: 'POST',
url: 'https://api.m.jd.com/client.action',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Cookie: $.cookie,
Origin: 'https://prodev.m.jd.com',
Referer: 'https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html',
'User-Agent': $.userAgent,
},
data: sign.qs,
};
$.restApi(options, (err, resp, data) => {
try {
if (err) {
console.log(`🚫 ${arguments.callee.name.toString()} API请求失败请检查网路\n${JSON.stringify(err)}`);
} else {
const { data } = await axios.request(options);
console.log(data);
if (data.success) {
//temp adjustment
if (selected === 2) {
if (data.success && data.data) {
if (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) : "";
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 {
@ -385,14 +472,6 @@ function try_MyTrials(page, selected) {
} 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() {
@ -411,7 +490,7 @@ async function showMsg() {
message += `🎉 ${$.completeNum}个商品已完成\n`;
message += `🗑 ${$.giveupNum}个商品已放弃\n\n`;
}
if (!args_xh.jdNotify || args_xh.jdNotify === "false") {
if (!args_xh.jdNotify || args_xh.jdNotify === 'false') {
console.log($.name, message);
notifyMsg += `${message}`;
} else {
@ -427,73 +506,93 @@ async function try_rafflecount() {
method: 'POST',
url: 'https://api.m.jd.com/client.action',
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Content-Type': 'application/x-www-form-urlencoded',
Cookie: $.cookie,
Origin: 'https://prodev.m.jd.com',
Referer: "https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html",
"User-Agent": $.userAgent,
Referer: 'https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html',
'User-Agent': $.userAgent,
},
data: qs.stringify({
appid: 'ysas-new',
functionId: 'try_rafflecount',
body: JSON.stringify({"previewTime": ""})
})
body: JSON.stringify({ previewTime: '' }),
}),
};
try {
const {data} = await axios.request(options);
const { data } = await axios.request(options);
if (data.code !== '0') {
$.isLogin = false;
console.log(`${data.message}`);
return;
}
console.log(`${data.data.promptDesc}${data.data.remainingNum}`)
console.log(`${data.data.promptDesc}${data.data.remainingNum}`);
if (data.data.remainingNum === 0) {
args_xh.except.push($.UserName);
}
} catch (e) {
console.log(e)
console.log(e);
}
}
async function initSmashUtils() {
try {
$.smashUtils = new SmashUtils(
'https://prodev.m.jd.com/mall/active/3mpGVQDhvLsMvKfZZumWPQyWt83L/index.html?activityId=501742184&sku=10097544183544',
$.cookie,
$.userAgent
);
$.smashUtils["getLocalData"]();
$.smashUtils["getAppOs"]();
$.smashUtils = new SmashUtils('https://prodev.m.jd.com/mall/active/3mpGVQDhvLsMvKfZZumWPQyWt83L/index.html?activityId=501742184&sku=10097544183544', $.cookie, $.userAgent);
$.smashUtils['getLocalData']();
$.smashUtils['getAppOs']();
$.smashUtils.getBlog();
$.smashUtils["getFpv"]();
$.smashUtils['getFpv']();
await $.smashUtils.getInfo();
$.smashUtils.setjoyyaCookie("init");
$.smashUtils.setjoyyaCookie('init');
$.smashUtils.getJrInfo();
} catch (e) {
$.smashUtils.getInterfaceData({
funcName: "other",
real_msg: "initial",
error_msg: e && e.message
})
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
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;
},
});
}
async function initJsToken() {
const currentTime = Date.now();
if ($.cache[$.UserName] && $.cache[$.UserName].expiry > currentTime) {
$.jsToken = $.cache[$.UserName].jsToken;
} else {
const jsTokenData = await getJsToken();
$.jsToken = jsTokenData.token;
// 更新缓存
$.cache[$.UserName] = {
jsToken: jsTokenData.token,
expiry: currentTime + 604800000,
};
await writeCache();
}
})
}
/**
* 获取商品列表并且过滤
*/
async function try_feedsList(tabId, page) {
const sign = await h5stSign({
const sign = await h5stSign(
{
functionId: 'try_SpecFeedList',
appid: 'newtry',
body: {
@ -503,23 +602,24 @@ async function try_feedsList(tabId, page) {
source: 'default',
client: 'outer',
},
'x-api-eid-token': $.jsToken,
},
'20240830232343586;tiz96gyymmmynn59;35fa0;tk03w74b71aa618n1t11vUdyHIggnHwEcPN9aklEa14dNUDG8_8G3G34c5d7s7mGwUJ2aADGh7Umx71p0_RW-DKW3kvy;9a6a37681b62443c25d331b98417422c;4.7;1725031423586;UOGBLFzTfNK9tsvi--7prGlZZovw_k_cuzzLZOX_1lNL2GXWq-BLKv79W5y_og7inaFiDDK3Ae6_yrIkNpgJDMfKGugQSF3ESrMz3pC-ykNOfoPVeBqaXc-5fy2PKHjCXsCQw7_9DHj2gyZac3nDQ_PHDPUC4w4R4VC0xw6qrsNoWgqVJnCSgi0bbY0Na0iXiIp-vEX_0jTQqomWsAj7w-lg2k23OvwymIfEyuhK2Iz68gXWZtrbMwW1s8bz2wV7F0KUgPZcEB1n85XGzhlRqTcv0N59rnqv7h_9kP3AAg5qR0yf4TIXlat5jjKAy_7oXS24_sb-UDolpGmS45s_pHfFbhaonAd2ZDhqrIZClpfaURLGsL4lbsJahK7fms-cuU0FRkGLeQ8kbqREPJQ0BkUJwRf8UpVqDlbAn9w0P6u9q6qLhyM7an-PhlwdrLeHyCtqGGrxPldbz2Ljo4j6iBSYEKV_kjHxZ6Ae0pfqutW7Aq0UPOuc5bhxfQ3EgG7unVUiRJVoUHW0b5Eg-tiymJxRPe7ZKTkRBMp99Ke-YgzrnelJvloLcMBx_SFuiGwdcHL8fY_p5xIpUsrVxOLCu7nZggE7nDk8PeheJO0dl8zjLad9Prk3hGJ0DQIeqffFGvzEemLTD52YgeDqWQHLXbk3;3c8d81286085ce3732829ecfcfa55587'
)
'20241020185331946;rdbso1cxc2kckcx8;35fa0;tk03w88961b8118nluC1DXb3DJMhGhAmD6LtSaZ85XeFEwgip5Y5pfJHB9iGxLTBVGXsi3oh9EbyayfKW5iC09GkS4Ty;4fd2fc17a1ef09a6bb36b9716c77b1ee;4.8;1729421611946;TKmWZt2Oe2f_rJg8kKQ4zRj7jNQ9kNUOcOU6wNUO2uWLkSTOcO07zJwO2W0UqO0JhOg_0JgJxNjKjOwKx5T9zNQKjKjJxJT9kCjJiSjJyNUOcOU6Qlg90Bg50WUOMm0Oh2TJ0FD9zJQKdOA9z1jKwBA_kGTJyJDIdSwJdWjJ0BzO2uzOjRw5oRg_0WUOMm0OkeUIoGz53BQ7t9g-h2wO2uzOgNUO2uWL0CQBlayDq1SImFgC0W0I0ig7ydA_kNUO2uWL0OjKoxgB0W0I0_Q60WUOMmE32W0UmW0I02D50NUO2WUOMm0O0W0I06D50NUO2WUOMmkJlW0I0_D50NUO2WUOMmUK2uzOhCv_0WUO2W0UqWTOcOUJhNwO2WUO2uWLf_TOcOkKhNwO2WUO2uWLliUOcO0KhNwO2WUO2uWL0CzLleUK3BQ5tlwO2uzOlCv_0WUO2W0UqWTOcOk8fNUO2WUOMmEJ2uzOjlwO2WUO2uWLmW0I0mwO2WUO2uWLmW0I0Gg50WUO2W0UbV0I0Gw7xFP4xNUO2uWLZVUOMO09hGAKeOzJhCg_eKjJ3Fw80W0I0ST60WUO2W0UbV0I0WP60WUOMm0Oi_T42qTJgeA8-VkImeUKlWUBIVk6fZQ9oxgB0W0I0SA5jNUO2um4;cd3b5aecc1a5b56a0af543c68634c201',
);
try {
const {data} = await api({
method: "POST",
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",
"User-Agent": $.userAgent,
"x-referer-page": "https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html",
'x-rp-client': 'h5_1.0.0'
'content-type': 'application/x-www-form-urlencoded',
origin: 'https://prodev.m.jd.com',
Referer: 'https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html',
'User-Agent': $.userAgent,
'x-referer-page': 'https://prodev.m.jd.com/mall/active/3C751WNneAUaZ8Lw8xYN7cbSE8gm/index.html',
'x-rp-client': 'h5_1.0.0',
},
data: sign.qs
data: sign.qs,
});
let tempKeyword = ``;
@ -528,19 +628,19 @@ async function try_feedsList(tabId, 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`) : "";
args_xh.printLog ? console.log(`商品未到申请时间:${item.skuTitle}\n`) : '';
continue;
}
if (trialActivityIdList.length >= args_xh.maxLength) {
console.log("商品列表长度已满.结束获取");
console.log('商品列表长度已满.结束获取');
break;
}
if (item.applyState === 1) {
args_xh.printLog ? console.log(`商品已申请试用:${item.skuTitle}\n`) : "";
args_xh.printLog ? console.log(`商品已申请试用:${item.skuTitle}\n`) : '';
continue;
}
if (item.applyState !== null) {
args_xh.printLog ? console.log(`商品状态异常未找到skuTitle\n`) : "";
args_xh.printLog ? console.log(`商品状态异常未找到skuTitle\n`) : '';
continue;
}
if (args_xh.passZhongCao) {
@ -548,11 +648,11 @@ async function try_feedsList(tabId, page) {
if (item.tagList.length !== 0) {
for (let itemTag of item.tagList) {
if (itemTag.tagType === 3) {
args_xh.printLog ? console.log("商品被过滤,该商品是种草官专属") : "";
args_xh.printLog ? console.log('商品被过滤,该商品是种草官专属') : '';
$.isPush = false;
break;
} else if (itemTag.tagType === 5) {
args_xh.printLog ? console.log("商品被跳过,该商品是付费试用!") : "";
args_xh.printLog ? console.log('商品被跳过,该商品是付费试用!') : '';
$.isPush = false;
break;
}
@ -560,29 +660,29 @@ async function try_feedsList(tabId, page) {
}
}
if (item.skuTitle && $.isPush) {
args_xh.printLog ? console.log(`检测 tabId:${args_xh.tabId[$.nowTabIdIndex]} 的 第 ${page} 页 第 ${$.nowItem++ + 1} 个商品\n${item.skuTitle}`) : "";
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`) : "";
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`) : "";
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`) : "";
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`) : "";
args_xh.printLog ? console.log(`商品被过滤,已申请人数大于预设的${args_xh.applyNumFilter}\n`) : '';
} else if (item.jdPrice === null) {
args_xh.printLog ? console.log(`商品被过滤,商品无价,不能申请 \n`) : "";
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`) : "";
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`) : "";
args_xh.printLog ? console.log(`商品通过加入试用组trialActivityId为${item.trialActivityId}\n`) : '';
if (trialActivityIdList.indexOf(item.trialActivityId) === -1) {
trialActivityIdList.push(item.trialActivityId);
trialActivityTitleList.push(item.skuTitle);
@ -590,7 +690,7 @@ async function try_feedsList(tabId, page) {
}
}
} else if ($.isPush !== false) {
console.error("skuTitle解析异常");
console.error('skuTitle解析异常');
return;
}
}
@ -604,7 +704,7 @@ async function try_feedsList(tabId, page) {
$.retrynum = 0;
} else {
// 这下是真的没了
$.retrynum = 999
$.retrynum = 999;
}
} else {
$.nowPage++;
@ -618,7 +718,7 @@ async function try_feedsList(tabId, page) {
$.retrynum++;
if ($.retrynum === 4) {
$.isForbidden = true;
$.log("多次尝试失败,换个时间再试!");
$.log('多次尝试失败,换个时间再试!');
} else {
console.log(`403${$.retrynum} 次重试`);
}
@ -629,41 +729,58 @@ async function try_feedsList(tabId, page) {
}
}
async function h5stSign(body, h5st) {
async function h5stSign(body, h5st, version = '4.8.2') {
const options = {
method: 'POST',
url: `${args_xh.h5st_server}/h5st`,
headers: {'content-type': 'application/json'},
headers: { 'content-type': 'application/json' },
data: {
version: '4.7.4',
version: version,
pin: $.UserName,
ua: $.userAgent,
body,
h5st
h5st,
},
};
const {data} = await axios.request(options);
const { data } = await axios.request(options);
return data.body;
}
async function readCache() {
try {
const data = await fs.readFile(cacheFilePath, 'utf8');
return JSON.parse(data);
} catch (err) {
return {};
}
}
async function writeCache() {
await fs.writeFile(cacheFilePath, JSON.stringify($.cache, null, 2), 'utf8');
}
function Env(name, opts) {
class Http {
constructor(env) {
this.env = env;
}
send(opts, method = "GET") {
opts = typeof opts === "string" ? {
send(opts, method = 'GET') {
opts =
typeof opts === 'string'
? {
url: opts,
} : opts;
}
: opts;
let sender = this.get;
if (method === "POST") {
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);
if (err) reject(err);
else resolve(resp);
});
});
}
@ -673,7 +790,7 @@ function Env(name, opts) {
}
post(opts) {
return this.send.call(this.env, opts, "POST");
return this.send.call(this.env, opts, 'POST');
}
}
@ -682,14 +799,14 @@ function Env(name, opts) {
this.name = name;
this.http = new Http(this);
this.data = null;
this.dataFile = "box.dat";
this.dataFile = 'box.dat';
this.logs = [];
this.isMute = false;
this.isNeedRewrite = false;
this.logSeparator = "\n";
this.logSeparator = '\n';
this.startTime = new Date().getTime();
Object.assign(this, opts);
this.log("", `🔔${this.name}, 开始!`);
this.log('', `🔔${this.name}, 开始!`);
}
initAxios() {
@ -698,19 +815,26 @@ function Env(name, opts) {
}
}
restApi(opts, callback = () => {
}) {
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;
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);
});
},
);
}
log(...logs) {
@ -727,10 +851,7 @@ function Env(name, opts) {
done() {
const endTime = new Date().getTime();
const costTime = (endTime - this.startTime) / 1000;
this.log("", `🔔${this.name}, 结束! 🕛 ${costTime}`);
this.log('', `🔔${this.name}, 结束! 🕛 ${costTime}`);
}
}
)
(name, opts);
})(name, opts);
}

File diff suppressed because one or more lines are too long

View File

@ -2,43 +2,45 @@ function setBaseCookie() {
var cookie = [];
function genUuid() {
return new Date().getTime() + "" + parseInt(2147483647 * Math.random());
return new Date().getTime() + '' + parseInt(2147483647 * Math.random());
}
function setCookie(e, t, i) {
if (e) {
var n = "";
var n = '';
if (i) {
var a = new Date;
a.setTime(a.getTime() + i),
n = ";expires=" + a.toGMTString()
var a = new Date();
a.setTime(a.getTime() + i), (n = ';expires=' + a.toGMTString());
}
document.cookie = e + "=" + t + n + ";path=/;domain=jd.com;";
document.cookie = e + '=' + t + n + ';path=/;domain=jd.com;';
}
}
function setJdv(e, t) {
var i = isPrey(10) && (!e || e.length > 400) ? t + "|direct|-|none|-|" + new Date().getTime() : e;
setCookie("__jdv", i, 1296000000);
var i = isPrey(10) && (!e || e.length > 400) ? t + '|direct|-|none|-|' + new Date().getTime() : e;
setCookie('__jdv', i, 1296000000);
}
function isPrey(e) {
if (e >= 100) return !0;
var t = uuid, r = t.substr(t.length - 2);
var t = uuid,
r = t.substr(t.length - 2);
return !!r && 1 * r < e;
}
var r = 122270672, i = genUuid(), s = parseInt(new Date().getTime() / 1e3);
var r = 122270672,
i = genUuid(),
s = parseInt(new Date().getTime() / 1e3);
var uuid = i;
setCookie("__jda", [r, i, s, s, s, 1].join("."), 15552000000);
setCookie("__jdb", [r, 1, i + "|" + 1, s].join("."), 1800000);
var j = encodeURIComponent([r, "direct", "-", "none", "-", new Date().getTime()].join("|"));
setCookie('__jda', [r, i, s, s, s, 1].join('.'), 15552000000);
setCookie('__jdb', [r, 1, i + '|' + 1, s].join('.'), 1800000);
var j = encodeURIComponent([r, 'direct', '-', 'none', '-', new Date().getTime()].join('|'));
setJdv(j, r);
setCookie("__jdc", r);
setCookie("mba_muid", encodeURI(i));
setCookie('__jdc', r);
setCookie('mba_muid', encodeURI(i));
return cookie.join('');
}
module.exports.setBaseCookie = setBaseCookie
module.exports.setBaseCookie = setBaseCookie;

File diff suppressed because it is too large Load Diff

284
utils/jsToken.js Normal file
View File

@ -0,0 +1,284 @@
var axios = require('axios');
var qs = require('qs');
function TDEncrypt(l) {
l = JSON.stringify(l);
l = encodeURIComponent(l);
var k = '',
f = 0;
do {
var h = l.charCodeAt(f++);
var d = l.charCodeAt(f++);
var a = l.charCodeAt(f++);
var b = h >> 2;
h = ((h & 3) << 4) | (d >> 4);
var e = ((d & 15) << 2) | (a >> 6);
var c = a & 63;
isNaN(d) ? (e = c = 64) : isNaN(a) && (c = 64);
k =
k +
'23IL<N01c7KvwZO56RSTAfghiFyzWJqVabGH4PQdopUrsCuX*xeBjkltDEmn89.-'.charAt(b) +
'23IL<N01c7KvwZO56RSTAfghiFyzWJqVabGH4PQdopUrsCuX*xeBjkltDEmn89.-'.charAt(h) +
'23IL<N01c7KvwZO56RSTAfghiFyzWJqVabGH4PQdopUrsCuX*xeBjkltDEmn89.-'.charAt(e) +
'23IL<N01c7KvwZO56RSTAfghiFyzWJqVabGH4PQdopUrsCuX*xeBjkltDEmn89.-'.charAt(c);
} while (f < l.length);
return k + '/';
}
function getAppVersionFromUserAgent(userAgent) {
const mozillaIndex = userAgent.indexOf('Mozilla/');
if (mozillaIndex !== -1) {
return userAgent.substring(mozillaIndex + 8);
}
return userAgent;
}
function getCurrentPageUrl(inputUrl) {
let l = inputUrl.startsWith('https:') ? 'https://' : 'http://';
let d = '';
try {
const queryIndex = inputUrl.indexOf('?');
if (queryIndex > 0) {
inputUrl = inputUrl.substring(0, queryIndex);
}
d = inputUrl.substring(l.length);
} catch (error) {
console.error('Error parsing URL:', error);
}
return d;
}
async function getJsToken(
userAgent = 'jdapp;android;11.2.8;;;Mozilla/5.0 (Linux; Android 10; ONEPLUS A5010 Build/QKQ1.191014.012; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/76.0.3809.89 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36',
url = 'https://plus.m.jd.com/',
bizId = 'JD-PLUS',
) {
const d = TDEncrypt({
ts: { deviceTime: Date.now(), deviceEndTime: Date.now() + 10 },
ca: {
tdHash: '5b7096a993d442aef38ceb90cce4b485',
contextName: 'webgl,experimental-webgl',
webglversion: 'WebGL 1.0 (OpenGL ES 2.0 Chromium)',
shadingLV: 'WebGL GLSL ES 1.0 (OpenGL ES GLSL ES 1.0 Chromium)',
vendor: 'WebKit',
renderer: 'WebKit WebGL',
extensions: [
'ANGLE_instanced_arrays',
'EXT_blend_minmax',
'EXT_clip_control',
'EXT_color_buffer_half_float',
'EXT_depth_clamp',
'EXT_disjoint_timer_query',
'EXT_float_blend',
'EXT_frag_depth',
'EXT_polygon_offset_clamp',
'EXT_shader_texture_lod',
'EXT_texture_compression_bptc',
'EXT_texture_compression_rgtc',
'EXT_texture_filter_anisotropic',
'EXT_texture_mirror_clamp_to_edge',
'EXT_sRGB',
'KHR_parallel_shader_compile',
'OES_element_index_uint',
'OES_fbo_render_mipmap',
'OES_standard_derivatives',
'OES_texture_float',
'OES_texture_float_linear',
'OES_texture_half_float',
'OES_texture_half_float_linear',
'OES_vertex_array_object',
'WEBGL_blend_func_extended',
'WEBGL_color_buffer_float',
'WEBGL_compressed_texture_s3tc',
'WEBGL_compressed_texture_s3tc_srgb',
'WEBGL_debug_renderer_info',
'WEBGL_debug_shaders',
'WEBGL_depth_texture',
'WEBGL_draw_buffers',
'WEBGL_lose_context',
'WEBGL_multi_draw',
'WEBGL_polygon_mode',
],
wuv: 'Google Inc. (Intel)',
wur: 'ANGLE (Intel, Intel(R) UHD Graphics 730 (0x00004C8B) Direct3D11 vs_5_0 ps_5_0, D3D11)',
},
m: { compatMode: 'CSS1Compat' },
n: {
vendorSub: '',
productSub: '20030107',
vendor: 'Google Inc.',
maxTouchPoints: 1,
pdfViewerEnabled: false,
hardwareConcurrency: 12,
cookieEnabled: true,
appCodeName: 'Mozilla',
appName: 'Netscape',
appVersion: getAppVersionFromUserAgent(userAgent),
platform: 'Win32',
product: 'Gecko',
userAgent: userAgent,
language: 'zh-CN',
onLine: true,
webdriver: false,
javaEnabled: false,
deprecatedRunAdAuctionEnforcesKAnonymity: true,
deviceMemory: 8,
enumerationOrder: [
'vendorSub',
'productSub',
'vendor',
'maxTouchPoints',
'scheduling',
'userActivation',
'doNotTrack',
'geolocation',
'connection',
'plugins',
'mimeTypes',
'pdfViewerEnabled',
'webkitTemporaryStorage',
'webkitPersistentStorage',
'windowControlsOverlay',
'hardwareConcurrency',
'cookieEnabled',
'appCodeName',
'appName',
'appVersion',
'platform',
'product',
'userAgent',
'language',
'languages',
'onLine',
'webdriver',
'getGamepads',
'javaEnabled',
'sendBeacon',
'vibrate',
'deprecatedRunAdAuctionEnforcesKAnonymity',
'protectedAudience',
'bluetooth',
'storageBuckets',
'clipboard',
'credentials',
'keyboard',
'managed',
'mediaDevices',
'storage',
'serviceWorker',
'virtualKeyboard',
'wakeLock',
'deviceMemory',
'userAgentData',
'login',
'ink',
'mediaCapabilities',
'hid',
'locks',
'gpu',
'mediaSession',
'permissions',
'presentation',
'usb',
'xr',
'serial',
'adAuctionComponents',
'runAdAuction',
'canLoadAdAuctionFencedFrame',
'canShare',
'share',
'clearAppBadge',
'getBattery',
'getUserMedia',
'requestMIDIAccess',
'requestMediaKeySystemAccess',
'setAppBadge',
'webkitGetUserMedia',
'clearOriginJoinedAdInterestGroups',
'createAuctionNonce',
'joinAdInterestGroup',
'leaveAdInterestGroup',
'updateAdInterestGroups',
'deprecatedReplaceInURN',
'deprecatedURNToURL',
'getInstalledRelatedApps',
'registerProtocolHandler',
'unregisterProtocolHandler',
],
},
p: [],
w: { devicePixelRatio: 4, screenTop: 0, screenLeft: 0 },
s: { availHeight: 740, availWidth: 360, colorDepth: 24, height: 740, width: 360, pixelDepth: 24 },
sc: {
ActiveBorder: 'rgb(0, 0, 0)',
ActiveCaption: 'rgb(0, 0, 0)',
AppWorkspace: 'rgb(255, 255, 255)',
Background: 'rgb(255, 255, 255)',
ButtonFace: 'rgb(240, 240, 240)',
ButtonHighlight: 'rgb(240, 240, 240)',
ButtonShadow: 'rgb(240, 240, 240)',
ButtonText: 'rgb(0, 0, 0)',
CaptionText: 'rgb(0, 0, 0)',
GrayText: 'rgb(109, 109, 109)',
Highlight: 'rgba(0, 86, 205, 0.8)',
HighlightText: 'rgb(255, 255, 255)',
InactiveBorder: 'rgb(0, 0, 0)',
InactiveCaption: 'rgb(255, 255, 255)',
InactiveCaptionText: 'rgb(128, 128, 128)',
InfoBackground: 'rgb(255, 255, 255)',
InfoText: 'rgb(0, 0, 0)',
Menu: 'rgb(255, 255, 255)',
MenuText: 'rgb(0, 0, 0)',
Scrollbar: 'rgb(255, 255, 255)',
ThreeDDarkShadow: 'rgb(0, 0, 0)',
ThreeDFace: 'rgb(240, 240, 240)',
ThreeDHighlight: 'rgb(0, 0, 0)',
ThreeDLightShadow: 'rgb(0, 0, 0)',
ThreeDShadow: 'rgb(0, 0, 0)',
Window: 'rgb(255, 255, 255)',
WindowFrame: 'rgb(0, 0, 0)',
WindowText: 'rgb(0, 0, 0)',
},
ss: { cookie: true, localStorage: true, sessionStorage: true, globalStorage: false, indexedDB: true },
tz: -480,
lil: '',
wil: '',
});
const a = TDEncrypt({
pin: '',
oid: '',
bizId: bizId,
fc: '',
mode: 'strict',
p: 's',
fp: 'b772d9635edebaa1a47c5a1fd086186a',
ctype: 1,
v: '3.2.1.0',
f: '3',
o: getCurrentPageUrl(url),
qs: '',
qi: '',
});
let { status, data } = await axios({
method: 'POST',
url: `https://jra.jd.com/jsTk.do?a=${encodeURIComponent(a)}`,
headers: {
'User-Agent': userAgent,
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
data: qs.stringify({
d: d,
}),
});
if (status === 200 && data.data) {
return data.data;
} else return null;
}
module.exports.getJsToken = getJsToken;

File diff suppressed because it is too large Load Diff