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.
86 lines
2.1 KiB
86 lines
2.1 KiB
// 服务器日志调试脚本
|
|
const WebSocket = require('ws');
|
|
|
|
const WS_URL = 'ws://localhost:3003';
|
|
const TEST_MANAGER_ID = '22';
|
|
let managerWs = null;
|
|
|
|
console.log('=== 启动服务器日志调试 ===');
|
|
|
|
// 连接客服WebSocket
|
|
managerWs = new WebSocket(WS_URL);
|
|
|
|
managerWs.on('open', () => {
|
|
console.log('✅ 客服WebSocket连接已建立');
|
|
|
|
// 发送认证消息
|
|
const authMsg = JSON.stringify({
|
|
type: 'auth',
|
|
managerId: TEST_MANAGER_ID,
|
|
userType: 'manager'
|
|
});
|
|
console.log('📤 客服发送认证消息');
|
|
managerWs.send(authMsg);
|
|
});
|
|
|
|
managerWs.on('message', (data) => {
|
|
try {
|
|
const message = JSON.parse(data.toString());
|
|
console.log('📥 客服收到消息类型:', message.type);
|
|
|
|
if (message.type === 'auth_success') {
|
|
console.log('✅ 客服认证成功');
|
|
|
|
// 等待2秒后发送测试消息
|
|
setTimeout(() => {
|
|
sendTestMessage();
|
|
}, 2000);
|
|
}
|
|
|
|
if (message.type === 'error') {
|
|
console.error('❌ 错误消息:', message.message);
|
|
}
|
|
|
|
if (message.type === 'message_sent') {
|
|
console.log('✅ 消息发送成功!');
|
|
}
|
|
} catch (e) {
|
|
console.error('❌ 解析消息失败:', e);
|
|
}
|
|
});
|
|
|
|
managerWs.on('error', (error) => {
|
|
console.error('❌ WebSocket错误:', error);
|
|
});
|
|
|
|
managerWs.on('close', () => {
|
|
console.log('❌ WebSocket连接已关闭');
|
|
});
|
|
|
|
// 发送测试消息
|
|
function sendTestMessage() {
|
|
// 使用一个固定的会话ID进行测试
|
|
const conversationId = '4fa4b92f-df20-40ae-94b9-f906753a4cfd';
|
|
const messageId = 'test_debug_' + Date.now();
|
|
|
|
console.log(`\n📤 发送测试消息 - 会话ID: ${conversationId}, 消息ID: ${messageId}`);
|
|
|
|
const testMessage = {
|
|
type: 'chat_message',
|
|
payload: {
|
|
messageId: messageId,
|
|
conversationId: conversationId,
|
|
content: '服务器日志调试消息',
|
|
contentType: 1
|
|
}
|
|
};
|
|
|
|
managerWs.send(JSON.stringify(testMessage));
|
|
|
|
// 5秒后退出
|
|
setTimeout(() => {
|
|
console.log('\n=== 调试结束 ===');
|
|
managerWs.close();
|
|
process.exit(0);
|
|
}, 5000);
|
|
}
|