const axios = require('axios');
|
|
async function testWxLogin() {
|
console.log('=== 测试微信登录接口 ===');
|
|
const graphqlEndpoint = 'http://localhost:8080/api/graphql';
|
|
// 测试微信登录的GraphQL查询
|
const wxLoginQuery = `
|
mutation {
|
wxLogin(input: {
|
code: "test_code_123",
|
loginIp: "192.168.1.100",
|
deviceInfo: "Test Device"
|
}) {
|
token
|
userInfo {
|
userId
|
name
|
phone
|
}
|
isNewUser
|
loginRecordId
|
sessionKey
|
}
|
}
|
`;
|
|
try {
|
console.log('发送微信登录请求...');
|
|
const response = await axios.post(graphqlEndpoint, {
|
query: wxLoginQuery
|
}, {
|
headers: {
|
'Content-Type': 'application/json'
|
}
|
});
|
|
console.log('响应状态:', response.status);
|
|
if (response.data.errors) {
|
console.log('❌ GraphQL错误:');
|
response.data.errors.forEach(error => {
|
console.log(' -', error.message);
|
});
|
}
|
|
if (response.data.data && response.data.data.wxLogin) {
|
const loginResult = response.data.data.wxLogin;
|
console.log('✅ 微信登录成功!');
|
console.log('- Token长度:', loginResult.token ? loginResult.token.length : 0);
|
console.log('- 用户ID:', loginResult.userInfo?.userId);
|
console.log('- 用户名:', loginResult.userInfo?.name);
|
console.log('- 是否新用户:', loginResult.isNewUser);
|
console.log('- 登录记录ID:', loginResult.loginRecordId);
|
console.log('- SessionKey:', loginResult.sessionKey ? `存在(长度: ${loginResult.sessionKey.length})` : '❌ 不存在');
|
|
if (loginResult.sessionKey) {
|
console.log('✅ SessionKey正确返回');
|
} else {
|
console.log('❌ SessionKey未返回,这是问题所在!');
|
}
|
}
|
|
} catch (error) {
|
console.log('❌ 请求失败:');
|
if (error.response) {
|
console.log('状态码:', error.response.status);
|
console.log('响应数据:', JSON.stringify(error.response.data, null, 2));
|
} else {
|
console.log('错误信息:', error.message);
|
}
|
}
|
}
|
|
// 运行测试
|
testWxLogin().catch(console.error);
|