京东自动签到,自动领京豆的代码
时间: 2024-05-13 22:08:13 浏览: 250
以下是一个使用 Python 语言编写的京东自动签到、自动领取京豆的代码:
```python
import requests
import json
import time
# 设置请求头
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36"
}
# 登录京东账号
def login(username, password):
# 获取登录页面
url = "https://passport.jd.com/new/login.aspx?"
response = session.get(url=url, headers=headers)
# 提取登录页面中的参数
sa_token = response.cookies.get("sa_token")
uuid = response.cookies.get("uuid")
login_page = response.text
s_token = login_page.split("name=\"s_token\" value=\"")[1].split("\"")[0]
# 构造登录请求的参数
payload = {
"uuid": uuid,
"loginType": "c",
"sa_token": sa_token,
"version": "2015",
"r": str(int(time.time() * 1000)),
"nloginSig": "",
"username": username,
"password": password,
"authcode": "",
"pubKey": "",
"fp": "",
"deviceinfo": "",
"loginname": "",
"loginpwd": "",
"chkRememberMe": "",
"machineNet": "",
"machineCpu": "",
"machineDisk": "",
"authcode1": "",
"source": "main",
"s_token": s_token,
}
# 发送登录请求
url = "https://passport.jd.com/uc/loginService"
response = session.post(url=url, headers=headers, data=payload)
result = json.loads(response.text[1:-1])
if result.get("success") == "true":
print("登录成功")
else:
print("登录失败:" + result.get("emptyAuthcodeUrl"))
# 自动签到
def sign():
url = "https://vip.jd.com/sign/index"
response = session.get(url=url, headers=headers)
sign_data = json.loads(response.text)
if sign_data.get("status") == "0":
print("今天已签到")
else:
sign_url = "https://vip.jd.com/sign/sign"
response = session.get(url=sign_url, headers=headers)
sign_result = json.loads(response.text)
if sign_result.get("status") == "0":
print("签到成功,获得" + str(sign_result.get("beanNum")) + "京豆")
else:
print("签到失败:" + sign_result.get("errMsg"))
# 自动领取京豆
def get_jd_bean():
url = "https://bean.m.jd.com/bean/signIndex.action"
response = session.get(url=url, headers=headers)
bean_data = json.loads(response.text)
if bean_data.get("status") == "1":
print("今天已领取京豆")
else:
url = "https://bean.m.jd.com/bean/SignIn.action"
response = session.get(url=url, headers=headers)
bean_result = json.loads(response.text)
if bean_result.get("status") == "1":
print("领取京豆成功,获得" + str(bean_result.get("amount")) + "京豆")
else:
print("领取京豆失败:" + bean_result.get("errorMessage"))
if __name__ == '__main__':
# 创建会话
session = requests.session()
# 登录京东账号
login("用户名", "密码")
# 自动签到
sign()
# 自动领取京豆
get_jd_bean()
# 关闭会话
session.close()
```
请将代码中的“用户名”和“密码”替换成您的京东账号的用户名和密码。代码中使用了 requests 库发送 HTTP 请求,使用前请确保已安装该库。代码执行过程中会输出相关信息,以实现自动签到、自动领取京豆的功能。
阅读全文