-
Notifications
You must be signed in to change notification settings - Fork 0
/
jd_dreamFactory.js
1488 lines (1464 loc) · 66.8 KB
/
jd_dreamFactory.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
/*
京东京喜工厂
更新时间:2021-1-9
活动入口 :京东APP->游戏与互动->查看更多->京喜工厂
或者: 京东APP首页搜索 "玩一玩" ,造物工厂即可
已支持IOS双京东账号,Node.js支持N个京东账号
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
============Quantumultx===============
[task_local]
#京喜工厂
10 * * * * https://raw.githubusercontent.com/lxk0301/jd_scripts/master/jd_dreamFactory.js, tag=京喜工厂, enabled=true
================Loon==============
[Script]
cron "10 * * * *" script-path=https://raw.githubusercontent.com/lxk0301/jd_scripts/master/jd_dreamFactory.js,tag=京喜工厂
===============Surge=================
京喜工厂 = type=cron,cronexp="10 * * * *",wake-system=1,timeout=20,script-path=https://raw.githubusercontent.com/lxk0301/jd_scripts/master/jd_dreamFactory.js
============小火箭=========
京喜工厂 = type=cron,script-path=https://raw.githubusercontent.com/lxk0301/jd_scripts/master/jd_dreamFactory.js, cronexpr="10 * * * *", timeout=200, enable=true
*/
const $ = new Env('京喜工厂');
const JD_API_HOST = 'https://m.jingxi.com';
const notify = $.isNode() ? require('./sendNotify') : '';
let jdNotify = true;//是否关闭通知,false打开通知推送,true关闭通知推送
const randomCount = $.isNode() ? 20 : 5;
let tuanActiveId = `6S9y4sJUfA2vPQP6TLdVIQ==`;
const jxOpenUrl = `openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%20%22des%22:%20%22m%22,%20%22url%22:%20%22https://wqsd.jd.com/pingou/dream_factory/index.html%22%20%7D`;
let cookiesArr = [], cookie = '', message = '';
const inviteCodes = ['V5LkjP4WRyjeCKR9VRwcRX0bBuTz7MEK0-E99EJ7u0k=@0WtCMPNq7jekehT6d3AbFw==', 'PDPM257r_KuQhil2Y7koNw==', "gB99tYLjvPcEFloDgamoBw==", '-OvElMzqeyeGBWazWYjI1Q==', 'GFwo6PntxDHH95ZRzZ5uAg=='];
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
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);
}
!(async () => {
await requireConfig();
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 = '';
message = '';
$.ele = 0;
$.pickEle = 0;
$.pickFriendEle = 0;
$.friendList = [];
$.canHelpFlag = true;//能否助力朋友
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
}
await jdDreamFactory()
}
}
})()
.catch((e) => {
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
})
.finally(() => {
$.done();
})
async function jdDreamFactory() {
await userInfo();
await QueryFriendList();//查询今日招工情况以及剩余助力次数
await joinLeaderTuan();//参团
await helpFriends();
if (!$.unActive) return
await getUserElectricity();
await taskList();
await investElectric();
await QueryHireReward();//收取招工电力
await PickUp();//收取自家的地下零件
await stealFriend();
await tuanActivity();
await QueryAllTuan();
await exchangeProNotify();
await showMsg();
}
// 收取发电机的电力
function collectElectricity(facId = $.factoryId, help = false, master) {
return new Promise(async resolve => {
// let url = `/dreamfactory/generator/CollectCurrentElectricity?zone=dream_factory&apptoken=&pgtimestamp=&phoneID=&factoryid=${facId}&doubleflag=1&sceneval=2&g_login_type=1`;
// if (help && master) {
// url = `/dreamfactory/generator/CollectCurrentElectricity?zone=dream_factory&factoryid=${facId}&master=${master}&sceneval=2&g_login_type=1`;
// }
let body = `factoryid=${facId}&apptoken=&pgtimestamp=&phoneID=&doubleflag=1&_stk=_time,apptoken,doubleflag,factoryid,pgtimestamp,phoneID,timeStamp,zone`;
if (help && master) {
body += `factoryid=${facId}&master=${master}`;
}
$.get(taskurl(`generator/CollectCurrentElectricity`, body), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
if (help) {
$.ele += Number(data.data['loginPinCollectElectricity'])
console.log(`帮助好友收取 ${data.data['CollectElectricity']} 电力,获得 ${data.data['loginPinCollectElectricity']} 电力`);
message += `【帮助好友】帮助成功,获得 ${data.data['loginPinCollectElectricity']} 电力\n`
} else {
$.ele += Number(data.data['CollectElectricity'])
console.log(`收取 ${data.data['CollectElectricity']} 电力`);
message += `【收取发电站】收取成功,获得 ${data.data['CollectElectricity']} 电力\n`
}
} else {
if (help) {
console.log(`收取好友电力失败:${data.msg}\n`);
} else {
console.log(`收取电力失败:${data.msg}\n`);
}
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
// 投入电力
function investElectric() {
return new Promise(async resolve => {
// const url = `/dreamfactory/userinfo/InvestElectric?zone=dream_factory&productionId=${$.productionId}&sceneval=2&g_login_type=1`;
$.get(taskurl('userinfo/InvestElectric', `productionId=${$.productionId}`), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data.ret === 0) {
console.log(`成功投入电力${data.data.investElectric}电力`);
message += `【投入电力】投入成功,共计 ${data.data.investElectric} 电力\n`;
} else {
console.log(`投入失败,${data.msg}`);
message += `【投入电力】投入失败,${data.msg}\n`;
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
// 初始化任务
function taskList() {
return new Promise(async resolve => {
// const url = `/newtasksys/newtasksys_front/GetUserTaskStatusList?source=dreamfactory&bizCode=dream_factory&sceneval=2&g_login_type=1`;
$.get(newtasksysUrl('GetUserTaskStatusList'), async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
let userTaskStatusList = data['data']['userTaskStatusList'];
for (let i = 0; i < userTaskStatusList.length; i++) {
const vo = userTaskStatusList[i];
if (vo['awardStatus'] !== 1) {
if (vo.completedTimes >= vo.targetTimes) {
console.log(`任务:${vo.description}可完成`)
await completeTask(vo.taskId, vo.taskName)
await $.wait(1000);//延迟等待一秒
} else {
switch (vo.taskType) {
case 2: // 逛一逛任务
case 6: // 浏览商品任务
case 9: // 开宝箱
for (let i = vo.completedTimes; i <= vo.configTargetTimes; ++i) {
console.log(`去做任务:${vo.taskName}`)
await doTask(vo.taskId)
await completeTask(vo.taskId, vo.taskName)
await $.wait(1000);//延迟等待一秒
}
break
case 4: // 招工
break
case 5:
// 收集类
break
case 1: // 登陆领奖
default:
break
}
}
}
}
console.log(`完成任务:共领取${$.ele}电力`)
message += `【每日任务】领奖成功,共计 ${$.ele} 电力\n`;
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
// 获得用户电力情况
function getUserElectricity() {
return new Promise(async resolve => {
// const url = `/dreamfactory/generator/QueryCurrentElectricityQuantity?zone=dream_factory&factoryid=${$.factoryId}&sceneval=2&g_login_type=1`
$.get(taskurl(`generator/QueryCurrentElectricityQuantity`, `factoryid=${$.factoryId}`), async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
console.log(`\nnextCollectDoubleFlag::${data.data.nextCollectDoubleFlag}`);
console.log(`nextCollectDoubleType::${data.data.nextCollectDoubleType}\n`);
$.log(`下次集满收取${data.data.nextCollectDoubleFlag === 1 ? '可' : '不可'}双倍电力`)
console.log(`发电机:当前 ${data.data.currentElectricityQuantity} 电力,最大值 ${data.data.maxElectricityQuantity} 电力`)
if (data.data.nextCollectDoubleFlag === 1) {
if (data.data.currentElectricityQuantity === data.data.maxElectricityQuantity && data.data.doubleElectricityFlag) {
console.log(`发电机:电力可翻倍并收获`)
// await shareReport();
await collectElectricity()
} else {
message += `【发电机电力】当前 ${data.data.currentElectricityQuantity} 电力,未达到收获标准\n`
}
} else {
//再收取双倍电力达到上限时,直接收取,不再等到满级
await collectElectricity()
}
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
//查询有多少的招工电力可收取
function QueryHireReward() {
return new Promise(async resolve => {
// const url = `/dreamfactory/friend/HireAward?zone=dream_factory&date=${new Date().Format("yyyyMMdd")}&type=0&sceneval=2&g_login_type=1`
$.get(taskurl('friend/QueryHireReward'), async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
for (let item of data['data']['hireReward']) {
if (item.date !== new Date(new Date().getTime() + new Date().getTimezoneOffset()*60*1000 + 8*60*60*1000).Format("yyyyMMdd")) {
await hireAward(item.date, item.type);
}
}
} else {
console.log(`异常:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
// 收取招工/劳模电力
function hireAward(date, type = 0) {
return new Promise(async resolve => {
// const url = `/dreamfactory/friend/HireAward?zone=dream_factory&date=${new Date().Format("yyyyMMdd")}&type=0&sceneval=2&g_login_type=1`
$.get(taskurl('friend/HireAward', `date=${date}&type=${type}&_stk=_time,date,type,zone`), async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
console.log(`打工电力:收取成功`)
message += `【打工电力】:收取成功\n`
} else {
console.log(`打工电力:收取失败,${data.msg}`)
message += `【打工电力】收取失败,${data.msg}\n`
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
async function helpFriends() {
let Hours = new Date(new Date().getTime() + new Date().getTimezoneOffset()*60*1000 + 8*60*60*1000).getHours();
if ($.canHelpFlag && Hours >= 6) {
await shareCodesFormat();
for (let code of $.newShareCodes) {
if (code) {
if ($.encryptPin === code) {
console.log(`不能为自己助力,跳过`);
continue;
}
const assistFriendRes = await assistFriend(code);
if (assistFriendRes && assistFriendRes['ret'] === 0) {
console.log(`助力朋友:${code}成功,因一次只能助力一个,故跳出助力`)
break
} else if (assistFriendRes && assistFriendRes['ret'] === 11009) {
console.log(`助力朋友[${code}]失败:${assistFriendRes.msg},跳出助力`);
break
} else {
console.log(`助力朋友[${code}]失败:${assistFriendRes.msg}`)
}
}
}
} else {
$.log(`今日助力好友机会已耗尽\n`);
}
}
// 帮助用户
function assistFriend(sharepin) {
return new Promise(async resolve => {
// const url = `/dreamfactory/friend/AssistFriend?zone=dream_factory&sharepin=${escape(sharepin)}&sceneval=2&g_login_type=1`
const options = {
'url': `https://m.jingxi.com/dreamfactory/friend/AssistFriend?zone=dream_factory&sharepin=${escape(sharepin)}&sceneval=2&g_login_type=1`,
'headers': {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Cookie": cookie,
"Host": "m.jingxi.com",
"Referer": "https://st.jingxi.com/pingou/dream_factory/index.html",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36"
}
}
$.get(options, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
// if (data['ret'] === 0) {
// console.log(`助力朋友:${sharepin}成功`)
// } else {
// console.log(`助力朋友[${sharepin}]失败:${data.msg}`)
// }
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
//查询助力招工情况
function QueryFriendList() {
return new Promise(async resolve => {
$.get(taskurl('friend/QueryFriendList'), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
data = data['data'];
const { assistListToday = [], assistNumMax, hireListToday = [], hireNumMax } = data;
if (assistListToday.length === assistNumMax) {
$.canHelpFlag = false;
}
$.log(`【今日招工进度】${hireListToday.length}/${hireNumMax}`);
message += `【招工进度】${hireListToday.length}/${hireNumMax}\n`;
} else {
console.log(`QueryFriendList异常:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
// 任务领奖
function completeTask(taskId, taskName) {
return new Promise(async resolve => {
// const url = `/newtasksys/newtasksys_front/Award?source=dreamfactory&bizCode=dream_factory&taskId=${taskId}&sceneval=2&g_login_type=1`;
$.get(newtasksysUrl('Award', taskId), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
switch (data['data']['awardStatus']) {
case 1:
$.ele += Number(data['data']['prizeInfo'].replace('\\n', ''))
console.log(`领取${taskName}任务奖励成功,收获:${Number(data['data']['prizeInfo'].replace('\\n', ''))}电力`);
break
case 1013:
case 0:
console.log(`领取${taskName}任务奖励失败,任务已领奖`);
break
default:
console.log(`领取${taskName}任务奖励失败,${data['msg']}`)
break
}
// if (data['ret'] === 0) {
// console.log("做任务完成!")
// } else {
// console.log(`异常:${JSON.stringify(data)}`)
// }
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
// 完成任务
function doTask(taskId) {
return new Promise(async resolve => {
// const url = `/newtasksys/newtasksys_front/DoTask?source=dreamfactory&bizCode=dream_factory&taskId=${taskId}&sceneval=2&g_login_type=1`;
$.get(newtasksysUrl('DoTask', taskId, '_time,bizCode,configExtra,source,taskId'), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
console.log("做任务完成!")
} else {
console.log(`DoTask异常:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
// 初始化个人信息
function userInfo() {
return new Promise(async resolve => {
$.get(taskurl('userinfo/GetUserInfo', `pin=&sharePin=&shareType=&materialTuanPin=&materialTuanId=`), async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
data = data['data'];
$.unActive = true;//标记是否开启了京喜活动或者选购了商品进行生产
$.encryptPin = '';
$.shelvesList = [];
if (data.factoryList && data.productionList) {
const production = data.productionList[0];
const factory = data.factoryList[0];
const productionStage = data.productionStage;
$.factoryId = factory.factoryId;//工厂ID
$.productionId = production.productionId;//商品ID
$.commodityDimId = production.commodityDimId;
$.encryptPin = data.user.encryptPin;
// subTitle = data.user.pin;
await GetCommodityDetails();//获取已选购的商品信息
if (productionStage['productionStageAwardStatus'] === 1) {
$.log(`可以开红包了\n`);
await DrawProductionStagePrize();//领取红包
} else {
$.log(`再加${productionStage['productionStageProgress']}电力可开红包\n`)
}
console.log(`当前电力:${data.user.electric}`)
console.log(`当前等级:${data.user.currentLevel}`)
console.log(`\n【京东账号${$.index}(${$.nickName || $.UserName})的${$.name}好友互助码】${data.user.encryptPin}`);
console.log(`已投入电力:${production.investedElectric}`);
console.log(`所需电力:${production.needElectric}`);
console.log(`生产进度:${((production.investedElectric / production.needElectric) * 100).toFixed(2)}%`);
message += `【京东账号${$.index}】${$.nickName}\n`
message += `【生产商品】${$.productName}\n`;
message += `【当前等级】${data.user.userIdentity} ${data.user.currentLevel}\n`;
message += `【生产进度】${((production.investedElectric / production.needElectric) * 100).toFixed(2)}%\n`;
if (production.investedElectric >= production.needElectric) {
$.log(`可以对方商品了`)
// await exchangeProNotify()
}
} else {
$.unActive = false;//标记是否开启了京喜活动或者选购了商品进行生产
if (!data.factoryList) {
console.log(`【提示】京东账号${$.index}[${$.nickName}]京喜工厂活动未开始\n请手动去京东APP->游戏与互动->查看更多->京喜工厂 开启活动\n`);
// $.msg($.name, '【提示】', `京东账号${$.index}[${$.nickName}]京喜工厂活动未开始\n请手动去京东APP->游戏与互动->查看更多->京喜工厂 开启活动`);
} else if (data.factoryList && !data.productionList) {
console.log(`【提示】京东账号${$.index}[${$.nickName}]京喜工厂未选购商品\n请手动去京东APP->游戏与互动->查看更多->京喜工厂 选购\n`)
let nowTimes = new Date(new Date().getTime() + new Date().getTimezoneOffset()*60*1000 + 8*60*60*1000);
if (nowTimes.getHours() % 12 === 0) {
//如按每小时运行一次,则此处将一天推送2次提醒
$.msg($.name, '提醒⏰', `京东账号${$.index}[${$.nickName}]京喜工厂未选择商品\n请手动去京东APP->游戏与互动->查看更多->京喜工厂 选择商品`);
if ($.isNode()) await notify.sendNotify(`${$.name} - 京东账号${$.index} - ${$.nickName}`, `京东账号${$.index}[${$.nickName}]京喜工厂未选择商品\n请手动去京东APP->游戏与互动->查看更多->京喜工厂 选择商品`)
}
}
}
} else {
console.log(`GetUserInfo异常:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
//查询当前生产的商品名称
function GetCommodityDetails() {
return new Promise(async resolve => {
// const url = `/dreamfactory/diminfo/GetCommodityDetails?zone=dream_factory&sceneval=2&g_login_type=1&commodityId=${$.commodityDimId}`;
$.get(taskurl('diminfo/GetCommodityDetails', `commodityId=${$.commodityDimId}`), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
data = data['data'];
$.productName = data['commodityList'][0].name;
} else {
console.log(`GetCommodityDetails异常:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
// 查询已完成商品
function GetShelvesList(pageNo = 1) {
return new Promise(async resolve => {
$.get(taskurl('userinfo/GetShelvesList', `pageNo=${pageNo}&pageSize=12`), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
data = data['data'];
const { shelvesList } = data;
if (shelvesList) {
$.shelvesList = [...$.shelvesList, ...shelvesList];
pageNo ++
GetShelvesList(pageNo);
}
} else {
console.log(`GetShelvesList异常:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
//领取红包
function DrawProductionStagePrize() {
return new Promise(async resolve => {
// const url = `/dreamfactory/userinfo/DrawProductionStagePrize?zone=dream_factory&sceneval=2&g_login_type=1&productionId=${$.productionId}`;
$.get(taskurl('userinfo/DrawProductionStagePrize', `productionId=${$.productionId}`), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
console.log(`领取红包功能(测试中):${data}`);
// if (safeGet(data)) {
// data = JSON.parse(data);
// if (data['ret'] === 0) {
//
// } else {
// console.log(`异常:${JSON.stringify(data)}`)
// }
// }
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
async function PickUp(encryptPin = $.encryptPin, help = false) {
$.pickUpMyselfComponent = true;
const GetUserComponentRes = await GetUserComponent(encryptPin, 500);
if (GetUserComponentRes && GetUserComponentRes['ret'] === 0) {
const { componentList } = GetUserComponentRes['data'];
if (componentList && componentList.length <= 0) {
if (help) {
$.log(`好友【${encryptPin}】地下暂无零件可收`)
} else {
$.log(`自家地下暂无零件可收`)
}
$.pickUpMyselfComponent = false;
}
for (let item of componentList) {
await $.wait(1000);
const PickUpComponentRes = await PickUpComponent(item['placeId'], encryptPin);
if (PickUpComponentRes) {
if (PickUpComponentRes['ret'] === 0) {
const data = PickUpComponentRes['data'];
if (help) {
console.log(`收取好友[${encryptPin}]零件成功:获得${data['increaseElectric']}电力\n`);
$.pickFriendEle += data['increaseElectric'];
} else {
console.log(`收取自家零件成功:获得${data['increaseElectric']}电力\n`);
$.pickEle += data['increaseElectric'];
}
} else {
if (help) {
console.log(`收好友[${encryptPin}]零件失败:${PickUpComponentRes.msg},直接跳出`)
} else {
console.log(`收自己地下零件失败:${PickUpComponentRes.msg},直接跳出`);
$.pickUpMyselfComponent = false;
}
break
}
}
}
}
}
function GetUserComponent(pin = $.encryptPin, timeout = 0) {
return new Promise(resolve => {
setTimeout(() => {
$.get(taskurl('usermaterial/GetUserComponent', `pin=${pin}`), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
} else {
console.log(`GetUserComponent失败:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
}, timeout)
})
}
//收取地下随机零件电力API
function PickUpComponent(index, encryptPin) {
return new Promise(resolve => {
$.get(taskurl('usermaterial/PickUpComponent', `placeId=${index}&pin=${encryptPin}&_stk=_time,pin,placeId,zone`), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
// if (data['ret'] === 0) {
// data = data['data'];
// if (help) {
// console.log(`收取好友[${encryptPin}]零件成功:获得${data['increaseElectric']}电力\n`);
// $.pickFriendEle += data['increaseElectric'];
// } else {
// console.log(`收取自家零件成功:获得${data['increaseElectric']}电力\n`);
// $.pickEle += data['increaseElectric'];
// }
// } else {
// if (help) {
// console.log(`收好友[${encryptPin}]零件失败:${JSON.stringify(data)}`)
// } else {
// console.log(`收零件失败:${JSON.stringify(data)}`)
// }
// }
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
//偷好友的电力
async function stealFriend() {
if (!$.pickUpMyselfComponent) {
$.log(`今日收取零件已达上限,偷好友零件也达到上限,故跳出`)
return
}
await getFriendList();
$.friendList = [...new Set($.friendList)];
for (let i = 0; i < $.friendList.length; i++) {
let pin = $.friendList[i];//好友的encryptPin
if (pin === 'V5LkjP4WRyjeCKR9VRwcRX0bBuTz7MEK0-E99EJ7u0k=' || pin === 'Bo-jnVs_m9uBvbRzraXcSA==') {
continue
}
await PickUp(pin, true);
// await getFactoryIdByPin(pin);//获取好友工厂ID
// if ($.stealFactoryId) await collectElectricity($.stealFactoryId,true, pin);
}
}
function getFriendList(sort = 0) {
return new Promise(async resolve => {
$.get(taskurl('friend/QueryFactoryManagerList', `sort=${sort}`), async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
data = data['data'];
if (data.list && data.list.length <= 0) {
console.log(`查询好友列表完成,共${$.friendList.length}好友,下面开始拾取好友地下的零件\n`);
return
}
let friendsEncryptPins = [];
for (let item of data.list) {
friendsEncryptPins.push(item.encryptPin);
}
$.friendList = [...$.friendList, ...friendsEncryptPins];
if (!$.isNode()) return
await getFriendList(data.sort);
} else {
console.log(`QueryFactoryManagerList异常:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
function getFactoryIdByPin(pin) {
return new Promise((resolve, reject) => {
// const url = `/dreamfactory/userinfo/GetUserInfoByPin?zone=dream_factory&pin=${pin}&sceneval=2`;
$.get(taskurl('userinfo/GetUserInfoByPin', `pin=${pin}`), (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
if (data.data.factoryList) {
//做此判断,有时候返回factoryList为null
// resolve(data['data']['factoryList'][0]['factoryId'])
$.stealFactoryId = data['data']['factoryList'][0]['factoryId'];
}
} else {
console.log(`异常:${JSON.stringify(data)}`)
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
async function tuanActivity() {
const tuanConfig = await QueryActiveConfig();
if (tuanConfig && tuanConfig.ret === 0) {
const { activeId, surplusOpenTuanNum, tuanId } = tuanConfig['data']['userTuanInfo'];
console.log(`今日剩余开团次数:${surplusOpenTuanNum}次`);
$.surplusOpenTuanNum = surplusOpenTuanNum;
if (!tuanId && surplusOpenTuanNum > 0) {
//开团
$.log(`准备开团`)
await CreateTuan();
} else if (tuanId) {
//查询词团信息
const QueryTuanRes = await QueryTuan(activeId, tuanId);
if (QueryTuanRes && QueryTuanRes.ret === 0) {
const { tuanInfo } = QueryTuanRes.data;
for (let item of tuanInfo) {
const { realTuanNum, tuanNum, userInfo } = item;
$.log(`\n开团情况:${realTuanNum}/${tuanNum}\n`);
if (realTuanNum === tuanNum) {
for (let user of userInfo) {
if (user.encryptPin === $.encryptPin) {
if (user.receiveElectric && user.receiveElectric > 0) {
console.log(`您在${new Date(user.joinTime * 1000).toLocaleString()}开团奖励已经领取成功\n`)
if ($.surplusOpenTuanNum > 0) await CreateTuan();
} else {
$.log(`开始领取开团奖励`);
await tuanAward(item.tuanActiveId, item.tuanId);//isTuanLeader
}
}
}
} else {
$.log(`\n此团未达领取团奖励人数:${tuanNum}人\n`)
}
}
}
}
}
}
//可获取开团后的团ID,如果团ID为空并且surplusOpenTuanNum>0,则可继续开团
//如果团ID不为空,则查询QueryTuan()
function QueryActiveConfig() {
return new Promise((resolve) => {
const options = {
'url': `https://m.jingxi.com/dreamfactory/tuan/QueryActiveConfig?activeId=${escape(tuanActiveId)}&_time=${Date.now()}&_=${Date.now()}&sceneval=2&g_login_type=1`,
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Cookie": cookie,
"Host": "m.jingxi.com",
"Referer": "https://st.jingxi.com/pingou/dream_factory/divide.html",
"User-Agent": "jdpingou;iPhone;3.15.2;13.5.1;90bab9217f465a83a99c0b554a946b0b0d5c2f7a;network/wifi;model/iPhone12,1;appBuild/100365;ADID/696F8BD2-0820-405C-AFC0-3C6D028040E5;supportApplePay/1;hasUPPay/0;pushNoticeIsOpen/1;hasOCPay/0;supportBestPay/0;session/14;pap/JA2015_311210;brand/apple;supportJDSHWK/1;"
}
}
$.get(options, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`);
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
const { userTuanInfo } = data['data'];
console.log(`\n团活动ID ${userTuanInfo.activeId}`);
console.log(`团ID ${userTuanInfo.tuanId}\n`);
} else {
console.log(`QueryActiveConfig异常:${JSON.stringify(data)}`);
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function QueryTuan(activeId, tuanId) {
return new Promise((resolve) => {
const options = {
'url': `https://m.jingxi.com/dreamfactory/tuan/QueryTuan?activeId=${escape(activeId)}&tuanId=${escape(tuanId)}&_time=${Date.now()}&_=${Date.now()}&sceneval=2&g_login_type=1`,
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Cookie": cookie,
"Host": "m.jingxi.com",
"Referer": "https://st.jingxi.com/pingou/dream_factory/divide.html",
"User-Agent": "jdpingou;iPhone;3.15.2;13.5.1;90bab9217f465a83a99c0b554a946b0b0d5c2f7a;network/wifi;model/iPhone12,1;appBuild/100365;ADID/696F8BD2-0820-405C-AFC0-3C6D028040E5;supportApplePay/1;hasUPPay/0;pushNoticeIsOpen/1;hasOCPay/0;supportBestPay/0;session/14;pap/JA2015_311210;brand/apple;supportJDSHWK/1;"
}
}
$.get(options, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`);
} else {
if (safeGet(data)) {
data = JSON.parse(data);
if (data['ret'] === 0) {
// $.log(`\n开团情况:${data.data.tuanInfo.realTuanNum}/${data.data.tuanInfo.tuanNum}\n`)
} else {
console.log(`异常:${JSON.stringify(data)}`);
}
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
//开团API
function CreateTuan() {
return new Promise((resolve) => {
const options = {
'url': `https://m.jingxi.com/dreamfactory/tuan/CreateTuan?activeId=${escape(tuanActiveId)}&isOpenApp=1&_time=${Date.now()}&_=${Date.now()}&sceneval=2&g_login_type=1&_stk=_time,activeId,isOpenApp`,
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Cookie": cookie,
"Host": "m.jingxi.com",
"Referer": "https://st.jingxi.com/pingou/dream_factory/divide.html",
"User-Agent": "jdpingou;iPhone;3.15.2;13.5.1;90bab9217f465a83a99c0b554a946b0b0d5c2f7a;network/wifi;model/iPhone12,1;appBuild/100365;ADID/696F8BD2-0820-405C-AFC0-3C6D028040E5;supportApplePay/1;hasUPPay/0;pushNoticeIsOpen/1;hasOCPay/0;supportBestPay/0;session/14;pap/JA2015_311210;brand/apple;supportJDSHWK/1;"
}
}
$.get(options, (err, resp, data) => {
try {