forked from hexstr/FGODailyBonus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
138 lines (115 loc) · 5.23 KB
/
user.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
# coding: utf-8
import uuid
import hashlib
import base64
from urllib.parse import quote_plus
import fgourl
import mytime
class ParameterBuilder:
def __init__(self, uid: str, auth_key: str, secret_key: str):
self.uid_ = uid
self.auth_key_ = auth_key
self.secret_key_ = secret_key
self.content_ = ''
self.parameter_list_ = [
('appVer', fgourl.app_ver_),
('authKey', self.auth_key_),
('dataVer', str(fgourl.data_ver_)),
('dateVer', str(fgourl.date_ver_)),
('idempotencyKey', str(uuid.uuid4())),
('lastAccessTime', str(mytime.GetTimeStamp())),
('userId', self.uid_),
('verCode', fgourl.ver_code_),
]
def AddParameter(self, key: str, value: str):
self.parameter_list_.append((key, value))
def Build(self) -> str:
self.parameter_list_.sort(key=lambda tup: tup[0])
temp = ''
for first, second in self.parameter_list_:
if temp:
temp += '&'
self.content_ += '&'
escaped_key = quote_plus(first)
if not second:
temp += first + '='
self.content_ += escaped_key + '='
else:
escaped_value = quote_plus(second)
temp += first + '=' + second
self.content_ += escaped_key + '=' + escaped_value
temp += ':' + self.secret_key_
self.content_ += '&authCode=' + quote_plus(base64.b64encode(hashlib.sha1(temp.encode('utf-8')).digest()))
return self.content_
def Clean(self):
self.content_ = ''
self.parameter_list_ = [
('appVer', fgourl.app_ver_),
('authKey', self.auth_key_),
('dataVer', str(fgourl.data_ver_)),
('dateVer', str(fgourl.date_ver_)),
('idempotencyKey', str(uuid.uuid4())),
('lastAccessTime', str(mytime.GetTimeStamp())),
('userId', self.uid_),
('verCode', fgourl.ver_code_),
]
class user:
def __init__(self, user_id: str, auth_key: str, secret_key: str):
self.name_ = ''
self.user_id_ = (int)(user_id)
self.s_ = fgourl.NewSession()
self.builder_ = ParameterBuilder(user_id, auth_key, secret_key)
def Post(self, url):
res = fgourl.PostReq(self.s_, url, self.builder_.Build())
self.builder_.Clean()
return res
def topLogin(self):
lastAccessTime = self.builder_.parameter_list_[5][1]
userState = (-int(lastAccessTime) >> 2) ^ self.user_id_ & fgourl.data_server_folder_crc_
self.builder_.AddParameter('assetbundleFolder', fgourl.asset_bundle_folder_)
self.builder_.AddParameter('isTerminalLogin', '1')
self.builder_.AddParameter('userState', str(userState))
data = self.Post(f'{fgourl.server_addr_}/login/top?_userId={self.user_id_}')
self.name_ = hashlib.md5(data['cache']['replaced']['userGame'][0]['name'].encode('utf-8')).hexdigest()
stone = data['cache']['replaced']['userGame'][0]['stone']
lv = data['cache']['replaced']['userGame'][0]['lv']
ticket = 0
# 呼符
for item in data['cache']['replaced']['userItem']:
if item['itemId'] == 4001:
ticket = item['num']
break
# 登陆天数
login_days = data['cache']['updated']['userLogin'][0]['seqLoginCount']
total_days = data['cache']['updated']['userLogin'][0]['totalLoginCount']
res = f'*{self.name_}*\n`登陆天数: {login_days}天 / {total_days}天\n'
# 角色信息
res += f'等级: {lv}\n石头: {stone}\n呼符: {ticket}\n'
# 现有体力
act_max = data['cache']['replaced']['userGame'][0]['actMax']
act_recover_at = data['cache']['replaced']['userGame'][0]['actRecoverAt']
now_act = (act_max - (act_recover_at - mytime.GetTimeStamp()) / 300)
res += f'体力: {now_act} / {act_max}\n'
# 友情点
add_fp = data['response'][0]['success']['addFriendPoint']
total_fp = data['cache']['replaced']['tblUserGame'][0]['friendPoint']
res += f'友情点: {add_fp} / {total_fp}`\n'
# 登陆奖励
if 'seqLoginBonus' in data['response'][0]['success']:
bonus_message = data['response'][0]['success']['seqLoginBonus'][0]['message']
res += f'*{bonus_message}*\n`'
for i in data['response'][0]['success']['seqLoginBonus'][0]['items']:
res += f'{i["name"]} X {i["num"]}\n'
if 'campaignbonus' in data['response'][0]['success']:
bonus_name = data['response'][0]['success']['campaignbonus'][0]['name']
bonus_detail = data['response'][0]['success']['campaignbonus'][0]['detail']
res += f'`*{bonus_name}*\n*{bonus_detail}*\n`'
for i in data['response'][0]['success']['campaignbonus'][0]['items']:
res += f'{i["name"]} X {i["num"]}\n'
res += '`'
server_now_time = mytime.TimeStampToString(data['cache']['serverTime'])
res += f'_{server_now_time}_\n--------\n'
print(res)
return res
def topHome(self):
self.Post(f'{fgourl.server_addr_}/home/top?_userId={self.user_id_}')