clientSession.py
2.43 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
# -*- coding: utf-8 -*-
# @Time : 2021/7/16 10:23
# @Author : Ljq
# @File : clientSession.py
# @Software: PyCharm
"""
"""
import requests
import json
from commons.scripts.readConf import readConfig
from commons.scripts.pwdCry import pwdCry
class cliSession(object):
def __init__(self):
rConf = readConfig()
def __init__(self):
rC = readConfig()
self.userName = rC.returnOptionsItems("loginInfo","userName")
self.password = pwdCry(rC.returnOptionsItems("loginInfo","password"))
self.loginUrl = rC.returnOptionsItems("host","uapHost")+"/api/authenticationApi/loginWeb"
self.loginData = {"userName":self.userName,"password":self.password}
self.webHeaders = {"X-Requested-With":"XMLHttpRequest",
"Content-Type":"application/x-www-form-urlencoded",
"Cookie":"UAP_accessToken=${UAP_accessToken}; UAP_refreshToken=${UAP_refreshToken};UAP_firmId=${UAP_firmId}"}
self.clientHeaders={"UAP_accessToken":"${UAP_accessToken}",
"UAP_refreshToken":"${UAP_refreshToken}",
"UAP_firmId":"${UAP_firmId}",
"Cookie":"UAP_accessToken=${UAP_accessToken}; UAP_refreshToken=${UAP_refreshToken}",
"Content-Type":"application/json"}
def loginUser(self):
"""
执行登录
:return:self.webHeaders,self.clientHeaders,res.json()
"""
# 返回登录信息,以及可用headers,clientHeaders用户客户端操作header,webHeaders用于web页面使用headers
res = requests.post(url=self.loginUrl,data=json.dumps(self.loginData))
print(res.json())
UAP_accessToken,UAP_refreshToken,UAP_firmId=res.json()["data"]["accessToken"],res.json()["data"]["refreshToken"],res.json()["data"]["user"]["firmId"]
webHeadersCookie = "UAP_accessToken="+UAP_accessToken+"; UAP_refreshToken="+UAP_refreshToken+";UAP_firmId="+str(UAP_firmId)
clientHeadersCookie = "UAP_accessToken="+UAP_accessToken+"; UAP_refreshToken="+UAP_refreshToken
self.webHeaders["Cookie"] = webHeadersCookie
self.clientHeaders["UAP_accessToken"] = UAP_accessToken
self.clientHeaders["UAP_refreshToken"]= UAP_refreshToken
self.clientHeaders["UAP_firmId"] = str(UAP_firmId)
self.clientHeaders["Cookie"] = clientHeadersCookie
return self.webHeaders,self.clientHeaders,res.json()