fix: 工牌鉴权注册逻辑
All checks were successful
iot-test-platform CI/CD / build-and-deploy (push) Successful in 24s

This commit is contained in:
lzh
2025-12-15 13:37:49 +08:00
parent 658c288f87
commit 8837757b25
5 changed files with 23 additions and 19 deletions

View File

@@ -42,9 +42,9 @@ public class RegisterPack extends DataPack {
private int cityId; private int cityId;
// 制造商ID(BYTE[5]) 5 个字节,终端制造商编码 // 制造商ID(BYTE[5]) 5 个字节,终端制造商编码
private String manufacturerId; private String manufacturerId;
// 终端型号(BYTE[8]) 个字节, 此终端型号 由制造商自行定义 位数不足八位的,补空格 // 终端型号(BYTE[20]) 20个字节,此终端型号由制造商自行定义位数不足后补“0X00”
private String terminalType; private String terminalType;
// 终端ID(BYTE[7]) 个字节, 由大写字母 和数字组成, 此终端 ID由制造 商自行定义 // 终端ID(BYTE[7]) 7个字节由大写字母和数字组成此终端ID由制造商自行定义位数不足时后补“0X00”。
private String terminalId; private String terminalId;
/** /**
* *

View File

@@ -195,17 +195,17 @@ public class DataDecoder {
// byte[] tmp = new byte[5]; // byte[] tmp = new byte[5];
body.setManufacturerId(this.parseStringFromBytes(data, 4, 5)); body.setManufacturerId(this.parseStringFromBytes(data, 4, 5));
// 4. byte[9-16] 终端型号(BYTE[8]) 个字节, 此终端型号 由制造商自行定义 位数不足八位的,补空格 // 4. byte[9-28] 终端型号(BYTE[20]) 20个字节,此终端型号由制造商自行定义位数不足后补“0X00”
body.setTerminalType(this.parseStringFromBytes(data, 9, 8)); body.setTerminalType(this.parseStringFromBytes(data, 9, 20));
// 5. byte[17-23] 终端ID(BYTE[7]) 个字节, 由大写字母 和数字组成, 此终端 ID由制造 商自行定义 // 5. byte[29-35] 终端ID(BYTE[7]) 7个字节由大写字母和数字组成此终端ID由制造商自行定义位数不足时后补“0X00”。
body.setTerminalId(this.parseStringFromBytes(data, 17, 7)); body.setTerminalId(this.parseStringFromBytes(data, 29, 7));
// 6. byte[24] 车牌颜色(BYTE) 车牌颜 色按照JT/T415-20065.4.12 的规定 // 6. byte[36] 车牌颜色(BYTE) 车牌颜色按照JT/T415-20065.4.12。未上牌时取值为0。
body.setLicensePlateColor(this.parseIntFromBytes(data, 24, 1)); body.setLicensePlateColor(this.parseIntFromBytes(data, 36, 1));
// 7. byte[25-x] 车(STRING) 公安交 通管理部门颁 发的机动车号牌 // 7. byte[37-x] 车辆标识(STRING) 车牌颜色为0时表示车辆VIN否则表示公安交通管理部门颁发的机动车号牌
body.setLicensePlate(this.parseStringFromBytes(data, 25, data.length - 25)); body.setLicensePlate(this.parseStringFromBytes(data, 37, data.length - 37));
ret.setTerminalRegInfo(body); ret.setTerminalRegInfo(body);
return ret; return ret;

View File

@@ -40,9 +40,9 @@ public class DataEncoder {
Consts.CMD_TEXT_INFO_DOWN, msgBody, msgBodyProps, session.currentFlowId()); Consts.CMD_TEXT_INFO_DOWN, msgBody, msgBodyProps, session.currentFlowId());
byte[] headerAndBody = this.bitUtil.concatAll(msgHeader, msgBody); byte[] headerAndBody = this.bitUtil.concatAll(msgHeader, msgBody);
// 校验码 // 校验码
int checkSum = this.bitUtil.getCheckSum4JT808(headerAndBody, 0, headerAndBody.length - 1); int checkSum = this.bitUtil.getCheckSum4JT808(headerAndBody, 0, headerAndBody.length);
return this.doEncode(headerAndBody, checkSum); return this.doEncode(headerAndBody, checkSum);
} }
public byte[] encode4LocationInquiry(LocationInquiryPack req, Session session) throws Exception { public byte[] encode4LocationInquiry(LocationInquiryPack req, Session session) throws Exception {
@@ -55,7 +55,7 @@ public class DataEncoder {
byte[] headerAndBody = this.bitUtil.concatAll(msgHeader, msgBody); byte[] headerAndBody = this.bitUtil.concatAll(msgHeader, msgBody);
// 校验码 // 校验码
int checkSum = this.bitUtil.getCheckSum4JT808(headerAndBody, 0, headerAndBody.length - 1); int checkSum = this.bitUtil.getCheckSum4JT808(headerAndBody, 0, headerAndBody.length);
return this.doEncode(headerAndBody, checkSum); return this.doEncode(headerAndBody, checkSum);
} }
@@ -84,7 +84,7 @@ public class DataEncoder {
byte[] headerAndBody = this.bitUtil.concatAll(msgHeader, msgBody); byte[] headerAndBody = this.bitUtil.concatAll(msgHeader, msgBody);
// 校验码 // 校验码
int checkSum = this.bitUtil.getCheckSum4JT808(headerAndBody, 0, headerAndBody.length - 1); int checkSum = this.bitUtil.getCheckSum4JT808(headerAndBody, 0, headerAndBody.length);
// 连接并且转义 // 连接并且转义
return this.doEncode(headerAndBody, checkSum); return this.doEncode(headerAndBody, checkSum);
} }
@@ -105,7 +105,7 @@ public class DataEncoder {
Consts.CMD_COMMON_RESP, msgBody, msgBodyProps, flowId); Consts.CMD_COMMON_RESP, msgBody, msgBodyProps, flowId);
byte[] headerAndBody = this.bitUtil.concatAll(msgHeader, msgBody); byte[] headerAndBody = this.bitUtil.concatAll(msgHeader, msgBody);
// 校验码 // 校验码
int checkSum = this.bitUtil.getCheckSum4JT808(headerAndBody, 0, headerAndBody.length - 1); int checkSum = this.bitUtil.getCheckSum4JT808(headerAndBody, 0, headerAndBody.length);
// 连接并且转义 // 连接并且转义
return this.doEncode(headerAndBody, checkSum); return this.doEncode(headerAndBody, checkSum);
} }
@@ -118,7 +118,7 @@ public class DataEncoder {
// 连接消息头和消息体 // 连接消息头和消息体
byte[] headerAndBody = this.bitUtil.concatAll(msgHeader, msgBodyBytes); byte[] headerAndBody = this.bitUtil.concatAll(msgHeader, msgBodyBytes);
// 校验码 // 校验码
int checkSum = this.bitUtil.getCheckSum4JT808(headerAndBody, 0, headerAndBody.length - 1); int checkSum = this.bitUtil.getCheckSum4JT808(headerAndBody, 0, headerAndBody.length);
// 连接并且转义 // 连接并且转义
return this.doEncode(headerAndBody, checkSum); return this.doEncode(headerAndBody, checkSum);
} }

View File

@@ -44,9 +44,9 @@ public class RegisterHandler extends MessageHandler {
RegisterBodyPack respMsgBody = new RegisterBodyPack(); RegisterBodyPack respMsgBody = new RegisterBodyPack();
respMsgBody.setReplyCode(RegisterBodyPack.success); respMsgBody.setReplyCode(RegisterBodyPack.success);
respMsgBody.setReplyFlowId(msg.getPackHead().getFlowId()); respMsgBody.setReplyFlowId(msg.getPackHead().getFlowId());
// 使用手机号作为鉴权码
respMsgBody.setReplyToken(msg.getPackHead().getTerminalPhone());
// TODO 鉴权码暂时写死
respMsgBody.setReplyToken("123");
int flowId = super.getFlowId(msg.getChannel()); int flowId = super.getFlowId(msg.getChannel());
byte[] bs = this.msgEncoder.encode4TerminalRegisterResp(msg, respMsgBody, flowId); byte[] bs = this.msgEncoder.encode4TerminalRegisterResp(msg, respMsgBody, flowId);
@@ -57,4 +57,5 @@ public class RegisterHandler extends MessageHandler {
} }
} }

View File

@@ -111,6 +111,9 @@ public class JT808Util {
if (bs[i] == 0x7e) { if (bs[i] == 0x7e) {
baos.write(0x7d); baos.write(0x7d);
baos.write(0x02); baos.write(0x02);
} else if (bs[i] == 0x7d) {
baos.write(0x7d);
baos.write(0x01);
} else { } else {
baos.write(bs[i]); baos.write(bs[i]);
} }