hyb
2025-11-07 cadac0a99d87c53805a07f3b4ca7fd11e524fe4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
import conftest
from 解密 import aes_encrypt
 
proxy = {
    'http': '127.0.0.1:8080',
    'https': '127.0.0.1:8080',
}
 
def get_Token():
    url = "http://192.168.7.104:8081/sys/login"
    headers = {
        "content-type":"application/json; charset=UTF-8"
    }
    # 获取用户账号密码
    df = conftest.read_excel("TestData/userinfo.xlsx")
    # 封装为字典列表
    UserList = conftest.get_list(df,["username","password"])
    # 遍历用户字典列表的索引和值
    for index, user in enumerate(UserList):
        # 账号密码加密
        username = aes_encrypt(user["username"], "abcdefgh12345678", "12345678abcdefgh")
        password = aes_encrypt(user["password"], "abcdefgh12345678", "12345678abcdefgh")
        # 构造请求体
        params = {"code": "","username": username, "password": password,}
        try:
            response = requests.post(url=url, headers=headers, json=params, verify=False)
            if response.status_code == 200:
                data = response.json()
                token = data["refreshToken"]
                print(user["username"])
                if token:
                    # Token写入Excel文件
                    conftest.write_excel("TestData/userinfo.xlsx",index,"token",token)
                else:
                    print(f"用户 {username} token为空")
            else:
                print(f"错误信息:{response.text} ")
        except Exception as e:
            print(f"用户 {username} 发生错误:{e}")
            return None
 
if __name__ == '__main__':
    get_Token()