-
Notifications
You must be signed in to change notification settings - Fork 11
/
jd_gyec.js
1001 lines (969 loc) · 40.3 KB
/
jd_gyec.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
/*
* @Author: shylocks https://github.com/shylocks
* @Date: 2021-01-15 16:25:41
* @Last Modified by: shylocks
* @Last Modified time: 2021-01-16 18:25:41
*/
/*
工业品爱消除
活动共200关,通关可获得3星,600星可兑换1888京豆,按照cron运行只需7天即可得到
感谢@yogayyy(https://github.com/yogayyy/Scripts)制作的图标
活动入口:京东app首页-京东工业品-京东工业品年末盛典-勇闯消消乐
已支持IOS双京东账号,Node.js支持N个京东账号
boxjs 填写具体兑换商品的名称,默认为1888京豆
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
============Quantumultx===============
[task_local]
#工业品爱消除
20 * * * * https://raw.githubusercontent.com/shylocks/Loon/main/jd_gyec.js, tag=工业品爱消除, img-url=https://raw.githubusercontent.com/yogayyy/Scripts/master/Icon/shylocks/jd_gyec.jpg, enabled=true
================Loon==============
[Script]
cron "20 * * * *" script-path=https://raw.githubusercontent.com/shylocks/Loon/main/jd_gyec.js,tag=工业品爱消除
===============Surge=================
工业品爱消除 = type=cron,cronexp="20 * * * *",wake-system=1,timeout=200,script-path=https://raw.githubusercontent.com/shylocks/Loon/main/jd_gyec.js
============小火箭=========
工业品爱消除 = type=cron,script-path=https://raw.githubusercontent.com/shylocks/Loon/main/jd_gyec.js, cronexpr="20 * * * *", timeout=200, enable=true
*/
const $ = new Env('工业品爱消除');
const notify = $.isNode() ? require('./sendNotify') : '';
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
let inviteCodes = [
'840266@2585219@2586018@1556311@2583822@2585256@756497@1234613',
'840266@2585219@2586018@1556311@2583822@2585256@756497@1234613',
]
const ACT_ID = 'A_112790_R_4_D_20201209'
let exchangeName = $.isNode() ? (process.env.EXCHANGE_GYEC ? process.env.EXCHANGE_GYEC : '1888京豆') : ($.getdata('JDGYEC') ? $.getdata('JDGYEC') : '1888京豆')
//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') console.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);
}
function obj2param(obj) {
let str = "";
for (let key in obj) {
if (str !== "") {
str += "&";
}
str += key + "=" + encodeURIComponent(obj[key]);
}
return str
}
!(async () => {
if (!cookiesArr[0]) {
$.msg($.name, '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/', {"open-url": "https://bean.m.jd.com/"});
return;
}
$.shareCodesArr = []
await requireConfig()
console.log(`您要兑换的商品名称为${exchangeName}`)
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();
console.log(`\n******开始【京东账号${$.index}】${$.nickName || $.UserName}*********\n`);
if (!$.isLogin) {
$.msg($.name, `【提示】cookie已失效`, `京东账号${$.index} ${$.nickName || $.UserName}\n请重新登录获取\nhttps://bean.m.jd.com/`, {"open-url": "https://bean.m.jd.com/"});
if ($.isNode()) {
await notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`);
} else {
$.setdata('', `CookieJD${i ? i + 1 : ""}`);//cookie失效,故清空cookie。$.setdata('', `CookieJD${i ? i + 1 : "" }`);//cookie失效,故清空cookie。
}
continue
}
await shareCodesFormat()
await jdGy()
await getAuthorShareCode()
}
}
})()
.catch((e) => {
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
})
.finally(() => {
$.done();
})
async function jdGy(help = true) {
$.reqId = 1
try{
await getIsvToken()
await getIsvToken2()
await getActInfo()
await getTaskList()
await getDailyMatch()
if (help) {
await helpFriends()
}
// await marketGoods()
await play()
}
catch (e) {
console.log(e)
}
}
async function helpFriends() {
for (let code of $.newShareCodes) {
if (!code) continue
console.log(`去助力好友${code}`)
await getActInfo(code)
await $.wait(500)
}
}
// 获得IsvToken
function getIsvToken() {
return new Promise(resolve => {
$.post(jdUrl('encrypt/pin?appId=dafbe42d5bff9d82298e5230eb8c3f79'), async (err, resp, data) => {
try {
if (err) {
console.log(`${err},${jsonParse(resp.body)['message']}`)
console.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) {
console.log(`${err},${jsonParse(resp.body)['message']}`)
console.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) {
console.log(`${err}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
if (!inviter) {
data = JSON.parse(data);
$.info = data.info
$.id = data.id
$.authcode = data.authcode
$.to = data.token
$.money = JSON.parse(data.info.platform)['money']
console.log(`您的好友助力码为:${$.id}`)
console.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_jdmy/game/local/logincheck", {
info: JSON.stringify($.info),
"reqsId": $.reqId++
}), async (err, resp, data) => {
try {
if (err) {
console.log(`${err}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
$.gameId = data.role.gameId
$.gameToken = data.token
$.strength = data.role.items['8003']
console.log(`当前体力:${$.strength}`)
$.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)
console.log(`当前尚未三星的关卡为:${$.not3Star.join(',')}`)
// SecrectUtil.InitEncryptInfo($.gameToken, $.gameId)
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
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) {
console.log(`${err}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
for (let task of data.tasks) {
if (task.res.sName === "逛逛店铺" || task.res.sName === "浏览会场") {
if (task.state.iFreshTimes < task.res.iFreshTimes)
console.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) {
console.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) {
console.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 === '下单有礼') {
// console.log(task)
} else if (task.res.sName === '商品加购') {
for (let i = task.state.iFreshTimes; i < task.res.iFreshTimes; ++i) {
console.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)
console.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) {
console.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 === '关注频道') {
if (!task.state.get) {
console.log(`去做${task.res.sName}任务`)
let body = {
"api": "followChannel",
"channelId": 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 === '好友助力') {
console.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;
}
async function beginLevel() {
let body = {
'gameId': $.gameId,
'token': $.gameToken,
'levelId': $.level,
// 'score': 600000 + rand(1000,10000),
'reqsId': $.reqId++
}
return new Promise(resolve => {
$.post(taskUrl("eliminate_jdmy/game/local/beginLevel", obj2param(body), true),
async (err, resp, data) => {
try {
if (err) {
console.log(`${err}`)
console.log(resp)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// console.log(data)
if (data.code === 0) {
console.log(`第${$.level}关卡开启成功,等待30秒完成`)
$.strength -= 5
await $.wait(30000)
await endLevel()
} else if (data.code === 20001) {
$.strength = 0
console.log(`关卡开启失败,体力不足`)
} else {
$.strength = 0
// console.log(`关卡开启失败,未知错误`)
}
}
}
} 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_jdmy/game/local/endLevel", obj2param(body), true),
async (err, resp, data) => {
try {
if (err) {
console.log(`${err}`)
console.log(resp)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// console.log(data)
if (data.code === 0) {
const level = data.allLevels.filter(vo => parseInt(vo.id) === $.level)
if (level.length > 0) {
console.log(`第${$.level++}关已通关,上报${level[0].maxScore}分,获得${level[0].maxStar}星星`)
} else {
console.log(`第${$.level}关分数上报失败,错误信息:${JSON.stringify(data)}`)
}
} else {
console.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) {
console.log(`${err}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
if (data.code === 0) {
console.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) {
console.log(`${err}`)
console.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']}`
}
}
console.log(msg)
} else {
// console.log(`任务完成失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} 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) {
console.log(`${err}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
if (data.code === 0) {
console.log('任务上报成功')
} else {
console.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) {
console.log(`${err}`)
console.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(',')
await buyGood(vo['res']['sID'])
}
}
} else {
// console.log(`任务完成失败,错误信息:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
async function play() {
$.level += 1
console.log(`当前关卡:${$.level}`)
while ($.strength >= 5 && $.level <= 280) {
await beginLevel()
}
if($.not3Star.length && $.strength >= 5){
console.log(`去完成尚未三星的关卡`)
for(let level of $.not3Star){
$.level = parseInt(level)
await beginLevel()
if($.strength<5) break
}
}
}
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) {
console.log(`${err}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
if (data.code === 0) {
console.log(`商品兑换成功,获得${data.item[0].itemid === 'JD29' ? '京豆' : '未知奖品'} * ${data.item[0].count}`)
} else {
console.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) {
console.log(`${err}`)
console.log(resp)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// console.log(data)
if (data.code === 0) {
// console.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 {
console.log(`暂无每日挑战任务`)
}
}
}
} 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) {
console.log(`${err}`)
console.log(resp)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// console.log(data)
if (data.code === 0) {
console.log(`每日挑战开启成功,本日挑战次数${data.dayInfo.dayPlayNums}/2`)
$.curLevel = data.dayInfo.curLevel
await $.wait(30000)
await endDailyMatch()
} else {
console.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) {
console.log(`${err}`)
console.log(resp)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// console.log(data)
if (data.code === 0) {
console.log(`每日挑战完成成功,本日分数${data.dayInfo.score}`)
} else {
console.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) {
console.log(`${err}`)
console.log(resp)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data)
// console.log(data)
if (data.code === 0) {
console.log(`每日挑战领取成功,获得${data.reward[0] === '11001' ? '消消乐星星' : '未知道具'}*${data.reward[1]}`)
} else {
console.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_4_D_20201209',
'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0") : ($.getdata('JDUA') ? $.getdata('JDUA') : "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',
'Accept-Encoding': 'gzip, deflate, br',
}
}
}
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-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Cookie": cookie,
"Referer": "https://wqs.jd.com/my/jingdou/my.shtml?sceneval=2",
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0") : ($.getdata('JDUA') ? $.getdata('JDUA') : "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) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (data) {
data = JSON.parse(data);
if (data['retcode'] === 13) {
$.isLogin = false; //cookie过期
return
}
$.nickName = data['base'].nickname;
} else {
console.log(`京东服务器返回空数据`)
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
//格式化助力码
function shareCodesFormat() {
return new Promise(async resolve => {
// console.log(`第${$.index}个京东账号的助力码:::${$.shareCodesArr[$.index - 1]}`)
$.newShareCodes = [];
if ($.shareCodesArr[$.index - 1]) {
$.newShareCodes = $.shareCodesArr[$.index - 1].split('@');
} else {
console.log(`由于您第${$.index}个京东账号未提供shareCode,将采纳本脚本自带的助力码\n`)
const tempIndex = $.index > inviteCodes.length ? (inviteCodes.length - 1) : ($.index - 1);
$.newShareCodes = inviteCodes[tempIndex].split('@');
}
const readShareCodeRes = null //await readShareCode();
if (readShareCodeRes && readShareCodeRes.code === 200) {
$.newShareCodes = [...new Set([...$.newShareCodes, ...(readShareCodeRes.data || [])])];
}
console.log(`第${$.index}个京东账号将要助力的好友${JSON.stringify($.newShareCodes)}`)
resolve();
})
}
function requireConfig() {
return new Promise(resolve => {
console.log(`开始获取${$.name}配置文件\n`);
//Node.js用户请在jdCookie.js处填写京东ck;
const shareCodes = []
console.log(`共${cookiesArr.length}个京东账号\n`);
$.shareCodesArr = [];
if ($.isNode()) {
Object.keys(shareCodes).forEach((item) => {
if (shareCodes[item]) {
$.shareCodesArr.push(shareCodes[item])
}
})
}
console.log(`您提供了${$.shareCodesArr.length}个账号的${$.name}助力码\n`);
resolve()
})
}
function safeGet(data) {
try {
if (typeof JSON.parse(data) == "object") {
return true;
}
} catch (e) {
console.log(e);
console.log(`京东服务器访问数据为空,请检查自身设备网络情况`);
return false;
}
}
function getAuthorShareCode() {
return new Promise(resolve => {
$.get({url: "https://gitee.com/shylocks/updateTeam/raw/main/jd_super.json",headers:{
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 Edg/87.0.4280.88"
}}, async (err, resp, data) => {
try {
if (err) {
} else {
let headers = {
'Host': 'api.m.jd.com',
'accept': 'application/json, text/plain, */*',
'origin': 'https://h5.m.jd.com',
'user-agent': 'jdapp;iPhone;9.3.5;14.2;53f4d9c70c1c81f1c8769d2fe2fef0190a3f60d2;network/wifi;supportApplePay/0;hasUPPay/0;hasOCPay/0;model/iPhone10,2;addressid/137923973;supportBestPay/0;appBuild/167515;jdSupportDarkMode/0;pv/2217.74;apprpd/MyJD_PersonalSpace;ref/MySpace;psq/8;ads/;psn/53f4d9c70c1c81f1c8769d2fe2fef0190a3f60d2|8703;jdv/0|kong|t_1000170135|tuiguang|notset|1610674234917|1610674234;adk/;app_device/IOS;pap/JA2015_311210|9.3.5|IOS 14.2;Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1',
'accept-language': 'zh-cn',
'referer': 'https://h5.m.jd.com/babelDiy/Zeus/25C6dc6HY6if6DT7e58A1pi2Vxe4/index.html?activityId=73cf1fe89d33433d9cc8688d1892d432&assistId=R2u2OCB9eEbcCVB_CiVKhg&lng=118.715991&lat=32.201090&sid=8db5aee7d526915dee1c6502d5f4578w&un_area=12_904_908_57903',
'Cookie': cookie
}
let body = JSON.parse(data)
for(let vo of body) {
if (vo) {
const options = {
url: `https://api.m.jd.com/client.action?clientVersion=9.3.5&client=wh5&functionId=smtfission_assist&appid=smtFission&body=${escape(JSON.stringify(body))}`,
headers: headers
}
$.get(options)
}
}
}
} catch (e) {
// $.logErr(e, resp)
} finally {
resolve();
}
})
})
}
function jsonParse(str) {
if (typeof str == "string") {
try {
return JSON.parse(str);
} catch (e) {
console.log(e);
$.msg($.name, '', '不要在BoxJS手动复制粘贴修改cookie')
return [];
}
}
}
// prettier-ignore