过滤无用消息
This commit is contained in:
@@ -14,45 +14,53 @@ module.exports = (app) => {
|
||||
console.log('socket客户端已连接');
|
||||
});
|
||||
socket.on('data', async function (data) {
|
||||
let value = data.toString('hex');
|
||||
console.log(value);
|
||||
let response = "000000068100";
|
||||
socket.write(Buffer.from(response, 'hex'));
|
||||
// 00000043010000000000000000000000000000000000000000 18 31353037365f32303236303330333135313835315f323832 00 0f 0102030405060708090a0b0c0d0e0f
|
||||
let sn_value = value.slice(52, 100),
|
||||
snBuffer = Buffer.from(sn_value, 'hex'),
|
||||
snNumber = snBuffer.toString('ascii').split("_")[0].padStart(8, '0'),
|
||||
msg_value = value.slice(104, value.length),
|
||||
msgBuffer = Buffer.from(msg_value, 'hex'),
|
||||
msgData = msgBuffer.toString('ascii');
|
||||
console.log(msgData)
|
||||
// socket接收消息后触发事件监听器,将消息发送给websocket客户端并存储在数据库中
|
||||
shunt.socketEmitter().emit(snNumber, { msg_data: msgData, created_at: new Date() });
|
||||
const shortMsg = await app.curl('http://127.0.0.1:' + app.server.address().port + '/shortMsg', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
sn_number: snNumber,
|
||||
original_msg: value,
|
||||
msg_data: msgData,
|
||||
created_at: new Date()
|
||||
},
|
||||
});
|
||||
if (shortMsg.data.code == 404) {
|
||||
await app.curl('http://127.0.0.1:' + app.server.address().port + '/saveUnknown', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
system_type: 1,
|
||||
original_msg: value,
|
||||
msg_data: msgData,
|
||||
created_at: new Date()
|
||||
},
|
||||
});
|
||||
let value = data.toString('hex');
|
||||
if (value.length > 60) {
|
||||
let Msg_id_len, length, Msg_id, msgID, snNumber, Total_len, Cmd_code, Token, Content_len, Content, msgData;
|
||||
Msg_id_len = value.slice(50, 52);
|
||||
length = 52 + parseInt(Msg_id_len, 16) * 2;
|
||||
Msg_id = value.slice(52, length);
|
||||
msgID = Buffer.from(Msg_id, 'hex').toString();
|
||||
snNumber = msgID.split("_")[0].padStart(8, '0');
|
||||
if (/^\d+$/.test(snNumber) && !/^0+$/.test(snNumber)) {
|
||||
Total_len = value.slice(0, 8);
|
||||
Cmd_code = value.slice(8, 10);
|
||||
Token = value.slice(10, 50);
|
||||
Content_len = value.slice(length, length + 4);
|
||||
Content = value.slice(length + 4, value.length);
|
||||
msgData = Buffer.from(Content, 'hex').toString('ascii');
|
||||
// socket接收消息后触发事件监听器,将消息发送给websocket客户端并存储在数据库中
|
||||
shunt.socketEmitter().emit(snNumber, { msg_data: msgData, created_at: new Date() });
|
||||
const shortMsg = await app.curl('http://127.0.0.1:' + app.server.address().port + '/shortMsg', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
sn_number: snNumber,
|
||||
original_msg: value,
|
||||
msg_data: msgData,
|
||||
created_at: new Date()
|
||||
},
|
||||
});
|
||||
if (shortMsg.data.code == 404) {
|
||||
await app.curl('http://127.0.0.1:' + app.server.address().port + '/saveUnknown', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
msg_id: msgID,
|
||||
sn_number: snNumber,
|
||||
original_msg: value,
|
||||
msg_data: msgData,
|
||||
created_at: new Date()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
socket.on('end', function (data) {
|
||||
|
||||
Reference in New Issue
Block a user