Skip to content

Commit

Permalink
fix: bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
qiin2333 committed Mar 1, 2021
1 parent c36467c commit 974b179
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
27 changes: 21 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ const ins = new MonkeyMaster({

await ins.init();

// 该商品需要实名认证才可抢购的情况 无法通过金融通道秒杀
const mode = prompt(
'选择运行模式: 1-有货下单, 2-按时下单, 3-提前秒杀, 默认为1',
'1'
);

switch (mode) {
case '1':
const interval = prompt('设置库存监控间隔最大时间, 系统将在此时间内随机刷新 单位秒', 5);
const interval = prompt(
'设置库存监控间隔最大时间, 系统将在此时间内随机刷新 单位秒',
5
);
const buyFunc =
skuids.length > 1 ? 'buyMultiSkusInStock' : 'buySingleSkuInStock';

Expand All @@ -40,14 +44,25 @@ switch (mode) {
break;

case '2':
const buyTime = prompt('输入抢购开始时间, 格式为 yyyy-MM-dd HH:mm:ss.SSS');
const buyTime = prompt(
'输入抢购开始时间, 格式为 yyyy-MM-dd HH:mm:ss.SSS'
);
await ins.buyOnTime(buyTime);
break;

case '3':
const killFunc = prompt('选择下单方式,1: 京东 web, 2: 京东金融 APP', 1) === '1' ? 'seckillOnTime' : 'fqkillOnTime';
const secKillTime = prompt('输入抢购开始时间, 格式为 yyyy-MM-dd HH:mm:ss.SSS');
await ins[killFunc](secKillTime, 1);
const killFunc =
prompt('选择下单方式,1: 京东 web, 2: 京东金融 APP', 1) === '1'
? 'seckillOnTime'
: 'fqkillOnTime';
const secKillTime = prompt(
'输入抢购开始时间, 格式为 yyyy-MM-dd HH:mm:ss.SSS'
);
if (await ins[killFunc](secKillTime, 1)) {
await fetch(
`https://sc.ftqq.com/${CONFIG.sckey}.send?text=Yes, you got it 🍌🍌🍌🍌🍌`
);
}
break;

default:
Expand Down
12 changes: 6 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export default class MonkeyMaster {
this.addCart(this.skuids);
await sleep(0.06);
this.getOrderInfo();
await sleep(0.25);
await sleep(0.3);
this.submitOrder();
};

Expand All @@ -432,7 +432,7 @@ export default class MonkeyMaster {
logger.info(`距离抢购还剩 ${(setTimeStamp - jdTime) / 1000} 秒`);

// 30秒同步一次时间
await sleep(30);
await sleep(random.real(5, 10));
clearTimeout(timer);
jdTime = await this.timeSyncWithJD();
timer = setTimeout(runOrder, setTimeStamp - jdTime);
Expand All @@ -452,7 +452,7 @@ export default class MonkeyMaster {

const runOrder = async () => {
// 抢5分钟
if (Date.now() - setTimeStamp > 1000 * 60 * 5) {
if (Date.now() - setTimeStamp > 1000 * 60 * 30) {
logger.critical('抢购时间已过,停止任务');
return Deno.exit();
}
Expand All @@ -477,7 +477,7 @@ export default class MonkeyMaster {
logger.critical('不存在抢购');
}

await sleep(0.2);
await sleep(random.real(2, 5));
runOrder();
};

Expand All @@ -490,7 +490,7 @@ export default class MonkeyMaster {
logger.info(`距离抢购还剩 ${(setTimeStamp - jdTime) / 1000} 秒`);

// 30秒同步一次时间
await sleep(30);
await sleep(random.real(5, 10));
clearTimeout(timer);
jdTime = await this.timeSyncWithJD();
timer = setTimeout(runOrder, setTimeStamp - jdTime);
Expand Down Expand Up @@ -535,7 +535,7 @@ export default class MonkeyMaster {
logger.info(`距离抢购还剩 ${(setTimeStamp - jdTime) / 1000} 秒`);

// 30秒同步一次时间
await sleep(10);
await sleep(random.real(5, 10));
clearTimeout(timer);
jdTime = await this.timeSyncWithJD();
timer = setTimeout(runOrder, setTimeStamp - jdTime);
Expand Down
2 changes: 1 addition & 1 deletion order/fqsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export default class SecKill {
ret = await res.json();
} catch (error) {}

logger.info(ret);
console.info(ret);

return ret.code === 0;
}
Expand Down

0 comments on commit 974b179

Please sign in to comment.