|
@@ -0,0 +1,431 @@
|
|
|
+package com.gis.common.util;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.tfsmy.aesrsa.util.*;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author XiongYu
|
|
|
+ * @version Create at :2020/7/2 14:29
|
|
|
+ */
|
|
|
+
|
|
|
+@Log4j2
|
|
|
+public class DoorUtils {
|
|
|
+ public static final String clientPrivateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMtrddtdI/St1CY4" +
|
|
|
+ "WLLCFVE3KQZoNygGklLe9IngznGOaxiW7Gj+tD3BFaig4yBFxfjxfViz8VIaWUoT" +
|
|
|
+ "kC2vdPL6ETAhyY4NROPOEupNnCXDqMkffkN/PB2o8RnUAJM9CwZCjtnnwSCCblz+" +
|
|
|
+ "BdM5G4GkRdtoqDNZeoOWGJ/A8q2lAgMBAAECgYBpywWMhLBCfHUtO3jF3zJ+/pUT" +
|
|
|
+ "g/fLlT9cYiAD5Sr42/zO2Q8yu+S5iUXeYW4+RotjoRRzoYIMFTAC2pHNcMb8+YPN" +
|
|
|
+ "pQbXkYLsng16TOlyGb2kTPpciE5vP48vL/Fps91sDOkaryWGW/QBFQvfhgdflMa/" +
|
|
|
+ "NybCEw2qldb9Qz28MQJBAO4xSzJhU71EA1CSICp8wfm8fd/9zTYf8Lof1ULQOC5j" +
|
|
|
+ "8jvp4IdrWw79vjZ67HAzzjF4yF3JwkcuCOfyHSWGMjMCQQDaoKjAgXW0qQOS2SUH" +
|
|
|
+ "2Fgyt2b1XVwoZolNKmLT0hjcqr6BPjLY9TNPAnF3UcjglmviRlRnFl+SlgsSmpMd" +
|
|
|
+ "P7jHAkAufgCnfMfTkYr0FxGgOWnDTT9kkS2U+vcJ3VzLBclxhKCrgSMKS7IiYvTV" +
|
|
|
+ "vXiZDgOZNHInnFIHgrzKST/XKzJxAkBN24cdPz1WwBXotvHsEEygixXcbYoDTTi6" +
|
|
|
+ "RUz6mEiIVToQtsDO6MuD6J/V2UdLS+ZRp7ApIhuZDVwWHPwlH2tDAkBjVF/M/cvW" +
|
|
|
+ "VZlh+KbFf+PTRH1xHU0miJ0Mk6669ZTgkh5YIfwjvrMRz5DqaEWwhRmGcXTSOUui" +
|
|
|
+ "zlXFT/cna2O3";
|
|
|
+
|
|
|
+ public static final String clientPublicKey = "";
|
|
|
+
|
|
|
+ public static final String serverPrivateKey = "";
|
|
|
+
|
|
|
+ public static final String serverPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC70qOhdhNm0d9oql+NFKMhm37T" +
|
|
|
+ "id2KeMnqVdoEfpga3oiUzmIBEGdjBKeZVIdSTFJ3yzAVpo4G4ZP5BlQy5MFWKxKM" +
|
|
|
+ "FbLa7eiCxg+yL8P48L/qDFc6NFSoY7IBxwCswBhdnhmfqfH6zaQJ2rbL3826nrA8" +
|
|
|
+ "BBLdBbFlDEJgE4BXVQIDAQAB";
|
|
|
+
|
|
|
+ /** 供应商提供 */
|
|
|
+ public static final String appId = "40288078758d2ccc01758d2d75220000";
|
|
|
+
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+
|
|
|
+// testbigetAlarmList();
|
|
|
+// biGetAlarmStat();
|
|
|
+// biGetDeviceList();
|
|
|
+// biGetDeviceStat();
|
|
|
+// biGetPersonCounting();
|
|
|
+// biGetPersonGatherList();
|
|
|
+// testPushParams();
|
|
|
+// testSubmitParams();
|
|
|
+// testArray();
|
|
|
+// testAlam();
|
|
|
+// testPushParams();
|
|
|
+// testArray();
|
|
|
+// testbigetAlarmList();
|
|
|
+// testDiviceType();
|
|
|
+// testLogPic();
|
|
|
+// testhourAvgList();
|
|
|
+// testhourAvgList();
|
|
|
+// getFaceSnap();
|
|
|
+// hourAvgDevice();
|
|
|
+ wearher();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void wearher() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+// params.put("deviceNo", "HDC5550100038");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void hourAvgDevice() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+ params.put("startTime", 1597104650000L);
|
|
|
+ params.put("endTime", System.currentTimeMillis() + 1000000);
|
|
|
+ params.put("deviceNo", "HDC5550100006");
|
|
|
+// params.put("deviceNo", "HDC5550100038");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void hourAvg() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+ params.put("startTime", 1597104650000L);
|
|
|
+ params.put("endTime", System.currentTimeMillis() + 1000000);
|
|
|
+ params.put("deviceNo", "12");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void getFaceSnap() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+// params.put("deviceNo", "HDC5550100038");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void testLogPic() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+ params.put("deviceNo", "HDC5550100038");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void testhourAvgList() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ ArrayList<String> objects = new ArrayList<>();
|
|
|
+ objects.add("HDC5550100038");
|
|
|
+ objects.add("HDC5550100039");
|
|
|
+ params.put("comNo", "51011500107601");
|
|
|
+ params.put("deviceNos", objects);
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void testDiviceType() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void testArray() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ params.put("smyComId", "51011500107601");
|
|
|
+ params.put("houseSmyId", "8a69c7ae7393fce501739422671f07ce");
|
|
|
+ params.put("personId", "8a69c60a73a3f5570173a44b944f0025");
|
|
|
+ params.put("arrayTime", "12");
|
|
|
+
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void testAlam() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ params.put("communityCode", "51011500107601");
|
|
|
+// params.put("communityCode", "51010701000201");
|
|
|
+ params.put("alarmBizName", "消防栓倾斜告警");
|
|
|
+ params.put("name", "消防栓倾斜告警");
|
|
|
+ params.put("id", "20200727140217_80029_-10202_10583895");
|
|
|
+
|
|
|
+
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void testSubmitParams() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ params.put("smyComId", "51011500107601");
|
|
|
+ params.put("personId", "ff808081737b22e601737b48998f0018");
|
|
|
+
|
|
|
+ params.put("passTime", "2020-12-12 18:12:21");
|
|
|
+ params.put("type", 2);
|
|
|
+ params.put("status", 1);
|
|
|
+
|
|
|
+
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void testPushParams() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<String, Object>();
|
|
|
+ params.put("smyComId", "51011500107601");
|
|
|
+ params.put("personId", "8a69c7c573a3f6410173a41a44f7000a");
|
|
|
+
|
|
|
+ params.put("passTime", "1595932780000");
|
|
|
+ params.put("type", 1);
|
|
|
+
|
|
|
+
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static void testbigetAlarmList() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<>();
|
|
|
+ params.put("pageNo", "1");
|
|
|
+ params.put("pageSize", "10");
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+ params.put("deviceNo", "HDC5550400002");
|
|
|
+ params.put("status", "2");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void biGetAlarmStat() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<>();
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+ params.put("endMonth", "2020-08");
|
|
|
+ params.put("startMonth", "2020-06");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static void biGetDeviceList() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<>();
|
|
|
+ params.put("type", "1");
|
|
|
+ params.put("state", "1");
|
|
|
+ params.put("pageNo", "1");
|
|
|
+ params.put("pageSize", "10");
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void biGetDeviceStat() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<>();
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+ params.put("startMonth", "2020-07");
|
|
|
+ params.put("endMonth ", "2020-09");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void biGetPersonCounting() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<>();
|
|
|
+ params.put("pageNo", "1");
|
|
|
+ params.put("pageSize", "10");
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void biGetPersonGatherList() throws Exception {
|
|
|
+ TreeMap<String, Object> params = new TreeMap<>();
|
|
|
+ params.put("pageNo", "1");
|
|
|
+ params.put("pageSize", "10");
|
|
|
+ params.put("code", "51011500107601");
|
|
|
+ client(params);
|
|
|
+ server();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加密算法
|
|
|
+ * params: 加密参数
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public static void client(TreeMap<String, Object> params) throws Exception {
|
|
|
+ // 生成RSA签名
|
|
|
+ String sign = EncryUtil.handleRSA(params, clientPrivateKey);
|
|
|
+ params.put("sign", sign);
|
|
|
+
|
|
|
+ String info = JSON.toJSONString(params);
|
|
|
+ //随机生成AES密钥
|
|
|
+ String aesKey = SecureRandomUtil.getRandom(16);
|
|
|
+ //AES加密数据
|
|
|
+ String data = AES.encryptToBase64(ConvertUtils.stringToHexString(info), aesKey);
|
|
|
+
|
|
|
+ // 使用RSA算法将自己随机生成的AESKey通过公钥加密
|
|
|
+ String encryptKey = RSA.encrypt(aesKey, serverPublicKey);
|
|
|
+
|
|
|
+ Req.data = data;
|
|
|
+ Req.encryptkey = encryptKey;
|
|
|
+
|
|
|
+ System.out.println("加密后的请求数据:\n" + new Req().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void server() throws Exception {
|
|
|
+
|
|
|
+ // 验签
|
|
|
+ boolean passSign = EncryUtil.checkDecryptAndSign(Req.data,
|
|
|
+ Req.encryptkey, clientPublicKey, serverPrivateKey);
|
|
|
+
|
|
|
+ if (passSign) {
|
|
|
+ // 验签通过时
|
|
|
+ // server的私钥解密获取AES
|
|
|
+ String aeskey = RSA.decrypt(Req.encryptkey, serverPrivateKey);
|
|
|
+ // AES解密获得Data
|
|
|
+ String data = ConvertUtils.hexStringToString(AES.decryptFromBase64(Req.data,
|
|
|
+ aeskey));
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println("解密后的明文" + data);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ System.out.println("验签失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static class Req {
|
|
|
+ public static String data;
|
|
|
+ public static String encryptkey;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "data:" + data + "\nencryptkey:" + encryptkey;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解密
|
|
|
+ */
|
|
|
+ public static JSONObject decrypt(String str, String aesKey) {
|
|
|
+ String result = ConvertUtils.hexStringToString(AES.decryptFromBase64(str, aesKey));
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加密
|
|
|
+ * @param params 输入参数
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static Map<String, Object> encrypt(TreeMap<String, Object> params) throws Exception {
|
|
|
+ // 生成RSA签名
|
|
|
+ String sign = EncryUtil.handleRSA(params, clientPrivateKey);
|
|
|
+ params.put("sign", sign);
|
|
|
+
|
|
|
+ String info = JSON.toJSONString(params);
|
|
|
+ //随机生成AES密钥,aes是对称加密
|
|
|
+ String aesKey = SecureRandomUtil.getRandom(16);
|
|
|
+ //AES加密数据
|
|
|
+ String data = AES.encryptToBase64(ConvertUtils.stringToHexString(info), aesKey);
|
|
|
+
|
|
|
+ // 使用RSA算法将自己随机生成的AESKey通过公钥加密
|
|
|
+ String encryptKey = RSA.encrypt(aesKey, serverPublicKey);
|
|
|
+
|
|
|
+ HashMap<String, Object> result = new HashMap<>();
|
|
|
+ result.put("data", data);
|
|
|
+ result.put("encryptKey", encryptKey);
|
|
|
+ result.put("appId", appId);
|
|
|
+ // 解密时使用
|
|
|
+ result.put("aesKey", aesKey);
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 涉及敏感信息以及为确保隐私安全,此接口返回值进行了AES加密处理;
|
|
|
+ */
|
|
|
+ public static Result doPostDecrypt(String url, TreeMap<String, Object> param) throws Exception {
|
|
|
+ Map<String, Object> encryptMap = encrypt(param);
|
|
|
+ String result = HttpUtil.post(url, encryptMap);
|
|
|
+ log.info("result: {}", result);
|
|
|
+ JSONObject resultJson = JSON.parseObject(result);
|
|
|
+ int code = resultJson.getInteger("code");
|
|
|
+ if (code == 2000) {
|
|
|
+ // 解密
|
|
|
+ String data = resultJson.get("data").toString();
|
|
|
+ return Result.success(decrypt(data, encryptMap.get("aesKey").toString()));
|
|
|
+ } else {
|
|
|
+ log.error(result);
|
|
|
+ return Result.failure(resultJson.getString("msg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static Result doPost(String url, TreeMap<String, Object> param) throws Exception {
|
|
|
+ String result = HttpUtil.post(url, encrypt(param));
|
|
|
+ log.info("result: {}", result);
|
|
|
+ JSONObject resultJson = JSON.parseObject(result);
|
|
|
+ int code = resultJson.getInteger("code");
|
|
|
+ if (code == 2000) {
|
|
|
+ return Result.success(resultJson.get("data"));
|
|
|
+ } else {
|
|
|
+ log.error(result);
|
|
|
+ return Result.failure(resultJson.getString("msg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static Result doGet(String url, TreeMap<String, Object> param) throws Exception {
|
|
|
+ String result = HttpUtil.get(url, encrypt(param));
|
|
|
+ log.info("result: {}", result);
|
|
|
+ JSONObject resultJson = JSON.parseObject(result);
|
|
|
+ int code = resultJson.getInteger("code");
|
|
|
+ if (code == 2000) {
|
|
|
+ return Result.success(resultJson.get("data"));
|
|
|
+ } else {
|
|
|
+ log.error(result);
|
|
|
+ return Result.failure(resultJson.getString("msg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void getVisitorCount() throws Exception {
|
|
|
+ String api = "https://cdpre.tfsmy.com/intelligence-access-control-api/bi/getVisitorCount";
|
|
|
+ TreeMap<String, Object> param = new TreeMap<>();
|
|
|
+ param.put("code", "510124112006001");
|
|
|
+ doPost(api, param);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2.今日进入和外出总数
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void dailyInOut() throws Exception {
|
|
|
+ String api = "https://cdpre.tfsmy.com/intelligence-access-control-api/bi/dailyInOut";
|
|
|
+
|
|
|
+ TreeMap<String, Object> param = new TreeMap<>();
|
|
|
+ param.put("code", "510124112006001");
|
|
|
+ doGet(api, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加密后的参数
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testClient() throws Exception {
|
|
|
+ TreeMap<String, Object> param = new TreeMap<>();
|
|
|
+ param.put("code", "510124112006001");
|
|
|
+ client(param);
|
|
|
+ }
|
|
|
+}
|