This commit is contained in:
Faker 2025-06-05 09:32:07 +08:00
parent b9513e66f4
commit d788d0a23e
3 changed files with 150 additions and 131 deletions

File diff suppressed because one or more lines are too long

147
jd_try.js
View File

@ -115,7 +115,7 @@ let args_xh = {
* C商品原价99元试用价1元如果下面设置为50那么C商品将会被加入到待提交的试用组 * C商品原价99元试用价1元如果下面设置为50那么C商品将会被加入到待提交的试用组
* 默认为0 * 默认为0
* */ * */
jdPrice: process.env.JD_TRY_PRICE * 1 || 20, jdPrice: process.env.JD_TRY_PRICE * 1 || 10,
/* /*
* 下面有一个function是可以获取tabId列表名为try_tabList * 下面有一个function是可以获取tabId列表名为try_tabList
* 可设置环境变量JD_TRY_TABID@进行分隔 * 可设置环境变量JD_TRY_TABID@进行分隔
@ -138,7 +138,7 @@ let args_xh = {
* C商品原价49元现在试用价1元如果下面设置为1那C商品也会被添加到带提交试用组因为1 = 1 * C商品原价49元现在试用价1元如果下面设置为1那C商品也会被添加到带提交试用组因为1 = 1
* 可设置环境变量JD_TRY_TRIALPRICE默认为0 * 可设置环境变量JD_TRY_TRIALPRICE默认为0
* */ * */
trialPrice: process.env.JD_TRY_TRIALPRICE * 1 || 0, trialPrice: process.env.JD_TRY_TRIALPRICE * 1 || 0.01,
/* /*
* 最小提供数量例如试用商品只提供2份试用资格当前设置为1则会进行申请 * 最小提供数量例如试用商品只提供2份试用资格当前设置为1则会进行申请
* 若只提供5分试用资格当前设置为10则不会申请 * 若只提供5分试用资格当前设置为10则不会申请
@ -594,19 +594,23 @@ async function initJsToken() {
async function try_feedsList(tabId, page) { async function try_feedsList(tabId, page) {
const sign = await h5stSign( const sign = await h5stSign(
{ {
functionId: 'try_SpecFeedList', functionId: 'qryH5BabelFloors',
appid: 'newtry', appid: 'newtry',
body: { body: {
tabId: String(tabId), activityId: '3C751WNneAUaZ8Lw8xYN7cbSE8gm',
page: Number(page), pageId: '5457569',
version: 2, uuid: '',
source: 'default', queryFloorsParam: {
client: 'outer', floorParams: { 115571575: { tabId: tabId, page: page, source: 'lottery', sessionId: 'b5a86af7e7524b50b38e66d1c96cc244' } },
type: 2,
},
siteClient: 'apple',
siteClientVersion: '12.4.1',
}, },
'x-api-eid-token': $.jsToken, 'x-api-eid-token': $.jsToken,
}, },
'35fa0', '35fa0'
); )
try { try {
const { data } = await api({ const { data } = await api({
@ -621,111 +625,126 @@ async function try_feedsList(tabId, page) {
'x-rp-client': 'h5_1.0.0', 'x-rp-client': 'h5_1.0.0',
}, },
data: sign.qs, data: sign.qs,
}); })
let tempKeyword = ``; let tempKeyword = ``
if (data.code === '0') { // 兼容两种结构
console.log(`${size++} 次获取试用商品成功tabId:${args_xh.tabId[$.nowTabIdIndex]} 的 第 ${page}`); let feedList, hasNext;
console.log(`获取到商品 ${data.data.feedList.length}`); if (data.data && data.data.feedList) {
for (let item of data.data.feedList) { feedList = data.data.feedList;
hasNext = data.data.hasNext;
} else if (
data.floorResponse &&
data.floorResponse['115571575'] &&
data.floorResponse['115571575'].providerData &&
data.floorResponse['115571575'].providerData.data &&
data.floorResponse['115571575'].providerData.data.feedsComponent
) {
feedList = data.floorResponse['115571575'].providerData.data.feedsComponent.feedList;
hasNext = data.floorResponse['115571575'].providerData.data.feedsComponent.hasNext;
}
if (data.code === '0' && feedList) {
console.log(`${size++} 次获取试用商品成功tabId:${args_xh.tabId[$.nowTabIdIndex]} 的 第 ${page}`)
console.log(`获取到商品 ${feedList.length}`)
for (let item of feedList) {
if (item.applyNum === null) { if (item.applyNum === null) {
args_xh.printLog ? console.log(`商品未到申请时间:${item.skuTitle}\n`) : ''; args_xh.printLog ? console.log(`商品未到申请时间:${item.skuTitle}\n`) : ''
continue; continue
} }
if (trialActivityIdList.length >= args_xh.maxLength) { if (trialActivityIdList.length >= args_xh.maxLength) {
console.log('商品列表长度已满.结束获取'); console.log('商品列表长度已满.结束获取')
break; break
} }
if (item.applyState === 1) { if (item.applyState === 1) {
args_xh.printLog ? console.log(`商品已申请试用:${item.skuTitle}\n`) : ''; args_xh.printLog ? console.log(`商品已申请试用:${item.skuTitle}\n`) : ''
continue; continue
} }
if (item.applyState !== null) { if (item.applyState !== null) {
args_xh.printLog ? console.log(`商品状态异常未找到skuTitle\n`) : ''; args_xh.printLog ? console.log(`商品状态异常未找到skuTitle\n`) : ''
continue; continue
} }
if (args_xh.passZhongCao) { if (args_xh.passZhongCao) {
$.isPush = true; $.isPush = true
if (item.tagList.length !== 0) { if (item.tagList.length !== 0) {
for (let itemTag of item.tagList) { for (let itemTag of item.tagList) {
if (itemTag.tagType === 3) { if (itemTag.tagType === 3) {
args_xh.printLog ? console.log('商品被过滤,该商品是种草官专属') : ''; args_xh.printLog ? console.log('商品被过滤,该商品是种草官专属') : ''
$.isPush = false; $.isPush = false
break; break
} else if (itemTag.tagType === 5) { } else if (itemTag.tagType === 5) {
args_xh.printLog ? console.log('商品被跳过,该商品是付费试用!') : ''; args_xh.printLog ? console.log('商品被跳过,该商品是付费试用!') : ''
$.isPush = false; $.isPush = false
break; break
} }
} }
} }
} }
if (item.skuTitle && $.isPush) { 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.whiteList) {
if (args_xh.whiteListKeywords.some((fileter_word) => item.skuTitle.includes(fileter_word))) { 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); trialActivityIdList.push(item.trialActivityId)
trialActivityTitleList.push(item.skuTitle); trialActivityTitleList.push(item.skuTitle)
} }
} else { } else {
tempKeyword = ``; tempKeyword = ``
if (parseFloat(item.jdPrice) <= args_xh.jdPrice) { 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) { } 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) { } 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) { } 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) { } else if (parseFloat(item.trialPrice) > args_xh.trialPrice) {
args_xh.printLog ? console.log(`商品被过滤,商品试用价大于预设试用价 \n`) : ''; args_xh.printLog ? console.log(`商品被过滤,商品试用价大于预设试用价 \n`) : ''
} else if (args_xh.titleFilters.some((fileter_word) => (item.skuTitle.includes(fileter_word) ? (tempKeyword = fileter_word) : ''))) { } 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(`商品被过滤,含有关键词 ${tempKeyword}\n`) : ''
} else { } 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) { if (trialActivityIdList.indexOf(item.trialActivityId) === -1) {
trialActivityIdList.push(item.trialActivityId); trialActivityIdList.push(item.trialActivityId)
trialActivityTitleList.push(item.skuTitle); trialActivityTitleList.push(item.skuTitle)
} }
} }
} }
} else if ($.isPush !== false) { } else if ($.isPush !== false) {
console.error('skuTitle解析异常'); console.error('skuTitle解析异常')
return; return
} }
} }
console.log(`当前试用组长度为:${trialActivityIdList.length}`); console.log(`当前试用组长度为:${trialActivityIdList.length}`)
console.log(`下一页状态:${data.data.hasNext}`); console.log(`下一页状态:${hasNext}`)
if (data.data.hasNext === false) { if (hasNext === false) {
if ($.nowTabIdIndex < args_xh.tabId.length) { if ($.nowTabIdIndex < args_xh.tabId.length) {
$.nowTabIdIndex++; $.nowTabIdIndex++
$.nowPage = 1; $.nowPage = 1
$.nowItem = 1; $.nowItem = 1
$.retrynum = 0; $.retrynum = 0
} else { } else {
// 这下是真的没了 // 这下是真的没了
$.retrynum = 999; $.retrynum = 999
} }
} else { } else {
$.nowPage++; $.nowPage++
$.retrynum = 0; $.retrynum = 0
} }
} else { } else {
console.log(`💩 获得试用列表失败: ${data.message}`); console.log(`💩 获得试用列表失败: ${data.message}`)
} }
} catch (e) { } catch (e) {
if (e.message === `Request failed with status code 403`) { if (e.message === `Request failed with status code 403`) {
$.retrynum++; $.retrynum++
if ($.retrynum === 4) { if ($.retrynum === 4) {
$.isForbidden = true; $.isForbidden = true
$.log('多次尝试失败,换个时间再试!'); $.log('多次尝试失败,换个时间再试!')
} else { } else {
console.log(`403${$.retrynum} 次重试`); console.log(`403${$.retrynum} 次重试`)
} }
} else { } else {
console.log(e.message); console.log(e.message)
console.log(`${$.name} API请求失败请检查网路重试`); console.log(`${$.name} API请求失败请检查网路重试`)
} }
} }
} }

File diff suppressed because one or more lines are too long