test_publish_task61.cjs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/usr/bin/env node
  2. /**
  3. * 完整的发布测试 - Task #61
  4. * 使用增强的反检测功能和代理
  5. */
  6. const http = require('http');
  7. const fs = require('fs');
  8. const path = require('path');
  9. // 配置
  10. const PYTHON_API = 'http://localhost:5005';
  11. const TASK_ID = 61;
  12. // Task #61 的完整数据
  13. const PUBLISH_DATA = {
  14. platform: 'weixin', // 微信视频号
  15. cookie: JSON.stringify([
  16. {
  17. "name":"sessionid",
  18. "value":"BgAAXERdxFp7jCFlOv26QpoGfHFTWafeI1UHi%2F6RxenyzR8zhCfVtyOkJFAw4UJD2yzCpzRQ3phKnIIRiNDY2eM6sUHMCtSAdlG4%2FEqu89Qb",
  19. "domain":"channels.weixin.qq.com",
  20. "path":"/",
  21. "expires":1806737620.630474,
  22. "httpOnly":false,
  23. "secure":true,
  24. "sameSite":"no_restriction"
  25. },
  26. {
  27. "name":"wxuin",
  28. "value":"197897203",
  29. "domain":"channels.weixin.qq.com",
  30. "path":"/",
  31. "expires":1806737620.630622,
  32. "httpOnly":false,
  33. "secure":true,
  34. "sameSite":"no_restriction"
  35. }
  36. ]),
  37. title: '拍照机',
  38. description: '拍照机',
  39. video_path: 'E:\\Workspace\\multi-platform-media-manage\\server\\uploads\\videos\\88ce3597-0499-4882-bcb5-b6d0722547af.mp4',
  40. tags: [],
  41. headless: true, // 改回无头模式
  42. return_screenshot: true,
  43. user_id: 1,
  44. publish_task_id: TASK_ID,
  45. publish_account_id: 24,
  46. proxy: {
  47. enabled: true,
  48. provider: 'shenlong',
  49. productKey: 'o2ihwv3e',
  50. signature: 'ccff437b0c211d7a758b0926cbdcf958',
  51. regionCode: '310000', // 上海
  52. city: '上海'
  53. }
  54. };
  55. // 检查视频文件
  56. function checkVideoFile() {
  57. const videoPath = PUBLISH_DATA.video_path;
  58. console.log('\n📹 检查视频文件...');
  59. console.log('路径:', videoPath);
  60. if (!fs.existsSync(videoPath)) {
  61. console.error('❌ 视频文件不存在');
  62. return false;
  63. }
  64. const stats = fs.statSync(videoPath);
  65. console.log('✅ 文件大小:', (stats.size / 1024 / 1024).toFixed(2), 'MB');
  66. return true;
  67. }
  68. // 发布
  69. function publish() {
  70. return new Promise((resolve, reject) => {
  71. console.log('\n🚀 开始发布...');
  72. console.log('平台:', PUBLISH_DATA.platform);
  73. console.log('标题:', PUBLISH_DATA.title);
  74. console.log('代理: 启用 (上海地区)');
  75. console.log('Headless:', PUBLISH_DATA.headless);
  76. const postData = JSON.stringify(PUBLISH_DATA);
  77. const req = http.request(`${PYTHON_API}/publish/ai-assisted`, {
  78. method: 'POST',
  79. headers: {
  80. 'Content-Type': 'application/json',
  81. 'Content-Length': Buffer.byteLength(postData)
  82. },
  83. timeout: 180000 // 3分钟超时
  84. }, (res) => {
  85. let data = '';
  86. res.on('data', chunk => data += chunk);
  87. res.on('end', () => {
  88. try {
  89. const result = JSON.parse(data);
  90. console.log('\n📊 发布结果:');
  91. console.log('成功:', result.success);
  92. console.log('状态:', result.status);
  93. console.log('错误:', result.error || '无');
  94. console.log('需要验证码:', result.need_captcha || false);
  95. console.log('验证码类型:', result.captcha_type || '无');
  96. if (result.screenshot_base64) {
  97. console.log('截图: 已获取 (长度:', result.screenshot_base64.length, ')');
  98. // 保存截图
  99. const screenshotPath = `E:\\Workspace\\multi-platform-media-manage\\uploads\\screenshots\\test_task_${TASK_ID}_${Date.now()}.png`;
  100. fs.writeFileSync(screenshotPath, Buffer.from(result.screenshot_base64, 'base64'));
  101. console.log('截图已保存:', screenshotPath);
  102. }
  103. if (result.video_url) {
  104. console.log('视频链接:', result.video_url);
  105. }
  106. resolve(result);
  107. } catch (e) {
  108. console.error('❌ 解析响应失败:', e);
  109. console.log('原始响应:', data.substring(0, 500));
  110. reject(e);
  111. }
  112. });
  113. });
  114. req.on('error', (e) => {
  115. console.error('❌ 请求失败:', e.message);
  116. reject(e);
  117. });
  118. req.on('timeout', () => {
  119. console.error('❌ 请求超时');
  120. req.destroy();
  121. reject(new Error('Timeout'));
  122. });
  123. req.write(postData);
  124. req.end();
  125. });
  126. }
  127. // 主函数
  128. async function main() {
  129. try {
  130. console.log('🎯 完整发布测试 - Task #' + TASK_ID);
  131. console.log('='.repeat(60));
  132. // 1. 检查视频文件
  133. if (!checkVideoFile()) {
  134. return;
  135. }
  136. // 2. 发布
  137. const result = await publish();
  138. console.log('\n' + '='.repeat(60));
  139. if (result.success) {
  140. console.log('✅ 发布成功!');
  141. } else if (result.need_captcha) {
  142. console.log('⚠️ 需要验证码:', result.captcha_type);
  143. console.log('💡 建议: 在有头浏览器模式下处理验证码');
  144. } else {
  145. console.log('❌ 发布失败');
  146. console.log('💡 建议: 检查 Cookie 是否有效,或查看截图分析原因');
  147. }
  148. } catch (error) {
  149. console.error('\n❌ 测试失败:', error);
  150. }
  151. }
  152. main();