四个平台接入

This commit is contained in:
jjz
2025-09-13 19:54:30 +08:00
parent 22122660df
commit 08613313d3
5 changed files with 1250 additions and 768 deletions

View File

@@ -87,7 +87,7 @@ class PddBackendService:
if isinstance(platform_message, dict):
if 'store_id' not in platform_message and self.current_store_id:
platform_message['store_id'] = self.current_store_id
# 通过统一后端连接发送
backend.send_message(platform_message)
return True
@@ -503,7 +503,7 @@ class ChatPdd:
if not uid or not content:
self._log("❌ [External] 参数不完整", "ERROR")
return False
result = await self.send_ai_reply(uid, content)
if result:
self._log(f"✅ [External] 外部消息发送成功: uid={uid}", "SUCCESS")
@@ -962,23 +962,23 @@ class PddListenerForGUI:
"""使用后端下发的登录参数执行登录并启动监听"""
try:
self._log("🔵 [PDD] 收到后端登录参数开始执行登录获取cookies", "INFO")
# 1. 解析登录参数
params_dict = self._parse_login_params(login_params)
if not params_dict:
self._log("❌ [PDD] 登录参数解析失败", "ERROR")
return False
# 2. 执行登录获取Cookie
cookies = await self._execute_pdd_login(params_dict)
if not cookies:
self._log("❌ [PDD] 登录失败无法获取cookies", "ERROR")
return False
# 3. 使用获取的Cookie继续原有流程
self._log("✅ [PDD] 登录成功使用获取的cookies连接平台", "SUCCESS")
return await self.start_with_cookies(store_id, cookies)
except Exception as e:
self._log(f"❌ [PDD] 使用登录参数启动失败: {str(e)}", "ERROR")
import traceback
@@ -1123,12 +1123,12 @@ class PddListenerForGUI:
login_request = self._build_login_request(login_params)
if not login_request:
return ""
# 2. 发送登录请求
response_data = await self._send_login_request(login_request)
if not response_data:
return ""
# 3. 处理登录响应
if "需要验证图形验证码" in str(response_data):
self._log("⚠️ [PDD] 登录需要验证码,暂不支持自动处理", "WARNING")
@@ -1148,7 +1148,7 @@ class PddListenerForGUI:
error_msg = response_data.get("errorMsg", "登录失败")
self._log(f"❌ [PDD] 登录失败: {error_msg}", "ERROR")
return ""
except Exception as e:
self._log(f"❌ [PDD] 执行登录失败: {e}", "ERROR")
import traceback
@@ -1163,13 +1163,13 @@ class PddListenerForGUI:
anti_content = login_params.get("anti_content", "")
risk_sign = login_params.get("risk_sign", "")
timestamp = login_params.get("timestamp", int(time.time() * 1000))
if not all([username, password, anti_content, risk_sign]):
self._log("❌ [PDD] 登录参数不完整", "ERROR")
return {}
import random
# 构造请求头
headers = {
"authority": "mms.pinduoduo.com",
@@ -1189,7 +1189,7 @@ class PddListenerForGUI:
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"anti-content": anti_content # 后端提供的关键参数
}
# 构造请求体完全复用pdd_login/login.py的结构
payload = {
"username": username,
@@ -1249,14 +1249,14 @@ class PddListenerForGUI:
"timestamp": timestamp,
"crawlerInfo": anti_content # 后端提供
}
self._log("✅ [PDD] 登录请求构造成功", "INFO")
return {
"url": "https://mms.pinduoduo.com/janus/api/auth",
"headers": headers,
"payload": payload
}
except Exception as e:
self._log(f"❌ [PDD] 构造登录请求失败: {e}", "ERROR")
return {}
@@ -1266,22 +1266,22 @@ class PddListenerForGUI:
try:
import requests
import asyncio
url = login_request["url"]
headers = login_request["headers"]
payload = login_request["payload"]
# 使用线程池执行同步请求
def _send_request():
response = requests.post(url, headers=headers, json=payload, timeout=30)
return response
# 在事件循环中执行
loop = asyncio.get_event_loop()
response = await loop.run_in_executor(None, _send_request)
self._log(f"✅ [PDD] 登录请求发送完成,状态码: {response.status_code}", "INFO")
if response.status_code == 200:
result = response.json()
cookies = response.cookies.get_dict()
@@ -1294,7 +1294,7 @@ class PddListenerForGUI:
else:
self._log(f"❌ [PDD] 登录请求失败HTTP状态码: {response.status_code}", "ERROR")
return {}
except Exception as e:
self._log(f"❌ [PDD] 发送登录请求异常: {e}", "ERROR")
return {}