2 次代码提交 8126b4b304 ... bc38c573e7

作者 SHA1 备注 提交日期
  Ethanfly bc38c573e7 Merge branch 'main' of http://gitlab.pubdata.cn/hlm/multi-platform-media-manage 2 周之前
  Ethanfly eaa51f33f5 feat(proxy): 增强代理配置支持并添加调试信息 2 周之前
共有 3 个文件被更改,包括 15 次插入3 次删除
  1. 1 0
      server/python/platforms/base.py
  2. 9 2
      server/python/platforms/weixin.py
  3. 5 1
      server/python/platforms/xiaohongshu.py

+ 1 - 0
server/python/platforms/base.py

@@ -229,6 +229,7 @@ class BasePublisher(ABC):
 
         proxy = proxy_config or self.proxy_config
         if proxy and isinstance(proxy, dict) and proxy.get('server'):
+            print(f"[{self.platform_name}] 使用代理: {proxy.get('server')}", flush=True)
             self.browser = await playwright.chromium.launch(headless=self.headless, proxy=proxy)
         else:
             self.browser = await playwright.chromium.launch(headless=self.headless)

+ 9 - 2
server/python/platforms/weixin.py

@@ -320,18 +320,25 @@ class WeixinPublisher(BasePublisher):
         from playwright.async_api import async_playwright
         
         playwright = await async_playwright().start()
+        proxy = self.proxy_config if isinstance(getattr(self, 'proxy_config', None), dict) else None
+        if proxy and proxy.get('server'):
+            print(f"[{self.platform_name}] 使用代理: {proxy.get('server')}", flush=True)
         
         # 参考 matrix: 使用系统内的 Chrome 浏览器,避免 H264 编码错误
         # 如果没有安装 Chrome,则使用默认 Chromium
         try:
             self.browser = await playwright.chromium.launch(
                 headless=self.headless,
-                channel="chrome"  # 使用系统 Chrome
+                channel="chrome",  # 使用系统 Chrome
+                proxy=proxy if proxy and proxy.get('server') else None
             )
             print(f"[{self.platform_name}] 使用系统 Chrome 浏览器")
         except Exception as e:
             print(f"[{self.platform_name}] Chrome 不可用,使用 Chromium: {e}")
-            self.browser = await playwright.chromium.launch(headless=self.headless)
+            self.browser = await playwright.chromium.launch(
+                headless=self.headless,
+                proxy=proxy if proxy and proxy.get('server') else None
+            )
         
         # 设置 HTTP Headers 防止重定向
         headers = {

+ 5 - 1
server/python/platforms/xiaohongshu.py

@@ -255,7 +255,11 @@ class XiaohongshuPublisher(BasePublisher):
         print(f"[{self.platform_name}] 视频文件存在,大小: {os.path.getsize(params.video_path)} bytes")
         
         self.report_progress(5, "正在准备发布...")
-        
+
+        if isinstance(getattr(self, 'proxy_config', None), dict) and self.proxy_config.get('server'):
+            print(f"[{self.platform_name}] 检测到代理配置,跳过 SDK 方式,使用 Playwright 走代理发布", flush=True)
+            return await self.publish_via_playwright(cookies, params)
+
         # 参考 matrix: 优先使用 XHS SDK API 方式发布(更稳定)
         if XHS_SDK_AVAILABLE:
             try: