用 Python 修改微信(支付寶)運動步數(shù),每天輕松 TOP1!

作者:Tsubasa_Ou
來源:https://blog.csdn.net/jiangfan2017/article/details/108984940
文末有獲取源碼方式
1、項目意義
如果你想在支付寶螞蟻森林收集很多能量種樹,為環(huán)境綠化出一份力量,又或者是想每天稱霸微信運動排行榜裝逼,卻不想出門走路,那么該 Python 腳本可以幫你實現(xiàn)。
2、實現(xiàn)方法
手機安裝第三方軟件樂心健康,注冊賬號登錄,將運動數(shù)據(jù)同步到微信和支付寶。用python腳本遠程修改樂心健康當前登錄賬號的步數(shù)即可。
第一步:在手機上安裝樂心健康app。

安卓版下載地址:
http://app.mi.com/details?id=gz.lifesense.weidong
蘋果版下載地址:
https://apps.apple.com/us/app/lifesense-health/id1479525632
第二步:注冊賬號登錄,并設(shè)置登錄密碼。
第三步:完成第三方同步,將運動數(shù)據(jù)同步到微信和支付寶。
第四步:運行python腳本,修改樂心健康步數(shù)。



Python 代碼
程序設(shè)定是每天7點自動修改步數(shù),在下面腳本對應(yīng)的位置替換填入樂心健康手機號、樂心健康密碼、修改步數(shù)(默認為60000),然后運行程序。修改步數(shù)推薦設(shè)置范圍是30000至90000,步數(shù)值太大會導(dǎo)致修改不成功。如果想改變第二天自動修改步數(shù)的時間,請修改圖示位置的25200,+25200代表第二天0點后加上的秒數(shù),也就是7x60x60,即7小時,根據(jù)自己的需要修改即可。如果每天都要修改步數(shù),那么讓程序一直保持運行即可。
注意:運行程序會立刻修改當天的步數(shù),自動修改步數(shù)是從程序保持運行的第二天開始。


change_step.py
# -*- coding: utf-8 -*-
import requests
import json
import hashlib
import time
import datetime
class LexinSport:
def __init__(self, phone, password, step):
# 手機號
self.phone = phone
# 密碼
self.password = password
# 修改步數(shù)
self.step = step
# 用戶id
self.user_id = ''
# 訪問令牌
self.access_token = ''
# 登錄
def login(self):
url = 'https://sports.lifesense.com/sessions_service/login?systemType=2&version=4.6.7'
data = {'loginName': self.phone, 'password': hashlib.md5(self.password.encode('utf8')).hexdigest(),
'clientId': '49a41c9727ee49dda3b190dc907850cc', 'roleType': 0, 'appType': 6}
headers = {
'Content-Type': 'application/json; charset=utf-8',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 7.1.2; LIO-AN00 Build/LIO-AN00)'
}
response = requests.post(url, data=json.dumps(data), headers=headers)
# print('登錄狀態(tài)碼:%s' % response.status_code)
# print('登錄返回數(shù)據(jù):%s' % response.text)
if response.status_code != 200:
return '登錄失敗'
else:
response_text = json.loads(response.text)
# 無論賬號密碼是否對得上,響應(yīng)狀態(tài)碼都是200,但如果賬號密碼對不上,返回數(shù)據(jù)中的code就不是200
if response_text['code'] != 200:
return '賬號密碼對不上,登錄失敗'
else:
self.user_id = response_text['data']['userId']
self.access_token = response_text['data']['accessToken']
return '登錄成功'
# 修改步數(shù)
def change_step(self):
url = 'https://sports.lifesense.com/sport_service/sport/sport/uploadMobileStepV2?systemType=2&version=4.6.7'
data = {'list': [{'DataSource': 2, 'active': 1, 'calories': int(self.step/4), 'dataSource': 2,
'deviceId': 'M_NULL', 'distance': int(self.step/3), 'exerciseTime': 0, 'isUpload': 0,
'measurementTime': time.strftime('%Y-%m-%d %H:%M:%S'), 'priority': 0, 'step': self.step,
'type': 2, 'updated': int(round(time.time() * 1000)), 'userId': self.user_id}]}
headers = {
'Content-Type': 'application/json; charset=utf-8',
'Cookie': 'accessToken=%s' % self.access_token
}
response = requests.post(url, data=json.dumps(data), headers=headers)
# print('修改步數(shù)狀態(tài)碼:%s' % response.status_code)
# print('修改步數(shù)返回數(shù)據(jù):%s' % response.text)
if response.status_code == 200:
return '【%s】修改步數(shù)為【%s】成功' % (self.phone, self.step)
else:
return '【%s】修改步數(shù)失敗' % self.phone
# 一鍵修改步數(shù)
def one_click_change_step(self):
login_result = self.login()
if login_result != '登錄成功':
print(login_result)
return
change_step_result = self.change_step()
print(change_step_result)
# 睡眠到第二天執(zhí)行修改步數(shù)的時間
def get_sleep_time():
# 第二天日期
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
# 第二天7點時間戳
tomorrow_run_time = int(time.mktime(time.strptime(str(tomorrow), '%Y-%m-%d'))) + 25200
# print(tomorrow_run_time)
# 當前時間戳
current_time = int(time.time())
# print(current_time)
return tomorrow_run_time - current_time
if __name__ == "__main__":
# 最大運行出錯次數(shù)
fail_num = 3
while 1:
while fail_num > 0:
try:
# 執(zhí)行一鍵修改步數(shù)
LexinSport('樂心健康手機號', '樂心健康密碼', 60000).one_click_change_step()
break
except Exception as e:
print('運行出錯,原因:%s' % e)
fail_num -= 1
if fail_num == 0:
print('修改步數(shù)失敗')
# 重置運行出錯次數(shù)
fail_num = 3
# 獲取睡眠時間
sleep_time = get_sleep_time()
# 睡眠到下次執(zhí)行時間
time.sleep(sleep_time)
公眾號后臺回復(fù)【運動步數(shù)】獲取全部源碼。
如果您覺得這篇文章對您有點用的話,麻煩您為本文來個四連:轉(zhuǎn)發(fā)分享、點贊、點在看、留言,因為這將是我寫作與分享更多優(yōu)質(zhì)文章的最強動力!
本公眾號全部博文已整理成一個目錄,請在公眾號后臺回復(fù)「m」獲取!
推薦閱讀:
1、原創(chuàng)專輯 | Python 與 數(shù)據(jù)分析
2、為了探究妹紙對內(nèi)衣的喜好,我爬了淘寶內(nèi)衣店的數(shù)據(jù)!
3、手把手教你用 Python 搞定網(wǎng)頁爬蟲!
4、5 行代碼爬取 3000+ 上市公司信息!
5、超硬核的 Python 數(shù)據(jù)可視化教程!
6、Python 用不好?看官方中文文檔啦!
關(guān)注微信公眾號「杰哥的IT之旅」,后臺回復(fù)「1024」查看更多內(nèi)容,回復(fù)「加群」備注:地區(qū)-職業(yè)方向-昵稱 即可加入讀者交流群。
推薦閱讀:
2、為了探究妹紙對內(nèi)衣的喜好,我爬了淘寶內(nèi)衣店的數(shù)據(jù)!
3、手把手教你用 Python 搞定網(wǎng)頁爬蟲!
4、5 行代碼爬取 3000+ 上市公司信息!
5、超硬核的 Python 數(shù)據(jù)可視化教程!
6、Python 用不好?看官方中文文檔啦!
點個[在看],是對杰哥最大的支持!
