mirror of
https://github.com/Remik1r3n/maimaiDX-Api.git
synced 2025-05-20 04:17:28 +08:00
106 lines
3.3 KiB
Python
106 lines
3.3 KiB
Python
import sys
|
|
import json
|
|
|
|
from PyQt6.QtWidgets import (
|
|
QApplication, QMainWindow, QWidget, QVBoxLayout, QLineEdit, QTextEdit, QPushButton, QLabel, QHBoxLayout
|
|
)
|
|
from PyQt6.QtCore import Qt
|
|
|
|
# 将当前目录的父目录加入到 sys.path 中
|
|
from pathlib import Path
|
|
current_dir = Path(__file__).resolve().parent
|
|
parent_dir = current_dir.parent
|
|
sys.path.append(str(parent_dir))
|
|
|
|
from API_TitleServer import *
|
|
|
|
def sendRequest(requestText:str, apiNameText:str, uid:int) -> str:
|
|
try:
|
|
data = json.loads(requestText)
|
|
data = json.dumps(data)
|
|
except:
|
|
return "给出的输入不是有效的 JSON"
|
|
try:
|
|
result = apiSDGB(data, apiNameText, uid)
|
|
except Exception as e:
|
|
return "请求失败:" + str(e)
|
|
return result
|
|
|
|
|
|
class ApiTester(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
# 主窗口设定
|
|
self.setWindowTitle("舞萌DX 2024 API 测试器")
|
|
self.resize(640, 400)
|
|
# 布局
|
|
mainWidget = QWidget()
|
|
self.setCentralWidget(mainWidget)
|
|
MainLayout = QVBoxLayout(mainWidget)
|
|
|
|
# 目标 API 输入框布局
|
|
TargetAPILayout = QHBoxLayout()
|
|
# API 输入框
|
|
self.TargetAPIInputBox = QLineEdit()
|
|
self.TargetAPIInputBox.setPlaceholderText("指定 API")
|
|
TargetAPILayout.addWidget(self.TargetAPIInputBox)
|
|
# API 后缀标签
|
|
TargetAPILabel = QLabel("MaimaiChn")
|
|
TargetAPILayout.addWidget(TargetAPILabel)
|
|
# 添加到主布局
|
|
MainLayout.addLayout(TargetAPILayout)
|
|
|
|
# UA额外信息输入框
|
|
self.AgentExtraInputBox = QLineEdit()
|
|
self.AgentExtraInputBox.setPlaceholderText("指定附加信息(UID或狗号)")
|
|
MainLayout.addWidget(self.AgentExtraInputBox)
|
|
|
|
# 请求输入框
|
|
self.RequestInputBox = QTextEdit()
|
|
self.RequestInputBox.setPlaceholderText("此处填入请求")
|
|
MainLayout.addWidget(self.RequestInputBox)
|
|
# 发送按钮
|
|
SendRequestButton = QPushButton("发送!")
|
|
SendRequestButton.clicked.connect(self.prepareRequest)
|
|
MainLayout.addWidget(SendRequestButton)
|
|
# 响应输出框
|
|
self.ResponseTextBox = QTextEdit()
|
|
self.ResponseTextBox.setPlaceholderText("此处显示输出")
|
|
self.ResponseTextBox.setReadOnly(True)
|
|
MainLayout.addWidget(self.ResponseTextBox)
|
|
|
|
|
|
|
|
# 布局设定
|
|
MainLayout.setContentsMargins(5, 5, 5, 5)
|
|
MainLayout.setSpacing(5)
|
|
MainLayout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
|
|
|
|
|
def prepareRequest(self):
|
|
# 发送请求用
|
|
try:
|
|
RequestDataString = self.RequestInputBox.toPlainText()
|
|
TargetAPIString = self.TargetAPIInputBox.text()
|
|
AgentExtraString = int(self.AgentExtraInputBox.text())
|
|
except:
|
|
self.ResponseTextBox.setPlainText("输入无效")
|
|
return
|
|
|
|
Result = sendRequest(RequestDataString, TargetAPIString, AgentExtraString)
|
|
|
|
# 显示出输出
|
|
self.ResponseTextBox.setPlainText(Result)
|
|
|
|
if __name__ == "__main__":
|
|
app = QApplication(sys.argv)
|
|
# Set proper style for each OS
|
|
#if sys.platform == "win32":
|
|
# app.setStyle("windowsvista")
|
|
#else:
|
|
# app.setStyle("Fusion")
|
|
window = ApiTester()
|
|
window.show()
|
|
sys.exit(app.exec())
|