Requests实现简单的注册登录

import requests

# 请求头
headers = {
    "X-huiya-Media-Type": "huiya.v2"
}
# ===================  注册接口   =======================
url = "https://huiya-app-company.jia400.com/auth/login"

req_data = {
    "username": "blj",
    "password": "hy1234567",
}
resp = requests.post(url, json=req_data, headers=headers)
print("注册的响应结果: \n", resp.text)


# ===================  登陆接口   =======================

# url地址
url = "https://huiya-app-company.jia400.com/auth/login"
# 请求类型:post

# 请求体
req_data = {
    "username": "blj",
    "password": "hy1234567",
}

resp = requests.post(url, json=req_data,headers=headers)
print("登陆的响应结果: \n", resp.text)

# 提取出来,给到下一接口去作为请求
json_res = resp.json()
##三个字典,一层一层去取值
token = json_res["data"]["token_info"]["token"]
user_id = json_res["data"]["id"]

# ===================  充值接口   加入鉴权 =======================
# 请求头
headers = {
    "X-huiya-Media-Type": "huiya.v2",
    "Authorization": "Bearer {}".format(token)
}
# url
url = "https://huiya-app-company.jia400.com/auth/login"
# 请求数据
req_data = {
    "user_id": user_id,
    "amount": 1000
}
res = requests.post(url, json=req_data, headers=headers)
print("充值的响应结果: \n", res.json())

 

posted @ 2022-01-02 17:54  乘风破浪的小落夜  阅读(165)  评论(0编辑  收藏  举报