You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

81 lines
1.9 KiB

// 最小化的消息查询测试脚本
const WebSocket = require('ws');
// 配置
const SERVER_URL = 'ws://localhost:3003';
const MANAGER_ID = '22'; // 客服ID
console.log('=== 最小化消息中心测试 ===');
// 创建WebSocket连接
const ws = new WebSocket(SERVER_URL);
// 连接建立
ws.on('open', () => {
console.log('✅ 连接已建立');
// 发送认证请求
const authMsg = {
type: 'auth',
managerId: MANAGER_ID,
userType: 'manager'
};
console.log('🔑 发送认证:', JSON.stringify(authMsg));
ws.send(JSON.stringify(authMsg));
});
// 消息处理
ws.on('message', (data) => {
const message = JSON.parse(data.toString());
console.log('📥 收到:', JSON.stringify(message));
// 认证成功后发送消息查询
if (message.type === 'auth_success') {
console.log('✅ 认证成功');
// 尝试不同的消息查询格式
setTimeout(() => {
const query = {
type: 'get_message_list',
managerId: MANAGER_ID
};
console.log('\n🔍 尝试查询格式1:', JSON.stringify(query));
ws.send(JSON.stringify(query));
}, 1000);
setTimeout(() => {
const query = {
action: 'fetch_chat_list',
managerId: MANAGER_ID
};
console.log('\n🔍 尝试查询格式2:', JSON.stringify(query));
ws.send(JSON.stringify(query));
}, 3000);
setTimeout(() => {
const query = {
cmd: 'get_chat_history',
managerId: MANAGER_ID
};
console.log('\n🔍 尝试查询格式3:', JSON.stringify(query));
ws.send(JSON.stringify(query));
}, 5000);
}
// 回复心跳
else if (message.type === 'heartbeat') {
ws.send(JSON.stringify({ type: 'heartbeat' }));
}
});
// 错误处理
ws.on('error', (error) => {
console.error('❌ 错误:', error);
});
// 超时关闭
setTimeout(() => {
console.log('\n⏰ 测试超时,关闭连接');
ws.close();
}, 15000);