test_proxy_weixin.cjs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. const http = require('http');
  2. const https = require('https');
  3. // 神龙代理配置
  4. const SHENLONG_CONFIG = {
  5. productKey: 'o2ihwv3e',
  6. signature: 'ccff437b0c211d7a758b0926cbdcf958',
  7. regionCode: '310000', // 上海
  8. platform: 'weixin'
  9. };
  10. // 测试代理
  11. function testProxy() {
  12. return new Promise((resolve, reject) => {
  13. console.log('\n🔍 测试神龙代理对微信视频号的可用性...');
  14. console.log('配置:', JSON.stringify(SHENLONG_CONFIG, null, 2));
  15. const postData = JSON.stringify(SHENLONG_CONFIG);
  16. const req = http.request('http://127.0.0.1:5005/proxy/test', {
  17. method: 'POST',
  18. headers: {
  19. 'Content-Type': 'application/json',
  20. 'Content-Length': Buffer.byteLength(postData)
  21. },
  22. timeout: 30000
  23. }, (res) => {
  24. let data = '';
  25. res.on('data', chunk => data += chunk);
  26. res.on('end', () => {
  27. try {
  28. const result = JSON.parse(data);
  29. console.log('\n✅ 代理测试结果:');
  30. console.log(JSON.stringify(result, null, 2));
  31. resolve(result);
  32. } catch (e) {
  33. console.error('❌ 解析响应失败:', e);
  34. reject(e);
  35. }
  36. });
  37. });
  38. req.on('error', (e) => {
  39. console.error('❌ 请求失败:', e.message);
  40. console.log('\n💡 Python 服务未启动,让我直接测试神龙 API...');
  41. testShenlongAPI().then(resolve).catch(reject);
  42. });
  43. req.on('timeout', () => {
  44. console.error('❌ 请求超时');
  45. req.destroy();
  46. testShenlongAPI().then(resolve).catch(reject);
  47. });
  48. req.write(postData);
  49. req.end();
  50. });
  51. }
  52. // 直接测试神龙 API
  53. async function testShenlongAPI() {
  54. return new Promise((resolve, reject) => {
  55. console.log('\n🔍 直接测试神龙代理 API...');
  56. const params = new URLSearchParams({
  57. key: SHENLONG_CONFIG.productKey,
  58. sign: SHENLONG_CONFIG.signature,
  59. count: 1,
  60. pattern: 'json',
  61. mr: 1,
  62. area: SHENLONG_CONFIG.regionCode
  63. });
  64. const url = `http://api.shenlongip.com/ip?${params.toString()}`;
  65. console.log('API URL:', url);
  66. http.get(url, {
  67. headers: {
  68. 'User-Agent': 'Mozilla/5.0',
  69. 'Accept': 'application/json'
  70. },
  71. timeout: 15000
  72. }, (res) => {
  73. let data = '';
  74. res.on('data', chunk => data += chunk);
  75. res.on('end', () => {
  76. console.log('\n神龙 API 响应:');
  77. try {
  78. const result = JSON.parse(data);
  79. console.log(JSON.stringify(result, null, 2));
  80. if (result.code === 200 && result.data && result.data.length > 0) {
  81. const proxy = result.data[0];
  82. console.log(`\n✅ 获取到代理IP: ${proxy.ip}:${proxy.port}`);
  83. console.log(` 城市: ${proxy.city}`);
  84. console.log(` 运营商: ${proxy.isp}`);
  85. // 测试代理连通性
  86. testProxyConnectivity(proxy.ip, proxy.port).then(() => {
  87. resolve(result);
  88. }).catch(reject);
  89. } else {
  90. console.log('\n❌ 获取代理失败:', result.msg || '未知错误');
  91. resolve(result);
  92. }
  93. } catch (e) {
  94. console.log('原始响应:', data);
  95. resolve({ raw: data });
  96. }
  97. });
  98. }).on('error', (e) => {
  99. console.error('❌ 神龙 API 请求失败:', e.message);
  100. reject(e);
  101. });
  102. });
  103. }
  104. // 测试代理连通性
  105. function testProxyConnectivity(host, port) {
  106. return new Promise((resolve, reject) => {
  107. console.log(`\n🔍 测试代理连通性: ${host}:${port}...`);
  108. const options = {
  109. hostname: host,
  110. port: port,
  111. path: 'http://myip.ipip.net',
  112. method: 'GET',
  113. timeout: 10000
  114. };
  115. const req = http.request(options, (res) => {
  116. let data = '';
  117. res.on('data', chunk => data += chunk);
  118. res.on('end', () => {
  119. console.log('\n✅ 代理连通性测试成功');
  120. console.log('IP信息:', data.trim());
  121. resolve();
  122. });
  123. });
  124. req.on('error', (e) => {
  125. console.error('❌ 代理连通性测试失败:', e.message);
  126. resolve(); // 不reject,继续
  127. });
  128. req.on('timeout', () => {
  129. console.error('❌ 代理连接超时');
  130. req.destroy();
  131. resolve();
  132. });
  133. req.end();
  134. });
  135. }
  136. // 主函数
  137. async function main() {
  138. try {
  139. console.log('🚀 开始测试 Task #61 的代理配置');
  140. console.log('=' .repeat(60));
  141. await testProxy();
  142. console.log('\n' + '=' .repeat(60));
  143. console.log('✅ 测试完成');
  144. } catch (error) {
  145. console.error('\n❌ 测试失败:', error);
  146. }
  147. }
  148. main();