|
|
@@ -133,7 +133,6 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
jsonString = handleRegister(msgStr);
|
|
|
|
|
|
|
|
|
- // 验证 JSON 格式
|
|
|
JSONObject jsonObject = validateAndParseJson(jsonString);
|
|
|
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
@@ -178,7 +177,6 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
logger.error("regist error:" + e);
|
|
|
}
|
|
|
|
|
|
- /** 输出操作 **/
|
|
|
//执行加密操作
|
|
|
byte[] resultRegister = AES.encrypt(jsonString, key);
|
|
|
System.out.println("加密数据");
|
|
|
@@ -218,12 +216,8 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
NetworkType network = NetworkType.NetworkTypeName(networkCode);
|
|
|
|
|
|
|
|
|
- //判断是否为老代码
|
|
|
boolean isOldCode = paramJson.containsKey("platform");
|
|
|
if (isOldCode) {
|
|
|
- /**
|
|
|
- * 老代码处理
|
|
|
- */
|
|
|
String deviceName = paramJson.getString("deviceId"); //device表中的mac
|
|
|
|
|
|
//执行设备注册操作或查询操作
|
|
|
@@ -242,9 +236,6 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- /**
|
|
|
- * 新代码处理
|
|
|
- */
|
|
|
//平台
|
|
|
Platform platform = null;
|
|
|
//版本
|
|
|
@@ -262,20 +253,14 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
|
//产品编号
|
|
|
String productId = paramJson.getString("productId");
|
|
|
- //如果为空,则默认为1dbfd476b7nm2
|
|
|
productId = StrUtil.isBlank(productId) ? "1dbfd476b7nm2" : productId;
|
|
|
|
|
|
//设备编号
|
|
|
- String deviceName = paramJson.getString("deviceId"); //device表中的mac
|
|
|
+ String deviceName = paramJson.getString("deviceId");
|
|
|
|
|
|
//编码
|
|
|
- String userId = paramJson.getString("userId"); // user表中的code
|
|
|
+ String userId = paramJson.getString("userId");
|
|
|
|
|
|
- /**
|
|
|
- * 先判断UserId和DeviceId是否存在
|
|
|
- * 如果存在进行注册,如果不存在返回code 401
|
|
|
- *
|
|
|
- */
|
|
|
User userIdCode = userMapper.selectByCode(userId);
|
|
|
if (userIdCode == null || StrUtil.isBlank(userIdCode.getCode())) {
|
|
|
json.put("code", NExcCode.ERROR_USERID.getCode());
|
|
|
@@ -287,18 +272,14 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
|
//根据网络类型进行判断
|
|
|
if (NetworkType.WIFI.equals(network)) {
|
|
|
- /**
|
|
|
- * wifi泵
|
|
|
- */
|
|
|
+
|
|
|
platform = Platform.PlatformName(Platform.LOCAL.getCode());
|
|
|
// 处理WiFi注册
|
|
|
json = handleWifiRegistration(paramJson, network, platform, protocol, productId, deviceName, userId);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- /**
|
|
|
- * 新NB,4G泵
|
|
|
- */
|
|
|
+
|
|
|
platform = Platform.PlatformName(Platform.ALIYUN.getCode());
|
|
|
|
|
|
//执行设备注册操作或查询操作
|
|
|
@@ -329,7 +310,6 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
}
|
|
|
|
|
|
|
|
|
- //获取参数中的deviceId
|
|
|
private String extractDeviceId(String msgStr) {
|
|
|
try {
|
|
|
JSONObject json = JSON.parseObject(msgStr);
|
|
|
@@ -340,7 +320,6 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //截取JSON数组中的数据
|
|
|
private JSONObject validateAndParseJson(String jsonString) throws Exception {
|
|
|
try {
|
|
|
return JSONObject.parseObject(jsonString);
|
|
|
@@ -351,7 +330,6 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
}
|
|
|
|
|
|
|
|
|
- //新wifi注册信息
|
|
|
private JSONObject handleWifiRegistration(JSONObject paramJson, NetworkType network, Platform platform, NetworkProtocol protocol, String productId, String deviceName, String userId) throws Exception {
|
|
|
JSONObject json = new JSONObject();
|
|
|
int version = paramJson.getIntValue("version");
|
|
|
@@ -375,10 +353,8 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
String addressArray = userConfig.getAddress();
|
|
|
String deviceSecret = userConfig.getDeviceSecret();
|
|
|
|
|
|
- // 将地址数据转换成JSON数组
|
|
|
JSONArray addressArrayJson = JSON.parseArray(addressArray);
|
|
|
|
|
|
- // 遍历循环, 查找与当前网络类型相同的地址
|
|
|
boolean found = false;
|
|
|
for (Object item : addressArrayJson) {
|
|
|
JSONObject networkInfo = (JSONObject) item;
|
|
|
@@ -397,9 +373,7 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
- // 将WiFi字符串转换成JSON数组
|
|
|
JSONArray wifiArray = JSON.parseArray(wifi);
|
|
|
- // 调用方法转换wifi数据
|
|
|
JSONArray transformWifiArray = WifiDataTrans.transformWifiArray(wifiArray);
|
|
|
json.put("deviceSecret", deviceSecret);
|
|
|
json.put("wifi", transformWifiArray);
|