Commit a68b3477 authored by yangxudong's avatar yangxudong

Add new file

parents
import json
import subprocess
import requests
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("契胜测试工具-V01")
Dialog.resize(708, 145)
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(50, 40, 161, 51))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.check_vpn_and_add_token)
self.textBrowser = QtWidgets.QTextBrowser(Dialog)
self.textBrowser.setGeometry(QtCore.QRect(250, 10, 411, 121))
self.textBrowser.setObjectName("textBrowser")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "契胜测试工具-V01"))
self.pushButton.setText(_translate("Dialog", "一键获取B端token"))
def ping_domain(self, domain='bmp-uat.crv.com.cn'):
# 使用 subprocess 执行 ping 命令
result = subprocess.run(['ping', '-c', '4', domain], capture_output=True, text=True, timeout=2)
# 检查命令执行结果
if result.returncode == 0:
return False
else:
return True
def login_test(self):
url='https://bmp-uat.crv.com.cn/api/fea-bmp/authentication/login?grant_type=password'
data={"account":"miya-27","password":"SERAcTEyYWJj","terminal":"PC-WEB","entId":1,"loginAppId":1000}
herd={"Content-Type":"application/json"}
login_data=requests.post(url,data=json.dumps(data),headers=herd,verify=False)
# print(login_data.text)
token=login_data.json()["data"]["access_token"]
print(token)
return token
def get_appid(self):
url='https://bmp-uat.crv.com.cn/api/fea-bmp/authentication/application/apply'
data={"entId":1,"appId":"100000102"}
head={"Content-Type":"application/json",
"ssotoken":"{}".format(self.login_test())}
appid_data=requests.post(url,data=json.dumps(data),headers=head,verify=False)
token=appid_data.json()["data"]["access_token"]
return token
def add_token(self):
tokens=self.get_appid()
self.textBrowser.append("连接VPN成功............")
self.textBrowser.append("获取B端token为:{}".format(tokens))
self.textBrowser.append("域名拼接:https://ewop-uat.crv.com.cn/?apptoken={}".format(tokens))
self.textBrowser.append("************************************")
def check_vpn_and_add_token(self):
try:
if self.ping_domain():
self.add_token()
else:
self.textBrowser.append("连接VPN失败............")
except:
self.textBrowser.append("未连接VPN或网络异常...")
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QWidget()
ui = Ui_Dialog()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment