Commit 9917ef7a by luozhenzhen

修改字符串存储为对象

parent 178f4418
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
<version>1.2.54</version> <version>1.2.54</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
......
package com.demo.entity.dto; package com.demo.entity.dto;
import com.alibaba.fastjson.JSONObject;
public class DeviceReturnDto { public class DeviceReturnDto {
private String data; private JSONObject data;
private int datelen; private int datelen;
private String akey; //RSA加密的AES密钥 private String akey; //RSA加密的AES密钥
private String pkey; //RSA公钥 private String pkey; //RSA公钥
...@@ -10,18 +12,18 @@ public class DeviceReturnDto { ...@@ -10,18 +12,18 @@ public class DeviceReturnDto {
public DeviceReturnDto() { public DeviceReturnDto() {
} }
public DeviceReturnDto(String data, int datelen, String akey, String pkey) { public DeviceReturnDto(JSONObject data, int datelen, String akey, String pkey) {
this.data = data; this.data = data;
this.datelen = datelen; this.datelen = datelen;
this.akey = akey; this.akey = akey;
this.pkey = pkey; this.pkey = pkey;
} }
public String getData() { public JSONObject getData() {
return data; return data;
} }
public void setData(String data) { public void setData(JSONObject data) {
this.data = data; this.data = data;
} }
......
package com.demo.entity.po; package com.demo.entity.po;
import com.alibaba.fastjson.JSONObject;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
...@@ -10,24 +11,24 @@ import org.springframework.data.mongodb.core.mapping.Document; ...@@ -10,24 +11,24 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection = "DeviceConf") @Document(collection = "DeviceConf")
public class DeviceConf { public class DeviceConf {
private String confInfo; private JSONObject confInfo;
private Boolean status; private Boolean status;
private String os; private String os;
public DeviceConf() { public DeviceConf() {
} }
public DeviceConf(String confInfo, Boolean status, String os) { public DeviceConf(JSONObject confInfo, Boolean status, String os) {
this.confInfo = confInfo; this.confInfo = confInfo;
this.status = status; this.status = status;
this.os = os; this.os = os;
} }
public String getConfInfo() { public JSONObject getConfInfo() {
return confInfo; return confInfo;
} }
public void setConfInfo(String confInfo) { public void setConfInfo(JSONObject confInfo) {
this.confInfo = confInfo; this.confInfo = confInfo;
} }
......
package com.demo.entity.po; package com.demo.entity.po;
import com.alibaba.fastjson.JSONObject;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date; import java.util.Date;
...@@ -8,14 +9,14 @@ import java.util.Date; ...@@ -8,14 +9,14 @@ import java.util.Date;
public class DeviceInfo { public class DeviceInfo {
private String os; private String os;
private String info; private JSONObject info;
private String reyunId; private String reyunId;
private Long timestamp; private Long timestamp;
public DeviceInfo() { public DeviceInfo() {
} }
public DeviceInfo(String os, String info, String reyunId) { public DeviceInfo(String os, JSONObject info, String reyunId) {
this.os = os; this.os = os;
this.info = info; this.info = info;
this.reyunId = reyunId; this.reyunId = reyunId;
...@@ -30,11 +31,11 @@ public class DeviceInfo { ...@@ -30,11 +31,11 @@ public class DeviceInfo {
this.os = os; this.os = os;
} }
public String getInfo() { public JSONObject getInfo() {
return info; return info;
} }
public void setInfo(String info) { public void setInfo(JSONObject info) {
this.info = info; this.info = info;
} }
......
package com.demo.entity.po; package com.demo.entity.po;
import com.alibaba.fastjson.JSONObject;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
...@@ -10,13 +11,13 @@ public class SensorInfo { ...@@ -10,13 +11,13 @@ public class SensorInfo {
private String reyunId; private String reyunId;
private Long timestamp; private Long timestamp;
private String sensorInfo; private JSONObject sensorInfo;
private String os; private String os;
public SensorInfo() { public SensorInfo() {
} }
public SensorInfo(String reyunId, Long timestamp, String sensorInfo, String os) { public SensorInfo(String reyunId, Long timestamp, JSONObject sensorInfo, String os) {
this.reyunId = reyunId; this.reyunId = reyunId;
this.timestamp = timestamp; this.timestamp = timestamp;
this.sensorInfo = sensorInfo; this.sensorInfo = sensorInfo;
...@@ -39,11 +40,11 @@ public class SensorInfo { ...@@ -39,11 +40,11 @@ public class SensorInfo {
this.timestamp = timestamp; this.timestamp = timestamp;
} }
public String getSensorInfo() { public JSONObject getSensorInfo() {
return sensorInfo; return sensorInfo;
} }
public void setSensorInfo(String sensorInfo) { public void setSensorInfo(JSONObject sensorInfo) {
this.sensorInfo = sensorInfo; this.sensorInfo = sensorInfo;
} }
......
...@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray; ...@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.demo.entity.po.DeviceConf; import com.demo.entity.po.DeviceConf;
import com.demo.util.ResultObject; import com.demo.util.ResultObject;
import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -312,7 +313,9 @@ public class DataImportController { ...@@ -312,7 +313,9 @@ public class DataImportController {
str = str.replaceAll("\n",""); str = str.replaceAll("\n","");
str = str.replaceAll("\t",""); str = str.replaceAll("\t","");
DeviceConf deviceConf = new DeviceConf(str, true, "ios"); str = StringEscapeUtils.unescapeJavaScript(str);
JSONObject data = JSON.parseObject(str);
DeviceConf deviceConf = new DeviceConf(data, true, "ios");
mongoTemplate.insert(deviceConf); mongoTemplate.insert(deviceConf);
return new ResultObject(HttpServletResponse.SC_OK); return new ResultObject(HttpServletResponse.SC_OK);
...@@ -750,9 +753,10 @@ public class DataImportController { ...@@ -750,9 +753,10 @@ public class DataImportController {
"}"; "}";
str = str.replaceAll("\n",""); str = str.replaceAll("\n","");
str = str.replaceAll("\t",""); str = str.replaceAll("\t","");
DeviceConf deviceConf = new DeviceConf(str, true, "android"); str = StringEscapeUtils.unescapeJavaScript(str);
JSONObject data = JSON.parseObject(str);
DeviceConf deviceConf = new DeviceConf(data, true, "android");
mongoTemplate.insert(deviceConf); mongoTemplate.insert(deviceConf);
return new ResultObject(HttpServletResponse.SC_OK); return new ResultObject(HttpServletResponse.SC_OK);
} }
......
...@@ -14,6 +14,7 @@ import com.reyun.Algorithm; ...@@ -14,6 +14,7 @@ import com.reyun.Algorithm;
import com.demo.util.DeformedBase64; import com.demo.util.DeformedBase64;
import com.demo.util.RSAUtil; import com.demo.util.RSAUtil;
import com.demo.util.SecretUtil; import com.demo.util.SecretUtil;
import org.apache.commons.lang.StringEscapeUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -116,11 +117,11 @@ public class DeviceService { ...@@ -116,11 +117,11 @@ public class DeviceService {
logger.info("getDeviceConf 获取配置信息失败:{}", JSONObject.toJSONString(deviceConfVo)); logger.info("getDeviceConf 获取配置信息失败:{}", JSONObject.toJSONString(deviceConfVo));
return null; return null;
} }
String data = deviceConf.getConfInfo(); JSONObject data = deviceConf.getConfInfo();
try{ try{
logger.info("secret.getAesKey():{} secret.getPrivateRsaKey():{}", secret.getAesKey(), secret.getPrivateRsaKey()); logger.info("secret.getAesKey():{} secret.getPrivateRsaKey():{}", secret.getAesKey(), secret.getPrivateRsaKey());
DeviceReturnDto deviceReturnDto = new DeviceReturnDto(data, data.length(), DeviceReturnDto deviceReturnDto = new DeviceReturnDto(data, data.toJSONString().length(),
SpecialSecret.getSecretAesStr(secret.getAesKey(), secret.getPrivateRsaKey()), SpecialSecret.getSecretAesStr(secret.getAesKey(), secret.getPrivateRsaKey()),
SpecialSecret.getSecretRSAStr(secret.getPublicRsaKey())); SpecialSecret.getSecretRSAStr(secret.getPublicRsaKey()));
...@@ -190,24 +191,27 @@ public class DeviceService { ...@@ -190,24 +191,27 @@ public class DeviceService {
} }
} }
String reyunId = getReyunId(clientReyunId, deviceId, secret.getPublicRsaKey()); String reyunId = getReyunId(clientReyunId, deviceId, secret.getPublicRsaKey());
// String reyunId = UUID.randomUUID()+""; String reyunIdReal = reyunId.replaceAll("\\\\","");//去掉\反义字符,防止后面转化的时候导致不一致
reyunIdMap.put("reyunId", reyunId); reyunIdMap.put("reyunId", reyunIdReal);
//区分系统保存数据 //区分系统保存数据
//去掉转义字符 //去掉转义字符
data = StringUtils.isEmpty(data) ? data : data.replaceAll("\\\\", ""); data = StringUtils.isEmpty(data) ? data : data.replaceAll("\n","");
DeviceInfo deviceInfo = new DeviceInfo(osEnum.getVal(), data, reyunId); String dataReal = StringEscapeUtils.unescapeJavaScript(data);
JSONObject jsonData = JSONObject.parseObject(dataReal);
DeviceInfo deviceInfo = new DeviceInfo(osEnum.getVal(), jsonData, reyunIdReal);
deviceInfoDao.insert(deviceInfo); deviceInfoDao.insert(deviceInfo);
String dataStr = JSONObject.toJSONString(reyunIdMap); JSONObject result = (JSONObject) JSON.toJSON(reyunIdMap);
try{ try{
DeviceReturnDto deviceReturnDto = new DeviceReturnDto(dataStr, dataStr.length(), DeviceReturnDto deviceReturnDto = new DeviceReturnDto(result, result.toJSONString().length(),
SpecialSecret.getSecretAesStr(secret.getAesKey(), secret.getPublicRsaKey()), SpecialSecret.getSecretAesStr(secret.getAesKey(), secret.getPublicRsaKey()),
SpecialSecret.getSecretRSAStr(secret.getPublicRsaKey())); SpecialSecret.getSecretRSAStr(secret.getPublicRsaKey()));
String result = SpecialSecret.aesData(JSONObject.toJSONString(deviceReturnDto), secret.getAesKey()); String resultStr = SpecialSecret.aesData(JSONObject.toJSONString(deviceReturnDto), secret.getAesKey());
return result; return resultStr;
}catch (Exception e){ }catch (Exception e){
logger.info("getDeviceId 获取dll动态库失败:{}", JSONObject.toJSONString(deviceIdVo)); logger.info("getDeviceId 获取dll动态库失败:{}", JSONObject.toJSONString(deviceIdVo));
} }
...@@ -320,8 +324,10 @@ public class DeviceService { ...@@ -320,8 +324,10 @@ public class DeviceService {
//保存数据 //保存数据
String reyunId = dataObject.getString("reyunId"); String reyunId = dataObject.getString("reyunId");
//去掉转义字符 //去掉转义字符
data = StringUtils.isEmpty(data) ? data : data.replaceAll("\\\\",""); data = StringUtils.isEmpty(data) ? data : data.replaceAll("\n","");
SensorInfo sensorInfo = new SensorInfo(reyunId, new Date().getTime(), data, osEnum.getVal()); String dataReal = StringEscapeUtils.unescapeJavaScript(data);
JSONObject dataJson = JSONObject.parseObject(dataReal);
SensorInfo sensorInfo = new SensorInfo(reyunId, new Date().getTime(), dataJson, osEnum.getVal());
sensorInfoDao.insert(sensorInfo); sensorInfoDao.insert(sensorInfo);
return true; return true;
} }
......
...@@ -87,7 +87,7 @@ public class FileEncryptor { ...@@ -87,7 +87,7 @@ public class FileEncryptor {
} }
public static byte[] inputStreamToByte(InputStream input) throws IOException{ public static byte[] inputStreamToByte(InputStream input) throws IOException{
byte[] b = new byte[4096]; byte[] b = new byte[input.available()];
for (int n; (n = input.read(b)) != -1;) { for (int n; (n = input.read(b)) != -1;) {
} }
return b; return b;
...@@ -171,7 +171,7 @@ public class FileEncryptor { ...@@ -171,7 +171,7 @@ public class FileEncryptor {
public static void downloadFileToPath(String sourceFilePath, String fileName, HttpServletResponse resp) throws Exception{ public static void downloadFileToPath(String sourceFilePath, String fileName, HttpServletResponse resp) throws Exception{
String realName = fileName; String realName = fileName;
try{ try{
realName = URLEncoder.encode(realName,"utf-8"); realName = URLEncoder.encode(realName,"utf-8");
}catch (Exception e){ }catch (Exception e){
...@@ -183,23 +183,22 @@ public class FileEncryptor { ...@@ -183,23 +183,22 @@ public class FileEncryptor {
try { try {
File sourceFile = new File(sourceFilePath); File sourceFile = new File(sourceFilePath);
if (sourceFile.exists() && sourceFile.isFile()) { if (sourceFile.exists() && sourceFile.isFile()) {
FileInputStream in = new FileInputStream(sourceFile); FileInputStream in = new FileInputStream(sourceFile);
out = resp.getOutputStream(); out = resp.getOutputStream();
// byte[] cache = new byte[CACHE_SIZE]; byte[] data = inputStreamToByte(in);
// int nRead = 0; //base64
// while ((nRead = in.read(cache)) != -1) { char[] aesData = DeformedBase64.encode(data);
// out.write(cache, 0, nRead); ByteArrayInputStream cin = StringToInputStream(getBytes(aesData));
// out.flush();
// } int nRead = 0;
int nRead = 0; while ((nRead = cin.read()) != -1) {
while ((nRead = in.read()) != -1) { out.write(nRead);
out.write(nRead); out.flush();
out.flush(); }
} }
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -219,6 +218,13 @@ public class FileEncryptor { ...@@ -219,6 +218,13 @@ public class FileEncryptor {
//// InputStream in = new FileInputStream(sourceFilePath); //// InputStream in = new FileInputStream(sourceFilePath);
//// System.out.println(inputStreamToString(in)); //// System.out.println(inputStreamToString(in));
//// downloadFileToPath(sourceFilePath, "C:\\Users\\reyun\\Desktop\\mongo.jar"); //// downloadFileToPath(sourceFilePath, "C:\\Users\\reyun\\Desktop\\mongo.jar");
// }
// String data = "{ \"initialFirmware\" : \"8.0\", \"riskExist\" : \"0\", \"systemVersion\" : \"11.1\", \"isp\" : \"46001\", \"netWorkType\" : \"WIFI\", \"usedDiskValue\" : \"6363.00\", \"iPhoneName\" : \"iPhone\", \"purgableMemoryValue\" : \"7.95\", \"totalMemoryValue\" : \"989.00\", \"wifiDbm\" : \"-64\", \"wifiAddress\" : \"fe80::14fb:2b53:573a:9331\", \"platform\" : \"iOS\", \"allBusFrequency\" : 0, \"isDebugging\" : \"1\", \"freeMemoryValue\" : \"55.17\", \"totalDiskValue\" : \"15248.76\", \"systemWiredMemoryValue\" : \"190.02\", \"useLanuage\" : \"zh-Hans-CN\", \"localDeviceIp\" : \"192.168.168.124\", \"networkIp\" : \"119.57.108.226\", \"isUsingVPN\" : \"0\", \"cpuUsage\" : 0.2101379781961441, \"reyunId\" : \"QLQ08\\/KgnyoqYZEPNp4bv\\/ySCP5QN\\/NxM348iR6qQZNcNLBKYeBEg54+ClBGny7P2L4plE8\\/le5ZNi4fvR708Sp15R7UMi7e5SYLmluIT5\\/1vGKeNbNck\\/5HTijdi\\/5lvMYG5S7JkR7hQ5QMgM8\\/CPN2QSQenbCfi5NRmPNvgZ\\/4CppKmE8ZMeroNsudlsBPgbXvcp7Tkbuqe3grcbYJCi8vlEP8veKiNDLoJc==\", \"remainBattery\" : \"1647.10\", \"systemName\" : \"iOS\", \"batteryStatus\" : \"Charging\", \"ramMemorySize\" : 1037041664, \"isJailbreak\" : \"1\", \"screenWidth\" : \"375.00\", \"screenBrightness\" : \"0.56\", \"cpuName\" : \"Apple A8\", \"wifiStrength\" : 3, \"deviceName\" : \"iPhone 6\", \"idfv\" : \"BBEF0D9C-75A2-41D8-ACB3-0BB367965E37\", \"cellStrength\" : 4, \"ispName\" : \"中国联通\", \"canMakePhoneCall\" : \"1\", \"httpProxy\" : \"192.168.168.176\", \"networkCountryIso\" : \"cn\", \"screenHeight\" : \"667.00\", \"batteryVoltage\" : \"3.82\", \"httpPort\" : 8888, \"batteryCapacityValue\" : \"1810\", \"currentCountry\" : \"zh_CN\", \"activeMemoryValue\" : \"474.96\", \"iPhoneCellIP\" : \"null\", \"gatewayAddress\" : \"192.168.168.1\", \"idfa\" : \"8AAAC858-396E-4467-8B47-7EF1363B4EDD\", \"appVersion\" : \"1.0\", \"localizedModel\" : \"iPhone\", \"ssidName\" : \"Reyun-online5G\", \"latestSystemUptime\" : \"2019-09-20 18:25:29\", \"usedMemoryValue\" : \"860.39\", \"latestFirmware\" : \"12.3.1\", \"deviceModel\" : \"iPhone7,2\", \"perCPUUsage\" : \"0.18|0.03\", \"isAppActive\" : \"1\", \"batteryLevel\" : \"0.91\", \"isInjection\" : \"0\", \"isUsingProxy\" : \"1\", \"cpuFrequency\" : 0, \"cpuCounts\" : 2, \"inActiveMemoryValue\" : \"195.41\", \"freeDiskValue\" : \"8885.77\"}\n";
// System.out.println(data.replaceAll("\\\\",""));
// String str = data.replaceAll("\\\\","");
// System.out.println(str);
//
//
// }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment