前言

  • 不是原创,提前申明,我是转载了来的,现在正在学习Python,所以遇到了正要研究一下,测试后发现居然还可以使用,所以需要的可以直接拿走了!
  • 转载来的论坛发现很多人不会用,我这里就拿宝塔Linux面板为例!

代码

# -*- coding: utf8 -*-
# python >=3.8
 
import requests,time,re,json,random
 
now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
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)"
        }
    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)
    location = r1.headers["Location"]
    try:
        code = get_code(location)
    except:
        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()
    login_token = r2["token_info"]["login_token"]
    #print("login_token获取成功!")
    #print(login_token)
    userid = r2["token_info"]["user_id"]
    #print("userid获取成功!")
    #print(userid)
  
    return login_token,userid
  
#主函数
def main_handle(user, passwd, step, sckey):
    user = str(user)
    password = str(passwd)
    step = str(step)
    if user == '' or password == '':
        print ("用户名或密码填写有误!")
        return
   
    if step == '':
        print ("已设置为随机步数(10000-19999)")
        step = str(random.randint(10000,19999))
    login_token = 0
    login_token,userid = login(user,password)
    if login_token == 0:
        print("登陆失败!")
        return "login fail!"
  
    t = get_time()
  
    app_token = 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%2FVv%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F0v%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F9e%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F0n%5C%2Fa%5C%2F%5C%2F%5C%2FS%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F0b%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F1FK%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2FR%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F9PTFFpaf9L%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2FR%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F0j%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F%5C%2F9K%5C%2F%5C%2F%5C%2F%5C%2F%5C%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%22src%22%3A24%7D%5D%2C%22summary%22%3A%22%7B%5C%22v%5C%22%3A6%2C%5C%22slp%5C%22%3A%7B%5C%22st%5C%22%3A1597349880%2C%5C%22ed%5C%22%3A1597369860%2C%5C%22dp%5C%22%3A39%2C%5C%22lt%5C%22%3A294%2C%5C%22wk%5C%22%3A0%2C%5C%22usrSt%5C%22%3A-1440%2C%5C%22usrEd%5C%22%3A-1440%2C%5C%22wc%5C%22%3A0%2C%5C%22is%5C%22%3A169%2C%5C%22lb%5C%22%3A10%2C%5C%22to%5C%22%3A23%2C%5C%22dt%5C%22%3A0%2C%5C%22rhr%5C%22%3A58%2C%5C%22ss%5C%22%3A69%2C%5C%22stage%5C%22%3A%5B%7B%5C%22start%5C%22%3A1698%2C%5C%22stop%5C%22%3A1711%2C%5C%22mode%5C%22%3A4%7D%2C%7B%5C%22start%5C%22%3A1712%2C%5C%22stop%5C%22%3A1728%2C%5C%22mode%5C%22%3A5%7D%2C%7B%5C%22start%5C%22%3A1729%2C%5C%22stop%5C%22%3A1818%2C%5C%22mode%5C%22%3A4%7D%2C%7B%5C%22start%5C%22%3A1819%2C%5C%22stop%5C%22%3A1832%2C%5C%22mode%5C%22%3A5%7D%2C%7B%5C%22start%5C%22%3A1833%2C%5C%22stop%5C%22%3A1920%2C%5C%22mode%5C%22%3A4%7D%2C%7B%5C%22start%5C%22%3A1921%2C%5C%22stop%5C%22%3A1928%2C%5C%22mode%5C%22%3A5%7D%2C%7B%5C%22start%5C%22%3A1929%2C%5C%22stop%5C%22%3A2030%2C%5C%22mode%5C%22%3A4%7D%5D%7D%2C%5C%22stp%5C%22%3A%7B%5C%22ttl%5C%22%3A125%2C%5C%22dis%5C%22%3A82%2C%5C%22cal%5C%22%3A5%2C%5C%22wk%5C%22%3A7%2C%5C%22rn%5C%22%3A0%2C%5C%22runDist%5C%22%3A23%2C%5C%22runCal%5C%22%3A3%7D%2C%5C%22goal%5C%22%3A8000%2C%5C%22tz%5C%22%3A%5C%2228800%5C%22%2C%5C%22sn%5C%22%3A%5C%22e716882f93da%5C%22%7D%22%2C%22source%22%3A24%2C%22type%22%3A0%7D%5D'
  
    finddate = re.compile(r'.*?date%22%3A%22(.*?)%22%2C%22data.*?')
    findstep = re.compile(r'.*?ttl%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}'
    head = {
        "apptoken": app_token,
        "Content-Type": "application/x-www-form-urlencoded"
        }
  
    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)
    result = f"[{now}] 修改步数({step})"+ response['message']
    print(result)
    push_wx(sckey, result)
    return result
   
#获取时间戳
def get_time():
    url = 'http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp'
    response = requests.get(url,headers=headers).json()
    t = response['data']['t']
    return t
   
#获取app_token
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)
    return app_token
   
# 推送server
def push_wx(sckey, desp=""):
    """
    推送消息到微信
    """
    if sckey == '':
        print("[注意] 未提供sckey,不进行推送!")
    else:
        server_url = f"https://sc.ftqq.com/{sckey}.send"
        params = {
            "text": '小米运动 步数修改',
            "desp": desp
        }
  
        response = requests.get(server_url, params=params)
        json_data = response.json()
  
        if json_data['errno'] == 0:
            print(f"[{now}] 推送成功。")
        else:
            print(f"[{now}] 推送失败:{json_data['errno']}({json_data['errmsg']})")

#这里输入Server酱申请到的key
sckey = 0
if str(sckey) == '0':
     sckey = ''
# 用户名(格式为 13800138000)
user = '17765078970'
# 登录密码
passwd = '52pojie'
# 要修改的步数,直接输入想要修改的步数值,留空为随机步数
step = str(8888+random.randint(987,8732) )
setp_array = step.split('-')
if len(setp_array) == 2:
    step = str(random.randint(int(setp_array[0]),int(setp_array[1])))
elif str(step) == '0':
     step = ''
main_handle(user, passwd, step, sckey)

需要的东西

  1. 一台服务器,随意,只要能运行宝塔即可。
  2. 已经安装好了宝塔,这里就不赘述宝塔咋安装了,需要的请自行跳转官网
  3. 申请Server酱,不知道的,可以往下看,有介绍。
  4. 通过宝塔安装py运行环境等等,博客里面有帖子会说道。
  5. 测试py是否可以正常运行。
  6. 设置计划每天来执行一次。

Server酱

就是说下Server是什么

这里就是得到的SendKey

宝塔运行Py

这里会有一个单独帖子说明

测试Py项目运行

显示的结果

设置每天计划

计划页面

cd /www/wwwroot/Python
source 小米刷步_venv/bin/activate
python xiaomi.py

注意,小米刷步,这里是我自己命名的任务名,你这里按照你自己填写的来。还有xiaomi.py这个也是一样的!

总结

具体也就这样了,已经够清楚了,还有不明白的,可以留言看看能不能解决!

最后修改:2021 年 04 月 18 日
如果觉得我的文章对你有用,请随意赞赏