handle_token.py
1.8 KB
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
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2022/12/15 22:55
# @Author : Shitou
# @FileName: handle_token.py
# @Software: PyCharm
"""
登陆获取token
"""
import requests
from common.handle_config import conf
from jsonpath import jsonpath
# ==================获取登陆token========
class LoginToken:
def login_token():
# 登陆获取token
login_url = conf.get("url", "url_ip") + "/auth/v1/login"
headers = eval(conf.get('url', 'login_token'))
params = {
"way": conf.get('user_data', 'way'),
"password": conf.get('user_data', 'userpassword'),
"type": conf.get('user_data', 'type'),
"username": conf.get('user_data', 'username'),
"schoolId": conf.get('user_data', 'schoolId'),
}
response = requests.request(url=login_url, method="post", json=params, headers=headers)
res = response.json()
# 获取token
token = "Bearer" + " " + jsonpath(res, "$..access_token")[0]
return token
class StudentLoginToken:
def login_token():
# 登陆学生获取token
login_url = conf.get("url", "url_ip") + "/auth/v1/login"
headers = eval(conf.get('url', 'login_token'))
params = {
"way": conf.get("student_user_data", "way"),
"phone": conf.get("student_user_data", "phone"),
"code": conf.get("student_user_data", "code"),
"type": conf.get("student_user_data", "type")
}
response = requests.request(url=login_url, method="post", json=params, headers=headers)
res = response.json()
# 获取token
token = "Bearer" + " " + jsonpath(res, "$..access_token")[0]
return token
if __name__ == '__main__':
StudentLoginToken.login_token()