mirror of https://github.com/yuxian158/check.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
20 KiB
119 lines
20 KiB
3 years ago
|
# -*- coding: utf8 -*-
|
||
|
"""
|
||
|
new Env('小米运动');
|
||
|
"""
|
||
|
from utils import check
|
||
|
import random
|
||
|
import re
|
||
|
import time
|
||
|
|
||
|
import requests
|
||
|
|
||
|
|
||
|
class MiMotion:
|
||
|
name = "小米运动"
|
||
|
|
||
|
def __init__(self, check_item):
|
||
|
self.check_item = check_item
|
||
|
self.headers = {"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 9; MI 6 MIUI/20.6.18)"}
|
||
|
|
||
|
def get_time(self):
|
||
|
url = "http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp"
|
||
|
response = requests.get(url, headers=self.headers).json()
|
||
|
t = response["data"]["t"]
|
||
|
return t
|
||
|
|
||
|
def get_app_token(self, login_token):
|
||
|
url = f"https://account-cn.huami.com/v1/client/app_tokens?app_name=com.xiaomi.hm.health&dn=api-user.huami.com%2Capi-mifit.huami.com%2Capp-analytics.huami.com&login_token={login_token}"
|
||
|
response = requests.get(url=url, headers=self.headers).json()
|
||
|
app_token = response["token_info"]["app_token"]
|
||
|
return app_token
|
||
|
|
||
|
@staticmethod
|
||
|
def login(phone, password):
|
||
|
url1 = f"https://api-user.huami.com/registrations/+86{phone}/tokens"
|
||
|
headers = {
|
||
|
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
||
|
"User-Agent": "MiFit/4.6.0 (iPhone; iOS 14.0.1; Scale/2.00)",
|
||
|
}
|
||
|
data1 = {
|
||
|
"client_id": "HuaMi",
|
||
|
"password": f"{password}",
|
||
|
"redirect_uri": "https://s3-us-west-2.amazonaws.com/hm-registration/successsignin.html",
|
||
|
"token": "access",
|
||
|
}
|
||
|
r1 = requests.post(url=url1, data=data1, headers=headers, allow_redirects=False)
|
||
|
location = r1.headers["Location"]
|
||
|
try:
|
||
|
code_pattern = re.compile("(?<=access=).*?(?=&)")
|
||
|
code = code_pattern.findall(location)[0]
|
||
|
except Exception as e:
|
||
|
print(e)
|
||
|
return 0, 0
|
||
|
url2 = "https://account.huami.com/v2/client/login"
|
||
|
data2 = {
|
||
|
"app_name": "com.xiaomi.hm.health",
|
||
|
"app_version": "5.0.2",
|
||
|
"code": f"{code}",
|
||
|
"country_code": "CN",
|
||
|
"device_id": "10E2A98F-D36F-4DF1-A7B9-3FBD8FBEB800",
|
||
|
"device_model": "phone",
|
||
|
"grant_type": "access_token",
|
||
|
"third_name": "huami_phone",
|
||
|
}
|
||
|
r2 = requests.post(url=url2, data=data2, headers=headers).json()
|
||
|
login_token = r2["token_info"]["login_token"]
|
||
|
userid = r2["token_info"]["user_id"]
|
||
|
return login_token, userid
|
||
|
|
||
|
def main(self):
|
||
|
phone = str(self.check_item.get("phone"))
|
||
|
password = str(self.check_item.get("password"))
|
||
|
try:
|
||
|
min_step = int(self.check_item.get("min_step", 10000))
|
||
|
except Exception as e:
|
||
|
print("初始化步数失败: 已将最小值设置为 19999", e)
|
||
|
min_step = 10000
|
||
|
try:
|
||
|
max_step = int(self.check_item.get("max_step", 19999))
|
||
|
except Exception as e:
|
||
|
print("初始化步数失败: 已将最大值设置为 19999", e)
|
||
|
max_step = 19999
|
||
|
step = str(random.randint(min_step, max_step))
|
||
|
login_token, userid = self.login(phone, password)
|
||
|
if login_token == 0:
|
||
|
msg = [
|
||
|
{"name": "帐号信息", "value": f"{phone[:4]}****{phone[-4:]}"},
|
||
|
{"name": "修改信息", "value": f"登陆失败"},
|
||
|
]
|
||
|
else:
|
||
|
t = self.get_time()
|
||
|
app_token = self.get_app_token(login_token)
|
||
|
today = time.strftime("%F")
|
||
|
data_json = "%5B%7B%22data_hr%22%3A%22%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F9L%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2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5C%22%3A(.*?)%2C%5C%22dis.*?")
|
||
|
data_json = re.sub(finddate.findall(data_json)[0], today, str(data_json))
|
||
|
data_json = re.sub(findstep.findall(data_json)[0], step, str(data_json))
|
||
|
url = f"https://api-mifit-cn.huami.com/v1/data/band_data.json?&t={t}"
|
||
|
headers = {"apptoken": app_token, "Content-Type": "application/x-www-form-urlencoded"}
|
||
|
data = f"userid={userid}&last_sync_data_time=1628256960&device_type=0&last_deviceid=C4BDB6FFFE2BCA4C&data_json={data_json}"
|
||
|
response = requests.post(url=url, data=data, headers=headers).json()
|
||
|
msg = [
|
||
|
{"name": "帐号信息", "value": f"{phone[:4]}****{phone[-4:]}"},
|
||
|
{"name": "修改信息", "value": f"{response['message']}"},
|
||
|
{"name": "修改步数", "value": f"{step}"},
|
||
|
]
|
||
|
msg = "\n".join([f"{one.get('name')}: {one.get('value')}" for one in msg])
|
||
|
return msg
|
||
|
|
||
|
|
||
|
@check(run_script_name="小米运动",run_script_expression="MIMOTION")
|
||
|
def main(*args, **kwargs):
|
||
|
return MiMotion(check_item=kwargs.get("value")).main()
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|
||
|
|