feat(auth): 添加系统登录并获取token功能

- 实现用户登录接口调用
- 解析响应数据提取token
- 添加异常处理机制
- 支持JSON格式请求体- 集成requests库进行HTTP通信
- 提供登录成功/失败状态提示
main
wsy182 2025-10-15 11:07:33 +08:00
parent 266ba6ad31
commit ce607c5637
1 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,43 @@
import requests
import json
# 接口地址
url = "http://127.0.0.1:8084/c/v1/wellMudLogAndWireLine/system/privateManager/userLoginAggregate/other/login"
# 请求体
payload = {
"encType": 0,
"x_flag": "",
"data": {
"userId": "admin",
"password": "123456"
}
}
# 请求头
headers = {
"Content-Type": "application/json"
}
try:
# 发送 POST 请求
response = requests.post(url, headers=headers, data=json.dumps(payload))
# 检查状态码
response.raise_for_status()
# 转为 JSON
result = response.json()
# 从响应中解析 token
token = result.get("data", {}).get("token")
if token:
print("登录成功Token", token)
else:
print("未获取到 Token响应内容", result)
except requests.RequestException as e:
print("请求异常:", e)
except ValueError:
print("响应不是合法的 JSON 格式")