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.
111 lines
2.9 KiB
111 lines
2.9 KiB
|
3 months ago
|
// 极简调试脚本
|
||
|
|
const WebSocket = require('ws');
|
||
|
|
|
||
|
|
const WS_URL = 'ws://localhost:3003';
|
||
|
|
const TEST_MANAGER_ID = '22';
|
||
|
|
let managerWs = null;
|
||
|
|
|
||
|
|
// 启动调试
|
||
|
|
function startDebug() {
|
||
|
|
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'
|
||
|
|
});
|
||
|
|
managerWs.send(authMsg);
|
||
|
|
});
|
||
|
|
|
||
|
|
managerWs.on('message', (data) => {
|
||
|
|
try {
|
||
|
|
const message = JSON.parse(data.toString());
|
||
|
|
console.log('📥 收到消息:', JSON.stringify(message));
|
||
|
|
|
||
|
|
if (message.type === 'auth_success') {
|
||
|
|
console.log('✅ 客服认证成功');
|
||
|
|
|
||
|
|
// 等待2秒后发送测试消息
|
||
|
|
setTimeout(() => {
|
||
|
|
// 尝试发送测试消息,使用不同的格式
|
||
|
|
sendTestMessage();
|
||
|
|
}, 2000);
|
||
|
|
}
|
||
|
|
} catch (e) {
|
||
|
|
console.error('❌ 解析消息失败:', e);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
managerWs.on('error', (error) => {
|
||
|
|
console.error('❌ WebSocket错误:', error);
|
||
|
|
});
|
||
|
|
|
||
|
|
managerWs.on('close', () => {
|
||
|
|
console.log('❌ WebSocket连接已关闭');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// 发送测试消息
|
||
|
|
function sendTestMessage() {
|
||
|
|
console.log('\n🔄 测试不同的消息格式...');
|
||
|
|
|
||
|
|
// 测试格式1: 不使用payload包装
|
||
|
|
const format1 = {
|
||
|
|
type: 'chat_message',
|
||
|
|
conversationId: '4fa4b92f-df20-40ae-94b9-f906753a4cfd',
|
||
|
|
content: '测试格式1: 不使用payload包装',
|
||
|
|
contentType: 1
|
||
|
|
};
|
||
|
|
|
||
|
|
console.log('\n📤 发送格式1:', JSON.stringify(format1));
|
||
|
|
managerWs.send(JSON.stringify(format1));
|
||
|
|
|
||
|
|
// 等待1秒后发送下一个格式
|
||
|
|
setTimeout(() => {
|
||
|
|
// 测试格式2: 使用payload包装,但字段名改为驼峰式
|
||
|
|
const format2 = {
|
||
|
|
type: 'chat_message',
|
||
|
|
payload: {
|
||
|
|
conversationId: '4fa4b92f-df20-40ae-94b9-f906753a4cfd',
|
||
|
|
content: '测试格式2: 使用payload包装',
|
||
|
|
contentType: 1
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
console.log('\n📤 发送格式2:', JSON.stringify(format2));
|
||
|
|
managerWs.send(JSON.stringify(format2));
|
||
|
|
|
||
|
|
// 等待1秒后发送下一个格式
|
||
|
|
setTimeout(() => {
|
||
|
|
// 测试格式3: 使用payload包装,添加messageId
|
||
|
|
const format3 = {
|
||
|
|
type: 'chat_message',
|
||
|
|
payload: {
|
||
|
|
messageId: 'test_' + Date.now(),
|
||
|
|
conversationId: '4fa4b92f-df20-40ae-94b9-f906753a4cfd',
|
||
|
|
content: '测试格式3: 添加messageId',
|
||
|
|
contentType: 1
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
console.log('\n📤 发送格式3:', JSON.stringify(format3));
|
||
|
|
managerWs.send(JSON.stringify(format3));
|
||
|
|
|
||
|
|
// 等待5秒后关闭连接
|
||
|
|
setTimeout(() => {
|
||
|
|
console.log('\n=== 调试结束 ===');
|
||
|
|
managerWs.close();
|
||
|
|
}, 5000);
|
||
|
|
}, 1000);
|
||
|
|
}, 1000);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 启动调试
|
||
|
|
startDebug();
|