-
Notifications
You must be signed in to change notification settings - Fork 188
/
TYQH.py
executable file
·1212 lines (1115 loc) · 49.7 KB
/
TYQH.py
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
# !/usr/bin/python3
# -- coding: utf-8 --
# -------------------------------
# @Author : cherwin
# -------------------------------
# cron "25 10-22/2 * * *" script-path=xxx.py,tag=匹配cron用
# const $ = new Env('统一快乐星球小程序-茄皇的家')
import json
import os
import random
import time
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
IS_DEV = False
if os.path.isfile('DEV_ENV.py'):
import DEV_ENV
IS_DEV = True
if os.path.isfile('notify.py'):
from notify import send
print("加载通知服务成功!")
else:
print("加载通知服务失败!")
send_msg = ''
one_msg=''
def Log(cont=''):
global send_msg,one_msg
print(cont)
if cont:
one_msg += f'{cont}\n'
send_msg += f'{cont}\n'
USER_INFO = {}
class RUN:
def __init__(self, info,index):
global one_msg
one_msg = ''
split_info = info.split('@')
self.third_id = split_info[0]
self.wid = split_info[1]
len_split_info = len(split_info)
last_info = split_info[len_split_info - 1]
self.send_UID = None
if len_split_info > 0 and "UID_" in last_info:
self.send_UID = last_info
self.user_index = index + 1
print(f"\n---------开始执行第{self.user_index}个账号>>>>>")
self.s = requests.session()
self.s.verify = False
self.UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x6309080f) XWEB/8555'
self.headers = {
'User-Agent': self.UA,
'Sec-Fetch-Site': 'cross-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Origin': 'https://thekingoftomato.ioutu.cn',
'Referer': 'https://thekingoftomato.ioutu.cn/'
}
self.base_url = 'https://qiehuang-apig.xiaoyisz.com/qiehuangsecond/ga'
self.sun = 0
self.land = {}
self.refresh_land_step = False
self.need_help_unlock = True
self.need_help_task = True
self.need_help_risk = True
self.can_go_risk = True
self.can_add_friend = True
self.can_help_task = True
self.can_help_risk = True
self.can_help_unlock = True
self.role_id =''
self.role_progress=''
self.role_max=''
self.all_land_unlock = True
self.all_role_unlock = True
self.help_task_config = {}
self.help_role_config = {}
self.group_step = ['发育期', '幼苗期', '开花期', '结果期', '收获期']
self.Login_res = self.login()
def load_json(self):
try:
with open(f"INVITE_CODE/{ENV_NAME}_INVITE_CODE.json", 'r', encoding='utf-8') as file:
data = json.load(file)
return data
except FileNotFoundError:
print("未找到文件,返回空字典")
return {}
except Exception as e:
print(f"发生错误:{e}")
return {}
def make_request(self, url, method='post', headers={}, params={}):
if headers == {}:
headers = self.headers
if params == {}:
params = self.params
try:
if method.lower() == 'get':
response = requests.get(url, headers=headers, verify=False)
elif method.lower() == 'post':
response = requests.post(url, headers=headers, json=params, verify=False)
else:
raise ValueError("不支持的请求方法: " + method)
return response.json()
except requests.exceptions.RequestException as e:
print("请求异常:", e)
except ValueError as e:
print("值错误或不支持的请求方法:", e)
except Exception as e:
print("发生了未知错误:", e)
def gen_sign(self, parameters={}, body=None):
sign_header = CHERWIN_TOOLS.TYQH_SIGN(parameters, body)
self.headers.update(sign_header)
return self.headers
def login(self):
login_successful = False
try:
login_params = {
'thirdId': self.third_id,
'wid': self.wid
}
sign_header = self.gen_sign({}, login_params)
# print(self.headers)
# Hypothetically speaking, this is how you might perform a POST request in Python with the requests library.
response = self.s.post(f'{self.base_url}/public/api/login', json=login_params, headers=sign_header)
if response.status_code == 200:
response_data = response.json()
if response_data.get('code', -1) == 0:
auth = response_data['data']['token'] or ''
if auth:
login_successful = True
print(f'账号【{self.user_index}】登录成功')
Authorization = {'Authorization': auth}
self.headers.update(Authorization)
else:
print(f'账号【{self.user_index}】登录获取auth失败')
else:
print(f"登录获取auth失败[{response_data['code']}]: {response_data['message']}")
elif response.status_code == 403:
print('登录失败[403]: 黑IP了, 换个IP试试吧')
except Exception as e:
print(e)
finally:
return login_successful
def userInfo_get(self,END=False):
print(f'获取用户[{self.user_index}]信息--->>>')
try:
sign_header = self.gen_sign()
# print(self.headers)
url = f'{self.base_url}/userInfo/get'
# 发起GET请求
response = self.s.get(url, headers=sign_header, verify=False)
data = response.json()
code = data.get('code', -1)
if code == 0:
data = data.get('data', {})
self.userId = data['userId']
self.gold = int(data['gold'])
self.score = int(data['score'])
self.sun = int(data['sun'])
self.sunMax = int(data['sunMax'])
self.nickName = data['nickName']
if self.nickName == None:self.nickName = '未命名'
new_data = {
self.userId:
{
'name': self.nickName
}
}
USER_INFO.update(new_data)
CHERWIN_TOOLS.SAVE_INVITE_CODE(f"INVITE_CODE/{ENV_NAME}_INVITE_CODE.json", new_data)
if END:
Log(f"-----用户[{self.user_index}]信息-----\n用户Id:{self.userId}\n用户名:{self.nickName}\n调料🧂x{self.gold}\n番茄🍅x{self.score}\n阳光☀x{self.sun}\n------用户[{self.user_index}]信息END------")
else:
print(f"-----用户[{self.user_index}]信息-----\n用户Id:{self.userId}\n用户名:{self.nickName}\n调料🧂x{self.gold}\n番茄🍅x{self.score}\n阳光☀x{self.sun}\n------用户[{self.user_index}]信息END------")
else:
error_message = data.get('message', '')
print(f"获取账号信息失败[{str(code)}]: {error_message}")
except Exception as e:
print(e)
finally:
return
def userInfo_autoSun(self):
print('收集阳光--->>>')
sign_header = self.gen_sign()
url = f'{self.base_url}/userInfo/autoSun'
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code == 0:
sun = data.get('data', {}).get('sun', 0)
print(f"刷新收集到【{sun}】阳光---√")
else:
print(f"刷新收集阳光失败[{data['code']}]: {str(code)}")
def task_get(self):
print(f'获取任务列表--->>>')
sign_header = self.gen_sign()
url = f'{self.base_url}/task/get'
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code == 0:
tasks = data.get('data', [])
for task in tasks:
self.task_id = task['id']
self.task_title = task['title']
task_status = task['status']
self.task_progress = task.get('currentProgress', 0)
self.task_max_progress = task.get('progress', 1)
print(f"任务:【{self.task_title}】进度:【{self.task_progress}/{self.task_max_progress}】")
if self.task_title == '邀请好友助力':
if self.task_progress == self.task_max_progress:
self.need_help_task = False
# new_data = {
# self.userId: {
# 'task_id': self.task_id,
# 'task_stu': self.can_help_task,
# 'current_progress': self.task_progress
# }
# }
# USER_INFO.update(new_data)
# CHERWIN_TOOLS.SAVE_INVITE_CODE("INVITE_CODE/QH_INVITE_CODE.json", new_data)
print(f"任务 '{self.task_title}' 【跳过】---》")
continue
elif self.task_title == '邀请新人助力':
print(f"任务 '{self.task_title}' 【跳过】---》")
continue
if task_status == 0 and self.task_progress < self.task_max_progress:
# 此任务尚未完成,根据具体业务逻辑进行处理,如启动任务
print(f"任务【{self.task_title}】【未完成】执行任务---》")
self.task_doTask() # 取消这行注释来执行任务
elif task_status == 1:
# 任务已完成但奖励未被领取,根据业务逻辑领取奖励
print(f"任务【{self.task_title}】【已完成】领取奖励---》")
self.task_reward() # 取消这行注释来领取奖励
else:
print(f"获取任务列表失败[{data['code']}]: {str(code)}")
def task_doHelpTask(self,help_data):
# print('开始助力任务---》')
params = {'id': help_data["task_id"]}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/task/doTask'
response = self.s.get(url, headers=sign_header,params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
print(f"助力账号[{help_data['index']}][{help_data['name']}]成功---√")
elif '已超出' in data.get('message', ''):
self.can_help_task = False
error_message = data.get('message', '')
print(f"助力账号[{help_data['index']}][{help_data['name']}]失败[{code}]: {error_message}")
else:
error_message = data.get('message', '')
print(f"助力账号[{help_data['index']}][{help_data['name']}]失败[{code}]: {error_message}")
if '助力次数' in error_message:
self.can_help_task = False
def task_doTask(self):
sign_header = self.gen_sign({'id': self.task_id})
url = f'{self.base_url}/task/doTask'
params = {'id': self.task_id}
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
print(f"完成任务[{self.task_title}]成功---√")
else:
print(f"完成任务[{self.task_title}]失败[{str(code)}]: {data.get('message', '')}")
def task_reward(self):
sign_header = self.gen_sign({'id': self.task_id})
url = f'{self.base_url}/task/reward'
params = {'id': self.task_id}
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
print(f"领取任务[{self.task_title}]奖励成功---√")
else:
print(f"领取任务[{self.task_title}]奖励失败[{str(code)}]: {data.get('message', '')}")
def user_role_get(self):
print('\n查询角色信息--->>>')
try:
sign_header = self.gen_sign()
url = f'{self.base_url}/user-role/get'
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code == 0:
data = data.get('data')
if data and data.get('isReward'):
print('可领取定时奖励,开始领取---》')
self.user_role_reward() # 此处调用 user_role_reward 函数
for role in data.get('roleList', []):
if role['status'] > 0:
print(f"角色【{role['name']}】已解锁---√")
continue
if role['unlockType'] == 1:
if self.gold >= role['unlockNum']:
print(f"调料包充足,开始解锁角色【{role['name']}】---》")
self.user_role_goldUnlock(role) # 此处调用 user_role_goldUnlock 函数
else:
print(f"调料包不足解锁角色【{role['name']}】---!")
elif role['unlockType'] == 2:
self.user_role_findFriendHelpInfo(role) # 此处调用 user_role_findFriendHelpInfo 函数
else:
message = data.get('message', '')
print(f'角色信息失败【{code}】: {message}')
except Exception as e:
print(e)
def user_role_findFriendHelpInfo(self, role):
print(f'查询角色邀请进度--->>>')
try:
params = {'userRoleId': role['id']}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/user-role/findFriendHelpInfo'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
data = data.get('data')
self.help_role_config = {
'id': role['id'],
'progress': len(data) if data else 0,
'max': role['unlockNum']
}
self.role_id = role['id']
self.role_progress = len(data) if data else 0
self.role_max = role['unlockNum']
if role['unlockNum'] == len(data) if data else 0:
self.need_help_unlock=False
# new_data = {
# self.userId:
# {
# 'role_id': self.role_id,
# 'role_can_help': self.can_help_unlock,
# 'role_progress': self.role_progress,
# 'role_max': self.role_max
# }
# }
# USER_INFO.update(new_data)
# CHERWIN_TOOLS.SAVE_INVITE_CODE("INVITE_CODE/QH_INVITE_CODE.json", new_data)
print(f'查询角色【{role["name"]}】邀请进度成功---√')
else:
message = data.get('message', '')
print(f'查询角色【{role["name"]}】邀请进度失败[{code}]: {message}')
except Exception as e:
print(e)
def user_role_friendHelpUnlock(self, help_data):
print('开始角色解锁互助--->>>')
# try:
params = {'userRoleId': help_data['role_id']}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/user-role/friendHelpUnlock'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
help_data['role_progress'] += 1
print(f'助力账号[{help_data["index"]}][{help_data["name"]}]解锁角色成功---√')
else:
message = data.get('message', '')
print(f'助力账号[{help_data["index"]}][{help_data["name"]}]解锁角色失败[{code}]: {message}')
# except Exception as e:
# print(e)
def user_role_goldUnlock(self, role):
print(f'解锁角色开始--->>>')
try:
params = {'roleId': role['roleId']}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/user-role/goldUnlock'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
self.gold -= role['unlockNum']
print(f'解锁角色[{role["name"]}]成功')
self.user_role_reward() # 此处调用 user_role_reward 函数
else:
message = data.get('message', '')
print(f'解锁角色[{role["name"]}]失败[{code}]: {message}')
except Exception as e:
print(e)
def user_role_reward(self):
print(f'领取伴手礼--->>>')
try:
sign_header = self.gen_sign()
url = f'{self.base_url}/user-role/reward'
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code == 0:
data = data.get('data')
name = data.get('name') if data else 'unknown'
print(f'领取伴手礼【{name}】成功')
else:
message = data.get('message', '')
print(f'领取伴手礼失败[{code}]: {message}')
except Exception as e:
print(e)
def user_land_get(self):
print(f'\n刷新土地信息--->>>')
try:
sign_header = self.gen_sign()
url = f'{self.base_url}/user-land/get'
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code == 0:
print('土地信息刷新成功---√')
for land in data.get('data', {}).get('gaUserLandList', []):
ga_user_land_list = data.get('data', {}).get('gaUserLandList', [])
for land_info in ga_user_land_list:
land_id = land_info['id']
land_no = land_info['no']
status = land_info['status']
step = land_info['step']
left_sun_count = land_info['leftSunCount']
sum_sun_count = land_info['sumSunCount']
sun_time = land_info['sunTime']
sun_timestamp = land_info['sunTimestamp']
need_sun = land_info['needSun']
use_sun_count = land_info['useSunCount']
unlock_gold = land_info['unlockGold']
if not self.land.get(land_no):
self.land[land_no] = {}
self.land[land_no].update({
'id': land_id,
'no': land_no,
'status': status,
'step': step,
'leftSunCount': left_sun_count,
'sumSunCount': sum_sun_count,
'sunTime': sun_time,
'sunTimestamp': sun_timestamp,
'needSun': need_sun,
'useSunCount': use_sun_count,
'unlockGold': unlock_gold
})
if land['status'] == 0:
# 检查是否应该解锁土地
if self.gold >= land['unlockGold']:
print('开始解锁新土地---》')
self.user_land_unlock(self.land[land_no])
else:
# print('调料包不足以解锁新土地')
self.all_land_unlock = False
else:
message = data.get('message', '')
# 这里应该是日志记录的代码
print('获取账号信息失败[{}]: {}'.format(str(code), message))
except Exception as e:
print(e)
def user_land_unlock(self, land_info):
print(f'解锁土地--->>>')
try:
sign_header = self.gen_sign()
url = f'{self.base_url}/user-land/unlock'
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code == 0:
print(f"[{land_info['no']}号土地]解锁成功---√")
self.gold -= land_info['unlockGold']
self.user_land_get()
else:
message = data.get('message', '')
print(f"[{land_info['no']}号土地]解锁失败[{str(code)}]:{message}")
except Exception as e:
print(e)
def user_land_result(self, land_info):
print(f'收获番茄--->>>')
try:
params = {'no': land_info['no']}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/user-land/result'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
self.refresh_land_step = True
print(f'[{land_info["no"]}号土地]收获成功: 番茄x{data.get("data", 0)}---√')
self.user_land_get()
else:
message = data.get('message', '')
print(f"[{land_info['no']}号土地]收获失败[{str(code)}]: {message}")
except Exception as e:
print(e)
def user_land_sow(self, land_info):
print(f'播种--->>>')
try:
params = {'no': land_info['no']}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/user-land/sow'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
self.refresh_land_step = True
print(f"[{land_info['no']}号土地]种植成功---√")
self.user_land_get()
else:
message = data.get('message', '')
print(f"[{land_info['no']}号土地]种植失败[{str(code)}]: {message}")
except Exception as e:
print(e)
def user_land_sun(self, land_info):
print(f'撒阳光--->>>')
try:
params = {'no': land_info['no']}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/user-land/sun'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
print(f"[{land_info['no']}号土地]撒阳光成功---√")
time.sleep(1)
self.sun -= land_info['needSun']
self.user_land_get()
else:
message = data.get('message', '')
print(f"[{land_info['no']}号土地]撒阳光失败[{str(code)}]:{message}")
except Exception as e:
print(e)
def user_land_level(self, land_info):
print(f'浇水升级--->>>')
try:
params = {'no': land_info['no']}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/user-land/level'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
self.refresh_land_step = True
print(f"[{land_info['no']}号土地]浇水升级成功---√")
self.user_land_get()
else:
message = data.get('message', '')
print(f"[{land_info['no']}号土地]浇水升级失败[{str(code)}]: {message}")
except Exception as e:
print(e)
def take_risk_online(self):
print(f'进入冒险页--->>>')
try:
sign_header = self.gen_sign()
url = f'{self.base_url}/take-risk/online'
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code != 0:
message = data.get('message', '')
print(f'进入冒险页失败{str(code)}: {message}')
else:
print(f'进入冒险页成功---√')
end = data.get('data', {}).get('end', True)
if end == True:
self.need_help_risk = False
except Exception as e:
print(e)
def take_risk_get(self):
print(f'查询冒险次数--->>>')
try:
sign_header = self.gen_sign()
url = f'{self.base_url}/common/take-risk/get'
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code == 0:
self.risk_num = data.get('data', {}).get('num', 0)
if data.get('data', {}).get('complete', False) == False:
self.take_risk_up(data.get('data', {}).get('gameMapEvent'))
print(f"剩余冒险【{self.risk_num}】次")
else:
message = data.get('message', '')
print(f'查询冒险次数失败: {message}' )
except Exception as e:
print(e)
def take_risk_go(self):
print(f'开始冒险--->>>')
try:
sign_header = self.gen_sign()
url = f'{self.base_url}/common/take-risk/go'
response = self.s.get(url, headers=sign_header)
data = response.json()
# print(data)
code = data.get('code', -1)
if code == 0:
self.risk_num = data.get('data', {}).get('num', 0)
if data.get('data', {}).get('complete'):
game_map_event_answer_list = data.get('data', {}).get('gameMapEvent', {}).get(
'gameMapEventAnswerList', [])
filtered_list = filter(lambda x: x.get('dropReward', {}).get('finalNum'),game_map_event_answer_list)
rewards = []
for item in filtered_list:
reward_name = item['dropReward']['name']
final_num = item['dropReward']['finalNum']
rewards.append(f'{reward_name}x{final_num}')
if rewards:
print(f'冒险奖励: {rewards}---√')
else:
print('触发冒险事件没有获取奖励')
else:
# print(data.get('data', {}).get('gameMapEvent'))
self.take_risk_up(data.get('data', {}).get('gameMapEvent'))
elif code == 4000:
slideImgInfo = data.get('data', {}).get('slideImgInfo', None)
validateCount = data.get('data', {}).get('validateCount', None)
if slideImgInfo and validateCount:
print('本次冒险需要验证码')
self.can_go_risk = False
if self.get_CapCode(slideImgInfo):
if self.checkUserCapCode():
self.take_risk_go()
else:
print(f"验证次数上限")
self.can_go_risk = False
else:
message = data.get('message', '')
print(f'冒险失败{code}]: {message}')
if message and '冒险暂停中' in message or code == 4000:
self.can_go_risk = False
except Exception as e:
print(e)
def take_risk_up(self, game_map_event):
print(f'触发冒险事件--->>>')
# try:
gameMapEventAnswerList = game_map_event.get('gameMapEventAnswerList', [])
index = random.randint(0, len(gameMapEventAnswerList) - 1)
gameMapEventAnswer = gameMapEventAnswerList[index]
json_id = gameMapEventAnswer['jsonId']
# print(json_id)
params = {'jsonId': json_id}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/common/take-risk/up'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
self.risk_num = data.get('data', {}).get('num', 0)
print(f'剩余次数:【{self.risk_num}】')
game_map_event_list = data.get('data', {}).get('gameMapEvent', {}).get('gameMapEventAnswerList', [])
reward_list = [event['dropReward']['name'] + 'x' + str(event['dropReward']['finalNum']) for event in
game_map_event_list if event.get('dropReward', {}).get('finalNum')]
if reward_list:
print(f'冒险奖励: {reward_list}---√')
else:
print('触发冒险事件没有获取奖励')
else:
message = data.get('message', '')
print(f'触发冒险事件[ {json_id} ]失败{code}]: {message}')
# except Exception as e:
# print(e)
def take_risk_reward(self):
print(f'领取冒险定时奖励--->>>')
try:
url = f'{self.base_url}/take-risk/reward'
sign_header = self.gen_sign()
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code == 0:
print('领取冒险定时奖励成功---√')
else:
message = data.get('message', '').replace('\r', '').split('\n')
message = ','.join(filter(lambda x: x, message))
print(f'领取冒险定时奖励失败{code}]: {message}')
except Exception as e:
print(e)
def randomString(self,length, chars='abcdef0123456789'):
return ''.join(random.choice(chars) for _ in range(length))
def friend_help_task_risk(self, friend_info):
print('开始冒险互助--->>>')
# try:
params = {
'userId': friend_info['userId'],
'type': 0x1,
'randomId': self.randomString(32, '0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM')
}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/friend-help/help'
response = self.s.get(url, headers=sign_header,params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
if data.get('data'):
self.can_help_risk = False
print(f"冒险助力账号[{friend_info['index']}][{friend_info['name']}]成功---√")
else:
message = data.get('message', '').replace('\r', '').split('\n')
message = ','.join(filter(lambda x: x, message))
print(f"冒险助力账号[{friend_info['index']}][{friend_info['name']}]失败{message}")
if '助力次数' in message:
self.can_help_risk = False
elif '挂机时间已完成' in message:
friend_info['need_help_risk'] = False
# except Exception as e:
# print(e)
def friend_help(self, friend_info):
print(f'开始阳光互助--->>>')
# try:
params = {
'userId': friend_info['userId'],
'type': 0x0,
'randomId': self.randomString(32, '0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM')
}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/friend-help/help'
response = self.s.get(url, headers=sign_header,params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
if data.get('data'):
# print(f"请求助力账号[{friend_info['index']}][{friend_info['name']}] 成功---√")
self.task_doHelpTask(friend_info)
else:
message = data.get('message', '').replace('\r', '').split('\n')
message = ','.join(filter(lambda x: x, message))
print(f"请求助力账号[{friend_info['index']}][{friend_info['name']}] 失败: {message}")
if '助力次数' in message:
self.can_help_task = False
# except Exception as e:
# print(e)
def friend_findRecommend(self):
print(f'查询添加好友列表--->>>')
try:
url = f'{self.base_url}/friend/findRecommend'
sign_header = self.gen_sign()
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code == 0:
print(f'查询添加好友列表成功---√')
for user_info in data.get('data', []):
if not self.can_add_friend:
print('好友已满')
break
# if len(list(filter(lambda user: user['userId'] == user_info['userId'], self.user_list))) > 0:
# continue
self.friend_addFriend(user_info)
# self.friend_deleteFriend(user_info)
else:
message = data.get('message', '')
print(f'查询添加好友列表失败{code}]: {message}')
except Exception as e:
print(e)
def friend_addFriend(self, user_data):
print(f'添加好友--->>>')
try:
friend_user_id = user_data['userId']
params = {'friendUserId': friend_user_id}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/friend/addFriend'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
print(f"添加好友[{user_data['nickName']}]成功---√")
else:
message = data.get('message', '')
print(f'添加好友{user_data["nickName"]}失败{code}]: {message}')
if message and '达到好友上限' in message:
self.can_add_friend = False
except Exception as e:
print(e)
def friend_deleteFriend(self, user_data):
print(f'删除好友--->>>')
try:
friend_user_id = user_data['userId']
params = {'friendUserId': friend_user_id}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/friend/delFriend'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
print(f"删除好友[{user_data['nickName']}]成功---√")
else:
message = data.get('message', '')
print(f'删除好友{user_data["nickName"]}失败{code}]: {message}')
except Exception as e:
print(e)
def friend_findFriend(self):
print(f'\n查询好友列表--->>>')
try:
sign_header = self.gen_sign()
url = f'{self.base_url}/friend/findFriend'
response = self.s.get(url, headers=sign_header)
data = response.json()
code = data.get('code', -1)
if code == 0:
print(f'查询好友列表成功---√')
friend_list = data.get('data', {}).get('friendList', [])
friend_list.sort(key=lambda x: x['gold'], reverse=True)
for friend in friend_list:
if friend.get('stealFlag', False):
if not self.friend_stealGold(friend):
break
else:
message = data.get('message', '')
print(f'查询好友列表失败[{str(code)}]:{message}')
except Exception as e:
print(e)
def get_CapCode(self, slideImgInfo):
slidingImage = slideImgInfo.get('slidingImage', None)
backImage = slideImgInfo.get('backImage', None)
dddddocr_api = os.environ.get('OCR_API',False)
if not dddddocr_api:
print('未定义变量【OCR_API】\n取消验证码识别\n搭建方式:https://github.com/CHERWING/CHERWIN_OCR')
return False
if slidingImage and backImage:
data = {
"slidingImage": slidingImage,
"backImage": backImage
}
response = requests.post(f"{dddddocr_api}/capcode", data=json.dumps(data),headers={'Content-Type': 'application/json'})
print(response.json())
self.capcode = response.json().get('result','')
if self.capcode:
return True
else:
return False
def get_CapCode_local(self, slideImgInfo):
slidingImage = slideImgInfo.get('slidingImage', None)
backImage = slideImgInfo.get('backImage', None)
if slidingImage and backImage:
self.capcode =CHERWIN_TOOLS.CAPCODE(slidingImage,backImage)
if self.capcode:
return True
else:
return False
def friend_stealGold(self, user_data):
print(f'偷取好友--->>>')
# try:
friend_user_id = user_data['userId']
params = {'friendUserId': friend_user_id}
sign_header = self.gen_sign(params)
url = f'{self.base_url}/friend/stealGold'
response = self.s.get(url, headers=sign_header, params=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
print(f"偷取好友[{user_data['nickName']}]: 阳光x{data.get('data', 0)}")
return True
elif code == 4000:
slideImgInfo = data.get('data', {}).get('slideImgInfo', None)
validateCount = data.get('data', {}).get('validateCount', None)
if slideImgInfo and validateCount:
print(f"偷取好友[{user_data['nickName']}],需要滑块验证")
self.can_stealGold = False
if self.get_CapCode(slideImgInfo):
if self.checkUserCapCode():
self.friend_stealGold(user_data)
else:
print(f"偷取好友[{user_data['nickName']}]验证码上限")
self.can_stealGold = False
else:
message = data.get('message', '')
print(f"偷取好友[{user_data['nickName']}]阳光失败[{str(code)}]: {message}")
return False
# except Exception as e:
# print(e)
def checkUserCapCode(self):
print(f'提交验证码--->>>')
# try:
print(f'验证码:{self.capcode}')
params = {'xpos':self.capcode}
print(params)
sign_header = self.gen_sign(body=params)
url = f'{self.base_url}/checkUserCapCode'
response = self.s.post(url, headers=sign_header, json=params)
data = response.json()
code = data.get('code', -1)
if code == 0:
data = data.get('data', 0)
print(f"验证码正确,获取到[{data}]")
return True
else:
message = data.get('message', '')
print(f"验证码错误[{message}]")
return False
# except Exception as e:
# print(e)
def risk_task(self):
self.take_risk_get()
self.take_risk_online()
self.take_risk_reward()
print(f'可以冒险【{self.risk_num}】次')
while self.risk_num > 0 and self.can_go_risk == True:
self.take_risk_go()
time.sleep(2)
def land_task(self):
self.user_land_get()
if self.all_land_unlock and self.all_role_unlock:
pass
for land_number, land_info in self.land.items():
# print(land_number)
# print(land_info)
if land_info['status'] == 0:
continue
step, use_sun_count, left_sun_count = land_info['step'], land_info['useSunCount'], land_info['leftSunCount']
total_sun_count = (use_sun_count if use_sun_count else 0) + (left_sun_count if left_sun_count else 0)
print(f"\n---[{land_info['no']}号土地]---\n{self.group_step[step-1]},阶段{step}, 进度{use_sun_count}/{total_sun_count}")
self.refresh_land_step = True
while self.refresh_land_step:
self.refresh_land_step = False
if land_info['status'] == 0:
break
if step == 0:
self.user_land_sow(land_info)
else:
if left_sun_count == 0:
if step == 5:
self.user_land_result(land_info)
else:
current_time = int(time.time() * 1000)
if current_time >= (land_info['sunTime'] + land_info['sunTimestamp']) * 1000:
self.user_land_level(land_info)
else:
if self.sun >= land_info['needSun']:
current_time = int(time.time() * 1000)
if current_time >= (land_info['sunTime'] + land_info['sunTimestamp']) * 1000:
self.user_land_sun(land_info)
# time.sleep(2)
def userTask(self):
print('\n--------------- 开始日常任务 ---------------')
wait_time = random.randint(1000, 3000) / 1000.0 # 转换为秒
if not self.Login_res:
return False
self.userInfo_autoSun()
self.userInfo_get()