const http = require('http');

// 测试开发环境免密登录
const loginData = JSON.stringify({ phone: '13800138000', code: '123456' });

const loginOptions = {
  hostname: 'localhost',
  port: 3000,
  path: '/api/auth/login',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': loginData.length
  }
};

const req = http.request(loginOptions, (res) => {
  console.log(`状态码：${res.statusCode}`);
  console.log(`响应头：${JSON.stringify(res.headers)}`);
  
  let data = '';
  res.on('data', (chunk) => { 
    data += chunk;
    console.log('接收中...');
  });
  res.on('end', () => {
    console.log('\n=== 登录响应 ===');
    console.log(data);
    try {
      const response = JSON.parse(data);
      if (response.code === 0) {
        console.log('\n✅ 登录成功!');
        console.log('Token:', response.data.token);
        console.log('用户信息:', JSON.stringify(response.data.user, null, 2));
      } else {
        console.log('\n❌ 登录失败:', response.message);
      }
    } catch (e) {
      console.log('\n解析响应失败:', e.message);
    }
  });
});

req.on('error', (e) => {
  console.error('请求错误:', e.message);
});

console.log('正在发送登录请求...');
req.write(loginData);
req.end();
