lrj
19 小时以前 9f8395fab13ca4b230a0f7d62636e209745c91d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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);