login.py 2.94 KB
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
import json
import urllib3
from commons import ConfigDB as db
from commons import common as com
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
from commons.MyRequest2 import myrequest

#列表查询
class login():
    url="http://test.uap.diligrp.com/login/login.action"
    header={
    "Host": "test.uap.diligrp.com",
    "Connection": "keep-alive",
    "Content-Length": "33",
    "Cache-Control": "max-age=0",
    "Upgrade-Insecure-Requests": "1",
    "Origin": "http://test.uap.diligrp.com",
    "Content-Type": "application/x-www-form-urlencoded",
    "User-Agent": "Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/90.0.4430.212Safari/537.36",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
    "Referer": "http://test.uap.diligrp.com/login/index.html",
    "Accept-Encoding": "gzip,deflate",
    "Accept-Language": "zh-CN,zh-TW;q=0.9,zh;q=0.8,en;q=0.7",
    "Cookie": "UAP_accessToken=;UAP_refreshToken=;UAP_loginPath="}
    body="userName=sg_wenze&password=111111"
    
    def __init__(self):
        self.url=login.url.replace("test.uap.diligrp.com",com.get_global_config("global_data", "environment", "en") )
        self.header=login.header
        self.body=login.body

    def get_session(self,name,password,**kwargs):
        self.body=login.body.replace("sg_wenze", name)
        self.body=login.body.replace("111111", password)
        self.se=requests.session()
        self.se.post(url=login.url, headers=login.header,data=login.body,**kwargs)
        return self.se
    
    def get_session2(self,account,**kwargs):
        self.body=self.body.replace("sg_wenze", com.get_global_config("global_data", "account", account).split("&")[0])
        self.body=self.body.replace("111111", com.get_global_config("global_data", "account", account).split("&")[1])
        self.se=requests.session()
        re=self.se.post(url=self.url, headers=self.header,data=self.body,**kwargs)
        return self.se    

    def close_session(self):
        print("close session")
        self.se.close()
        
    def post(self,name,password,firmid,**kwargs):
        self.body=self.body.replace("sg_wenze", name)
        self.body=self.body.replace("111111", password)
        re=requests.post(url=self.url, headers=self.header,data=self.body,**kwargs)

        print(re.headers)
        return re


# t=login()
# print(t.url)
# t.get_session2("user01",proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'},allow_redirects=False)

# t.post("sg_wenze", "111111",proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})
# def tt(**kwargs):
#     print(kwargs)

# t.get_session(http="http://localhost:8888", https="http://localhost:8888")
# t.post("sg_wenze", "1111111",proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})