test_direct_publish.cjs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env node
  2. /**
  3. * 测试直连模式发布 - Task #61
  4. * 不使用代理,配合反检测脚本
  5. */
  6. const http = require('http');
  7. const fs = require('fs');
  8. const PYTHON_API = 'http://localhost:5005';
  9. const TASK_ID = 61;
  10. const PUBLISH_DATA = {
  11. platform: 'weixin',
  12. cookie: JSON.stringify([
  13. {
  14. "name":"sessionid",
  15. "value":"BgAAXERdxFp7jCFlOv26QpoGfHFTWafeI1UHi%2F6RxenyzR8zhCfVtyOkJFAw4UJD2yzCpzRQ3phKnIIRiNDY2eM6sUHMCtSAdlG4%2FEqu89Qb",
  16. "domain":"channels.weixin.qq.com",
  17. "path":"/",
  18. "expires":1806737620.630474,
  19. "httpOnly":false,
  20. "secure":true,
  21. "sameSite":"no_restriction"
  22. },
  23. {
  24. "name":"wxuin",
  25. "value":"197897203",
  26. "domain":"channels.weixin.qq.com",
  27. "path":"/",
  28. "expires":1806737620.630622,
  29. "httpOnly":false,
  30. "secure":true,
  31. "sameSite":"no_restriction"
  32. }
  33. ]),
  34. title: '拍照机',
  35. description: '拍照机',
  36. video_path: 'E:\\Workspace\\multi-platform-media-manage\\server\\uploads\\videos\\88ce3597-0499-4882-bcb5-b6d0722547af.mp4',
  37. tags: [],
  38. headless: false, // 显示浏览器
  39. return_screenshot: true,
  40. user_id: 1,
  41. publish_task_id: TASK_ID,
  42. publish_account_id: 24,
  43. proxy: {
  44. enabled: false // ⚠️ 关键:不使用代理,避免超时
  45. }
  46. };
  47. console.log('🎯 测试直连模式发布 - Task #' + TASK_ID);
  48. console.log('='.repeat(60));
  49. console.log('策略: 使用直连 + 反检测脚本');
  50. console.log('原因: 神龙代理 IP 有效期仅 3 分钟,大文件上传会超时');
  51. console.log('='.repeat(60));
  52. const postData = JSON.stringify(PUBLISH_DATA);
  53. const req = http.request(`${PYTHON_API}/publish/ai-assisted`, {
  54. method: 'POST',
  55. headers: {
  56. 'Content-Type': 'application/json',
  57. 'Content-Length': Buffer.byteLength(postData)
  58. },
  59. timeout: 600000 // 10 分钟超时(大文件)
  60. }, (res) => {
  61. let data = '';
  62. res.on('data', chunk => data += chunk);
  63. res.on('end', () => {
  64. try {
  65. const result = JSON.parse(data);
  66. console.log('\n📊 发布结果:');
  67. console.log(JSON.stringify(result, null, 2));
  68. if (result.screenshot_base64) {
  69. const screenshotPath = `E:\\Workspace\\multi-platform-media-manage\\server\\uploads\\screenshots\\direct_publish_${TASK_ID}_${Date.now()}.png`;
  70. fs.writeFileSync(screenshotPath, Buffer.from(result.screenshot_base64, 'base64'));
  71. console.log('\n📷 截图已保存:', screenshotPath);
  72. }
  73. } catch (e) {
  74. console.error('❌ 解析失败:', e);
  75. console.log('响应:', data.substring(0, 500));
  76. }
  77. });
  78. });
  79. req.on('error', (e) => console.error('❌ 请求失败:', e));
  80. req.on('timeout', () => {
  81. console.error('❌ 请求超时(10分钟)');
  82. req.destroy();
  83. });
  84. req.write(postData);
  85. req.end();
  86. console.log('\n⏳ 发布中...(大文件上传需要较长时间)');
  87. console.log('💡 可以在浏览器窗口观察进度');