forked from Aaron-lv/sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jd_try.js
1218 lines (1177 loc) · 55.5 KB
/
jd_try.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_TRY,值填 true 即可运行
* 脚本兼容: Node.js
* X1a0He留
* 脚本是否耗时只看args_xh.maxLength的大小
* 上一作者说了每天最多300个商店,总上限为500个,jd_unsubscribe.js我已更新为批量取关版
* 请提前取关至少250个商店确保京东试用脚本正常运行
*
* @Address: https://github.com/X1a0He/jd_scripts_fixed/blob/main/jd_try_xh.js
* @LastEditors: X1a0He
*/
const $ = new Env('京东试用')
const URL = 'https://api.m.jd.com/client.action'
let trialActivityIdList = []
let trialActivityTitleList = []
let notifyMsg = ''
let size = 1;
$.isPush = true;
$.isLimit = false;
$.isForbidden = false;
$.wrong = false;
$.giveupNum = 0;
$.successNum = 0;
$.completeNum = 0;
$.getNum = 0;
$.try = true;
$.sentNum = 0;
$.cookiesArr = []
$.innerKeyWords =
[
"幼儿园", "教程", "英语", "辅导", "培训",
"孩子", "小学", "成人用品", "套套", "情趣",
"自慰", "阳具", "飞机杯", "男士用品", "女士用品",
"内衣", "高潮", "避孕", "乳腺", "肛塞", "肛门",
"宝宝", "玩具", "芭比", "娃娃", "男用",
"女用", "神油", "足力健", "老年", "老人",
"宠物", "饲料", "丝袜", "黑丝", "磨脚",
"脚皮", "除臭", "性感", "内裤", "跳蛋",
"安全套", "龟头", "阴道", "阴部"
]
//下面很重要,遇到问题请把下面注释看一遍再来问
let args_xh = {
/*
* 每个Tab页要便遍历的申请页数,由于京东试用又改了,获取不到每一个Tab页的总页数了(显示null),所以特定增加一个环境变了以控制申请页数
* 例如设置 JD_TRY_PRICE 为 30,假如现在正在遍历tab1,那tab1就会被遍历到30页,到31页就会跳到tab2,或下一个预设的tab页继续遍历到30页
* 默认为20
*/
totalPages: process.env.JD_TRY_TOTALPAGES * 1 || 20,
/*
* 由于每个账号每次获取的试用产品都不一样,所以为了保证每个账号都能试用到不同的商品,之前的脚本都不支持采用统一试用组的
* 以下环境变量是用于指定是否采用统一试用组的
* 例如当 JD_TRY_UNIFIED 为 true时,有3个账号,第一个账号跑脚本的时候,试用组是空的
* 而当第一个账号跑完试用组后,第二个,第三个账号所采用的试用组默认采用的第一个账号的试用组
* 优点:减少除第一个账号外的所有账号遍历,以减少每个账号的遍历时间
* 缺点:A账号能申请的东西,B账号不一定有
* 提示:想每个账号独立不同的试用产品的,请设置为false,想减少脚本运行时间的,请设置为true
* 默认为false
*/
unified: process.env.JD_TRY_UNIFIED || false,
//以上环境变量新增于2022.01.25
/*
* 商品原价,低于这个价格都不会试用,意思是
* A商品原价49元,试用价1元,如果下面设置为50,那么A商品不会被加入到待提交的试用组
* B商品原价99元,试用价0元,如果下面设置为50,那么B商品将会被加入到待提交的试用组
* C商品原价99元,试用价1元,如果下面设置为50,那么C商品将会被加入到待提交的试用组
* 默认为0
* */
jdPrice: process.env.JD_TRY_PRICE * 1 || 0,
/*
* 获取试用商品类型,默认为1
* 下面有一个function是可以获取所有tabId的,名为try_tabList
* 可设置环境变量:JD_TRY_TABID,用@进行分隔
* 默认为 1 到 10
* */
tabId: process.env.JD_TRY_TABID && process.env.JD_TRY_TABID.split('@').map(Number) || [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
/*
* 试用商品标题过滤,黑名单,当标题存在关键词时,则不加入试用组
* 当白名单和黑名单共存时,黑名单会自动失效,优先匹配白名单,匹配完白名单后不会再匹配黑名单,望周知
* 例如A商品的名称为『旺仔牛奶48瓶特价』,设置了匹配白名单,白名单关键词为『牛奶』,但黑名单关键词存在『旺仔』
* 这时,A商品还是会被添加到待提交试用组,白名单优先于黑名单
* 已内置对应的 成人类 幼儿类 宠物 老年人类关键词,请勿重复添加
* 可设置环境变量:JD_TRY_TITLEFILTERS,关键词与关键词之间用@分隔
* */
titleFilters: process.env.JD_TRY_TITLEFILTERS && process.env.JD_TRY_TITLEFILTERS.split('@') || [],
/*
* 试用价格(中了要花多少钱),高于这个价格都不会试用,小于等于才会试用,意思就是
* A商品原价49元,现在试用价1元,如果下面设置为10,那A商品将会被添加到待提交试用组,因为1 < 10
* B商品原价49元,现在试用价2元,如果下面设置为1,那B商品将不会被添加到待提交试用组,因为2 > 1
* C商品原价49元,现在试用价1元,如果下面设置为1,那C商品也会被添加到带提交试用组,因为1 = 1
* 可设置环境变量:JD_TRY_TRIALPRICE,默认为0
* */
trialPrice: process.env.JD_TRY_TRIALPRICE * 1 || 0,
/*
* 最小提供数量,例如试用商品只提供2份试用资格,当前设置为1,则会进行申请
* 若只提供5分试用资格,当前设置为10,则不会申请
* 可设置环境变量:JD_TRY_MINSUPPLYNUM
* */
minSupplyNum: process.env.JD_TRY_MINSUPPLYNUM * 1 || 1,
/*
* 过滤大于设定值的已申请人数,例如下面设置的1000,A商品已经有1001人申请了,则A商品不会进行申请,会被跳过
* 可设置环境变量:JD_TRY_APPLYNUMFILTER
* */
applyNumFilter: process.env.JD_TRY_APPLYNUMFILTER * 1 || 10000,
/*
* 商品试用之间和获取商品之间的间隔, 单位:毫秒(1秒=1000毫秒)
* 可设置环境变量:JD_TRY_APPLYINTERVAL
* 默认为3000,也就是3秒
* */
applyInterval: process.env.JD_TRY_APPLYINTERVAL * 1 || 5000,
/*
* 商品数组的最大长度,通俗来说就是即将申请的商品队列长度
* 例如设置为20,当第一次获取后获得12件,过滤后剩下5件,将会进行第二次获取,过滤后加上第一次剩余件数
* 例如是18件,将会进行第三次获取,直到过滤完毕后为20件才会停止,不建议设置太大
* 可设置环境变量:JD_TRY_MAXLENGTH
* */
maxLength: process.env.JD_TRY_MAXLENGTH * 1 || 100,
/*
* 过滤种草官类试用,某些试用商品是专属官专属,考虑到部分账号不是种草官账号
* 例如A商品是种草官专属试用商品,下面设置为true,而你又不是种草官账号,那A商品将不会被添加到待提交试用组
* 例如B商品是种草官专属试用商品,下面设置为false,而你是种草官账号,那A商品将会被添加到待提交试用组
* 例如B商品是种草官专属试用商品,下面设置为true,即使你是种草官账号,A商品也不会被添加到待提交试用组
* 可设置环境变量:JD_TRY_PASSZC,默认为true
* */
passZhongCao: process.env.JD_TRY_PASSZC || true,
/*
* 是否打印输出到日志,考虑到如果试用组长度过大,例如100以上,如果每个商品检测都打印一遍,日志长度会非常长
* 打印的优点:清晰知道每个商品为什么会被过滤,哪个商品被添加到了待提交试用组
* 打印的缺点:会使日志变得很长
*
* 不打印的优点:简短日志长度
* 不打印的缺点:无法清晰知道每个商品为什么会被过滤,哪个商品被添加到了待提交试用组
* 可设置环境变量:JD_TRY_PLOG,默认为true
* */
printLog: process.env.JD_TRY_PLOG || true,
/*
* 白名单,是否打开,如果下面为true,那么黑名单会自动失效
* 白名单和黑名单无法共存,白名单永远优先于黑名单
* 可通过环境变量控制:JD_TRY_WHITELIST,默认为false
* */
whiteList: process.env.JD_TRY_WHITELIST || false,
/*
* 白名单关键词,当标题存在关键词时,加入到试用组
* 例如A商品的名字为『旺仔牛奶48瓶特价』,白名单其中一个关键词是『牛奶』,那么A将会直接被添加到待提交试用组,不再进行另外判断
* 就算设置了黑名单也不会判断,希望这种写得那么清楚的脑瘫问题就别提issues了
* 可通过环境变量控制:JD_TRY_WHITELIST,用@分隔
* */
whiteListKeywords: process.env.JD_TRY_WHITELISTKEYWORDS && process.env.JD_TRY_WHITELISTKEYWORDS.split('@') || [],
/*
* 每多少个账号发送一次通知,默认为4
* 可通过环境变量控制 JD_TRY_SENDNUM
* */
sendNum: process.env.JD_TRY_SENDNUM * 1 || 4,
}
//上面很重要,遇到问题请把上面注释看一遍再来问
!(async () => {
console.log('X1a0He留:遇到问题请把脚本内的注释看一遍再来问,谢谢')
console.log('X1a0He留:遇到问题请把脚本内的注释看一遍再来问,谢谢')
console.log('X1a0He留:遇到问题请把脚本内的注释看一遍再来问,谢谢')
await $.wait(500)
// 如果你要运行京东试用这个脚本,麻烦你把环境变量 JD_TRY 设置为 true
if (process.env.JD_TRY && process.env.JD_TRY === 'true') {
await requireConfig()
if (!$.cookiesArr[0]) {
$.msg($.name, '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/', {
"open-url": "https://bean.m.jd.com/"
})
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"
});
await $.notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`);
continue
}
$.totalTry = 0
$.totalSuccess = 0
$.nowTabIdIndex = 0;
$.nowPage = 1;
$.nowItem = 1;
if (!args_xh.unified) {
trialActivityIdList = []
trialActivityTitleList = []
}
$.isLimit = false;
// 获取tabList的,不知道有哪些的把这里的注释解开跑一遍就行了
// await try_tabList();
// return;
$.isForbidden = false
$.wrong = false
size = 1
while(trialActivityIdList.length < args_xh.maxLength && $.isForbidden === false){
if($.nowTabIdIndex === args_xh.tabId.length){
console.log(`tabId组已遍历完毕,不在获取商品\n`);
break;
} else {
await try_feedsList(args_xh.tabId[$.nowTabIdIndex], $.nowPage) //获取对应tabId的试用页面
}
if(trialActivityIdList.length < args_xh.maxLength){
console.log(`间隔等待中,请等待 3 秒\n`)
await $.wait(3000);
}
}
if ($.isForbidden === false && $.isLimit === false) {
console.log(`稍后将执行试用申请,请等待 2 秒\n`)
await $.wait(2000);
for(let i = 0; i < trialActivityIdList.length && $.isLimit === false; i++){
if($.isLimit){
console.log("试用上限")
break
}
await try_apply(trialActivityTitleList[i], trialActivityIdList[i])
console.log(`间隔等待中,请等待 ${args_xh.applyInterval} ms\n`)
await $.wait(args_xh.applyInterval);
}
console.log("试用申请执行完毕...")
// await try_MyTrials(1, 1) //申请中的商品
$.giveupNum = 0;
$.successNum = 0;
$.getNum = 0;
$.completeNum = 0;
await try_MyTrials(1, 2) //申请成功的商品
// await try_MyTrials(1, 3) //申请失败的商品
await showMsg()
}
}
if($.isNode()){
if($.index % args_xh.sendNum === 0){
$.sentNum++;
console.log(`正在进行第 ${$.sentNum} 次发送通知,发送数量:${args_xh.sendNum}`)
await $.notify.sendNotify(`${$.name}`, `${notifyMsg}`)
notifyMsg = "";
}
}
}
if($.isNode()){
if(($.cookiesArr.length - ($.sentNum * args_xh.sendNum)) < args_xh.sendNum){
console.log(`正在进行最后一次发送通知,发送数量:${($.cookiesArr.length - ($.sentNum * args_xh.sendNum))}`)
await $.notify.sendNotify(`${$.name}`, `${notifyMsg}`)
notifyMsg = "";
}
}
} else {
console.log(`\n您未设置运行【京东试用】脚本,结束运行!\n`)
}
})().catch((e) => {
console.error(`❗️ ${$.name} 运行错误!\n${e}`)
}).finally(() => $.done())
function requireConfig() {
return new Promise(resolve => {
console.log('开始获取配置文件\n')
$.notify = $.isNode() ? require('./sendNotify') : { sendNotify: async () => { } }
//获取 Cookies
$.cookiesArr = []
if ($.isNode()) {
//Node.js用户请在jdCookie.js处填写京东ck;
const jdCookieNode = require('./jdCookie.js');
Object.keys(jdCookieNode).forEach((item) => {
if (jdCookieNode[item]) $.cookiesArr.push(jdCookieNode[item])
})
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => { };
} else {
//IOS等用户直接用NobyDa的jd $.cookie
$.cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item);
}
if (typeof process.env.JD_TRY_WHITELIST === "undefined") args_xh.whiteList = false;
else args_xh.whiteList = process.env.JD_TRY_WHITELIST === 'true';
if (typeof process.env.JD_TRY_PLOG === "undefined") args_xh.printLog = true;
else args_xh.printLog = process.env.JD_TRY_PLOG === 'true';
if (typeof process.env.JD_TRY_UNIFIED === "undefined") args_xh.unified = false;
else args_xh.unified = process.env.JD_TRY_UNIFIED === 'true';
if (typeof process.env.JD_TRY_PASSZC === "undefined") args_xh.passZhongCao = true;
else args_xh.passZhongCao = process.env.JD_TRY_PASSZC === 'true';
for (let keyWord of $.innerKeyWords) args_xh.titleFilters.push(keyWord)
console.log(`共${$.cookiesArr.length}个京东账号\n`)
console.log('=====环境变量配置如下=====')
console.log(`totalPages: ${typeof args_xh.totalPages}, ${args_xh.totalPages}`)
console.log(`unified: ${typeof args_xh.unified}, ${args_xh.unified}`)
console.log(`jdPrice: ${typeof args_xh.jdPrice}, ${args_xh.jdPrice}`)
console.log(`tabId: ${typeof args_xh.tabId}, ${args_xh.tabId}`)
console.log(`titleFilters: ${typeof args_xh.titleFilters}, ${args_xh.titleFilters}`)
console.log(`trialPrice: ${typeof args_xh.trialPrice}, ${args_xh.trialPrice}`)
console.log(`minSupplyNum: ${typeof args_xh.minSupplyNum}, ${args_xh.minSupplyNum}`)
console.log(`applyNumFilter: ${typeof args_xh.applyNumFilter}, ${args_xh.applyNumFilter}`)
console.log(`applyInterval: ${typeof args_xh.applyInterval}, ${args_xh.applyInterval}`)
console.log(`maxLength: ${typeof args_xh.maxLength}, ${args_xh.maxLength}`)
console.log(`passZhongCao: ${typeof args_xh.passZhongCao}, ${args_xh.passZhongCao}`)
console.log(`printLog: ${typeof args_xh.printLog}, ${args_xh.printLog}`)
console.log(`whiteList: ${typeof args_xh.whiteList}, ${args_xh.whiteList}`)
console.log(`whiteListKeywords: ${typeof args_xh.whiteListKeywords}, ${args_xh.whiteListKeywords}`)
console.log('=======================')
resolve()
})
}
//获取tabList的,如果不知道tabList有哪些,跑一遍这个function就行了
function try_tabList() {
return new Promise((resolve, reject) => {
console.log(`获取tabList中...`)
const body = JSON.stringify({
"version": 2,
"previewTime": ""
});
let option = taskurl_xh('newtry', 'try_tabList', body)
$.get(option, (err, resp, data) => {
try {
if (err) {
if (JSON.stringify(err) === `\"Response code 403 (Forbidden)\"`) {
$.isForbidden = true
console.log('账号被京东服务器风控,不再请求该帐号')
} else {
console.log(JSON.stringify(err))
console.log(`${$.name} API请求失败,请检查网路重试`)
}
} else {
data = JSON.parse(data)
if (data.success) {
for (let tabId of data.data.tabList) console.log(`${tabId.tabName} - ${tabId.tabId}`)
} else {
console.log("获取失败", data)
}
}
} catch (e) {
reject(`⚠️ ${arguments.callee.name.toString()} API返回结果解析出错\n${e}\n${JSON.stringify(data)}`)
} finally {
resolve()
}
})
})
}
//获取商品列表并且过滤 By X1a0He
function try_feedsList(tabId, page) {
return new Promise((resolve, reject) => {
const body = JSON.stringify({
"tabId": `${tabId}`,
"page": page,
"version": 2,
"source": "default",
"client": "app",
"previewTime": ""
});
let option = taskurl_xh('newtry', 'try_feedsList', body)
$.get(option, (err, resp, data) => {
try {
if (err) {
if (JSON.stringify(err) === `\"Response code 403 (Forbidden)\"`) {
$.isForbidden = true
console.log('账号被京东服务器风控,不再请求该帐号')
} else {
console.log(JSON.stringify(err))
console.log(`${$.name} API请求失败,请检查网路重试`)
}
} else {
data = JSON.parse(data)
let tempKeyword = ``;
if (data.success) {
$.nowPage === args_xh.totalPages ? $.nowPage = 1 : $.nowPage++;
console.log(`第 ${size++} 次获取试用商品成功,tabId:${args_xh.tabId[$.nowTabIdIndex]} 的 第 ${page}/${args_xh.totalPages} 页`)
console.log(`获取到商品 ${data.data.feedList.length} 条`)
for (let item of data.data.feedList) {
if (item.applyNum === null) {
args_xh.printLog ? console.log(`商品未到申请时间:${item.skuTitle}\n`) : ''
continue
}
if (trialActivityIdList.length >= args_xh.maxLength) {
console.log('商品列表长度已满.结束获取')
break
}
if (item.applyState === 1) {
args_xh.printLog ? console.log(`商品已申请试用:${item.skuTitle}\n`) : ''
continue
}
if (item.applyState !== null) {
args_xh.printLog ? console.log(`商品状态异常,未找到skuTitle\n`) : ''
continue
}
if (args_xh.passZhongCao) {
$.isPush = true;
if (item.tagList.length !== 0) {
for (let itemTag of item.tagList) {
if (itemTag.tagType === 3) {
args_xh.printLog ? console.log('商品被过滤,该商品是种草官专属') : ''
$.isPush = false;
break;
}
else if (itemTag.tagType === 5) {
args_xh.printLog ? console.log('商品被跳过,该商品是付费试用!') : ''
$.isPush = false;
break;
}
}
}
}
if (item.skuTitle && $.isPush) {
args_xh.printLog ? console.log(`检测 tabId:${args_xh.tabId[$.nowTabIdIndex]} 的 第 ${page}/${args_xh.totalPages} 页 第 ${$.nowItem++ + 1} 个商品\n${item.skuTitle}`) : ''
if (args_xh.whiteList) {
if (args_xh.whiteListKeywords.some(fileter_word => item.skuTitle.includes(fileter_word))) {
args_xh.printLog ? console.log(`商品白名单通过,将加入试用组,trialActivityId为${item.trialActivityId}\n`) : ''
trialActivityIdList.push(item.trialActivityId)
trialActivityTitleList.push(item.skuTitle)
}
} else {
tempKeyword = ``;
if (parseFloat(item.jdPrice) <= args_xh.jdPrice) {
args_xh.printLog ? console.log(`商品被过滤,${item.jdPrice} < ${args_xh.jdPrice} \n`) : ''
} else if (parseFloat(item.supplyNum) < args_xh.minSupplyNum && item.supplyNum !== null) {
args_xh.printLog ? console.log(`商品被过滤,提供申请的份数小于预设申请的份数 \n`) : ''
} else if (parseFloat(item.applyNum) > args_xh.applyNumFilter && item.applyNum !== null) {
args_xh.printLog ? console.log(`商品被过滤,已申请试用人数大于预设人数 \n`) : ''
} else if (parseFloat(item.jdPrice) < args_xh.jdPrice) {
args_xh.printLog ? console.log(`商品被过滤,商品原价低于预设商品原价 \n`) : ''
} else if (args_xh.titleFilters.some(fileter_word => item.skuTitle.includes(fileter_word) ? tempKeyword = fileter_word : '')) {
args_xh.printLog ? console.log(`商品被过滤,含有关键词 ${tempKeyword}\n`) : ''
} else {
args_xh.printLog ? console.log(`商品通过,将加入试用组,trialActivityId为${item.trialActivityId}\n`) : ''
trialActivityIdList.push(item.trialActivityId)
trialActivityTitleList.push(item.skuTitle)
}
}
} else if ($.isPush !== false) {
console.error('skuTitle解析异常')
return
}
}
console.log(`当前试用组长度为:${trialActivityIdList.length}`)
args_xh.printLog ? console.log(`${trialActivityIdList}`) : ''
if (page >= args_xh.totalPages && $.nowTabIdIndex < args_xh.tabId.length) {
//这个是因为每一个tab都会有对应的页数,获取完如果还不够的话,就获取下一个tab
$.nowTabIdIndex++;
$.nowPage = 1;
$.nowItem = 1;
}
} else {
console.log(`💩 获得试用列表失败: ${data.message}`)
}
}
} catch (e) {
reject(`⚠️ ${arguments.callee.name.toString()} API返回结果解析出错\n${e}\n${JSON.stringify(data)}`)
} finally {
resolve()
}
})
})
}
function try_apply(title, activityId) {
return new Promise((resolve, reject) => {
console.log(`申请试用商品提交中...`)
args_xh.printLog ? console.log(`商品:${title}`) : ''
args_xh.printLog ? console.log(`id为:${activityId}`) : ''
const body = JSON.stringify({
"activityId": activityId,
"previewTime": ""
});
let option = taskurl_xh('newtry', 'try_apply', body)
$.get(option, (err, resp, data) => {
try {
if (err) {
if (JSON.stringify(err) === `\"Response code 403 (Forbidden)\"`) {
$.isForbidden = true
console.log('账号被京东服务器风控,不再请求该帐号')
} else {
console.log(JSON.stringify(err))
console.log(`${$.name} API请求失败,请检查网路重试`)
}
} else {
$.totalTry++
data = JSON.parse(data)
if (data.success && data.code === "1") { // 申请成功
console.log("申请提交成功")
$.totalSuccess++
} else if (data.code === "-106") {
console.log(data.message) // 未在申请时间内!
} else if (data.code === "-110") {
console.log(data.message) // 您的申请已成功提交,请勿重复申请…
} else if (data.code === "-120") {
console.log(data.message) // 您还不是会员,本品只限会员申请试用,请注册会员后申请!
} else if (data.code === "-167") {
console.log(data.message) // 抱歉,此试用需为种草官才能申请。查看下方详情了解更多。
} else if (data.code === "-131") {
console.log(data.message) // 申请次数上限。
$.isLimit = true;
} else if (data.code === "-113") {
console.log(data.message) // 操作不要太快哦!
} else {
console.log("申请失败", data)
}
}
} catch (e) {
reject(`⚠️ ${arguments.callee.name.toString()} API返回结果解析出错\n${e}\n${JSON.stringify(data)}`)
} finally {
resolve()
}
})
})
}
function try_MyTrials(page, selected) {
return new Promise((resolve, reject) => {
switch (selected) {
case 1:
console.log('正在获取已申请的商品...')
break;
case 2:
console.log('正在获取申请成功的商品...')
break;
case 3:
console.log('正在获取申请失败的商品...')
break;
default:
console.log('selected错误')
}
let options = {
url: URL,
body: `appid=newtry&functionId=try_MyTrials&clientVersion=10.3.4&client=wh5&body=%7B%22page%22%3A${page}%2C%22selected%22%3A${selected}%2C%22previewTime%22%3A%22%22%7D`,
headers: {
'origin': 'https://prodev.m.jd.com',
'User-Agent': 'jdapp;iPhone;10.3.4;;;M/5.0;appBuild/167945;jdSupportDarkMode/1;;;Mozilla/5.0 (iPhone; CPU iPhone OS 15_2_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1;',
'referer': 'https://prodev.m.jd.com/',
'cookie': $.cookie
},
}
$.post(options, (err, resp, data) => {
try {
if (err) {
console.log(`🚫 ${arguments.callee.name.toString()} API请求失败,请检查网路\n${JSON.stringify(err)}`)
} else {
data = JSON.parse(data)
if (data.success) {
//temp adjustment
if (selected === 2) {
if (data.success && data.data) {
for (let item of data.data.list) {
item.status === 4 || item.text.text.includes('已放弃') ? $.giveupNum += 1 : ''
item.status === 2 && item.text.text.includes('试用资格将保留') ? $.successNum += 1 : ''
item.status === 2 && item.text.text.includes('请收货后尽快提交报告') ? $.getNum += 1 : ''
item.status === 2 && item.text.text.includes('试用已完成') ? $.completeNum += 1 : ''
}
console.log(`待领取 | 已领取 | 已完成 | 已放弃:${$.successNum} | ${$.getNum} | ${$.completeNum} | ${$.giveupNum}`)
} else {
console.log(`获得成功列表失败: ${data.message}`)
}
}
} else {
console.error(`ERROR:try_MyTrials`)
}
}
} catch (e) {
reject(`⚠️ ${arguments.callee.name.toString()} API返回结果解析出错\n${e}\n${JSON.stringify(data)}`)
} finally {
resolve()
}
})
})
}
function taskurl_xh(appid, functionId, body = JSON.stringify({})) {
return {
"url": `${URL}?appid=${appid}&functionId=${functionId}&clientVersion=10.3.4&client=wh5&body=${encodeURIComponent(body)}`,
'headers': {
'Cookie': $.cookie,
'UserAgent': 'jdapp;iPhone;10.1.2;15.0;ff2caa92a8529e4788a34b3d8d4df66d9573f499;network/wifi;model/iPhone13,4;addressid/2074196292;appBuild/167802;jdSupportDarkMode/1;Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1',
'Referer': 'https://prodev.m.jd.com/'
},
}
}
async function showMsg() {
let message = ``;
message += `👤 京东账号${$.index} ${$.nickName || $.UserName}\n`;
if ($.totalSuccess !== 0 && $.totalTry !== 0) {
message += `🎉 本次提交申请:${$.totalSuccess}/${$.totalTry}个商品🛒\n`;
message += `🎉 ${$.successNum}个商品待领取\n`;
message += `🎉 ${$.getNum}个商品已领取\n`;
message += `🎉 ${$.completeNum}个商品已完成\n`;
message += `🗑 ${$.giveupNum}个商品已放弃\n\n`;
} else {
message += `⚠️ 本次执行没有申请试用商品\n`;
message += `🎉 ${$.successNum}个商品待领取\n`;
message += `🎉 ${$.getNum}个商品已领取\n`;
message += `🎉 ${$.completeNum}个商品已完成\n`;
message += `🗑 ${$.giveupNum}个商品已放弃\n\n`;
}
if (!args_xh.jdNotify || args_xh.jdNotify === 'false') {
$.msg($.name, ``, message, {
"open-url": 'https://try.m.jd.com/user'
})
if ($.isNode())
notifyMsg += `${message}`
} else {
console.log(message)
}
}
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 : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;14.3;network/4g;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1")
},
"timeout": 10000,
}
$.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
}
if (data['retcode'] === 0) {
$.nickName = (data['base'] && data['base'].nickname) || $.UserName;
} else {
$.nickName = $.UserName
}
} else {
console.log(`京东服务器返回空数据`)
}
}
} 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输入框修改内容\n建议通过脚本去获取cookie')
return [];
}
}
}
function Env(name, opts) {
class Http {
constructor(env) {
this.env = env
}
send(opts, method = 'GET') {
opts = typeof opts === 'string' ? {
url: opts
} : opts
let sender = this.get
if (method === 'POST') {
sender = this.post
}
return new Promise((resolve, reject) => {
sender.call(this, opts, (err, resp, body) => {
if (err) reject(err)
else resolve(resp)
})
})
}
get(opts) {
return this.send.call(this.env, opts)
}
post(opts) {
return this.send.call(this.env, opts, 'POST')
}
}
return new (class {
constructor(name, opts) {
this.name = name
this.http = new Http(this)
this.data = null
this.dataFile = 'box.dat'
this.logs = []
this.isMute = false
this.isNeedRewrite = false
this.logSeparator = '\n'
this.startTime = new Date().getTime()
Object.assign(this, opts)
this.log('', `🔔${this.name}, 开始!`)
}
isNode() {
return 'undefined' !== typeof module && !!module.exports
}
isQuanX() {
return 'undefined' !== typeof $task
}
isSurge() {
return 'undefined' !== typeof $httpClient && 'undefined' === typeof $loon
}
isLoon() {
return 'undefined' !== typeof $loon
}
toObj(str, defaultValue = null) {
try {
return JSON.parse(str)
} catch {
return defaultValue
}
}
toStr(obj, defaultValue = null) {
try {
return JSON.stringify(obj)
} catch {
return defaultValue
}
}
getjson(key, defaultValue) {
let json = defaultValue
const val = this.getdata(key)
if (val) {
try {
json = JSON.parse(this.getdata(key))
} catch { }
}
return json
}
setjson(val, key) {
try {
return this.setdata(JSON.stringify(val), key)
} catch {
return false
}
}
getScript(url) {
return new Promise((resolve) => {
this.get({
url
}, (err, resp, body) => resolve(body))
})
}
runScript(script, runOpts) {
return new Promise((resolve) => {
let httpapi = this.getdata('@chavy_boxjs_userCfgs.httpapi')
httpapi = httpapi ? httpapi.replace(/\n/g, '').trim() : httpapi
let httpapi_timeout = this.getdata('@chavy_boxjs_userCfgs.httpapi_timeout')
httpapi_timeout = httpapi_timeout ? httpapi_timeout * 1 : 20
httpapi_timeout = runOpts && runOpts.timeout ? runOpts.timeout : httpapi_timeout
const [key, addr] = httpapi.split('@')
const opts = {
url: `http://${addr}/v1/scripting/evaluate`,
body: {
script_text: script,
mock_type: 'cron',
timeout: httpapi_timeout
},
headers: {
'X-Key': key,
'Accept': '*/*'
}
}
this.post(opts, (err, resp, body) => resolve(body))
}).catch((e) => this.logErr(e))
}
loaddata() {
if (this.isNode()) {
this.fs = this.fs ? this.fs : require('fs')
this.path = this.path ? this.path : require('path')
const curDirDataFilePath = this.path.resolve(this.dataFile)
const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile)
const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath)
const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath)
if (isCurDirDataFile || isRootDirDataFile) {
const datPath = isCurDirDataFile ? curDirDataFilePath : rootDirDataFilePath
try {
return JSON.parse(this.fs.readFileSync(datPath))
} catch (e) {
return {}
}
} else return {}
} else return {}
}
writedata() {
if (this.isNode()) {
this.fs = this.fs ? this.fs : require('fs')
this.path = this.path ? this.path : require('path')
const curDirDataFilePath = this.path.resolve(this.dataFile)
const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile)
const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath)
const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath)
const jsondata = JSON.stringify(this.data)
if (isCurDirDataFile) {
this.fs.writeFileSync(curDirDataFilePath, jsondata)
} else if (isRootDirDataFile) {
this.fs.writeFileSync(rootDirDataFilePath, jsondata)
} else {
this.fs.writeFileSync(curDirDataFilePath, jsondata)
}
}
}
lodash_get(source, path, defaultValue = undefined) {
const paths = path.replace(/\[(\d+)\]/g, '.$1').split('.')
let result = source
for (const p of paths) {
result = Object(result)[p]
if (result === undefined) {
return defaultValue
}
}
return result
}
lodash_set(obj, path, value) {
if (Object(obj) !== obj) return obj
if (!Array.isArray(path)) path = path.toString().match(/[^.[\]]+/g) || []
path.slice(0, -1).reduce((a, c, i) => (Object(a[c]) === a[c] ? a[c] : (a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {})), obj)[
path[path.length - 1]
] = value
return obj
}
getdata(key) {
let val = this.getval(key)
// 如果以 @
if (/^@/.test(key)) {
const [, objkey, paths] = /^@(.*?)\.(.*?)$/.exec(key)
const objval = objkey ? this.getval(objkey) : ''
if (objval) {
try {
const objedval = JSON.parse(objval)
val = objedval ? this.lodash_get(objedval, paths, '') : val
} catch (e) {
val = ''
}
}
}
return val
}
setdata(val, key) {
let issuc = false
if (/^@/.test(key)) {
const [, objkey, paths] = /^@(.*?)\.(.*?)$/.exec(key)
const objdat = this.getval(objkey)
const objval = objkey ? (objdat === 'null' ? null : objdat || '{}') : '{}'
try {
const objedval = JSON.parse(objval)
this.lodash_set(objedval, paths, val)
issuc = this.setval(JSON.stringify(objedval), objkey)
} catch (e) {
const objedval = {}
this.lodash_set(objedval, paths, val)
issuc = this.setval(JSON.stringify(objedval), objkey)
}
} else {
issuc = this.setval(val, key)
}
return issuc
}
getval(key) {
if (this.isSurge() || this.isLoon()) {
return $persistentStore.read(key)
} else if (this.isQuanX()) {
return $prefs.valueForKey(key)
} else if (this.isNode()) {
this.data = this.loaddata()
return this.data[key]
} else {
return (this.data && this.data[key]) || null
}
}
setval(val, key) {
if (this.isSurge() || this.isLoon()) {
return $persistentStore.write(val, key)
} else if (this.isQuanX()) {
return $prefs.setValueForKey(val, key)
} else if (this.isNode()) {
this.data = this.loaddata()
this.data[key] = val
this.writedata()
return true
} else {
return (this.data && this.data[key]) || null
}
}
initGotEnv(opts) {
this.got = this.got ? this.got : require('got')
this.cktough = this.cktough ? this.cktough : require('tough-cookie')
this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar()
if (opts) {
opts.headers = opts.headers ? opts.headers : {}
if (undefined === opts.headers.Cookie && undefined === opts.cookieJar) {
opts.cookieJar = this.ckjar
}
}
}
get(opts, callback = () => { }) {
if (opts.headers) {
delete opts.headers['Content-Type']
delete opts.headers['Content-Length']
}
if (this.isSurge() || this.isLoon()) {
if (this.isSurge() && this.isNeedRewrite) {
opts.headers = opts.headers || {}
Object.assign(opts.headers, {
'X-Surge-Skip-Scripting': false
})
}
$httpClient.get(opts, (err, resp, body) => {
if (!err && resp) {
resp.body = body
resp.statusCode = resp.status
}
callback(err, resp, body)
})
} else if (this.isQuanX()) {
if (this.isNeedRewrite) {
opts.opts = opts.opts || {}
Object.assign(opts.opts, {
hints: false
})
}
$task.fetch(opts).then(
(resp) => {
const {
statusCode: status,
statusCode,
headers,
body
} = resp
callback(null, {
status,
statusCode,
headers,
body
}, body)
},
(err) => callback(err)
)
} else if (this.isNode()) {
this.initGotEnv(opts)
this.got(opts).on('redirect', (resp, nextOpts) => {
try {
if (resp.headers['set-cookie']) {
const ck = resp.headers['set-cookie'].map(this.cktough.Cookie.parse).toString()
if (ck) {
this.ckjar.setCookieSync(ck, null)
}
nextOpts.cookieJar = this.ckjar
}
} catch (e) {
this.logErr(e)
}
// this.ckjar.setCookieSync(resp.headers['set-cookie'].map(Cookie.parse).toString())
}).then(
(resp) => {
const {
statusCode: status,
statusCode,
headers,
body
} = resp
callback(null, {
status,
statusCode,
headers,