-
Notifications
You must be signed in to change notification settings - Fork 0
/
jd_ddaixiaochu.js
965 lines (931 loc) · 25.7 KB
/
jd_ddaixiaochu.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
let exchangeName = '京豆*1888'
$.maxLevel=480;
let ACT_ID = 'A_112790_R_1_D_20201028'
//Node.js用户请在jdCookie.js处填写京东ck;
//IOS等用户直接用NobyDa的jd cookie
let cookiesArr = [],
cookie = '',
message;
if ($.isNode()) {
Object.keys(jdCookieNode).forEach((item) => {
cookiesArr.push(jdCookieNode[item])
})
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') that.log = () => {};
} else {
let cookiesData = $.getdata('CookiesJD') || "[]";
cookiesData = jsonParse(cookiesData);
cookiesArr = cookiesData.map(item => item.cookie);
cookiesArr.reverse();
cookiesArr.push(...[$.getdata('CookieJD2'), $.getdata('CookieJD')]);
cookiesArr.reverse();
cookiesArr = cookiesArr.filter(item => item !== "" && item !== null && item !== undefined);
}
!(async () => {
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 = '';
message = '';
await TotalBean();
that.log(`\n******开始【京东账号${$.index}】${$.nickName || $.UserName}*********`);
if (!$.isLogin) {
$.msg($.name, `【提示】cookie已失效`, `京东账号${$.index} ${$.nickName || $.UserName}\n请重新登录获取\nhttps://bean.m.jd.com/`, {
"open-url": "https://bean.m.jd.com/"
});
return;
}
await jdBeauty()
await jdBeauty(false)
}
}
})()
.catch((e) => {
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
})
.finally(() => {
$.done();
})
function obj2param(obj) {
let str = "";
for (let key in obj) {
if (str !== "") {
str += "&";
}
str += key + "=" + encodeURIComponent(obj[key]);
}
return str
}
async function jdBeauty(help = true) {
$.reqId = 1
await getIsvToken()
await getIsvToken2()
await getActInfo()
await getTaskList()
await getDailyMatch()
await play();
// await marketGoods()
if (help) await helpFriends()
}
async function helpFriends() {
$.newShareCodes = [];
await getHelp();
for (let code of $.newShareCodes) {
if (code) {
that.log(`去助力好友${code}`)
await getActInfo(code)
await $.wait(500)
}
}
await setHelp();
}
function getHelp() {
$.newShareCodes = [];
return new Promise(resolve => {
$.get({
url: "https://actapi.tyh52.com/act/get/ddaixiaochu/3",
}, (err, resp, data) => {
try {
if (data) {
data = JSON.parse(data);
if (data.code == 1) {
that.log("获取随机助力好友邀请码成功");
let list = data.data;
if (!(list instanceof Array)) {
list = JSON.parse(list);
}
if (list.length > 0) {
for (var i in list) {
$.newShareCodes.push(list[i]);
}
}
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
});
}
function setHelp() {
return new Promise(resolve => {
if ($.shareId) {
$.get({
url: "https://actapi.tyh52.com/act/set/ddaixiaochu/" + $.shareId
}, (err, resp, data) => {
try {
if (data) {
data = JSON.parse(data);
if (data.code == 1) {
that.log("提交自己的邀請碼成功");
} else {
that.log("已经提交过自己的邀请码");
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
} else {
resolve();
}
});
}
// 获得IsvToken
function getIsvToken() {
return new Promise(resolve => {
$.post(jdUrl('encrypt/pin?appId=dafbe42d5bff9d82298e5230eb8c3f79'), async (err, resp, data) => {
try {
if (err) {
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
$.lkEPin = data.data
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
// 获得对应游戏的访问Token
function getIsvToken2() {
return new Promise(resolve => {
$.post(jdUrl('user/token?appId=dafbe42d5bff9d82298e5230eb8c3f79&client=m&url=pengyougou.m.jd.com'), async (err,
resp, data) => {
try {
if (err) {
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
$.token = data.data
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function getActInfo(inviter = null) {
let body = {
"inviter": inviter,
"activeId": ACT_ID,
"refid": "wojing",
"lkEPin": $.lkEPin,
"token": $.token,
"un_area": "12_904_908_57903",
"source": "wojing",
"scene": "3"
}
return new Promise(resolve => {
$.post(taskUrl("platform/active/role/login", body), async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (!inviter) {
$.info = data.info
$.id = data.id
$.authcode = data.authcode
$.to = data.token
$.money = JSON.parse(data.info.platform)['money']
$.shareId = data.id
that.log(`您的好友助力码为:${$.id}`)
that.log(`当前星星:${$.money}`)
// SecrectUtil2.InitEncryptInfo(data.token, data.info.pltId)
await checkLogin()
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function checkLogin() {
return new Promise(resolve => {
$.post(taskUrl("eliminate_jd/game/local/logincheck", {
info: JSON.stringify($.info),
"reqsId": $.reqId++
}), async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
$.gameId = data.role.gameId
$.gameToken = data.token
$.strength = data.role.items['8003']
that.log(`当前体力:${$.strength}`)
// that.log(JSON.stringify(data))
$.curLevel = data.role.gameInfo.levelId || 40103
$.not3Star = []
for (let level of data.role.allLevels) {
if (level.maxStar !== 3) {
$.not3Star.push(level.id)
}
}
if (data.role.allLevels.length)
$.level = parseInt(data.role.allLevels[data.role.allLevels.length - 1]['id'])
else
$.level = 1
if ($.not3Star.length)
that.log(`当前尚未三星的关卡为:${$.not3Star.join(',')}`)
// SecrectUtil.InitEncryptInfo($.gameToken, $.gameId)
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
async function play() {
//$.level += 1
console.log(`当前关卡:${$.level}`)
while ($.strength >= 5 && $.level <= $.maxLevel) {
await beginLevel()
}
if ($.not3Star.length && $.strength >= 5) {
console.log(`去完成尚未三星的关卡`)
for (let level of $.not3Star) {
$.level = parseInt(level)
await beginLevel()
if ($.strength < 5) break
}
}
}
function getTaskList() {
return new Promise(resolve => {
$.post(taskUrl("platform/active/jingdong/gametasks", {
"activeid": ACT_ID,
"id": $.id,
"token": $.gameToken,
"authcode": $.authcode,
}),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
for (let task of data.tasks) {
if (task.res.sName === "闯关集星") {
$.level = task.state.value + 1
that.log(`当前关卡:${$.level}`)
while ($.strength >= 5 && $.level <= 240) {
await beginLevel()
}
if ($.not3Star.length && $.strength >= 5) {
that.log(`去完成尚未三星的关卡`)
for (let level of $.not3Star) {
$.level = parseInt(level)
await beginLevel()
if ($.strength < 5) break
}
}
} else if (task.res.sName === "逛逛店铺") {
if (task.state.iFreshTimes < task.res.iFreshTimes)
that.log(`去做${task.res.sName}任务`)
for (let i = task.state.iFreshTimes; i < task.res.iFreshTimes; ++i) {
await uploadTask(task.res.eType, task.res.iValue)
await $.wait(500)
await finishTask(task.res.sID)
}
} else if (task.res.sName === "收藏商品") {
if (task.state.iFreshTimes < task.res.iFreshTimes) {
that.log(`去做${task.res.sName}任务`)
let body = {
"api": "followSku",
"skuId": task.adInfo.sValue,
"id": $.id,
"activeid": ACT_ID,
"activeId": ACT_ID,
"authcode": $.authcode,
}
await execute(body)
await $.wait(500)
await finishTask(task.res.sID)
}
} else if (task.res.sName === '加入会员') {
continue
if (!task.state.get) {
that.log(`去做${task.res.sName}任务`)
let body = {
"api": "checkMember",
"memberId": task.adInfo.sValue,
"id": $.id,
"activeid": ACT_ID,
"activeId": ACT_ID,
"authcode": $.authcode,
}
await execute(body)
// await uploadTask(task.res.eType,task.res.iValue)
await $.wait(500)
await finishTask(task.res.sID)
}
} else if (task.res.sName === '下单有礼') {
// that.log(task)
} else if (task.res.sName === '商品加购') {
for (let i = task.state.iFreshTimes; i < task.res.iFreshTimes; ++i) {
that.log(`去做${task.res.sName}任务`)
let body = {
"api": "addProductToCart",
"skuList": task.adInfo.sValue,
"id": $.id,
"activeid": ACT_ID,
"activeId": ACT_ID,
"authcode": $.authcode,
}
await execute(body)
await $.wait(500)
await finishTask(task.res.sID)
}
} else if (task.res.sName === '关注店铺') {
if (task.state.iFreshTimes < task.res.iFreshTimes)
that.log(`去做${task.res.sName}任务`)
for (let i = task.state.iFreshTimes; i < task.res.iFreshTimes; ++i) {
let body = {
"api": "followShop",
"shopId": task.adInfo.sValue,
"id": $.id,
"activeid": ACT_ID,
"activeId": ACT_ID,
"authcode": $.authcode,
}
await execute(body)
await $.wait(500)
await finishTask(task.res.sID)
}
} else if (task.res.sName === '喂养狗狗' || task.res.sName === '每日签到') {
if (!task.state.get) {
if (task.state.iFreshTimes < task.res.iFreshTimes)
that.log(`去做${task.res.sName}任务`)
await uploadTask(task.res.eType, task.res.iValue)
await $.wait(500)
await finishTask(task.res.sID)
}
} else if (task.res.sName === '好友助力') {
that.log(`去领取好友助力任务`)
await finishTask(task.res.sID)
}
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function rand(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function beginLevel() {
let body = {
'gameId': $.gameId,
'token': $.gameToken,
'levelId': $.level,
// 'score': 600000 + rand(1000,10000),
'reqsId': $.reqId++
}
return new Promise(resolve => {
$.post(taskUrl("eliminate_jd/game/local/beginLevel", obj2param(body), true),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(resp)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
if (data.code === 0) {
let waittime=30+rand(0,10);
that.log(`第${$.level}关卡开启成功,等待${waittime}秒完成`)
$.strength -= 5
await $.wait(waittime*1000)
await endLevel()
} else if (data.code === 20001) {
$.strength = 0
that.log(`关卡开启失败,体力不足`)
} else {
$.strength = 0
// that.log(`关卡开启失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function endLevel() {
let body = {
'gameId': $.gameId,
'token': $.gameToken,
'levelId': $.level,
'score': 600000 + rand(100000, 300000),
'reqsId': $.reqId++
}
return new Promise(resolve => {
$.post(taskUrl("eliminate_jd/game/local/endLevel", obj2param(body), true),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(resp)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// that.log(data)
if (data.code === 0) {
const level = data.allLevels.filter(vo => parseInt(vo.id) === $.level)
if (level.length > 0) {
that.log(`第${$.level++}关已通关,上报${level[0].maxScore}分,获得${level[0].maxStar}星星`)
} else {
that.log(`第${$.level}关分数上报失败,错误信息:${JSON.stringify(data)}`)
}
} else {
that.log(`第${$.level}关分数上报失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function uploadTask(taskType, value) {
let body = {
"taskType": taskType,
"value": value,
"id": $.id,
"activeid": ACT_ID,
"activeId": ACT_ID,
"authcode": $.authcode,
}
return new Promise(resolve => {
$.post(taskUrl("platform//role/base/uploadtask", body),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
if (data.code === 0) {
that.log('任务上报成功')
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function finishTask(taskId) {
let body = {
"taskid": taskId,
"id": $.id,
"activeid": ACT_ID,
"activeId": ACT_ID,
// "inviter": undefined,
"token": $.to,
"authcode": $.authcode
}
return new Promise(resolve => {
$.post(taskUrl("/platform/active/jingdong/finishtask", body),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
if (data.code === 0) {
let msg = `任务完成成功,获得`
for (let item of data.item) {
if (item['itemid'] === 'JD01') {
msg += ` 体力*${item['count']}`
} else if (item['itemid'] === 'X028') {
msg += ` 消消乐星星*${item['count']}`
} else {
msg += ` ${item['itemid']}*${item['count']}`
}
}
that.log(msg)
} else {
that.log(`暂无每日挑战任务`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function execute(body) {
return new Promise(resolve => {
$.post(taskUrl("/platform/active/jingdong/execute", body),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
if (data.code === 0) {
that.log('任务上报成功')
} else {
that.log(`任务上报失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function getDailyMatch() {
let body = {
'gameId': $.gameId,
'token': $.gameToken,
'reqsId': $.reqId++
}
return new Promise(resolve => {
$.post(taskUrl("eliminate_jd/game/local/getDailyMatch", obj2param(body), true),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(resp)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// that.log(data)
if (data.code === 0) {
// that.log(data)
$.maxScore = parseInt(data.dailyMatchList[data.dailyMatchList.length - 1]['sScore'])
if (data.dayInfo.score >= $.maxScore && data.dayInfo.boxAwardIndex < 2) {
await getDailyMatchAward()
}
if (data.dayInfo.dayPlayNums < 2) {
await beginDailyMatch()
}
} else {
that.log(`关卡开启失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function beginDailyMatch() {
let body = {
'gameId': $.gameId,
'token': $.gameToken,
'reqsId': $.reqId++,
'levelId': $.curLevel
}
return new Promise(resolve => {
$.post(taskUrl("eliminate_jd/game/local/beginDailyMatch", obj2param(body), true),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(resp)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// that.log(data)
if (data.code === 0) {
that.log(`每日挑战开启成功,本日挑战次数${data.dayInfo.dayPlayNums}/2`)
$.curLevel = data.dayInfo.curLevel
await $.wait(30000)
await endDailyMatch()
} else {
that.log(`每日挑战开启失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function endDailyMatch() {
let body = {
'gameId': $.gameId,
'token': $.gameToken,
'reqsId': $.reqId++,
'score': Math.trunc($.maxScore / 2) + 3,
'levelId': $.curLevel,
}
return new Promise(resolve => {
$.post(taskUrl("eliminate_jd/game/local/endDailyMatch", obj2param(body), true),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(resp)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// that.log(data)
if (data.code === 0) {
that.log(`每日挑战完成成功,本日分数${data.dayInfo.score}`)
} else {
that.log(`每日挑战完成失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function getDailyMatchAward() {
let body = {
'gameId': $.gameId,
'token': $.gameToken,
'reqsId': $.reqId++
}
return new Promise(resolve => {
$.post(taskUrl("eliminate_jd/game/local/getDailyMatchAward", obj2param(body), true),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(resp)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// that.log(data)
if (data.code === 0) {
that.log(`每日挑战领取成功,获得${data.reward[0] === '11001' ? '消消乐星星' : '未知道具'}*${data.reward[1]}`)
} else {
that.log(`每日挑战领取失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function marketGoods() {
let body = {
"id": $.id,
"activeid": ACT_ID,
"activeId": ACT_ID,
"token": $.to,
"authcode": $.authcode
}
return new Promise(resolve => {
$.post(taskUrl("/platform/active/role/marketgoods", body),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
if (data.code === 0) {
for (let vo of data.list) {
if (vo.name === exchangeName) {
let cond = vo['res']['asConsume'][0].split(',')
if (vo['left'] === 1 && vo['count'] !== 0 && cond[0] === 'X028' && parseInt(cond[1]) <= $.money) {
await buyGood(vo['res']['sID'])
}
}
}
} else {
that.log(`任务完成失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function buyGood(consumeid) {
let body = {
"consumeid": consumeid,
"id": $.id,
"activeid": ACT_ID,
"activeId": ACT_ID,
"token": $.to,
"authcode": $.authcode
}
return new Promise(resolve => {
$.post(taskUrl("/platform/active/role/marketbuy", body),
async (err, resp, data) => {
try {
if (err) {
that.log(`${err}`)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
if (data.code === 0) {
that.log(`商品兑换成功,获得${data.item[0].itemid === 'JD29' ? '京豆' : '未知奖品'} * ${data.item[0].count}`)
} else {
that.log(`任务完成失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function taskUrl(functionId, body = {}, decrypt = false) {
return {
url: `https://jd.moxigame.cn/${functionId}`,
body: decrypt ? body : JSON.stringify(body),
headers: {
'Host': 'jd.moxigame.cn',
'Connection': 'keep-alive',
'Content-Type': decrypt ? 'application/x-www-form-urlencoded' : 'application/json',
'Referer': 'https://game-cdn.moxigame.cn/eliminateJD/index.html?activeId=A_112790_R_1_D_20201028',
'User-Agent': "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0",
'Accept-Language': 'zh-cn',
}
}
}
function getDailyReward() {
let headers = {
'Host': 'api.m.jd.com',
'accept': '*/*',
'content-type': 'application/json',
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.20(0x1700142b) NetType/WIFI Language/zh_CN',
'referer': 'https://servicewechat.com/wx91d27dbf599dff74/499/page-frame.html',
'accept-language': 'zh-cn',
'Cookie': cookie
};
let body = {
"platform": 1,
"unionActId": "31125",
"actId": "8mCuSXtK1MgxzDTbJEPtYU1AchA",
"unionShareId": "",
"type": 1,
"eid": "DPIFTWTK6N7EEVHNJW3JW7PZDALZNTODNUBBYWQBAYXPAJCH7AMIUEGY7LVCWCRILXXEYOAM5DXZJKY5Y5AZNHQFJI"
}
$.get({
url: `https://api.m.jd.com/api?functionId=getCoupons&appid=u&_=${new Date().getTime()}&loginType=2&body=${escape(JSON.stringify(body))}&client=wh5&clientVersion=1.0.0`,
headers: headers
}, (err, resp, data) => {
that.log(data)
})
}
function jdUrl(functionId, body = '') {
return {
url: `https://jdjoy.jd.com/saas/framework/${functionId}`,
body: body,
headers: {
'Host': 'jdjoy.jd.com',
'accept': '*/*',
'user-agent': 'JD4iPhone/167490 (iPhone; iOS 14.2; Scale/3.00)',
'accept-language': 'zh-Hans-JP;q=1, en-JP;q=0.9, zh-Hant-TW;q=0.8, ja-JP;q=0.7, en-US;q=0.6',
'content-type': 'application/x-www-form-urlencoded',
'Cookie': cookie
}
}
}
function TotalBean() {
return new Promise(async resolve => {
const options = {
"url": `https://wq.jd.com/user/info/QueryJDUserInfo?sceneval=2`,
"headers": {
"Accept": "application/json,text/plain, */*",
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Cookie": cookie,
"Referer": "https://wqs.jd.com/my/jingdou/my.shtml?sceneval=2",
"User-Agent": "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0"
}
}
$.post(options, (err, resp, data) => {
try {
if (err) {
that.log(`${JSON.stringify(err)}`)
that.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (data) {
data = JSON.parse(data);
if (data['retcode'] === 13) {
$.isLogin = false; //cookie过期
return
}
$.nickName = data['base'].nickname;
} else {
that.log(`京东服务器返回空数据`)
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
function safeGet(data) {
try {
if (typeof JSON.parse(data) == "object") {
return true;
}
} catch (e) {
that.log(e);
that.log(`京东服务器访问数据为空,请检查自身设备网络情况`);
return false;
}
}
function jsonParse(str) {
if (typeof str == "string") {
try {
return JSON.parse(str);
} catch (e) {
that.log(e);
$.msg($.name, '', '请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie')
return [];
}
}
}