feat: 添加启动时会员状态检查功能
This commit is contained in:
@@ -107,6 +107,8 @@ class MainWindow(QMainWindow):
|
|||||||
logging.info("正在初始化主窗口...")
|
logging.info("正在初始化主窗口...")
|
||||||
self.updater = CursorTokenUpdater()
|
self.updater = CursorTokenUpdater()
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
|
# 检查会员状态
|
||||||
|
self.check_member_status()
|
||||||
logging.info("主窗口初始化完成")
|
logging.info("主窗口初始化完成")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"初始化主窗口时发生错误: {str(e)}")
|
logging.error(f"初始化主窗口时发生错误: {str(e)}")
|
||||||
@@ -359,6 +361,37 @@ class MainWindow(QMainWindow):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
QMessageBox.critical(self, "错误", f"操作失败: {str(e)}")
|
QMessageBox.critical(self, "错误", f"操作失败: {str(e)}")
|
||||||
|
|
||||||
|
def check_member_status(self):
|
||||||
|
"""检查会员状态"""
|
||||||
|
try:
|
||||||
|
logging.info("正在检查会员状态...")
|
||||||
|
self.member_info.clear()
|
||||||
|
self.member_info.append("正在检查会员状态...")
|
||||||
|
QApplication.processEvents()
|
||||||
|
|
||||||
|
# 调用API检查状态
|
||||||
|
success, message, account_info = self.updater.check_member_status()
|
||||||
|
|
||||||
|
if success and account_info:
|
||||||
|
# 更新会员信息显示
|
||||||
|
self.member_info.clear()
|
||||||
|
self.member_info.append(f"会员状态: 已激活")
|
||||||
|
self.member_info.append(f"到期时间: {account_info['expire_time']}")
|
||||||
|
self.member_info.append(f"剩余天数: {account_info['days_left']}天")
|
||||||
|
logging.info(f"会员状态检查完成 - 到期时间: {account_info['expire_time']}")
|
||||||
|
else:
|
||||||
|
# 显示未激活状态
|
||||||
|
self.member_info.clear()
|
||||||
|
self.member_info.append("会员状态: 未激活")
|
||||||
|
self.member_info.append("请输入激活码进行激活")
|
||||||
|
logging.warning("会员状态检查结果:未激活")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.member_info.clear()
|
||||||
|
self.member_info.append("会员状态: 检查失败")
|
||||||
|
self.member_info.append("请稍后重试")
|
||||||
|
logging.error(f"检查会员状态时发生错误: {str(e)}")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
# 设置日志
|
# 设置日志
|
||||||
|
|||||||
@@ -467,6 +467,97 @@ class CursorTokenUpdater:
|
|||||||
# 如果所有重试都失败了
|
# 如果所有重试都失败了
|
||||||
return False, "多次尝试后激活失败,请检查网络连接或稍后重试", None
|
return False, "多次尝试后激活失败,请检查网络连接或稍后重试", None
|
||||||
|
|
||||||
|
def check_member_status(self) -> Tuple[bool, str, Optional[Dict]]:
|
||||||
|
"""检查会员状态
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple[bool, str, Optional[Dict]]:
|
||||||
|
- 是否成功
|
||||||
|
- 错误信息
|
||||||
|
- 账号数据(如果成功)
|
||||||
|
"""
|
||||||
|
max_retries = 3
|
||||||
|
retry_delay = 1
|
||||||
|
|
||||||
|
for attempt in range(max_retries):
|
||||||
|
try:
|
||||||
|
data = {
|
||||||
|
"machine_id": self.hardware_id
|
||||||
|
}
|
||||||
|
|
||||||
|
# 禁用SSL警告
|
||||||
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
|
|
||||||
|
# 设置请求参数
|
||||||
|
request_kwargs = {
|
||||||
|
"json": data,
|
||||||
|
"headers": {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
|
||||||
|
"Accept": "*/*",
|
||||||
|
"Connection": "keep-alive"
|
||||||
|
},
|
||||||
|
"timeout": 10,
|
||||||
|
"verify": False
|
||||||
|
}
|
||||||
|
|
||||||
|
# 创建session
|
||||||
|
session = requests.Session()
|
||||||
|
session.verify = False
|
||||||
|
|
||||||
|
# 设置重试策略
|
||||||
|
retry_strategy = urllib3.Retry(
|
||||||
|
total=3,
|
||||||
|
backoff_factor=0.5,
|
||||||
|
status_forcelist=[500, 502, 503, 504]
|
||||||
|
)
|
||||||
|
adapter = requests.adapters.HTTPAdapter(max_retries=retry_strategy)
|
||||||
|
session.mount("http://", adapter)
|
||||||
|
session.mount("https://", adapter)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 发送请求
|
||||||
|
response = session.post(
|
||||||
|
"https://cursorapi.nosqli.com/admin/api.member/status",
|
||||||
|
**request_kwargs
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
|
result = response.json()
|
||||||
|
if result["code"] == 200:
|
||||||
|
api_data = result["data"]
|
||||||
|
account_info = {
|
||||||
|
"status": "active",
|
||||||
|
"expire_time": api_data.get("expire_time", ""),
|
||||||
|
"days_left": api_data.get("days_left", 0),
|
||||||
|
"device_info": self.get_device_info()
|
||||||
|
}
|
||||||
|
return True, "success", account_info
|
||||||
|
else:
|
||||||
|
error_msg = result.get("msg", "未知错误")
|
||||||
|
if attempt < max_retries - 1:
|
||||||
|
logging.warning(f"第{attempt + 1}次检查失败: {error_msg}, 准备重试...")
|
||||||
|
time.sleep(retry_delay)
|
||||||
|
continue
|
||||||
|
return False, error_msg, None
|
||||||
|
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
if attempt < max_retries - 1:
|
||||||
|
logging.warning(f"第{attempt + 1}次网络请求失败: {str(e)}, 准备重试...")
|
||||||
|
time.sleep(retry_delay)
|
||||||
|
continue
|
||||||
|
error_msg = self._get_network_error_message(e)
|
||||||
|
return False, f"网络连接失败: {error_msg}", None
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
if attempt < max_retries - 1:
|
||||||
|
logging.warning(f"第{attempt + 1}次请求发生错误: {str(e)}, 准备重试...")
|
||||||
|
time.sleep(retry_delay)
|
||||||
|
continue
|
||||||
|
return False, f"检查失败: {str(e)}", None
|
||||||
|
|
||||||
|
return False, "多次尝试后检查失败,请稍后重试", None
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
updater = CursorTokenUpdater()
|
updater = CursorTokenUpdater()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user