美文网首页大数据 爬虫Python AI Sql
利用Python实现App自动签到领取积分

利用Python实现App自动签到领取积分

作者: 1a076099f916 | 来源:发表于2018-12-24 19:35 被阅读14次

要自动签到,最简单的是打开页面分析请求,然后我们用脚本实现请求的自动化。但是发现食行没有页面,只有 APP,这不是一个好消息,这意味着需要抓包处理了。

利用Python实现App自动签到领取积分

进群进群:943752371可以获取Python各类入门学习资料!

这是我的微信公众号【Python编程之家】各位大佬用空可以关注下,每天更新Python学习方法,感谢!

111111111111.png

不过还好,我们有微信。

在微信里面,我们发现也可以登录食行,这时选择在浏览器中打开页面, ,柳暗花明了,我们找到了一个可用的网页地址:wechatx.34580.com

利用Python实现App自动签到领取积分

下面的操作就好办了,在电脑端的浏览器打开网址,按下 F12,开始起飞~

登录分析

点击签到后,会跳转到用户登录页面: https://wechatx.34580.com/mart/#/sign/in,输入登录信息后,点击登录,同时关注开发调试栏的网络交互信息

利用Python实现App自动签到领取积分

可以发现,登录的请求地址是: https://wechatx.34580.com/sz/Sign/SignInV2,并且会在请求时带着登录信息

<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">{
"SourceType": "9",
"Phone": "18800000000",
"PassWord": "98a53578bd74e150",
"ZhuGeDeviceMd5": "164edd53b71674-02922cef4808a-47e1039-e1000-164edd53b7222e",
"DeviceId": ""
}
</pre>

现在,还无法确定哪些字段是必填的,哪些是可以不传的。

有一个问题是,密码是经过加密的,我在页面输入的 000000 ,这里变成了 98a53578bd74e150。这里我找了半天是如何加密的,也没有找到,若是有大神有办法,还请留言告知!

不过还好,加密方式是固定的,也就是 000000 一直对应的是 98a53578bd74e150,我们只要记下这个加密后的密码,在登录时,传入后台即可。

登录成功后,请求会响应一些 token 数据:

<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">{
"Error": 0,
"Message": "返回正确",
"Data": {
"CustomerGuid": "d8cd7c84-xxxx-4369-xxxx-b1e86c027407",
"Phone": "18800000000",
"AccessToken": "73c7b5fxxxxxxx"
}
}
</pre>

只要 Error 字段为 0,就代表登录成功!

签到分析

登录成功后,页面会自动跳转到首页,我们可以看到签到图标,点击它,进入签到页面:

利用Python实现App自动签到领取积分

发现进来还是一个签到按钮,套娃啊!再点它!

终于签到成功!

发现签到的请求: https://wechatx.34580.com/sz/SignUp/CustomerSignUp

利用Python实现App自动签到领取积分

签到请求中有两个重要的参数,accesstoken 和 customerguid,这两个参数就是登陆后返回的。

签到请求响应:

<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">{
"Error": 0,
"Message": "返回正确",
"Data": {
"GetPoints": 5,
"SumGetPoints": 840
}
}
</pre>

返回说这次签到获得了 5 个积分,其实连续签到 4 天后,每天就可以获得 20 积分了!

实现

通过上面的分析,我们的签到流程也很清晰了,首先就是登陆获取 accesstoken 和 customerguid,然后再去签到就可以了!

<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">import requests, json, sys
def login(Phone, PassWord):
url = "https://wechatx.34580.com/sz/Sign/SignInV2"
payload = {
'SourceType': 9,
'Phone': Phone,
'PassWord': PassWord
}

测试下来发现,连 header 都不需要

response = requests.post(url, data=json.dumps(payload))
data = json.loads(response.text)
is_error = data['Error']

登录失败直接退出

if is_error:
print('登录失败:{}'.format(data['Message']))
sys.exit(1)
else:
print('登录成功!')
return data['Data']['CustomerGuid'], data['Data']['AccessToken']
def signin(customerguid, accesstoken):
url = "https://wechatx.34580.com/sz/SignUp/CustomerSignUp"
querystring = {"accesstoken": accesstoken,
"customerguid": customerguid, "sourcetype": "9"}

这次不需要 body 中的传入数据

response = requests.post(url, params=querystring)
data = json.loads(response.text)
is_error = data['Error']
if is_error:
print(data['Message'])
else:
print("签到成功,获取到 {} 个积分".format(data['Data']['GetPoints']))
if name == "main":
Phone = input('请输入账号:')
PassWord = input('请输入密码:')
customerguid, accesstoken = login(Phone.strip(), PassWord.strip())
signin(customerguid, accesstoken)
</pre>

运行:

<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">$ python shsx.py
请输入账号:188xxxxxxxx
请输入密码:98a53578bd74e150
登录成功!
签到成功,获取到 20 个积分
</pre>

最后,怎么自动执行?把登录信息写死到代码里,然后放到 Linux 下的 crontab 里,每天早上执行一次就行啦~

总结

这里还有一个遗留问题,就是登录密码的获取,现在还只能通过 F12 查看请求获取到,然后记下来。

相关文章

网友评论

    本文标题:利用Python实现App自动签到领取积分

    本文链接:https://www.haomeiwen.com/subject/asqtlqtx.html