-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathxmsq.py
285 lines (266 loc) · 12.9 KB
/
xmsq.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
"""
小米社区 v1.0
任务:日常任务
export xiaomi="账户&密码" 多账户 # 分割
cron: 5 9,15,20 * * *
const $ = new Env("小米社区");
"""
import os
import sys
import requests
import json
import hashlib
import base64
import binascii
import time
class XiaomiSign:
# 初始化
def __init__(self, account, password):
self.account = account
self.password = password
self.userId = None
self.cookie = None
self.html_user = None
# 获取cookie
def get_cookie(self, account, password):
md5 = hashlib.md5()
md5.update(password.encode())
Hash = md5.hexdigest()
url = "https://account.xiaomi.com/pass/serviceLoginAuth2"
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 12; M2007J17C Build/SKQ1.211006.001) APP/xiaomi.vipaccount APPV/220301 MK/UmVkbWkgTm90ZSA5IFBybw== PassportSDK/3.7.8 passport-ui/3.7.8",
"Cookie": "deviceId=X0jMu7b0w-jcne-S; pass_o=2d25bb648d023d7f; sdkVersion=accountsdk-2020.01.09",
"Host": "account.xiaomi.com",
"Connection": "Keep-Alive",
"Accept-Encoding": "gzip"
}
data = {
"cc": "+86",
"qs": "%3F_json%3Dtrue%26sid%3Dmiui_vip%26_locale%3Dzh_CN",
"callback": "https://api.vip.miui.com/sts",
"_json": "true",
"user": account,
"hash": Hash.upper(),
"sid": "miui_vip",
"_sign": "ZJxpm3Q5cu0qDOMkKdWYRPeCwps%3D",
"_locale": "zh_CN"
}
Auth = requests.post(url=url, headers=headers, data=data).text.replace("&&&START&&&", "")
Auth = json.loads(Auth)
ssecurity = Auth["ssecurity"]
nonce = Auth["nonce"]
sha1 = hashlib.sha1()
Str = "nonce=" + str(nonce) + "&" + ssecurity
sha1.update(Str.encode("utf-8"))
clientSign = base64.encodebytes(binascii.a2b_hex(sha1.hexdigest().encode("utf-8"))).decode(encoding="utf-8").strip()
nurl = Auth["location"] + "&_userIdNeedEncrypt=true&clientSign=" + clientSign
sts = requests.get(url=nurl)
cookies = requests.utils.dict_from_cookiejar(sts.cookies)
cookie_str = '; '.join([f'{key}={value}' for key, value in cookies.items()])
return cookie_str
# 签到任务
def sign_in(self):
max_retries = 10
retries = 0
while retries < max_retries:
cookie = self.get_cookie(self.account, self.password)
self.cookie = cookie
url = 'https://api.vip.miui.com/mtop/planet/vip/user/checkin'
headers = {
'Host': 'api.vip.miui.com',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 10; zh-cn; M2007J1SC Build/RKQ1.200826.002) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.116 Mobile Safari/537.36 XiaoMi/MiuiBrowser/15.7.22 app/vipaccount',
'Accept': '*/*',
'Origin': 'https://web.vip.miui.com',
'X-Requested-With': 'com.xiaomi.vipaccount',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://web.vip.miui.com/page/info/mio/mio/checkIn?app_version=dev.220804',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': f'{cookie}'
}
user_url = 'https://api.vip.miui.com/api/community/user/home/page'
html = requests.get(url=url, headers=headers)
html_user = requests.get(url=user_url, headers=headers)
self.html_user = html_user
result = json.loads(html.text)
try:
result_user = json.loads(html_user.text)
userId = result_user['entity']['userId']
self.userId = userId
return '⚠️签到失败'
#print('✅' + result['message'])
#print('✅userId | ' + userId + ' 用户名 | ' + result_user['entity']['userName'] + ' 段位 | ' + result_user['entity']['userGrowLevelInfo']['showLevel'])
break
except KeyError:
retries += 1
time.sleep(3)
# 点赞任务
def like_post(self):
for _ in range(2):
like_url = 'https://api.vip.miui.com/mtop/planet/vip/content/announceThumbUp'
headers = {
'Host': 'api.vip.miui.com',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 10; zh-cn; M2007J1SC Build/RKQ1.200826.002) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.116 Mobile Safari/537.36 XiaoMi/MiuiBrowser/15.7.22 app/vipaccount',
'Accept': '*/*',
'Origin': 'https://web.vip.miui.com',
'X-Requested-With': 'com.xiaomi.vipaccount',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://web.vip.miui.com/page/info/mio/mio/checkIn?app_version=dev.220804',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': f'{self.cookie}'
}
data = {
'postId': '36625780',
'sign': '36625780',
'timestamp': int(round(time.time() * 1000))
}
response = requests.get(url=like_url, headers=headers, params=data)
result = json.loads(response.text)
if result['status'] == 200:
return '✅点赞帖子成功'
else:
return '⚠️点赞帖子失败'
# 加入圈子
def join_group(self):
unfollow_url = 'https://api.vip.miui.com/api/community/board/unfollow?boardId=558495'
headers = {
'Host': 'api.vip.miui.com',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 10; zh-cn; M2007J1SC Build/RKQ1.200826.002) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.116 Mobile Safari/537.36 XiaoMi/MiuiBrowser/15.7.22 app/vipaccount',
'Accept': '*/*',
'Origin': 'https://web.vip.miui.com',
'X-Requested-With': 'com.xiaomi.vipaccount',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://web.vip.miui.com/page/info/mio/mio/checkIn?app_version=dev.220804',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': f'{self.cookie}'
}
response_unfollow = requests.get(url=unfollow_url, headers=headers)
result_unfollow = json.loads(self.html_user.text)
if result_unfollow['status']==200:
unfollow_message = '✅退出圈子成功'
else:
unfollow_message = '⚠️退出圈子失败'
follow_url = 'https://api.vip.miui.com/api/community/board/follow?boardId=558495'
response_follow = requests.get(url=follow_url, headers=headers)
result_follow = json.loads(self.html_user.text)
if result_follow['status']==200:
follow_message = '✅加入圈子成功'
else:
follow_message = '⚠️加入圈子失败'
# 返回
return f'{unfollow_message}\n{follow_message}'
# 浏览主页
def browse_home(self):
info_url = f'https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByAction?userId={self.userId}&action=BROWSE_SPECIAL_PAGES_USER_HOME'
headers = {
'Host': 'api.vip.miui.com',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 10; zh-cn; M2007J1SC Build/RKQ1.200826.002) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.116 Mobile Safari/537.36 XiaoMi/MiuiBrowser/15.7.22 app/vipaccount',
'Accept': '*/*',
'Origin': 'https://web.vip.miui.com',
'X-Requested-With': 'com.xiaomi.vipaccount',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://web.vip.miui.com/page/info/mio/mio/checkIn?app_version=dev.220804',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': f'{self.cookie}'
}
response = requests.get(url=info_url, headers=headers)
result = json.loads(response.text)
if result['status'] == 200:
return '✅浏览主页成功,获得积分: '+str(result['entity']['score'])
else:
return '⚠️今日已达上限'
# 浏览专题
def browse_special_pages(self):
llzt_url = f'https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByAction?userId={self.userId}&action=BROWSE_SPECIAL_PAGES_SPECIAL_PAGE'
headers = {
'Host': 'api.vip.miui.com',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 10; zh-cn; M2007J1SC Build/RKQ1.200826.002) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.116 Mobile Safari/537.36 XiaoMi/MiuiBrowser/15.7.22 app/vipaccount',
'Accept': '*/*',
'Origin': 'https://web.vip.miui.com',
'X-Requested-With': 'com.xiaomi.vipaccount',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://web.vip.miui.com/page/info/mio/mio/checkIn?app_version=dev.220804',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': f'{self.cookie}'
}
response = requests.get(url=llzt_url, headers=headers)
result = json.loads(response.text)
if result['status'] == 200:
return '✅浏览主页成功,获得积分: '+str(result['entity']['score'])
else:
return '⚠️今日已达上限'
# 浏览帖子
def browse_posts(self):
for _ in range(3):
watch_url = f'https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByAction?userId={self.userId}&action=BROWSE_POST_10S'
headers = {
'Host': 'api.vip.miui.com',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 10; zh-cn; M2007J1SC Build/RKQ1.200826.002) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.116 Mobile Safari/537.36 XiaoMi/MiuiBrowser/15.7.22 app/vipaccount',
'Accept': '*/*',
'Origin': 'https://web.vip.miui.com',
'X-Requested-With': 'com.xiaomi.vipaccount',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://web.vip.miui.com/page/info/mio/mio/checkIn?app_version=dev.220804',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': f'{self.cookie}'
}
response = requests.get(url=watch_url, headers=headers)
result = json.loads(response.text)
if result['status'] == 200:
return '✅浏览主页成功,获得积分: '+str(result['entity']['score'])
else:
return '⚠️今日已达上限'
def run(self):
self.sign_in()
# 任务列表
tasks = [
("签到任务", self.sign_in),
("点赞任务", self.like_post),
("加入圈子", self.join_group),
("浏览主页", self.browse_home),
("浏览专题", self.browse_special_pages),
("浏览帖子", self.browse_posts)
]
# 执行任务
for task_name, task_function in tasks:
print(f'🔁{self.userId} | 正在执行任务 | {task_name}')
result = task_function()
print(result)
time.sleep(5)
print('*****************************************')
if __name__ == '__main__':
print('🔔小米社区 | 开始')
#检测账户变量
xiaomi_accounts = os.environ.get("xiaomi")
if not xiaomi_accounts or "&" not in xiaomi_accounts:
sys.exit("⚠️未发现有效账号,退出程序!")
#分割账户
accounts = [acc.split('&') for acc in xiaomi_accounts.split('#')]
# 遍历账户列表 | 为每个账户创建一个类实例并执行任务
for account, password in accounts:
xiaomi_signer = XiaomiSign(account, password)
xiaomi_signer.run()