forked from scccy/jd_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jd_joy.js
1247 lines (1234 loc) · 55.9 KB
/
jd_joy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
jd宠汪汪 搬的https://github.com/uniqueque/QuantumultX/blob/4c1572d93d4d4f883f483f907120a75d925a693e/Script/jd_joy.js
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
IOS用户支持京东双账号,NodeJs用户支持N个京东账号
更新时间:2021-6-6
活动入口:京东APP我的-更多工具-宠汪汪
建议先凌晨0点运行jd_joy.js脚本获取狗粮后,再运行此脚本(jd_joy_steal.js)可偷好友积分,6点运行可偷好友狗粮
feedCount:自定义 每次喂养数量; 等级只和喂养次数有关,与数量无关
推荐每次投喂10个,积累狗粮,然后去玩聚宝盆赌
Combine from Zero-S1/JD_tools(https://github.com/Zero-S1/JD_tools)
==========Quantumult X==========
[task_local]
#京东宠汪汪
15 0-23/2 * * * jd_joy.js, tag=京东宠汪汪, img-url=https://raw.githubusercontent.com/58xinian/icon/master/jdcww.png, enabled=true
============Loon===========
[Script]
cron "15 0-23/2 * * *" script-path=jd_joy.js,tag=京东宠汪汪
============Surge==========
[Script]
京东宠汪汪 = type=cron,cronexp="15 0-23/2 * * *",wake-system=1,timeout=3600,script-path=jd_joy.js
===============小火箭==========
京东宠汪汪 = type=cron,script-path=jd_joy.js, cronexpr="15 0-23/2 * * *", timeout=3600, enable=true
*/
const $ = new Env('宠汪汪');
const zooFaker = require('./utils/JDJRValidator_Pure');
$.get = zooFaker.injectToRequest2($.get.bind($));
$.post = zooFaker.injectToRequest2($.post.bind($));
const notify = $.isNode() ? require('./sendNotify') : '';
//Node.js用户请在jdCookie.js处填写京东ck;
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
let allMessage = '';
//IOS等用户直接用NobyDa的jd cookie
let cookiesArr = [], cookie = '';
if ($.isNode()) {
Object.keys(jdCookieNode).forEach((item) => {
cookiesArr.push(jdCookieNode[item])
})
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => {};
} else {
cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item);
}
let message = '', subTitle = '';
let FEED_NUM = ($.getdata('joyFeedCount') * 1) || 10; //每次喂养数量 [10,20,40,80]
let teamLevel = `2`;//参加多少人的赛跑比赛,默认是双人赛跑,可选2,10,50。其他不可选,其中2代表参加双人PK赛,10代表参加10人突围赛,50代表参加50人挑战赛,如若想设置不同账号参加不同类别的比赛则用&区分即可(如:`2&10&50`)
//是否参加宠汪汪双人赛跑(据目前观察,参加双人赛跑不消耗狗粮,如需参加其他多人赛跑,请关闭)
// 默认 'true' 参加双人赛跑,如需关闭 ,请改成 'false';
let joyRunFlag = true;
let jdNotify = true;//是否开启静默运行,默认true开启
let joyRunNotify = true;//宠汪汪赛跑获胜后是否推送通知,true推送,false不推送通知
const JD_API_HOST = 'https://jdjoy.jd.com/pet'
const weAppUrl = 'https://draw.jdfcloud.com//pet';
!(async () => {
if (!cookiesArr[0]) {
$.msg($.name, '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/bean/signIndex.action', {"open-url": "https://bean.m.jd.com/bean/signIndex.action"});
return;
}
for (let i = 0; i < cookiesArr.length; i++) {
if (cookiesArr[i]) {
cookie = cookiesArr[i];
$.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1])
$.index = i + 1;
$.isLogin = true;
$.nickName = '';
await TotalBean();
console.log(`\n******开始【京东账号${$.index}】${$.nickName || $.UserName}*******\n`);
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"});
if ($.isNode()) {
await notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`);
}
continue
}
message = '';
subTitle = '';
$.validate = '';
// const zooFaker = require('./utils/JDJRValidator_Pure');
// $.validate = await zooFaker.injectToRequest()
await jdJoy();
await showMsg();
// await joinTwoPeopleRun();
}
}
if ($.isNode() && joyRunNotify === 'true' && allMessage) await notify.sendNotify(`${$.name}`, `${allMessage}`)
})()
.catch((e) => {
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
})
.finally(() => {
$.done();
})
async function jdJoy() {
try {
await getPetTaskConfig();
if ($.getPetTaskConfigRes.success) {
if ($.isNode()) {
if (process.env.JOY_FEED_COUNT) {
if ([0, 10, 20, 40, 80].indexOf(process.env.JOY_FEED_COUNT * 1) > -1) {
FEED_NUM = process.env.JOY_FEED_COUNT ? process.env.JOY_FEED_COUNT * 1 : FEED_NUM;
} else {
console.log(`您输入的 JOY_FEED_COUNT 为非法数字,请重新输入`);
}
}
}
await feedPets(FEED_NUM);//喂食
await Promise.all([
petTask(),
appPetTask()
])
await deskGoodsTask();//限时货柜
await enterRoom();
await joinTwoPeopleRun()//参加双人赛跑
} else {
message += `${$.getPetTaskConfigRes.errorMessage}`;
}
} catch (e) {
$.logErr(e)
}
}
//逛商品得100积分奖励任务
async function deskGoodsTask() {
const deskGoodsRes = await getDeskGoodDetails();
if (deskGoodsRes && deskGoodsRes.success) {
if (deskGoodsRes.data && deskGoodsRes.data.deskGoods) {
const { deskGoods, taskChance, followCount = 0 } = deskGoodsRes.data;
console.log(`浏览货柜商品 ${followCount ? followCount : 0}/${taskChance}`);
if (taskChance === followCount) return
for (let item of deskGoods) {
if (!item['status'] && item['sku']) {
await followScan(item['sku'])
}
}
} else {
console.log(`\n限时商品货架已下架`);
}
}
}
//参加双人赛跑
async function joinTwoPeopleRun() {
joyRunFlag = $.getdata('joyRunFlag') ? $.getdata('joyRunFlag') : joyRunFlag;
if ($.isNode() && process.env.JOY_RUN_FLAG) {
joyRunFlag = process.env.JOY_RUN_FLAG;
}
if (`${joyRunFlag}` === 'true') {
let teamLevelTemp = [];
teamLevelTemp = $.isNode() ? (process.env.JOY_TEAM_LEVEL ? process.env.JOY_TEAM_LEVEL.split('&') : teamLevel.split('&')) : ($.getdata('JOY_TEAM_LEVEL') ? $.getdata('JOY_TEAM_LEVEL').split('&') : teamLevel.split('&'));
teamLevelTemp = teamLevelTemp[$.index - 1] ? teamLevelTemp[$.index - 1] : 2;
await getPetRace();
console.log(`\n===以下是京东账号${$.index} ${$.nickName} ${$.petRaceResult.data.teamLimitCount || teamLevelTemp}人赛跑信息===\n`)
if ($.petRaceResult) {
let petRaceResult = $.petRaceResult.data.petRaceResult;
// let raceUsers = $.petRaceResult.data.raceUsers;
console.log(`赛跑状态:${petRaceResult}\n`);
if (petRaceResult === 'not_participate') {
console.log(`暂未参赛,现在为您参加${teamLevelTemp}人赛跑`);
await runMatch(teamLevelTemp * 1);
if ($.runMatchResult.success) {
await getWinCoin();
console.log(`${$.getWinCoinRes.data.teamLimitCount || teamLevelTemp}人赛跑参加成功\n`);
message += `${$.getWinCoinRes.data.teamLimitCount || teamLevelTemp}人赛跑:成功参加\n`;
// if ($.getWinCoinRes.data['supplyOrder']) await energySupplyStation($.getWinCoinRes.data['supplyOrder']);
await energySupplyStation('2');
// petRaceResult = $.petRaceResult.data.petRaceResult;
// await getRankList();
console.log(`双人赛跑助力请自己手动去邀请好友,脚本不带赛跑助力功能\n`);
}
}
if (petRaceResult === 'unbegin') {
console.log('比赛还未开始,请九点再来');
}
if (petRaceResult === 'time_over') {
console.log('今日参赛的比赛已经结束,请明天九点再来');
}
if (petRaceResult === 'unreceive') {
console.log('今日参赛的比赛已经结束,现在领取奖励');
await getWinCoin();
let winCoin = 0;
if ($.getWinCoinRes && $.getWinCoinRes.success) {
winCoin = $.getWinCoinRes.data.winCoin;
}
await receiveJoyRunAward();
console.log(`领取赛跑奖励结果:${JSON.stringify($.receiveJoyRunAwardRes)}`)
if ($.receiveJoyRunAwardRes.success) {
joyRunNotify = $.isNode() ? (process.env.JOY_RUN_NOTIFY ? process.env.JOY_RUN_NOTIFY : `${joyRunNotify}`) : ($.getdata('joyRunNotify') ? $.getdata('joyRunNotify') : `${joyRunNotify}`);
$.msg($.name, '', `【京东账号${$.index}】${$.nickName}\n太棒了,${$.name}赛跑取得获胜\n恭喜您已获得${winCoin}积分奖励`);
allMessage += `京东账号${$.index}${$.nickName}\n太棒了,${$.name}赛跑取得获胜\n恭喜您已获得${winCoin}积分奖励${$.index !== cookiesArr.length ? '\n\n' : ''}`;
// if ($.isNode() && joyRunNotify === 'true') await notify.sendNotify(`${$.name} - 京东账号${$.index} - ${$.nickName}`, `京东账号${$.index}${$.nickName}\n太棒了,${$.name}赛跑取得获胜\n恭喜您已获得${winCoin}积分奖励`)
}
}
if (petRaceResult === 'participate') {
// if ($.getWinCoinRes.data['supplyOrder']) await energySupplyStation($.getWinCoinRes.data['supplyOrder']);
await energySupplyStation('2');
await getRankList();
if($.raceUsers && $.raceUsers.length > 0) {
for (let index = 0; index < $.raceUsers.length; index++) {
if (index === 0) {
console.log(`您当前里程:${$.raceUsers[index].distance}KM\n当前排名:第${$.raceUsers[index].rank}名\n将获得积分:${$.raceUsers[index].coin}\n`);
// message += `您当前里程:${$.raceUsers[index].distance}km\n`;
} else {
console.log(`对手 ${$.raceUsers[index].nickName} 当前里程:${$.raceUsers[index].distance}KM`);
// message += `对手当前里程:${$.raceUsers[index].distance}km\n`;
}
}
}
console.log('\n今日已参赛,下面显示应援团信息');
await getBackupInfo();
if ($.getBackupInfoResult.success) {
const { currentNickName, totalMembers, totalDistance, backupList } = $.getBackupInfoResult.data;
console.log(`${currentNickName}的应援团信息如下\n团员:${totalMembers}个\n团员助力的里程数:${totalDistance}\n`);
if (backupList && backupList.length > 0) {
for (let item of backupList) {
console.log(`${item.nickName}为您助力${item.distance}km`);
}
} else {
console.log(`暂无好友为您助力赛跑,如需助力,请手动去邀请好友助力\n`);
}
}
}
}
} else {
console.log(`您设置的是不参加双人赛跑`)
}
}
//日常任务
async function petTask() {
for (let item of $.getPetTaskConfigRes.datas || []) {
const joinedCount = item.joinedCount || 0;
if (item['receiveStatus'] === 'chance_full') {
console.log(`${item.taskName} 任务已完成`)
continue
}
//每日签到
if (item['taskType'] === 'SignEveryDay') {
if (item['receiveStatus'] === 'chance_left') {
console.log('每日签到未完成,需要自己手动去微信小程序【来客有礼】签到,可获得京豆奖励')
} else if (item['receiveStatus'] === 'unreceive') {
//已签到,领取签到后的狗粮
const res = await getFood('SignEveryDay');
console.log(`领取每日签到狗粮结果:${res.data}`);
}
}
//每日赛跑
if (item['taskType'] === 'race') {
if (item['receiveStatus'] === 'chance_left') {
console.log('每日赛跑未完成')
} else if (item['receiveStatus'] === 'unreceive') {
const res = await getFood('race');
console.log(`领取每日赛跑狗粮结果:${res.data}`);
}
}
//每日兑换
if (item['taskType'] === 'exchange') {
if (item['receiveStatus'] === 'chance_left') {
console.log('每日兑换未完成')
} else if (item['receiveStatus'] === 'unreceive') {
const res = await getFood('exchange');
console.log(`领取每日兑换狗粮结果:${res.data}`);
}
}
//每日帮好友喂一次狗粮
if (item['taskType'] === 'HelpFeed') {
if (item['receiveStatus'] === 'chance_left') {
console.log('每日帮好友喂一次狗粮未完成')
} else if (item['receiveStatus'] === 'unreceive') {
const res = await getFood('HelpFeed');
console.log(`领取每日帮好友喂一次狗粮 狗粮结果:${res.data}`);
}
}
//每日喂狗粮
if (item['taskType'] === 'FeedEveryDay') {
if (item['receiveStatus'] === 'chance_left') {
console.log(`\n${item['taskName']}任务进行中\n`)
} else if (item['receiveStatus'] === 'unreceive') {
const res = await getFood('FeedEveryDay');
console.log(`领取每日喂狗粮 结果:${res.data}`);
}
}
//
//邀请用户助力,领狗粮.(需手动去做任务)
if (item['taskType'] === 'InviteUser') {
if (item['receiveStatus'] === 'chance_left') {
console.log('未完成,需要自己手动去邀请好友给你助力,可以获得狗粮')
} else if (item['receiveStatus'] === 'unreceive') {
const InviteUser = await getFood('InviteUser');
console.log(`领取助力后的狗粮结果::${JSON.stringify(InviteUser)}`);
}
}
//每日三餐
if (item['taskType'] === 'ThreeMeals') {
console.log('-----每日三餐-----');
if (item['receiveStatus'] === 'unreceive') {
const ThreeMealsRes = await getFood('ThreeMeals');
if (ThreeMealsRes.success) {
if (ThreeMealsRes.errorCode === 'received') {
console.log(`三餐结果领取成功`)
message += `【三餐】领取成功,获得${ThreeMealsRes.data}g狗粮\n`;
}
}
}
}
//关注店铺
if (item['taskType'] === 'FollowShop') {
console.log('-----关注店铺-----');
const followShops = item.followShops;
for (let shop of followShops) {
if (!shop.status) {
await dofollowShop(shop.shopId);
await $.wait(1000)
const followShopRes = await followShop(shop.shopId);
console.log(`关注店铺${shop.name}结果::${JSON.stringify(followShopRes)}`)
await $.wait(5000)
}
}
}
//逛会场
if (item['taskType'] === 'ScanMarket') {
console.log('----逛会场----');
const scanMarketList = item.scanMarketList;
for (let scanMarketItem of scanMarketList) {
if (!scanMarketItem.status) {
const body = {
"marketLink": `${scanMarketItem.marketLink || scanMarketItem.marketLinkH5}`,
"taskType": "ScanMarket"
};
await doScanMarket('scan', encodeURI(body["marketLink"]));
await $.wait(1000)
const scanMarketRes = await scanMarket('scan', body);
console.log(`逛会场-${scanMarketItem.marketName}结果::${JSON.stringify(scanMarketRes)}`)
await $.wait(5000)
}
}
}
//浏览频道
if (item['taskType'] === 'FollowChannel') {
console.log('----浏览频道----');
const followChannelList = item.followChannelList;
for (let followChannelItem of followChannelList) {
if (!followChannelItem.status) {
const body = {
"channelId": followChannelItem.channelId,
"taskType": "FollowChannel"
};
await doScanMarket('follow_channel', followChannelItem.channelId);
await $.wait(1000)
const scanMarketRes = await scanMarket('scan', body);
console.log(`浏览频道-${followChannelItem.channelName}结果::${JSON.stringify(scanMarketRes)}`)
await $.wait(5000);
}
}
}
//关注商品
if (item['taskType'] === 'FollowGood') {
console.log('----关注商品----');
const followGoodList = item.followGoodList;
for (let followGoodItem of followGoodList) {
if (!followGoodItem.status) {
const body = `sku=${followGoodItem.sku}`;
await doScanMarket('follow_good', followGoodItem.sku);
await $.wait(1000)
const scanMarketRes = await scanMarket('followGood', body, 'application/x-www-form-urlencoded');
// const scanMarketRes = await appScanMarket('followGood', `sku=${followGoodItem.sku}&reqSource=h5`, 'application/x-www-form-urlencoded');
console.log(`关注商品-${followGoodItem.skuName}结果::${JSON.stringify(scanMarketRes)}`)
await $.wait(5000)
}
}
}
//看激励视频
if (item['taskType'] === 'ViewVideo') {
console.log('----激励视频----');
if (item.taskChance === joinedCount) {
console.log('今日激励视频已看完')
} else {
for (let i = 0; i < new Array(item.taskChance - joinedCount).fill('').length; i++) {
console.log(`开始第${i+1}次看激励视频`);
const body = {"taskType":"ViewVideo"}
let sanVideoRes = await scanMarket('scan', body);
console.log(`看视频激励结果--${JSON.stringify(sanVideoRes)}`);
}
}
}
}
}
async function appPetTask() {
await appGetPetTaskConfig();
// console.log('$.appGetPetTaskConfigRes', $.appGetPetTaskConfigRes.success)
if ($.appGetPetTaskConfigRes.success) {
for (let item of $.appGetPetTaskConfigRes.datas || []) {
if (item['taskType'] === 'ScanMarket' && item['receiveStatus'] === 'chance_left') {
const scanMarketList = item.scanMarketList;
for (let scan of scanMarketList) {
if (!scan.status && scan.showDest === 'h5') {
const body = { marketLink: `${scan.marketLink || scan.marketLinkH5}`, taskType: 'ScanMarket'}
await appScanMarket('scan', body);
await $.wait(5000);
}
}
}
}
}
}
function getDeskGoodDetails() {
return new Promise(resolve => {
// const url = `${JD_API_HOST}/getDeskGoodDetails`;
const host = `jdjoy.jd.com`;
const reqSource = 'h5';
let opt = {
url: "//jdjoy.jd.com/common/pet/getDeskGoodDetails?invokeKey=RtKLB8euDo7KwsO0",
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url, host, reqSource), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
data = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
})
}
function followScan(sku) {
return new Promise(resolve => {
// const url = `${JD_API_HOST}/scan`;
const host = `jdjoy.jd.com`;
const reqSource = 'h5';
const body = {
"taskType": "ScanDeskGood",
sku
}
let opt = {
url: "//jdjoy.jd.com/common/pet/scan?invokeKey=RtKLB8euDo7KwsO0",
method: "POST",
data: body,
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.post(taskPostUrl(url, JSON.stringify(body), reqSource, host, 'application/json'), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
data = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
})
}
//小程序逛会场,浏览频道,关注商品API
function scanMarket(type, body, cType = 'application/json') {
return new Promise(resolve => {
// const url = `${weAppUrl}/${type}`;
const host = `draw.jdfcloud.com`;
const reqSource = 'weapp';
let opt = {
url: `//draw.jdfcloud.com/common/pet/${type}?invokeKey=RtKLB8euDo7KwsO0`,
method: "POST",
data: body,
credentials: "include",
header: {"content-type": cType}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
if (cType === 'application/json') {
body = JSON.stringify(body)
}
$.post(taskPostUrl(url.replace(/reqSource=h5/, 'reqSource=weapp'), body, reqSource, host, cType), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
data = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
})
}
function doScanMarket(type, body) {
return new Promise(resolve => {
const host = `draw.jdfcloud.com`;
const reqSource = 'weapp';
let opt = {
url: `//draw.jdfcloud.com/common/pet/icon/click?iconCode=${type}&linkAddr=${body}&invokeKey=RtKLB8euDo7KwsO0`,
method: "GET",
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
// console.log(url);
$.get(taskUrl(url.replace(/reqSource=h5/, 'reqSource=weapp'), host, reqSource), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
data = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
})
}
//app逛会场
function appScanMarket(type, body) {
return new Promise(resolve => {
// const url = `${JD_API_HOST}/${type}`;
const host = `jdjoy.jd.com`;
const reqSource = 'h5';
let opt = {
url: `//jdjoy.jd.com/common/pet/${type}?invokeKey=RtKLB8euDo7KwsO0`,
method: "POST",
data: body,
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.post(taskPostUrl(url, JSON.stringify(body), reqSource, host, 'application/json'), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
// data = JSON.parse(data);
console.log(`京东app逛会场结果::${data}`)
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
})
}
//领取狗粮API
function getFood(type) {
return new Promise(resolve => {
// const url = `${weAppUrl}/getFood?reqSource=weapp&taskType=${type}`;
const host = `draw.jdfcloud.com`;
const reqSource = 'weapp';
let opt = {
url: `//draw.jdfcloud.com/common/pet/getFood?taskType=${type}&invokeKey=RtKLB8euDo7KwsO0`,
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url.replace(/reqSource=h5/, 'reqSource=weapp'), host, reqSource), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
data = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
})
}
//关注店铺api
function followShop(shopId) {
return new Promise(resolve => {
// const url = `${weAppUrl}/followShop`;
const body = `shopId=${shopId}`;
const reqSource = 'weapp';
const host = 'draw.jdfcloud.com';
let opt = {
url: "//draw.jdfcloud.com/common/pet/followShop?invokeKey=RtKLB8euDo7KwsO0",
method: "POST",
data: body,
credentials: "include",
header: {"content-type":"application/x-www-form-urlencoded"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.post(taskPostUrl(url.replace(/reqSource=h5/, 'reqSource=weapp'), body, reqSource, host,'application/x-www-form-urlencoded'), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
data = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
})
}
function dofollowShop(shopId) {
return new Promise(resolve => {
const reqSource = 'weapp';
const host = 'draw.jdfcloud.com';
let opt = {
url: `//draw.jdfcloud.com/common/pet/icon/click?iconCode=follow_shop&linkAddr=${shopId}&invokeKey=RtKLB8euDo7KwsO0`,
method: "GET",
credentials: "include",
header: {"content-type":"application/x-www-form-urlencoded"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url.replace(/reqSource=h5/, 'reqSource=weapp'), host, reqSource), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
data = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
})
}
function enterRoom() {
return new Promise(resolve => {
// const url = `${weAppUrl}/enterRoom/h5?reqSource=weapp&invitePin=&openId=`;
const host = `draw.jdfcloud.com`;
const reqSource = 'weapp';
let opt = {
url: `//draw.jdfcloud.com/common/pet/enterRoom/h5?invitePin=&openId=&invokeKey=RtKLB8euDo7KwsO0`,
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.post({...taskUrl(url.replace(/reqSource=h5/, 'reqSource=weapp'), host, reqSource),body:'{}'}, (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
// console.log('JSON.parse(data)', JSON.parse(data))
$.roomData = JSON.parse(data);
console.log(`现有狗粮: ${$.roomData.data.petFood}\n`)
subTitle = `【用户名】${$.roomData.data.pin}`
message = `现有积分: ${$.roomData.data.petCoin}\n现有狗粮: ${$.roomData.data.petFood}\n喂养次数: ${$.roomData.data.feedCount}\n宠物等级: ${$.roomData.data.petLevel}\n`
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
function appGetPetTaskConfig() {
return new Promise(resolve => {
const host = `jdjoy.jd.com`;
const reqSource = 'h5';
let opt = {
url: "//jdjoy.jd.com/common/pet/getPetTaskConfig?invokeKey=RtKLB8euDo7KwsO0",
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url, host, reqSource), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
// console.log('----', JSON.parse(data))
$.appGetPetTaskConfigRes = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
//喂食
function feedPets(feedNum) {
return new Promise(resolve => {
console.log(`您设置的喂食数量:${FEED_NUM}g\n`);
if (FEED_NUM === 0) { console.log(`跳出喂食`);resolve();return }
console.log(`实际的喂食数量:${feedNum}g\n`);
// const url = `${weAppUrl}/feed?feedCount=${feedNum}&reqSource=weapp`;
const host = `draw.jdfcloud.com`;
const reqSource = 'weapp';
let opt = {
url: `//draw.jdfcloud.com/common/pet/feed?feedCount=${feedNum}&invokeKey=RtKLB8euDo7KwsO0`,
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url.replace(/reqSource=h5/, 'reqSource=weapp'), host, reqSource), async (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
data = JSON.parse(data);
if (data.success) {
if (data.errorCode === 'feed_ok') {
console.log('喂食成功')
message += `【喂食成功】消耗${feedNum}g狗粮\n`;
} else if (data.errorCode === 'time_error') {
console.log('喂食失败:您的汪汪正在食用中,请稍后再喂食')
message += `【喂食失败】您的汪汪正在食用中,请稍后再喂食\n`;
} else if (data.errorCode === 'food_insufficient') {
console.log(`当前喂食${feedNum}g狗粮不够, 现为您降低一档次喂食\n`)
if ((feedNum) === 80) {
feedNum = 40;
} else if ((feedNum) === 40) {
feedNum = 20;
} else if ((feedNum) === 20) {
feedNum = 10;
} else if ((feedNum) === 10) {
feedNum = 0;
}
// 如果喂食设置的数量失败, 就降低一个档次喂食.
if ((feedNum) !== 0) {
await feedPets(feedNum);
} else {
console.log('您的狗粮已不足10g')
message += `【喂食失败】您的狗粮已不足10g\n`;
}
} else {
console.log(`其他状态${data.errorCode}`)
}
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
function getPetTaskConfig() {
return new Promise(resolve => {
// const url = `${weAppUrl}/getPetTaskConfig?reqSource=weapp`;
// const host = `jdjoy.jd.com`;
// const reqSource = 'h5';
const host = `draw.jdfcloud.com`;
const reqSource = 'weapp';
let opt = {
url: "//draw.jdfcloud.com//common/pet/getPetTaskConfig?invokeKey=RtKLB8euDo7KwsO0",
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url.replace(/reqSource=h5/, 'reqSource=weapp'), host, reqSource), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
// console.log('JSON.parse(data)', JSON.parse(data))
$.getPetTaskConfigRes = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
//查询赛跑信息API
function getPetRace() {
return new Promise(resolve => {
// const url = `${JD_API_HOST}/combat/detail/v2?help=false`;
const host = `jdjoy.jd.com`;
const reqSource = 'h5';
let opt = {
url: "//jdjoy.jd.com/common/pet/combat/detail/v2?help=false&invokeKey=RtKLB8euDo7KwsO0",
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url, host, reqSource), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
// console.log('查询赛跑信息API',(data))
// $.appGetPetTaskConfigRes = JSON.parse(data);
$.petRaceResult = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
//查询赛跑排行榜
function getRankList() {
return new Promise(resolve => {
// const url = `${JD_API_HOST}/combat/getRankList`;
$.raceUsers = [];
let opt = {
url: "//jdjoy.jd.com/common/pet/combat/getRankList?invokeKey=RtKLB8euDo7KwsO0",
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url, `jdjoy.jd.com`, 'h5'), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
// console.log('查询赛跑信息API',(data))
data = JSON.parse(data);
if (data.success) {
$.raceUsers = data.datas;
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
//参加赛跑API
function runMatch(teamLevel, timeout = 5000) {
if (teamLevel === 10 || teamLevel === 50) timeout = 60000;
console.log(`正在参赛中,请稍等${timeout / 1000}秒,以防多个账号匹配到统一赛场\n`)
return new Promise(async resolve => {
await $.wait(timeout);
// const url = `${JD_API_HOST}/combat/match?teamLevel=${teamLevel}`;
const host = `jdjoy.jd.com`;
const reqSource = 'h5';
let opt = {
url: `//jdjoy.jd.com/common/pet/combat/match?teamLevel=${teamLevel}&invokeKey=RtKLB8euDo7KwsO0`,
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url, host, reqSource), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
// console.log('参加赛跑API', JSON.parse(data))
// $.appGetPetTaskConfigRes = JSON.parse(data);
$.runMatchResult = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
//查询应援团信息API
function getBackupInfo() {
return new Promise(resolve => {
// const url = `${JD_API_HOST}/combat/getBackupInfo`;
const host = `jdjoy.jd.com`;
const reqSource = 'h5';
let opt = {
url: "//jdjoy.jd.com/common/pet/combat/getBackupInfo?invokeKey=RtKLB8euDo7KwsO0",
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url, host, reqSource), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
// console.log('查询应援团信息API',(data))
// $.appGetPetTaskConfigRes = JSON.parse(data);
$.getBackupInfoResult = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
//查询赛跑获得多少积分
function getWinCoin() {
return new Promise(resolve => {
// const url = `${weAppUrl}/combat/detail/v2?help=false&reqSource=weapp`;
let opt = {
url: "//draw.jdfcloud.com/common/pet/combat/detail/v2?help=false&invokeKey=RtKLB8euDo7KwsO0",
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url.replace(/reqSource=h5/, 'reqSource=weapp'), 'draw.jdfcloud.com', `weapp`), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
// console.log('查询应援团信息API',(data))
// $.appGetPetTaskConfigRes = JSON.parse(data);
if (data) {
$.getWinCoinRes = JSON.parse(data);
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
//领取赛跑奖励API
function receiveJoyRunAward() {
return new Promise(resolve => {
// const url = `${JD_API_HOST}/combat/receive`;
const host = `jdjoy.jd.com`;
const reqSource = 'h5';
let opt = {
url: "//jdjoy.jd.com/common/pet/combat/receive?invokeKey=RtKLB8euDo7KwsO0",
method: "GET",
data: {},
credentials: "include",
header: {"content-type": "application/json"}
}
const url = "https:"+ taroRequest(opt)['url'] + $.validate;
$.get(taskUrl(url, host, reqSource), (err, resp, data) => {
try {
if (err) {
console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️')
} else {
// console.log('查询应援团信息API',(data))
// $.appGetPetTaskConfigRes = JSON.parse(data);
$.receiveJoyRunAwardRes = JSON.parse(data);
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
})
})
}
//能力补给站
async function energySupplyStation(showOrder) {
let status;
await getSupplyInfo(showOrder);
if ($.getSupplyInfoRes && $.getSupplyInfoRes.success) {
if ($.getSupplyInfoRes.data) {
const { marketList } = $.getSupplyInfoRes.data;
for (let list of marketList) {
if (!list['status']) {
await scanMarket('combat/supply', { showOrder, 'supplyType': 'scan_market', 'taskInfo': list.marketLink || list['marketLinkH5'] });
await getSupplyInfo(showOrder);
} else {
$.log(`能力补给站 ${$.getSupplyInfoRes.data.addDistance}km里程 已领取\n`);
status = list['status'];
}