修改包名及结构
正在显示
6 个修改的文件
包含
204 行增加
和
10 行删除
... | @@ -62,6 +62,18 @@ | ... | @@ -62,6 +62,18 @@ |
62 | <artifactId>fastjson</artifactId> | 62 | <artifactId>fastjson</artifactId> |
63 | <version>1.2.56</version> | 63 | <version>1.2.56</version> |
64 | </dependency> | 64 | </dependency> |
65 | <!-- commons --> | ||
66 | <dependency> | ||
67 | <groupId>commons-lang</groupId> | ||
68 | <artifactId>commons-lang</artifactId> | ||
69 | <version>2.6</version> | ||
70 | </dependency> | ||
71 | <!--hutool--> | ||
72 | <dependency> | ||
73 | <groupId>cn.hutool</groupId> | ||
74 | <artifactId>hutool-all</artifactId> | ||
75 | <version>4.5.11</version> | ||
76 | </dependency> | ||
65 | <dependency> | 77 | <dependency> |
66 | <groupId>org.springframework.boot</groupId> | 78 | <groupId>org.springframework.boot</groupId> |
67 | <artifactId>spring-boot-starter-data-redis</artifactId> | 79 | <artifactId>spring-boot-starter-data-redis</artifactId> | ... | ... |
1 | package com.jkdata.controller; | 1 | package com.jkdata.controller; |
2 | 2 | ||
3 | import cn.hutool.http.HttpUtil; | ||
3 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
4 | import com.jkdata.service.IThirdService; | 5 | import com.jkdata.service.IThirdService; |
5 | import com.jkdata.tool.Result; | 6 | import com.jkdata.tool.Result; |
... | @@ -40,14 +41,14 @@ public class ThirdController { | ... | @@ -40,14 +41,14 @@ public class ThirdController { |
40 | 41 | ||
41 | //初始化数据 | 42 | //初始化数据 |
42 | private JSONObject initData(String resMsg) { | 43 | private JSONObject initData(String resMsg) { |
43 | resMsg = "{\"Gateway\":\"10030049\"," + | 44 | // resMsg = "{\"Gateway\":\"10030049\"," + |
44 | "\"NodeId\":\"CB8A1DEB\"," + | 45 | // "\"NodeId\":\"CB8A1DEB\"," + |
45 | "\"SystemId\":\"10990145\"," + | 46 | // "\"SystemId\":\"10990145\"," + |
46 | "\"Type\":\"location_pos\"," + | 47 | // "\"Type\":\"location_pos\"," + |
47 | "\"group\":\"5\"," + | 48 | // "\"group\":\"5\"," + |
48 | "\"groupNumber\":1," + | 49 | // "\"groupNumber\":1," + |
49 | "\"position\":{\"x\":214.44541185285127,\"y\":210.15474327170986}," + | 50 | // "\"position\":{\"x\":214.44541185285127,\"y\":210.15474327170986}," + |
50 | "\"scale\":0}"; | 51 | // "\"scale\":0}"; |
51 | System.out.println("***"+System.currentTimeMillis()+"报文***"+resMsg); | 52 | System.out.println("***"+System.currentTimeMillis()+"报文***"+resMsg); |
52 | JSONObject jsonObject = new JSONObject(); | 53 | JSONObject jsonObject = new JSONObject(); |
53 | jsonObject = JSONObject.parseObject(resMsg); | 54 | jsonObject = JSONObject.parseObject(resMsg); |
... | @@ -70,4 +71,31 @@ public class ThirdController { | ... | @@ -70,4 +71,31 @@ public class ThirdController { |
70 | 71 | ||
71 | } | 72 | } |
72 | 73 | ||
74 | /** | ||
75 | * 获取静态资源信息 | ||
76 | * @return | ||
77 | */ | ||
78 | @GetMapping("/buildingAllInfo") | ||
79 | public Result<String> getBuildingAllInfo() { | ||
80 | Result<String> result = new Result<String>(); | ||
81 | String res = thirdService.getBuildingAllInfo(); | ||
82 | result.setSuccess(true); | ||
83 | result.setResult(res); | ||
84 | return result; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * 获取历史轨迹 | ||
89 | * @param deviceId | ||
90 | * @return | ||
91 | */ | ||
92 | @GetMapping("/positionByDeviceId") | ||
93 | public Result<String> getPositionByDeviceId(String deviceId,String startTime,String endTime) { | ||
94 | Result<String> result = new Result<String>(); | ||
95 | String res = thirdService.getPositionByDeviceId(deviceId, startTime, endTime); | ||
96 | result.setSuccess(true); | ||
97 | result.setResult(res); | ||
98 | return result; | ||
99 | } | ||
100 | |||
73 | } | 101 | } | ... | ... |
... | @@ -2,8 +2,13 @@ package com.jkdata.service; | ... | @@ -2,8 +2,13 @@ package com.jkdata.service; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | 4 | ||
5 | import java.util.Map; | ||
6 | |||
5 | public interface IThirdService { | 7 | public interface IThirdService { |
6 | 8 | ||
7 | void savePosition(JSONObject jsonObject); | 9 | void savePosition(JSONObject jsonObject); |
8 | 10 | ||
11 | String getBuildingAllInfo(); | ||
12 | |||
13 | String getPositionByDeviceId(String deviceId,String startTime,String endTime); | ||
9 | } | 14 | } | ... | ... |
1 | package com.jkdata.service.impl; | 1 | package com.jkdata.service.impl; |
2 | 2 | ||
3 | import cn.hutool.http.HttpUtil; | ||
3 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
4 | import com.jkdata.tool.CommonConstant; | 5 | import com.jkdata.tool.CommonConstant; |
5 | import com.jkdata.entity.ThirdPosition; | 6 | import com.jkdata.entity.ThirdPosition; |
6 | import com.jkdata.mapper.ThirdMapper; | 7 | import com.jkdata.mapper.ThirdMapper; |
7 | import com.jkdata.service.IThirdService; | 8 | import com.jkdata.service.IThirdService; |
9 | import com.jkdata.tool.MD5Util; | ||
8 | import com.jkdata.tool.RedisUtil; | 10 | import com.jkdata.tool.RedisUtil; |
9 | import com.jkdata.tool.UUIDGenerator; | 11 | import com.jkdata.tool.UUIDGenerator; |
12 | import org.apache.commons.lang.StringUtils; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
11 | import org.springframework.stereotype.Service; | 14 | import org.springframework.stereotype.Service; |
12 | 15 | ||
13 | import java.text.DecimalFormat; | 16 | import java.text.DecimalFormat; |
14 | import java.text.SimpleDateFormat; | 17 | import java.text.SimpleDateFormat; |
15 | import java.util.Date; | 18 | import java.util.*; |
16 | import java.util.Map; | ||
17 | 19 | ||
18 | @Service | 20 | @Service |
19 | public class IThirdServiceImpl implements IThirdService { | 21 | public class IThirdServiceImpl implements IThirdService { |
... | @@ -129,4 +131,61 @@ public class IThirdServiceImpl implements IThirdService { | ... | @@ -129,4 +131,61 @@ public class IThirdServiceImpl implements IThirdService { |
129 | return ok; | 131 | return ok; |
130 | } | 132 | } |
131 | 133 | ||
134 | @Override | ||
135 | public String getBuildingAllInfo() { | ||
136 | HashMap<String,Object> map = new HashMap<>(); | ||
137 | String tmsp = String.valueOf(System.currentTimeMillis()/1000); | ||
138 | map.put("bldId",CommonConstant.BLD_ID); | ||
139 | map.put("ts",tmsp); | ||
140 | String [] arr = { CommonConstant.BLD_ID,tmsp,CommonConstant.CMCC_KEY }; | ||
141 | Comparator<String> c = String::compareTo; | ||
142 | Arrays.sort(arr, c); | ||
143 | System.out.println("sign参数:"+Arrays.toString(arr)); | ||
144 | String str = StringUtils.join(Arrays.asList(new String[]{CommonConstant.BLD_ID,tmsp,CommonConstant.CMCC_KEY}),",") | ||
145 | .replace(",",""); | ||
146 | System.out.println("sign参数:"+str); | ||
147 | String strMd5 = MD5Util.getMD5LowerCase(str); | ||
148 | |||
149 | System.out.println("加密后参数:"+str); | ||
150 | map.put("sgn",strMd5); | ||
151 | String post = HttpUtil.post(CommonConstant.BUILD_URL,map); | ||
152 | System.out.println("请求结果:"+post); | ||
153 | return post; | ||
154 | } | ||
155 | |||
156 | @Override | ||
157 | public String getPositionByDeviceId(String deviceId,String startTime,String endTime) { | ||
158 | HashMap<String,Object> map = new HashMap<>(); | ||
159 | String tmsp = String.valueOf(System.currentTimeMillis()/1000); | ||
160 | map.put("bldId",CommonConstant.BLD_ID); | ||
161 | map.put("ts",tmsp); | ||
162 | map.put("deviceId",deviceId); | ||
163 | map.put("page","0"); | ||
164 | map.put("count","200"); | ||
165 | map.put("startTime",startTime); | ||
166 | map.put("endTime",endTime); | ||
167 | |||
168 | String [] arr = { CommonConstant.BLD_ID,deviceId,startTime,endTime,"0","200",tmsp,CommonConstant.CMCC_KEY }; | ||
169 | Comparator<String> c = String::compareTo; | ||
170 | Arrays.sort(arr, c); | ||
171 | System.out.println("sign参数:"+Arrays.toString(arr)); | ||
172 | |||
173 | String str = StringUtils.join(Arrays.asList(new String[]{CommonConstant.BLD_ID,deviceId,startTime,endTime, | ||
174 | "0","1000",tmsp,CommonConstant.CMCC_KEY}),",") | ||
175 | .replace(",",""); | ||
176 | System.out.println("sign参数:"+str); | ||
177 | String strMd5 = MD5Util.getMD5LowerCase(str); | ||
178 | |||
179 | System.out.println("加密后参数:"+str); | ||
180 | map.put("sgn",strMd5); | ||
181 | String post = HttpUtil.post(CommonConstant.HISTORY_URL,map); | ||
182 | System.out.println("请求结果:"+post); | ||
183 | return post; | ||
184 | |||
185 | |||
186 | |||
187 | |||
188 | } | ||
189 | |||
190 | |||
132 | } | 191 | } | ... | ... |
... | @@ -25,4 +25,18 @@ public interface CommonConstant { | ... | @@ -25,4 +25,18 @@ public interface CommonConstant { |
25 | //**********************推送用户*************************** | 25 | //**********************推送用户*************************** |
26 | String CMCC = "CMCC";//联通推送用户 | 26 | String CMCC = "CMCC";//联通推送用户 |
27 | 27 | ||
28 | String BLD_ID = "10";//定位系统项目ID | ||
29 | String CMCC_KEY = "f9257afea27943d7bcd7cc510f1b50dc";//定位系统秘钥 | ||
30 | |||
31 | //************************场景信息******************************** | ||
32 | String BUILD_URL = "http://52.131.253.116/api/v1/buildingAllInfo.shtml"; | ||
33 | |||
34 | //************************历史轨迹******************************** | ||
35 | String HISTORY_URL = "http://52.131.253.116/api/positionByDeviceId.shtml"; | ||
36 | |||
37 | //************************历史轨迹******************************** | ||
38 | String ALARM_URL = "http://52.131.253.116/api/v1/alarmListByCount.shtml"; | ||
39 | |||
40 | |||
41 | |||
28 | } | 42 | } | ... | ... |
src/main/java/com/jkdata/tool/MD5Util.java
0 → 100644
1 | package com.jkdata.tool; | ||
2 | |||
3 | import java.math.BigInteger; | ||
4 | import java.security.MessageDigest; | ||
5 | |||
6 | public class MD5Util { | ||
7 | |||
8 | /** | ||
9 | * 对字符串md5加密 | ||
10 | * | ||
11 | * @param str 传入要加密的字符串 | ||
12 | * @return MD5加密后的字符串(小写+字母) | ||
13 | */ | ||
14 | public static String getMD5LowerCase(String str) { | ||
15 | try { | ||
16 | // 生成一个MD5加密计算摘要 | ||
17 | MessageDigest md = MessageDigest.getInstance("MD5"); | ||
18 | // 计算md5函数 | ||
19 | md.update(str.getBytes()); | ||
20 | // digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符 | ||
21 | // BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值 | ||
22 | return new BigInteger(1, md.digest()).toString(16); | ||
23 | } catch (Exception e) { | ||
24 | e.printStackTrace(); | ||
25 | return null; | ||
26 | } | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * 对字符串md5加密 | ||
31 | * | ||
32 | * @param s 传入要加密的字符串 | ||
33 | * @return MD5加密后的字符串(大写+数字) | ||
34 | */ | ||
35 | |||
36 | public static String getMD5UpperCase(String s) { | ||
37 | char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | ||
38 | 'A', 'B', 'C', 'D', 'E', 'F' }; | ||
39 | try { | ||
40 | byte[] btInput = s.getBytes(); | ||
41 | // 获得MD5摘要算法的 MessageDigest 对象 | ||
42 | MessageDigest mdInst = MessageDigest.getInstance("MD5"); | ||
43 | // 使用指定的字节更新摘要 | ||
44 | mdInst.update(btInput); | ||
45 | // 获得密文 | ||
46 | byte[] md = mdInst.digest(); | ||
47 | // 把密文转换成十六进制的字符串形式 | ||
48 | int j = md.length; | ||
49 | char str[] = new char[j * 2]; | ||
50 | int k = 0; | ||
51 | for (int i = 0; i < j; i++) { | ||
52 | byte byte0 = md[i]; | ||
53 | str[k++] = hexDigits[byte0 >>> 4 & 0xf]; | ||
54 | str[k++] = hexDigits[byte0 & 0xf]; | ||
55 | } | ||
56 | return new String(str); | ||
57 | } catch (Exception e) { | ||
58 | e.printStackTrace(); | ||
59 | return null; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | public static void main(String[] args) { | ||
64 | String str = "\"我+Admin1234~!@#¥%……&*()\""; | ||
65 | System.out.println(str); | ||
66 | //"我+Admin1234~!@#¥%……&*()" | ||
67 | |||
68 | String s1 = getMD5LowerCase(str); | ||
69 | System.out.println(s1); | ||
70 | //6bb6f83c026357a15cdf12e5d6b2b310 | ||
71 | |||
72 | String s2 = getMD5UpperCase(str); | ||
73 | System.out.println(s2); | ||
74 | //6BB6F83C026357A15CDF12E5D6B2B310 | ||
75 | } | ||
76 | } |
-
请 注册 或 登录 后发表评论