修复回消息
This commit is contained in:
@@ -1605,9 +1605,9 @@ class PddLogin:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
# 发送验证码通知给后端,并获取验证码
|
# 发送验证码通知给后端,并获取验证码
|
||||||
def request_verification_code(self, username, store_id, backend_anti_content):
|
def request_verification_code(self, username, store_id, backend_anti_content, phone_number=None):
|
||||||
"""向后端请求获取手机验证码"""
|
"""向后端请求获取手机验证码"""
|
||||||
self._log(f"开始请求验证码,用户名: {username}, 店铺ID: {store_id}", "INFO")
|
self._log(f"开始请求验证码,用户名: {username}, 店铺ID: {store_id}, 手机号: {phone_number}", "INFO")
|
||||||
|
|
||||||
# 使用后端下发的anti_content
|
# 使用后端下发的anti_content
|
||||||
anti_content = backend_anti_content
|
anti_content = backend_anti_content
|
||||||
@@ -1622,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)
|
self._send_verification_needed_message(store_id, phone_number)
|
||||||
|
|
||||||
# 这里需要等待后端重新下发包含验证码的登录参数
|
# 这里需要等待后端重新下发包含验证码的登录参数
|
||||||
# 实际实现中这个方法会在接收到新的登录参数后被重新调用
|
# 实际实现中这个方法会在接收到新的登录参数后被重新调用
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _send_verification_needed_message(self, store_id):
|
def _send_verification_needed_message(self, store_id, phone_number=None):
|
||||||
"""向后端发送需要验证码的通知"""
|
"""向后端发送需要验证码的通知"""
|
||||||
try:
|
try:
|
||||||
self._log(f"开始发送验证码需求通知,店铺ID: {store_id}", "INFO")
|
self._log(f"开始发送验证码需求通知,店铺ID: {store_id}, 手机号: {phone_number}", "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")
|
||||||
@@ -1643,11 +1643,12 @@ 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:
|
||||||
@@ -1864,8 +1865,20 @@ 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
|
# 🔥 从响应中提取手机号
|
||||||
self.request_verification_code(username, store_id, backend_anti_content)
|
phone_number = None
|
||||||
|
try:
|
||||||
|
response_json = response.json()
|
||||||
|
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")
|
||||||
|
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"
|
return "need_verification_code"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -71,9 +71,7 @@ class WebSocketManager:
|
|||||||
def connect_backend(self, token: str) -> bool:
|
def connect_backend(self, token: str) -> bool:
|
||||||
"""连接后端WebSocket"""
|
"""连接后端WebSocket"""
|
||||||
try:
|
try:
|
||||||
# 🔥 重置清理标记,准备下次重连检测
|
|
||||||
if hasattr(self, '_cleared'):
|
|
||||||
delattr(self, '_cleared')
|
|
||||||
|
|
||||||
# 1 保存token到配置
|
# 1 保存token到配置
|
||||||
try:
|
try:
|
||||||
@@ -147,12 +145,13 @@ class WebSocketManager:
|
|||||||
def _handle_platform_login(self, platform_name: str, store_id: str, cookies: str):
|
def _handle_platform_login(self, platform_name: str, store_id: str, cookies: str):
|
||||||
"""处理平台登录请求"""
|
"""处理平台登录请求"""
|
||||||
try:
|
try:
|
||||||
# 🔥 检查并清理旧连接(重连后首次登录时)
|
# 🔥 检查并清理当前店铺的旧连接
|
||||||
if not hasattr(self, '_cleared') and self.platform_listeners:
|
store_key_pattern = f":{store_id}" # 匹配 "平台名:store_id" 格式
|
||||||
self._log(f"🔄 检测到后端重连后首次登录,清理 {len(self.platform_listeners)} 个旧连接", "INFO")
|
keys_to_remove = [key for key in self.platform_listeners.keys() if key.endswith(store_key_pattern)]
|
||||||
self.platform_listeners.clear()
|
if keys_to_remove:
|
||||||
self.connected_platforms.clear()
|
self._log(f"🔄 检测到店铺 {store_id} 重连,清理 {len(keys_to_remove)} 个旧连接", "INFO")
|
||||||
self._cleared = True
|
for key in keys_to_remove:
|
||||||
|
self.platform_listeners.pop(key, None)
|
||||||
|
|
||||||
# 平台名称映射
|
# 平台名称映射
|
||||||
platform_map = {
|
platform_map = {
|
||||||
|
|||||||
Reference in New Issue
Block a user