This commit is contained in:
Leon 2021-08-10 18:26:57 +08:00
parent d478758b92
commit cb54dcc13f

View File

@ -41,9 +41,9 @@ def get_code(location):
return code return code
# 登录 # 登录
def login(_user, password): def login(user,password):
url1 = "https://api-user.huami.com/registrations/+86" + _user + "/tokens" url1 = "https://api-user.huami.com/registrations/+86" + user + "/tokens"
_headers = { headers = {
"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8", "Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",
"User-Agent":"MiFit/4.6.0 (iPhone; iOS 14.0.1; Scale/2.00)" "User-Agent":"MiFit/4.6.0 (iPhone; iOS 14.0.1; Scale/2.00)"
} }
@ -53,9 +53,9 @@ def login(_user, password):
"redirect_uri":"https://s3-us-west-2.amazonaws.com/hm-registration/successsignin.html", "redirect_uri":"https://s3-us-west-2.amazonaws.com/hm-registration/successsignin.html",
"token":"access" "token":"access"
} }
r1 = requests.post(url1, data=data1, headers=_headers, allow_redirects=False) r1 = requests.post(url1,data=data1,headers=headers,allow_redirects=False)
try:
location = r1.headers["Location"] location = r1.headers["Location"]
try:
code = get_code(location) code = get_code(location)
except: except:
return 0,0 return 0,0
@ -73,7 +73,7 @@ def login(_user, password):
"grant_type":"access_token", "grant_type":"access_token",
"third_name":"huami_phone", "third_name":"huami_phone",
} }
r2 = requests.post(url2, data=data2, headers=_headers).json() r2 = requests.post(url2,data=data2,headers=headers).json()
login_token = r2["token_info"]["login_token"] login_token = r2["token_info"]["login_token"]
#print("login_token获取成功") #print("login_token获取成功")
#print(login_token) #print(login_token)
@ -84,18 +84,19 @@ def login(_user, password):
return login_token,userid return login_token,userid
# 主函数 # 主函数
def main(_user, _passwd, _step): def main(user, passwd, step):
_user = str(_user) user = str(user)
password = str(_passwd) password = str(passwd)
_step = str(_step) step = str(step)
if _user == '' or password == '': if user == '' or password == '':
print("用户名或密码不能为空!") print("用户名或密码不能为空!")
return "user and passwd not empty" return "user and passwd not empty"
if _step == '': if step == '':
print ("已设置为随机步数18000-25000") print ("已设置为随机步数18000-25000")
_step = str(random.randint(18000, 25000)) step = str(random.randint(18000,25000))
login_token, userid = login(_user, password) login_token = 0
login_token,userid = login(user,password)
if login_token == 0: if login_token == 0:
print("登陆失败!") print("登陆失败!")
return "login fail!" return "login fail!"