Todo: 补充nsis集成需要的依赖 并提交uninstall logo的图片资源 并集成关于GUI版本控制显示代码
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -40,7 +40,7 @@ from Utils.message_models import PlatformMessage
|
||||
|
||||
class Track:
|
||||
"""滑块轨迹生成类"""
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_track(distance):
|
||||
distance = int(distance) + random.randint(7, 11) + 0.8
|
||||
@@ -853,7 +853,7 @@ class Track:
|
||||
|
||||
class ImgDistance:
|
||||
"""滑块图像识别距离计算类"""
|
||||
|
||||
|
||||
def __init__(self, bg, tp):
|
||||
self.bg = bg
|
||||
self.tp = tp
|
||||
@@ -999,8 +999,7 @@ class ImgDistance:
|
||||
save_path=save_path
|
||||
)
|
||||
|
||||
|
||||
# AutiContent类已移除 - 后端会提供所有必要的anti_content
|
||||
# AutiContent类已移除 - 后端会提供所有必要的anti_content
|
||||
|
||||
def gzip_compress(self, data):
|
||||
"""压缩数据"""
|
||||
@@ -1011,7 +1010,7 @@ class ImgDistance:
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(f"调用gzipCompress函数失败: {e}")
|
||||
|
||||
|
||||
# fallback处理:简单返回原数据
|
||||
logger.warning("使用fallback处理,返回原数据")
|
||||
return data
|
||||
@@ -1019,7 +1018,7 @@ class ImgDistance:
|
||||
|
||||
class EncryptTool:
|
||||
"""加密工具类"""
|
||||
|
||||
|
||||
@staticmethod
|
||||
def aes_encrypt(text, key, iv):
|
||||
cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv.encode('utf-8'))
|
||||
@@ -1059,7 +1058,7 @@ class EncryptTool:
|
||||
|
||||
class PddLogin:
|
||||
"""拼多多登录核心类"""
|
||||
|
||||
|
||||
def __init__(self, log_callback=None):
|
||||
super().__init__()
|
||||
self.login_api = "https://mms.pinduoduo.com/janus/api/auth"
|
||||
@@ -1608,11 +1607,11 @@ class PddLogin:
|
||||
def request_verification_code(self, username, store_id, backend_anti_content, phone_number=None):
|
||||
"""向后端请求获取手机验证码"""
|
||||
self._log(f"开始请求验证码,用户名: {username}, 店铺ID: {store_id}, 手机号: {phone_number}", "INFO")
|
||||
|
||||
|
||||
# 使用后端下发的anti_content
|
||||
anti_content = backend_anti_content
|
||||
self._log(f"使用后端下发的anti_content", "DEBUG")
|
||||
|
||||
|
||||
self.headers["anti-content"] = anti_content
|
||||
url = "https://mms.pinduoduo.com/janus/api/user/getLoginVerificationCode"
|
||||
payload = {
|
||||
@@ -1621,11 +1620,11 @@ class PddLogin:
|
||||
}
|
||||
response = requests.post(url, headers=self.headers, json=payload, cookies=self.cookies)
|
||||
self._log(f"发送验证码请求结果: {response.text}")
|
||||
|
||||
|
||||
# 发送消息给后端,告知需要验证码(包含手机号)
|
||||
self._log("准备向后端发送验证码需求通知", "INFO")
|
||||
self._send_verification_needed_message(store_id, phone_number)
|
||||
|
||||
|
||||
# 这里需要等待后端重新下发包含验证码的登录参数
|
||||
# 实际实现中这个方法会在接收到新的登录参数后被重新调用
|
||||
return None
|
||||
@@ -1637,7 +1636,7 @@ class PddLogin:
|
||||
from WebSocket.backend_singleton import get_backend_client
|
||||
backend = get_backend_client()
|
||||
self._log(f"获取到后端客户端: {backend is not None}", "DEBUG")
|
||||
|
||||
|
||||
if backend:
|
||||
message = {
|
||||
"type": "connect_message",
|
||||
@@ -1662,7 +1661,7 @@ class PddLogin:
|
||||
self._log(f"开始发送验证码错误通知,店铺ID: {store_id}, 错误: {error_msg}", "INFO")
|
||||
from WebSocket.backend_singleton import get_backend_client
|
||||
backend = get_backend_client()
|
||||
|
||||
|
||||
if backend:
|
||||
message = {
|
||||
"type": "connect_message",
|
||||
@@ -1686,12 +1685,13 @@ class PddLogin:
|
||||
self._log(f"开始发送登录成功通知,店铺ID: {store_id}", "INFO")
|
||||
from WebSocket.backend_singleton import get_backend_client
|
||||
backend = get_backend_client()
|
||||
|
||||
|
||||
if backend:
|
||||
message = {
|
||||
"type": "connect_message",
|
||||
"store_id": store_id,
|
||||
"status": True # 登录成功
|
||||
"status": True, # 登录成功
|
||||
"cookies": self.cookies # 🔥 新增:添加登录生成的cookie信息
|
||||
}
|
||||
self._log(f"准备发送登录成功消息: {message}", "DEBUG")
|
||||
backend.send_message(message)
|
||||
@@ -1709,7 +1709,7 @@ class PddLogin:
|
||||
self._log(f"开始发送登录失败通知,店铺ID: {store_id}, 错误: {error_msg}", "INFO")
|
||||
from WebSocket.backend_singleton import get_backend_client
|
||||
backend = get_backend_client()
|
||||
|
||||
|
||||
if backend:
|
||||
message = {
|
||||
"type": "connect_message",
|
||||
@@ -1732,10 +1732,12 @@ class PddLogin:
|
||||
self._log("🚀 [PddLogin] 开始使用参数登录", "INFO")
|
||||
# 检查验证码字段(兼容 code 和 verification_code)
|
||||
verification_code = login_params.get("verification_code") or login_params.get("code", "")
|
||||
self._log(f"📋 [PddLogin] 登录参数: username={login_params.get('username', 'N/A')}, 包含验证码={bool(verification_code)}", "DEBUG")
|
||||
|
||||
self._log(
|
||||
f"📋 [PddLogin] 登录参数: username={login_params.get('username', 'N/A')}, 包含验证码={bool(verification_code)}",
|
||||
"DEBUG")
|
||||
|
||||
self.headers["anti-content"] = login_params.get("anti_content", "")
|
||||
|
||||
|
||||
# 直接使用后端提供的参数构建登录请求
|
||||
ts = login_params.get("timestamp", int(round(time.time() * 1000)))
|
||||
payload = {
|
||||
@@ -1801,12 +1803,12 @@ class PddLogin:
|
||||
self._log(f"🔍 [Debug] 登录请求URL: {self.login_api}", "DEBUG")
|
||||
self._log(f"🔍 [Debug] 登录请求payload: {payload}", "DEBUG")
|
||||
self._log(f"🔍 [Debug] 登录请求headers: {dict(self.headers)}", "DEBUG")
|
||||
|
||||
|
||||
response = requests.post(self.login_api, headers=self.headers, json=payload, cookies=self.cookies)
|
||||
self.cookies.update(response.cookies.get_dict())
|
||||
self._log(f"登录响应状态码: {response.status_code}")
|
||||
self._log(f"登录响应内容: {response.text}")
|
||||
|
||||
|
||||
# 检查响应内容
|
||||
if "需要手机验证" in response.text:
|
||||
self._log("✅ 检测到需要手机验证的响应", "INFO")
|
||||
@@ -1820,7 +1822,8 @@ class PddLogin:
|
||||
|
||||
salt = self.vc_pre_ck_b() # 获取生成aes key和iv 的密文值
|
||||
pictures = self.obtain_captcha() # 获取验证码图片
|
||||
distance = round((ImgDistance(bg=pictures[0], tp=pictures[1]).main() * (272 / 320)) + (48.75 / 2), 2) # 计算距离
|
||||
distance = round((ImgDistance(bg=pictures[0], tp=pictures[1]).main() * (272 / 320)) + (48.75 / 2),
|
||||
2) # 计算距离
|
||||
|
||||
track_list = Track.get_track(distance=distance) # 生成轨迹
|
||||
captcha_collect = self.captcha_collect(salt=salt, track_list=track_list) # 生成captcha_collect参数
|
||||
@@ -1834,7 +1837,8 @@ class PddLogin:
|
||||
success_count += 1
|
||||
# 如果滑块成功 success_count 计数一次 成功8次还是显示验证码则失败 返回False
|
||||
if success_count < 8:
|
||||
return self.login_with_params(login_params=login_params, store_id=store_id, success_count=success_count)
|
||||
return self.login_with_params(login_params=login_params, store_id=store_id,
|
||||
success_count=success_count)
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
@@ -1854,7 +1858,7 @@ class PddLogin:
|
||||
response_data = response.json()
|
||||
error_msg = response_data.get('errorMsg', '验证码验证失败')
|
||||
self._log(f"服务器返回错误: {error_msg}", "WARNING")
|
||||
|
||||
|
||||
# 不要重新发送验证码请求,直接报告验证失败
|
||||
self._send_verification_error_message(store_id, error_msg) # 直接使用官方错误信息
|
||||
return "verification_code_error" # 返回特殊状态,避免重复发送消息
|
||||
@@ -1864,7 +1868,7 @@ class PddLogin:
|
||||
username = login_params.get("username")
|
||||
backend_anti_content = login_params.get("anti_content")
|
||||
self._log(f"为用户 {username} 发送验证码,使用后端anti_content", "INFO")
|
||||
|
||||
|
||||
# 🔥 从响应中提取手机号
|
||||
phone_number = None
|
||||
try:
|
||||
@@ -1876,7 +1880,7 @@ class PddLogin:
|
||||
self._log("⚠️ 响应中的result字段不包含有效手机号", "WARNING")
|
||||
except Exception as e:
|
||||
self._log(f"❌ 提取手机号时出错: {e}", "DEBUG")
|
||||
|
||||
|
||||
# 传递后端下发的anti_content和手机号
|
||||
self.request_verification_code(username, store_id, backend_anti_content, phone_number)
|
||||
return "need_verification_code"
|
||||
@@ -1896,6 +1900,7 @@ class PddLogin:
|
||||
self._send_login_failure_message(store_id, error_msg)
|
||||
return "login_failure" # 返回特殊状态,避免重复发送消息
|
||||
|
||||
|
||||
# ===== 登录相关类集成结束 =====
|
||||
|
||||
|
||||
@@ -1983,13 +1988,13 @@ class ChatPdd:
|
||||
raise FileNotFoundError(f"找不到必需的JS文件: {file_path}")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _get_resource_path(relative_path):
|
||||
"""获取资源文件的绝对路径(兼容PyInstaller打包环境)"""
|
||||
try:
|
||||
print(f"[DEBUG] 正在解析资源路径: {relative_path}")
|
||||
|
||||
|
||||
# PyInstaller环境下的基础路径
|
||||
if hasattr(sys, '_MEIPASS'):
|
||||
# PyInstaller 临时目录
|
||||
@@ -2005,10 +2010,10 @@ class ChatPdd:
|
||||
# 向上两级目录到项目根目录
|
||||
base_path = os.path.dirname(os.path.dirname(base_path))
|
||||
print(f"[DEBUG] 开发环境,计算的项目根目录: {base_path}")
|
||||
|
||||
|
||||
resource_path = os.path.join(base_path, relative_path)
|
||||
print(f"[DEBUG] 拼接后的完整资源路径: {resource_path}")
|
||||
|
||||
|
||||
# 检查路径是否存在
|
||||
if os.path.exists(resource_path):
|
||||
print(f"[DEBUG] ✅ 资源路径存在: {resource_path}")
|
||||
@@ -2025,7 +2030,7 @@ class ChatPdd:
|
||||
print(f"[DEBUG] 📄 {item}")
|
||||
except Exception as e:
|
||||
print(f"[DEBUG] 无法列出目录内容: {e}")
|
||||
|
||||
|
||||
return resource_path
|
||||
except Exception as e:
|
||||
print(f"[ERROR] 获取资源路径失败: {e}")
|
||||
@@ -2554,12 +2559,12 @@ class ChatPdd:
|
||||
"""专门判断是否为机器人消息需要过滤"""
|
||||
try:
|
||||
message_info = message_data.get("message", {})
|
||||
|
||||
|
||||
# 1. 基于消息类型过滤机器人特殊消息
|
||||
msg_type = message_info.get("type")
|
||||
if msg_type == 31: # 机器人干预消息(如:机器人已暂停接待)
|
||||
return True
|
||||
|
||||
|
||||
# 2. 基于模板名称识别机器人消息
|
||||
template_name = message_info.get("template_name", "")
|
||||
robot_templates = [
|
||||
@@ -2569,14 +2574,14 @@ class ChatPdd:
|
||||
]
|
||||
if template_name in robot_templates:
|
||||
return True
|
||||
|
||||
|
||||
# 3. 基于机器人特殊标志过滤
|
||||
if message_info.get("conv_silent") is True: # 静默会话标志
|
||||
return True
|
||||
|
||||
|
||||
if message_info.get("no_unreply_hint") == 1: # 无需回复提示标志
|
||||
return True
|
||||
|
||||
|
||||
# 4. 基于消息内容识别机器人提示消息
|
||||
content = message_info.get("content", "")
|
||||
robot_content_patterns = [
|
||||
@@ -2586,18 +2591,18 @@ class ChatPdd:
|
||||
"点击添加",
|
||||
"[当前用户来自",
|
||||
]
|
||||
|
||||
|
||||
if any(pattern in content for pattern in robot_content_patterns):
|
||||
return True
|
||||
|
||||
|
||||
# 5. 基于biz_context中的机器人标识
|
||||
biz_context = message_info.get("biz_context", {})
|
||||
if biz_context.get("robot_msg_id"): # 有机器人消息ID
|
||||
return True
|
||||
|
||||
|
||||
# 不是机器人消息,不过滤
|
||||
return False
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self._log(f"判断机器人消息时出错: {e}", "DEBUG")
|
||||
return False # 出错时不过滤,保持原有行为
|
||||
@@ -2628,7 +2633,7 @@ class ChatPdd:
|
||||
if self.should_filter_robot_message(message_data):
|
||||
self._log("🤖 检测到机器人消息,已过滤不发送给后端", "DEBUG")
|
||||
return
|
||||
|
||||
|
||||
message_info = message_data.get("message", {})
|
||||
if not message_info:
|
||||
return
|
||||
@@ -2801,6 +2806,28 @@ class ChatPdd:
|
||||
except Exception as e:
|
||||
self._log(f"❌ 获取或发送客服列表失败: {e}", "ERROR")
|
||||
|
||||
# 🔥 新增:Cookie登录成功后发送登录成功报告(与登录参数模式保持一致)
|
||||
try:
|
||||
if self.backend_service and hasattr(self, 'store_id') and self.store_id:
|
||||
# 构建cookie字典(从cookies_str解析)
|
||||
cookie_dict = {}
|
||||
if hasattr(self, 'cookie') and self.cookie:
|
||||
cookie_dict = self.cookie
|
||||
|
||||
message = {
|
||||
"type": "connect_message",
|
||||
"store_id": self.store_id,
|
||||
"status": True, # 登录成功
|
||||
"cookies": cookie_dict # 添加cookie信息
|
||||
}
|
||||
# 🔥 修复:使用正确的方法名 send_message_to_backend
|
||||
await self.backend_service.send_message_to_backend(message)
|
||||
self._log("✅ [PDD] 已向后端发送Cookie登录成功报告", "SUCCESS")
|
||||
else:
|
||||
self._log("⚠️ [PDD] 无法发送登录成功报告:backend_service或store_id缺失", "WARNING")
|
||||
except Exception as e:
|
||||
self._log(f"⚠️ [PDD] 发送登录成功报告失败: {e}", "WARNING")
|
||||
|
||||
# 启动消息监听和心跳
|
||||
await asyncio.gather(
|
||||
self.heartbeat(websocket),
|
||||
@@ -2959,11 +2986,11 @@ class PddListenerForGUI:
|
||||
self._log("🔄 [PDD] 开始创建PddLogin实例", "DEBUG")
|
||||
pdd_login = PddLogin(log_callback=self.log_callback)
|
||||
self._log("✅ [PDD] PddLogin实例创建成功", "DEBUG")
|
||||
|
||||
|
||||
self._log("🔄 [PDD] 开始执行登录", "DEBUG")
|
||||
login_result = pdd_login.login_with_params(params_dict, store_id)
|
||||
self._log(f"📊 [PDD] 登录结果: {login_result}", "DEBUG")
|
||||
|
||||
|
||||
if login_result == "need_verification_code":
|
||||
self._log("⚠️ [PDD] 需要手机验证码,已通知后端,等待重新下发包含验证码的登录参数", "WARNING")
|
||||
return "need_verification_code" # 返回特殊标识,避免被覆盖
|
||||
@@ -2979,7 +3006,7 @@ class PddListenerForGUI:
|
||||
elif isinstance(login_result, dict):
|
||||
# 登录成功,获取到cookies
|
||||
self._log("✅ [PDD] 登录成功,使用获取的cookies连接平台", "SUCCESS")
|
||||
|
||||
|
||||
# 将cookies字典转换为字符串格式,与原有逻辑兼容
|
||||
import json
|
||||
cookies_str = json.dumps(login_result)
|
||||
@@ -3080,6 +3107,7 @@ class PddListenerForGUI:
|
||||
cookies_str=cookies,
|
||||
store=store
|
||||
)
|
||||
|
||||
self._log("✅ [PDD] 拼多多平台连接成功,开始监听消息", "SUCCESS")
|
||||
return True
|
||||
except Exception as e:
|
||||
@@ -3125,8 +3153,6 @@ class PddListenerForGUI:
|
||||
self._log(f"❌ [PDD] 解析登录参数失败: {e}", "ERROR")
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
def get_status(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"running": self.running,
|
||||
|
||||
Reference in New Issue
Block a user