c3fb87d8 张雷

修改包名及结构

1 个父辈 a24316bc
......@@ -62,6 +62,18 @@
<artifactId>fastjson</artifactId>
<version>1.2.56</version>
</dependency>
<!-- commons -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!--hutool-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.5.11</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
......
package com.jkdata.controller;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.jkdata.service.IThirdService;
import com.jkdata.tool.Result;
......@@ -40,14 +41,14 @@ public class ThirdController {
//初始化数据
private JSONObject initData(String resMsg) {
resMsg = "{\"Gateway\":\"10030049\"," +
"\"NodeId\":\"CB8A1DEB\"," +
"\"SystemId\":\"10990145\"," +
"\"Type\":\"location_pos\"," +
"\"group\":\"5\"," +
"\"groupNumber\":1," +
"\"position\":{\"x\":214.44541185285127,\"y\":210.15474327170986}," +
"\"scale\":0}";
// resMsg = "{\"Gateway\":\"10030049\"," +
// "\"NodeId\":\"CB8A1DEB\"," +
// "\"SystemId\":\"10990145\"," +
// "\"Type\":\"location_pos\"," +
// "\"group\":\"5\"," +
// "\"groupNumber\":1," +
// "\"position\":{\"x\":214.44541185285127,\"y\":210.15474327170986}," +
// "\"scale\":0}";
System.out.println("***"+System.currentTimeMillis()+"报文***"+resMsg);
JSONObject jsonObject = new JSONObject();
jsonObject = JSONObject.parseObject(resMsg);
......@@ -70,4 +71,31 @@ public class ThirdController {
}
/**
* 获取静态资源信息
* @return
*/
@GetMapping("/buildingAllInfo")
public Result<String> getBuildingAllInfo() {
Result<String> result = new Result<String>();
String res = thirdService.getBuildingAllInfo();
result.setSuccess(true);
result.setResult(res);
return result;
}
/**
* 获取历史轨迹
* @param deviceId
* @return
*/
@GetMapping("/positionByDeviceId")
public Result<String> getPositionByDeviceId(String deviceId,String startTime,String endTime) {
Result<String> result = new Result<String>();
String res = thirdService.getPositionByDeviceId(deviceId, startTime, endTime);
result.setSuccess(true);
result.setResult(res);
return result;
}
}
......
......@@ -2,8 +2,13 @@ package com.jkdata.service;
import com.alibaba.fastjson.JSONObject;
import java.util.Map;
public interface IThirdService {
void savePosition(JSONObject jsonObject);
String getBuildingAllInfo();
String getPositionByDeviceId(String deviceId,String startTime,String endTime);
}
......
package com.jkdata.service.impl;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.jkdata.tool.CommonConstant;
import com.jkdata.entity.ThirdPosition;
import com.jkdata.mapper.ThirdMapper;
import com.jkdata.service.IThirdService;
import com.jkdata.tool.MD5Util;
import com.jkdata.tool.RedisUtil;
import com.jkdata.tool.UUIDGenerator;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.*;
@Service
public class IThirdServiceImpl implements IThirdService {
......@@ -129,4 +131,61 @@ public class IThirdServiceImpl implements IThirdService {
return ok;
}
@Override
public String getBuildingAllInfo() {
HashMap<String,Object> map = new HashMap<>();
String tmsp = String.valueOf(System.currentTimeMillis()/1000);
map.put("bldId",CommonConstant.BLD_ID);
map.put("ts",tmsp);
String [] arr = { CommonConstant.BLD_ID,tmsp,CommonConstant.CMCC_KEY };
Comparator<String> c = String::compareTo;
Arrays.sort(arr, c);
System.out.println("sign参数:"+Arrays.toString(arr));
String str = StringUtils.join(Arrays.asList(new String[]{CommonConstant.BLD_ID,tmsp,CommonConstant.CMCC_KEY}),",")
.replace(",","");
System.out.println("sign参数:"+str);
String strMd5 = MD5Util.getMD5LowerCase(str);
System.out.println("加密后参数:"+str);
map.put("sgn",strMd5);
String post = HttpUtil.post(CommonConstant.BUILD_URL,map);
System.out.println("请求结果:"+post);
return post;
}
@Override
public String getPositionByDeviceId(String deviceId,String startTime,String endTime) {
HashMap<String,Object> map = new HashMap<>();
String tmsp = String.valueOf(System.currentTimeMillis()/1000);
map.put("bldId",CommonConstant.BLD_ID);
map.put("ts",tmsp);
map.put("deviceId",deviceId);
map.put("page","0");
map.put("count","200");
map.put("startTime",startTime);
map.put("endTime",endTime);
String [] arr = { CommonConstant.BLD_ID,deviceId,startTime,endTime,"0","200",tmsp,CommonConstant.CMCC_KEY };
Comparator<String> c = String::compareTo;
Arrays.sort(arr, c);
System.out.println("sign参数:"+Arrays.toString(arr));
String str = StringUtils.join(Arrays.asList(new String[]{CommonConstant.BLD_ID,deviceId,startTime,endTime,
"0","1000",tmsp,CommonConstant.CMCC_KEY}),",")
.replace(",","");
System.out.println("sign参数:"+str);
String strMd5 = MD5Util.getMD5LowerCase(str);
System.out.println("加密后参数:"+str);
map.put("sgn",strMd5);
String post = HttpUtil.post(CommonConstant.HISTORY_URL,map);
System.out.println("请求结果:"+post);
return post;
}
}
......
......@@ -25,4 +25,18 @@ public interface CommonConstant {
//**********************推送用户***************************
String CMCC = "CMCC";//联通推送用户
String BLD_ID = "10";//定位系统项目ID
String CMCC_KEY = "f9257afea27943d7bcd7cc510f1b50dc";//定位系统秘钥
//************************场景信息********************************
String BUILD_URL = "http://52.131.253.116/api/v1/buildingAllInfo.shtml";
//************************历史轨迹********************************
String HISTORY_URL = "http://52.131.253.116/api/positionByDeviceId.shtml";
//************************历史轨迹********************************
String ALARM_URL = "http://52.131.253.116/api/v1/alarmListByCount.shtml";
}
......
package com.jkdata.tool;
import java.math.BigInteger;
import java.security.MessageDigest;
public class MD5Util {
/**
* 对字符串md5加密
*
* @param str 传入要加密的字符串
* @return MD5加密后的字符串(小写+字母)
*/
public static String getMD5LowerCase(String str) {
try {
// 生成一个MD5加密计算摘要
MessageDigest md = MessageDigest.getInstance("MD5");
// 计算md5函数
md.update(str.getBytes());
// digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符
// BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值
return new BigInteger(1, md.digest()).toString(16);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 对字符串md5加密
*
* @param s 传入要加密的字符串
* @return MD5加密后的字符串(大写+数字)
*/
public static String getMD5UpperCase(String s) {
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F' };
try {
byte[] btInput = s.getBytes();
// 获得MD5摘要算法的 MessageDigest 对象
MessageDigest mdInst = MessageDigest.getInstance("MD5");
// 使用指定的字节更新摘要
mdInst.update(btInput);
// 获得密文
byte[] md = mdInst.digest();
// 把密文转换成十六进制的字符串形式
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
String str = "\"我+Admin1234~!@#¥%……&*()\"";
System.out.println(str);
//"我+Admin1234~!@#¥%……&*()"
String s1 = getMD5LowerCase(str);
System.out.println(s1);
//6bb6f83c026357a15cdf12e5d6b2b310
String s2 = getMD5UpperCase(str);
System.out.println(s2);
//6BB6F83C026357A15CDF12E5D6B2B310
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!