1
0
mirror of https://github.com/okyyds/yyds.git synced 2026-07-13 00:51:17 +08:00
This commit is contained in:
YYDS
2022-02-04 03:57:50 +08:00
parent 4e2e8b2226
commit 77a32dad3f
13 changed files with 2869 additions and 84 deletions

121
jd_try.js
View File

@@ -8,6 +8,18 @@
*
* @Address: https://github.com/X1a0He/jd_scripts_fixed/blob/main/jd_try_xh.js
* @LastEditors: X1a0He
参考环境变量配置如下:
export JD_TRY="true"
export JD_TRY_PLOG="true" #是否打印输出到日志
export JD_TRY_PASSZC="true" #过滤种草官类试用
export JD_TRY_MAXLENGTH="50" #商品数组的最大长度
export JD_TRY_APPLYINTERVAL="5000" #商品试用之间和获取商品之间的间隔
export JD_TRY_APPLYNUMFILTER="100000" #过滤大于设定值的已申请人数
export JD_TRY_MINSUPPLYNUM="1" #最小提供数量
export JD_TRY_SENDNUM="10" #每隔多少账号发送一次通知,不需要可以不用设置
export JD_TRY_UNIFIED="false" 默认采用不同试用组
cron "4 1-22/8 * * *" jd_try.js, tag:京东试用
*/
const $ = new Env('京东试用')
const URL = 'https://api.m.jd.com/client.action'
@@ -36,10 +48,24 @@ $.innerKeyWords =
"女用", "神油", "足力健", "老年", "老人",
"宠物", "饲料", "丝袜", "黑丝", "磨脚",
"脚皮", "除臭", "性感", "内裤", "跳蛋",
"安全套", "龟头", "阴道", "阴部"
"安全套", "龟头", "阴道", "阴部", "手机卡",
"流量卡", "和田玉", "钢化膜", "手机壳","习题","试卷"
]
//下面很重要,遇到问题请把下面注释看一遍再来问
let args_xh = {
/*
* 控制是否输出当前环境变量设置默认为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
/*
* 每个Tab页要便遍历的申请页数由于京东试用又改了获取不到每一个Tab页的总页数了(显示null),所以特定增加一个环境变了以控制申请页数
* 例如设置 JD_TRY_PRICE 为 30假如现在正在遍历tab1那tab1就会被遍历到30页到31页就会跳到tab2或下一个预设的tab页继续遍历到30页
@@ -56,7 +82,7 @@ let args_xh = {
* 提示想每个账号独立不同的试用产品的请设置为false想减少脚本运行时间的请设置为true
* 默认为false
*/
unified: process.env.JD_TRY_UNIFIED || false,
unified: process.env.JD_TRY_UNIFIED === 'true' || false,
//以上环境变量新增于2022.01.25
/*
* 商品原价,低于这个价格都不会试用,意思是
@@ -100,7 +126,7 @@ let args_xh = {
* 过滤大于设定值的已申请人数例如下面设置的1000A商品已经有1001人申请了则A商品不会进行申请会被跳过
* 可设置环境变量JD_TRY_APPLYNUMFILTER
* */
applyNumFilter: process.env.JD_TRY_APPLYNUMFILTER * 1 || 10000,
applyNumFilter: process.env.JD_TRY_APPLYNUMFILTER * 1 || 100000,
/*
* 商品试用之间和获取商品之间的间隔, 单位:毫秒(1秒=1000毫秒)
* 可设置环境变量JD_TRY_APPLYINTERVAL
@@ -121,7 +147,7 @@ let args_xh = {
* 例如B商品是种草官专属试用商品下面设置为true即使你是种草官账号A商品也不会被添加到待提交试用组
* 可设置环境变量JD_TRY_PASSZC默认为true
* */
passZhongCao: process.env.JD_TRY_PASSZC || true,
passZhongCao: process.env.JD_TRY_PASSZC === 'true' || true,
/*
* 是否打印输出到日志考虑到如果试用组长度过大例如100以上如果每个商品检测都打印一遍日志长度会非常长
* 打印的优点:清晰知道每个商品为什么会被过滤,哪个商品被添加到了待提交试用组
@@ -131,13 +157,13 @@ let args_xh = {
* 不打印的缺点:无法清晰知道每个商品为什么会被过滤,哪个商品被添加到了待提交试用组
* 可设置环境变量JD_TRY_PLOG默认为true
* */
printLog: process.env.JD_TRY_PLOG || true,
printLog: process.env.JD_TRY_PLOG === 'true' || true,
/*
* 白名单是否打开如果下面为true那么黑名单会自动失效
* 白名单和黑名单无法共存,白名单永远优先于黑名单
* 可通过环境变量控制JD_TRY_WHITELIST默认为false
* */
whiteList: process.env.JD_TRY_WHITELIST || false,
whiteList: process.env.JD_TRY_WHITELIST === 'true' || false,
/*
* 白名单关键词,当标题存在关键词时,加入到试用组
* 例如A商品的名字为『旺仔牛奶48瓶特价』白名单其中一个关键词是『牛奶』那么A将会直接被添加到待提交试用组不再进行另外判断
@@ -152,10 +178,7 @@ let args_xh = {
sendNum: process.env.JD_TRY_SENDNUM * 1 || 4,
}
//上面很重要,遇到问题请把上面注释看一遍再来问
!(async () => {
console.log('X1a0He留遇到问题请把脚本内的注释看一遍再来问谢谢')
console.log('X1a0He留遇到问题请把脚本内的注释看一遍再来问谢谢')
console.log('X1a0He留遇到问题请把脚本内的注释看一遍再来问谢谢')
!(async() => {
await $.wait(500)
// 如果你要运行京东试用这个脚本,麻烦你把环境变量 JD_TRY 设置为 true
if (process.env.JD_TRY && process.env.JD_TRY === 'true') {
@@ -175,7 +198,13 @@ let args_xh = {
$.nickName = '';
await totalBean();
console.log(`\n开始【京东账号${$.index}${$.nickName || $.UserName}\n`);
if (!$.isLogin) {
$.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"
});
@@ -199,6 +228,7 @@ let args_xh = {
$.wrong = false
size = 1
while(trialActivityIdList.length < args_xh.maxLength && $.isForbidden === false){
if(args_xh.unified && trialActivityIdList.length !== 0) break;
if($.nowTabIdIndex === args_xh.tabId.length){
console.log(`tabId组已遍历完毕不在获取商品\n`);
break;
@@ -242,7 +272,7 @@ let args_xh = {
}
}
}
if($.isNode()){
if($.isNode() && $.except === false){
if(($.cookiesArr.length - ($.sentNum * args_xh.sendNum)) < args_xh.sendNum){
console.log(`正在进行最后一次发送通知,发送数量:${($.cookiesArr.length - ($.sentNum * args_xh.sendNum))}`)
await $.notify.sendNotify(`${$.name}`, `${notifyMsg}`)
@@ -273,32 +303,28 @@ function requireConfig() {
//IOS等用户直接用NobyDa的jd $.cookie
$.cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item);
}
if (typeof process.env.JD_TRY_WHITELIST === "undefined") args_xh.whiteList = false;
else args_xh.whiteList = process.env.JD_TRY_WHITELIST === 'true';
if (typeof process.env.JD_TRY_PLOG === "undefined") args_xh.printLog = true;
else args_xh.printLog = process.env.JD_TRY_PLOG === 'true';
if (typeof process.env.JD_TRY_UNIFIED === "undefined") args_xh.unified = false;
else args_xh.unified = process.env.JD_TRY_UNIFIED === 'true';
if (typeof process.env.JD_TRY_PASSZC === "undefined") args_xh.passZhongCao = true;
else args_xh.passZhongCao = process.env.JD_TRY_PASSZC === 'true';
for (let keyWord of $.innerKeyWords) args_xh.titleFilters.push(keyWord)
for(let keyWord of $.innerKeyWords) args_xh.titleFilters.push(keyWord)
console.log(`${$.cookiesArr.length}个京东账号\n`)
console.log('=====环境变量配置如下=====')
console.log(`totalPages: ${typeof args_xh.totalPages}, ${args_xh.totalPages}`)
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(`applyInterval: ${typeof args_xh.applyInterval}, ${args_xh.applyInterval}`)
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('=======================')
if(args_xh.env){
console.log('=====环境变量配置如下=====')
console.log(`env: ${typeof args_xh.env}, ${args_xh.env}`)
console.log(`except: ${typeof args_xh.except}, ${args_xh.except}`)
console.log(`totalPages: ${typeof args_xh.totalPages}, ${args_xh.totalPages}`)
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(`applyInterval: ${typeof args_xh.applyInterval}, ${args_xh.applyInterval}`)
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()
})
}
@@ -313,9 +339,9 @@ function try_tabList() {
});
let option = taskurl_xh('newtry', 'try_tabList', body)
$.get(option, (err, resp, data) => {
try {
if (err) {
if (JSON.stringify(err) === `\"Response code 403 (Forbidden)\"`) {
try{
if(err){
if(JSON.stringify(err) === `\"Response code 403 (Forbidden)\"`){
$.isForbidden = true
console.log('账号被京东服务器风控,不再请求该帐号')
} else {
@@ -352,9 +378,9 @@ function try_feedsList(tabId, page) {
});
let option = taskurl_xh('newtry', 'try_feedsList', body)
$.get(option, (err, resp, data) => {
try {
if (err) {
if (JSON.stringify(err) === `\"Response code 403 (Forbidden)\"`) {
try{
if(err){
if(JSON.stringify(err) === `\"Response code 403 (Forbidden)\"`){
$.isForbidden = true
console.log('账号被京东服务器风控,不再请求该帐号')
} else {
@@ -393,8 +419,7 @@ function try_feedsList(tabId, page) {
args_xh.printLog ? console.log('商品被过滤,该商品是种草官专属') : ''
$.isPush = false;
break;
}
else if (itemTag.tagType === 5) {
} else if(itemTag.tagType === 5){
args_xh.printLog ? console.log('商品被跳过,该商品是付费试用!') : ''
$.isPush = false;
break;
@@ -465,9 +490,9 @@ function try_apply(title, activityId) {
});
let option = taskurl_xh('newtry', 'try_apply', body)
$.get(option, (err, resp, data) => {
try {
if (err) {
if (JSON.stringify(err) === `\"Response code 403 (Forbidden)\"`) {
try{
if(err){
if(JSON.stringify(err) === `\"Response code 403 (Forbidden)\"`){
$.isForbidden = true
console.log('账号被京东服务器风控,不再请求该帐号')
} else {