🔨
This commit is contained in:
parent
d478758b92
commit
cb54dcc13f
@ -32,70 +32,71 @@ shanghai_time = datetime.now(tz=shanghai)
|
||||
now = shanghai_time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
headers = {
|
||||
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9; MI 6 MIUI/20.6.18)'
|
||||
}
|
||||
}
|
||||
|
||||
# 获取登录 code
|
||||
def get_code(location):
|
||||
code_pattern = re.compile("(?<=access=).*?(?=&)")
|
||||
code = code_pattern.findall(location)[0]
|
||||
return code
|
||||
|
||||
|
||||
# 登录
|
||||
def login(_user, password):
|
||||
url1 = "https://api-user.huami.com/registrations/+86" + _user + "/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)"
|
||||
}
|
||||
def login(user,password):
|
||||
url1 = "https://api-user.huami.com/registrations/+86" + user + "/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(url1, data=data1, headers=_headers, allow_redirects=False)
|
||||
"client_id":"HuaMi",
|
||||
"password":f"{password}",
|
||||
"redirect_uri":"https://s3-us-west-2.amazonaws.com/hm-registration/successsignin.html",
|
||||
"token":"access"
|
||||
}
|
||||
r1 = requests.post(url1,data=data1,headers=headers,allow_redirects=False)
|
||||
location = r1.headers["Location"]
|
||||
try:
|
||||
location = r1.headers["Location"]
|
||||
code = get_code(location)
|
||||
except:
|
||||
return 0, 0
|
||||
# print("access_code获取成功!")
|
||||
# print(code)
|
||||
|
||||
return 0,0
|
||||
#print("access_code获取成功!")
|
||||
#print(code)
|
||||
|
||||
url2 = "https://account.huami.com/v2/client/login"
|
||||
data2 = {
|
||||
"app_name": "com.xiaomi.hm.health",
|
||||
"app_version": "4.6.0",
|
||||
"code": f"{code}",
|
||||
"country_code": "CN",
|
||||
"device_id": "2C8B4939-0CCD-4E94-8CBA-CB8EA6E613A1",
|
||||
"device_model": "phone",
|
||||
"grant_type": "access_token",
|
||||
"third_name": "huami_phone",
|
||||
}
|
||||
r2 = requests.post(url2, data=data2, headers=_headers).json()
|
||||
"app_name":"com.xiaomi.hm.health",
|
||||
"app_version":"4.6.0",
|
||||
"code":f"{code}",
|
||||
"country_code":"CN",
|
||||
"device_id":"2C8B4939-0CCD-4E94-8CBA-CB8EA6E613A1",
|
||||
"device_model":"phone",
|
||||
"grant_type":"access_token",
|
||||
"third_name":"huami_phone",
|
||||
}
|
||||
r2 = requests.post(url2,data=data2,headers=headers).json()
|
||||
login_token = r2["token_info"]["login_token"]
|
||||
# print("login_token获取成功!")
|
||||
# print(login_token)
|
||||
#print("login_token获取成功!")
|
||||
#print(login_token)
|
||||
userid = r2["token_info"]["user_id"]
|
||||
# print("userid获取成功!")
|
||||
# print(userid)
|
||||
|
||||
return login_token, userid
|
||||
|
||||
#print("userid获取成功!")
|
||||
#print(userid)
|
||||
|
||||
return login_token,userid
|
||||
|
||||
# 主函数
|
||||
def main(_user, _passwd, _step):
|
||||
_user = str(_user)
|
||||
password = str(_passwd)
|
||||
_step = str(_step)
|
||||
if _user == '' or password == '':
|
||||
def main(user, passwd, step):
|
||||
user = str(user)
|
||||
password = str(passwd)
|
||||
step = str(step)
|
||||
if user == '' or password == '':
|
||||
print("用户名或密码不能为空!")
|
||||
return "user and passwd not empty!"
|
||||
|
||||
if _step == '':
|
||||
print("已设置为随机步数(18000-25000)")
|
||||
_step = str(random.randint(18000, 25000))
|
||||
login_token, userid = login(_user, password)
|
||||
|
||||
if step == '':
|
||||
print ("已设置为随机步数(18000-25000)")
|
||||
step = str(random.randint(18000,25000))
|
||||
login_token = 0
|
||||
login_token,userid = login(user,password)
|
||||
if login_token == 0:
|
||||
print("登陆失败!")
|
||||
return "login fail!"
|
||||
@ -122,7 +123,7 @@ def main(_user, _passwd, _step):
|
||||
data = f'userid={userid}&last_sync_data_time=1597306380&device_type=0&last_deviceid=DA932FFFFE8816E7&data_json={data_json}'
|
||||
|
||||
response = requests.post(url, data=data, headers=head).json()
|
||||
# print(response)
|
||||
#print(response)
|
||||
result = f"{user[:4]}****{user[-4:]}: [{now}] 修改步数({step})"+ response['message']
|
||||
print(result)
|
||||
return result
|
||||
@ -139,8 +140,8 @@ def get_app_token(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,headers=headers).json()
|
||||
app_token = response['token_info']['app_token']
|
||||
# print("app_token获取成功!")
|
||||
# print(app_token)
|
||||
#print("app_token获取成功!")
|
||||
#print(app_token)
|
||||
return app_token
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user