feat: 添加启动时会员状态检查功能
This commit is contained in:
@@ -467,6 +467,97 @@ class CursorTokenUpdater:
|
||||
# 如果所有重试都失败了
|
||||
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():
|
||||
updater = CursorTokenUpdater()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user