Codex Assistant
17 小时以前 58d9f460b2f8c34430285115e2557d18333c5cab
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const http = require('http');
 
// 模拟微信登录获取有效token
function wxLogin() {
    const postData = JSON.stringify({
        code: '0d3mWR000zzp6V1526100pOK7a2mWR0W', // 替换为实际的微信code
        encryptedData: '',
        iv: ''
    });
 
    const options = {
        hostname: 'localhost',
        port: 8080,
        path: '/api/auth/wx-login',
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Content-Length': Buffer.byteLength(postData)
        }
    };
 
    console.log('发送微信登录请求...');
 
    const req = http.request(options, (res) => {
        console.log('响应状态码:', res.statusCode);
 
        let data = '';
        res.on('data', (chunk) => {
            data += chunk;
        });
 
        res.on('end', () => {
            console.log('响应内容:', data);
            try {
                const response = JSON.parse(data);
                if (response.token) {
                    console.log('\n获取到token:', response.token);
                    console.log('用户信息:', response.userInfo);
                    
                    // 使用获取到的token测试saveUserInfo
                    setTimeout(() => {
                        testSaveUserInfo(response.token);
                    }, 1000);
                } else {
                    console.log('登录失败:', response);
                }
            } catch (e) {
                console.log('解析响应失败:', e.message);
            }
        });
    });
 
    req.on('error', (e) => {
        console.error('请求错误:', e.message);
    });
 
    req.write(postData);
    req.end();
}
 
// 使用有效token测试saveUserInfo
function testSaveUserInfo(token) {
    console.log('\n=== 使用有效token测试saveUserInfo ===');
    
    const mutation = `
        mutation SaveUserInfo($input: UserInput!) {
            saveUserInfo(input: $input) {
                id
                name
                phone
                gender
                birthday
                wxOpenId
                unionId
            }
        }
    `;
 
    const variables = {
        input: {
            name: "测试用户JWT",
            phone: "13981970816",
            gender: "MALE",
            birthday: "2025-10-07"
        }
    };
 
    const postData = JSON.stringify({
        query: mutation,
        variables: variables
    });
 
    const options = {
        hostname: 'localhost',
        port: 8080,
        path: '/api/graphql',
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Content-Length': Buffer.byteLength(postData),
            'Authorization': `Bearer ${token}`
        }
    };
 
    console.log('发送GraphQL请求,携带有效token...');
 
    const req = http.request(options, (res) => {
        console.log('响应状态码:', res.statusCode);
 
        let data = '';
        res.on('data', (chunk) => {
            data += chunk;
        });
 
        res.on('end', () => {
            console.log('响应内容:', data);
            try {
                const response = JSON.parse(data);
                if (response.errors) {
                    console.log('GraphQL错误:', response.errors);
                } else {
                    console.log('保存用户信息成功:', response.data);
                }
            } catch (e) {
                console.log('解析响应失败:', e.message);
            }
        });
    });
 
    req.on('error', (e) => {
        console.error('请求错误:', e.message);
    });
 
    req.write(postData);
    req.end();
}
 
// 开始测试
wxLogin();