const axios = require('axios'); async function testDirectAPI() { try { console.log('直接测试API调用...'); // 首先登录获取token const loginResponse = await axios.post('http://localhost:3000/login', { account: 'admin', password: '111111' }, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, transformRequest: [(data) => { return Object.keys(data).map(key => `${key}=${encodeURIComponent(data[key])}`).join('&'); }] }); console.log('登录响应:', loginResponse.status, loginResponse.data); if (loginResponse.data.success && loginResponse.data.data) { const token = loginResponse.data.data; console.log('获取到token:', token); // 使用token调用账号列表API const listResponse = await axios.post('http://localhost:3000/tgAccount/list', { page: 1, pageSize: 5 }, { headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'token': token }, transformRequest: [(data) => { return Object.keys(data).map(key => `${key}=${encodeURIComponent(data[key])}`).join('&'); }] }); console.log('列表API响应状态:', listResponse.status); console.log('列表API响应数据结构:', Object.keys(listResponse.data)); if (listResponse.data.data && listResponse.data.data.list) { console.log('总记录数:', listResponse.data.data.totalRow); console.log('当前页记录数:', listResponse.data.data.list.length); if (listResponse.data.data.list.length > 0) { const firstRecord = listResponse.data.data.list[0]; console.log('\n第一条记录的字段:'); console.log('- ID:', firstRecord.id); console.log('- 手机号:', firstRecord.phone); console.log('- 密码:', firstRecord.password); console.log('- Session长度:', firstRecord.session ? firstRecord.session.length : 'null'); console.log('- 姓:', firstRecord.firstname); console.log('- 名:', firstRecord.lastname); console.log('- 简介:', firstRecord.about); console.log('- 状态:', firstRecord.status); console.log('- 是否封号:', firstRecord.isBan); console.log('\n完整的第一条记录:'); console.log(JSON.stringify(firstRecord, null, 2)); } } } else { console.log('登录失败:', loginResponse.data); } } catch (error) { console.error('测试API时出错:', error.message); if (error.response) { console.error('响应状态:', error.response.status); console.error('响应数据:', error.response.data); } } } testDirectAPI();