_probe-sorftime-reviews.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // 探测 Sorftime ProductReviewsQuery 的响应字段名(生产环境 VOC skill 在用它)
  2. const https = require('https');
  3. function httpJson(opts, body = null) {
  4. return new Promise((res) => {
  5. const req = https.request({ ...opts, timeout: 45000 }, (x) => {
  6. const chunks = [];
  7. x.on('data', (c) => chunks.push(c));
  8. x.on('end', () => {
  9. const b = Buffer.concat(chunks).toString('utf-8');
  10. let j = null;
  11. try { j = JSON.parse(b); } catch (e) {}
  12. res({ status: x.statusCode, body: b, json: j });
  13. });
  14. });
  15. req.on('error', (e) => res({ status: 0, err: e.message }));
  16. req.on('timeout', () => { req.destroy(); res({ status: 0, err: 'timeout' }); });
  17. if (body) req.write(body);
  18. req.end();
  19. });
  20. }
  21. async function sorftime(apiPath, body) {
  22. const bs = JSON.stringify({ path: apiPath, method: 'POST', body, query: { domain: 1 } });
  23. return httpJson({
  24. hostname: 'server-msq.fmode.cn',
  25. path: '/api/sorftime/forward',
  26. method: 'POST',
  27. headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(bs) },
  28. }, bs);
  29. }
  30. async function main() {
  31. const asin = 'B079JX3FMC'; // Bronson from smoke test
  32. console.log('Probing ProductReviewsQuery for', asin);
  33. const r = await sorftime('/api/ProductReviewsQuery', { ASIN: asin });
  34. console.log('status:', r.status);
  35. if (r.json) {
  36. const d = r.json?.Data ?? r.json?.data ?? r.json;
  37. console.log('top keys:', Object.keys(d || {}));
  38. console.log('full response (first 1200 chars):');
  39. console.log(JSON.stringify(d, null, 2).slice(0, 1200));
  40. } else {
  41. console.log('body:', (r.body || '').slice(0, 600));
  42. }
  43. }
  44. main();