首先,本教程并非是我原创,只是看到论坛里有大神利用.net写过,用PHP写过,没看到有python的版本,本着我行我上的原则,小生特来献丑
废话不多说直接上代码【原贴地址我忘了,大家可以搜下】
需要的可以把这个代码保存成py文件,import进你的项目即可
[Python] 纯文本查看 复制代码 from hashlib import md5
from time import time
import requests
from random import randint
def addStep(zhuoYi, stepNum=None):
'''
增加微信运动步数
:zhuoYi 卓易健康账号
:stepNum 设定的步数,不给定步数的话会自动从1到35042随机一个数值
'''
if stepNum is None:
stepNum = randint(1, 35042)
salt = "8061FD"
timeStamp = int(time())
m5 = md5()
m5.update(("{}{}{}".format(zhuoYi, salt, timeStamp)).encode("utf-8"))
sign = m5.hexdigest()
host = "http://weixin.droi.com/health/phone/index.php/SendWechat/getWxOpenid"
data = {"accountId": zhuoYi, "timeStamp": timeStamp, "sign": sign}
res = requests.post(host, data=data)
if res.status_code != 200:
return "修改步数时网络异常,请稍后再试"
jRes = res.json()
if jRes["code"] != 0:
return jRes["messsage"]
openId = jRes["openid"]
timeStamp = int(time())
m5Str = "{}{}{}{}{}{}{}".format(zhuoYi, salt, stepNum, salt, timeStamp,
salt, openId)
m52 = md5()
m52.update(m5Str.encode("utf-8"))
sign = m52.hexdigest()
host = "http://weixin.droi.com/health/phone/index.php/SendWechat/stepSubmit"
data = {
"accountId": zhuoYi,
"jibuNuber": stepNum,
"timeStamp": timeStamp,
"sign": sign
}
res = requests.post(host, data=data)
if res.status_code != 200:
return "修改步数时网络异常,请稍后再试"
jRes = res.json()
if jRes["code"] != 0:
return jRes["messsage"]
else:
return "数据提交成功,提交的数据为:{}".format(stepNum)
if __name__ == "__main__":
zhuoYi = "155823"#这里是你的卓易健康注册的账号,记得要先绑定微信才行
stepNum = input("请输入步数:")
state = addStep(zhuoYi, stepNum)
print(state)
|