39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
import { Client } from 'ssh2';
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('=== 测试后端API(不编码中文) ===\n');
|
|
|
|
console.log('1. 测试查询宁赜的订单(不编码):');
|
|
conn.exec('curl -s "http://localhost:4000/api/orders?collector=宁赜"', (err, stream) => {
|
|
if (err) { console.log('ERR:', err); conn.end(); return; }
|
|
let output = '';
|
|
stream.on('data', (d) => output += d.toString());
|
|
stream.on('close', () => {
|
|
try {
|
|
const result = JSON.parse(output);
|
|
console.log(`返回订单数: ${result.data?.length || 0}`);
|
|
if (result.data && result.data.length > 0) {
|
|
result.data.forEach(order => {
|
|
console.log(` - 订单${order.id}: collector=${order.collector}`);
|
|
});
|
|
}
|
|
} catch (e) {
|
|
console.log('输出:', output);
|
|
}
|
|
conn.end();
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.log('连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect({
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
}); |