Merge remote-tracking branch 'origin/develop' into develop

# Conflicts:
#	Utils/Pdd/PddUtils.py
This commit is contained in:
2025-09-25 17:43:41 +08:00

View File

@@ -999,7 +999,8 @@ class ImgDistance:
save_path=save_path save_path=save_path
) )
# AutiContent类已移除 - 后端会提供所有必要的anti_content
# AutiContent类已移除 - 后端会提供所有必要的anti_content
def gzip_compress(self, data): def gzip_compress(self, data):
"""压缩数据""" """压缩数据"""
@@ -1604,9 +1605,9 @@ class PddLogin:
return result return result
# 发送验证码通知给后端,并获取验证码 # 发送验证码通知给后端,并获取验证码
def request_verification_code(self, username, store_id, backend_anti_content, phone_number=None): def request_verification_code(self, username, store_id, backend_anti_content):
"""向后端请求获取手机验证码""" """向后端请求获取手机验证码"""
self._log(f"开始请求验证码,用户名: {username}, 店铺ID: {store_id}, 手机号: {phone_number}", "INFO") self._log(f"开始请求验证码,用户名: {username}, 店铺ID: {store_id}", "INFO")
# 使用后端下发的anti_content # 使用后端下发的anti_content
anti_content = backend_anti_content anti_content = backend_anti_content
@@ -1621,18 +1622,18 @@ class PddLogin:
response = requests.post(url, headers=self.headers, json=payload, cookies=self.cookies) response = requests.post(url, headers=self.headers, json=payload, cookies=self.cookies)
self._log(f"发送验证码请求结果: {response.text}") self._log(f"发送验证码请求结果: {response.text}")
# 发送消息给后端,告知需要验证码(包含手机号) # 发送消息给后端,告知需要验证码
self._log("准备向后端发送验证码需求通知", "INFO") self._log("准备向后端发送验证码需求通知", "INFO")
self._send_verification_needed_message(store_id, phone_number) # 🔥 传递手机号 self._send_verification_needed_message(store_id)
# 这里需要等待后端重新下发包含验证码的登录参数 # 这里需要等待后端重新下发包含验证码的登录参数
# 实际实现中这个方法会在接收到新的登录参数后被重新调用 # 实际实现中这个方法会在接收到新的登录参数后被重新调用
return None return None
def _send_verification_needed_message(self, store_id, phone_number=None): def _send_verification_needed_message(self, store_id):
"""向后端发送需要验证码的通知""" """向后端发送需要验证码的通知"""
try: try:
self._log(f"开始发送验证码需求通知店铺ID: {store_id}, 手机号: {phone_number}", "INFO") self._log(f"开始发送验证码需求通知店铺ID: {store_id}", "INFO")
from WebSocket.backend_singleton import get_backend_client from WebSocket.backend_singleton import get_backend_client
backend = get_backend_client() backend = get_backend_client()
self._log(f"获取到后端客户端: {backend is not None}", "DEBUG") self._log(f"获取到后端客户端: {backend is not None}", "DEBUG")
@@ -1642,12 +1643,11 @@ class PddLogin:
"type": "connect_message", "type": "connect_message",
"store_id": store_id, "store_id": store_id,
"status": False, "status": False,
"content": "需要验证码", "content": "需要验证码"
"phone_number": phone_number # 🔥 新增手机号字段
} }
self._log(f"准备发送验证码通知消息: {message}", "DEBUG") self._log(f"准备发送验证码通知消息: {message}", "DEBUG")
backend.send_message(message) backend.send_message(message)
self._log("✅ 成功向后端发送验证码需求通知(含手机号)", "SUCCESS") self._log("✅ 成功向后端发送验证码需求通知", "SUCCESS")
else: else:
self._log("❌ 后端客户端为空,无法发送验证码需求通知", "ERROR") self._log("❌ 后端客户端为空,无法发送验证码需求通知", "ERROR")
except Exception as e: except Exception as e:
@@ -1731,9 +1731,7 @@ class PddLogin:
self._log("🚀 [PddLogin] 开始使用参数登录", "INFO") self._log("🚀 [PddLogin] 开始使用参数登录", "INFO")
# 检查验证码字段(兼容 code 和 verification_code # 检查验证码字段(兼容 code 和 verification_code
verification_code = login_params.get("verification_code") or login_params.get("code", "") verification_code = login_params.get("verification_code") or login_params.get("code", "")
self._log( self._log(f"📋 [PddLogin] 登录参数: username={login_params.get('username', 'N/A')}, 包含验证码={bool(verification_code)}", "DEBUG")
f"📋 [PddLogin] 登录参数: username={login_params.get('username', 'N/A')}, 包含验证码={bool(verification_code)}",
"DEBUG")
self.headers["anti-content"] = login_params.get("anti_content", "") self.headers["anti-content"] = login_params.get("anti_content", "")
@@ -1805,32 +1803,8 @@ class PddLogin:
response = requests.post(self.login_api, headers=self.headers, json=payload, cookies=self.cookies) response = requests.post(self.login_api, headers=self.headers, json=payload, cookies=self.cookies)
self.cookies.update(response.cookies.get_dict()) self.cookies.update(response.cookies.get_dict())
# 🔥 增强日志输出 - 打印完整响应信息
self._log(f"登录响应状态码: {response.status_code}") self._log(f"登录响应状态码: {response.status_code}")
self._log(f"登录响应Headers: {dict(response.headers)}") self._log(f"登录响应内容: {response.text}")
self._log(f"登录完整响应内容: {response.text}")
# 🔥 尝试解析JSON响应获取更多信息
response_json = None # 🔥 在外部定义变量
try:
response_json = response.json()
self._log(f"登录响应JSON结构: {json.dumps(response_json, ensure_ascii=False, indent=2)}")
# 特别关注result字段中可能包含的手机号信息
if "result" in response_json:
result_data = response_json["result"]
self._log(f"响应result字段详情: {json.dumps(result_data, ensure_ascii=False, indent=2)}")
# 查找可能的手机号字段
possible_phone_fields = ["phone", "mobile", "phoneNumber", "mobileNumber", "telephone", "tel",
"cellphone", "handphone"]
for field in possible_phone_fields:
if field in result_data:
self._log(f"🔍 发现可能的手机号字段 {field}: {result_data[field]}")
except Exception as e:
self._log(f"解析响应JSON失败: {e}", "DEBUG")
# 检查响应内容 # 检查响应内容
if "需要手机验证" in response.text: if "需要手机验证" in response.text:
@@ -1845,8 +1819,7 @@ class PddLogin:
salt = self.vc_pre_ck_b() # 获取生成aes key和iv 的密文值 salt = self.vc_pre_ck_b() # 获取生成aes key和iv 的密文值
pictures = self.obtain_captcha() # 获取验证码图片 pictures = self.obtain_captcha() # 获取验证码图片
distance = round((ImgDistance(bg=pictures[0], tp=pictures[1]).main() * (272 / 320)) + (48.75 / 2), distance = round((ImgDistance(bg=pictures[0], tp=pictures[1]).main() * (272 / 320)) + (48.75 / 2), 2) # 计算距离
2) # 计算距离
track_list = Track.get_track(distance=distance) # 生成轨迹 track_list = Track.get_track(distance=distance) # 生成轨迹
captcha_collect = self.captcha_collect(salt=salt, track_list=track_list) # 生成captcha_collect参数 captcha_collect = self.captcha_collect(salt=salt, track_list=track_list) # 生成captcha_collect参数
@@ -1860,8 +1833,7 @@ class PddLogin:
success_count += 1 success_count += 1
# 如果滑块成功 success_count 计数一次 成功8次还是显示验证码则失败 返回False # 如果滑块成功 success_count 计数一次 成功8次还是显示验证码则失败 返回False
if success_count < 8: if success_count < 8:
return self.login_with_params(login_params=login_params, store_id=store_id, return self.login_with_params(login_params=login_params, store_id=store_id, success_count=success_count)
success_count=success_count)
else: else:
return False return False
else: else:
@@ -1892,26 +1864,8 @@ class PddLogin:
backend_anti_content = login_params.get("anti_content") backend_anti_content = login_params.get("anti_content")
self._log(f"为用户 {username} 发送验证码使用后端anti_content", "INFO") self._log(f"为用户 {username} 发送验证码使用后端anti_content", "INFO")
# 🔥 从响应中提取手机号 # 传递后端下发的anti_content
phone_number = None self.request_verification_code(username, store_id, backend_anti_content)
try:
if response_json and isinstance(response_json, dict):
phone_number = response_json.get("result") # 手机号在result字段中
if phone_number and isinstance(phone_number, str):
self._log(f"🔍 从登录响应中提取到手机号: {phone_number}", "SUCCESS")
else:
self._log("⚠️ 响应中的result字段不包含有效手机号", "WARNING")
self._log(f"🔍 DEBUG: response_json = {response_json}", "DEBUG")
else:
self._log("⚠️ response_json 为空或格式不正确", "WARNING")
self._log(f"🔍 DEBUG: response_json = {response_json}", "DEBUG")
except Exception as e:
self._log(f"❌ 提取手机号时出错: {e}", "DEBUG")
import traceback
self._log(f"🔍 DEBUG: 错误详情: {traceback.format_exc()}", "DEBUG")
# 传递后端下发的anti_content和手机号
self.request_verification_code(username, store_id, backend_anti_content, phone_number) # 🔥 传递手机号
return "need_verification_code" return "need_verification_code"
else: else:
@@ -1929,7 +1883,6 @@ class PddLogin:
self._send_login_failure_message(store_id, error_msg) self._send_login_failure_message(store_id, error_msg)
return "login_failure" # 返回特殊状态,避免重复发送消息 return "login_failure" # 返回特殊状态,避免重复发送消息
# ===== 登录相关类集成结束 ===== # ===== 登录相关类集成结束 =====
@@ -3102,6 +3055,8 @@ class PddListenerForGUI:
self._log(f"❌ [PDD] 解析登录参数失败: {e}", "ERROR") self._log(f"❌ [PDD] 解析登录参数失败: {e}", "ERROR")
return {} return {}
def get_status(self) -> Dict[str, Any]: def get_status(self) -> Dict[str, Any]:
return { return {
"running": self.running, "running": self.running,