PasswordIssController.java 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. package com.template.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  5. import com.template.common.utils.AesUtils;
  6. import com.template.common.utils.HttpClientHelper;
  7. import com.template.common.utils.MD5;
  8. import com.template.config.DoorLockConfig;
  9. import com.template.model.dto.*;
  10. import com.template.model.enumModel.PasswordUrlEnum;
  11. import com.template.model.pojo.Unlocking;
  12. import com.template.model.pojo.UnlockingAdmin;
  13. import com.template.model.pojo.UnlockingCustom;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import java.text.SimpleDateFormat;
  17. import java.time.LocalDateTime;
  18. import java.time.ZoneId;
  19. import java.time.format.DateTimeFormatter;
  20. import java.util.HashMap;
  21. /**
  22. * 门锁
  23. */
  24. @RestController
  25. public class PasswordIssController {
  26. @Autowired
  27. DoorLockConfig doorLockConfig;
  28. // @Scheduled(cron = "0 0/1 * * * ?")
  29. public void test() {
  30. HashMap<String, String> map = new HashMap<>();
  31. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  32. map.put("luid", "80A036AE25AB");//"80A036AEA1D3"
  33. String jsonContent = JSONObject.toJSONString(map);
  34. try {
  35. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Device_Info.getUrl());
  36. JSONObject data = jsonObject.getJSONObject("data");
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. }
  40. // 密码下发,后续需通过luid(设备id)通过aes解码
  41. // HashMap<String, Object> map = new HashMap<>();
  42. // map.put("luid", "047863CA78E0");//"80A036AEA1D3");
  43. //// map.put("categoryId", "d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  44. // map.put("categoryId", doorLockConfig.getCategoryId());//设备分类ID 所有蓝牙wifi锁默认统一值
  45. // map.put("startTime", "1710753635000");
  46. // map.put("endTime", "1713432035000");
  47. // map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  48. // map.put("type", 4);
  49. //
  50. // String jsonContent = JSONObject.toJSONString(map);
  51. //
  52. //
  53. // try {
  54. //// Object data = queryData(jsonContent, PasswordUrlEnum.Password.getUrl());
  55. // JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Password.getUrl());
  56. // JSONObject data = jsonObject.getJSONObject("data");
  57. // String temporaryPassword = data.getString("temporaryPassword");
  58. // String decryptString = AesUtils.decrypt(temporaryPassword, "047863CA78E0");
  59. // String passWord = AesUtils.decrypt(temporaryPassword, "047863CA78E0");
  60. // System.out.println("passWord = " + passWord);
  61. // } catch (Exception e) {
  62. // e.printStackTrace();
  63. // }
  64. // 添加卡片
  65. // HashMap<String, Object> map = new HashMap<>();
  66. // map.put("luid", "047863CA78E0");//"80A036AEA1D3");
  67. // map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  68. // map.put("card", "70109262");//"0F8A50A9");
  69. // map.put("cardType", 0); //卡类型 0 卡片 1 身份证
  70. // map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  71. // map.put("type", 4);
  72. // map.put("startTime", "1700031770000");//"1686067200000");
  73. // map.put("endTime", "1700035370000");//"1686204000000");
  74. //
  75. // String jsonContent = JSONObject.toJSONString(map);
  76. //
  77. // try {
  78. // queryData(jsonContent, PasswordUrlEnum.Card_Info.getUrl());
  79. // } catch (Exception e) {
  80. // e.printStackTrace();
  81. // }
  82. // 指纹下发
  83. // HashMap<String, Object> map = new HashMap<>();
  84. // map.put("luid", "047863CA78E0");//"80A036AEA1D3");
  85. // map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  86. // // map.put("categoryId", "d0c248256f8346d2a19afa296562b319");//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  87. // map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  88. // map.put("fingerprintData","544D520204001700484AA20800050000400C0280000500003E0D620C00070000434E848A000B0000390E427B000B0000554F348C0007000044503280000B000053912487000700003DD2E477000B00004D93020F000500005D13F21200070000358A227B00010000300D827300050000268D6472000500002311C2600005000038D5E467000100002DD5A2E2000500003D49D20D0003000036CAD28300030000229652CD0003000036D66266000300002716C455000300003057845500030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080010000E0070000F00F0000F8070000FC0F0000FE1F0000FE7F0000FF7F0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FF7F0000FF070000FF0700007E000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003AEA");
  89. // map.put("type", 4);
  90. // map.put("startTime", "1724315400000");//"1686067200000");
  91. // map.put("endTime", "1724322600000");//"1686204000000");
  92. //
  93. // String jsonContent = JSONObject.toJSONString(map);
  94. //
  95. // try {
  96. // queryData(jsonContent, PasswordUrlEnum.Fingerprint_Data.getUrl());
  97. // } catch (Exception e) {
  98. // e.printStackTrace();
  99. // }
  100. // 删除
  101. // HashMap<String, Object> map = new HashMap<>();
  102. // map.put("categoryId", doorLockConfig.getCategoryId());
  103. // map.put("luid", "047863CA78E0");
  104. //// map.put("id", "12ea7b0761b040e18ab95348287d6bae");
  105. // map.put("id", "66336c9de4fa47b6aeb9e4216937f904");
  106. // String jsonContent = JSONObject.toJSONString(map);
  107. // try {
  108. // JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.DeleteLockUser.getUrl());
  109. // System.out.println("jsonObject = " + jsonObject);
  110. //// return jsonObject;
  111. // } catch (Exception e) {
  112. // e.printStackTrace();
  113. // }
  114. }
  115. /**
  116. * 获取设备详情
  117. */
  118. public String getDeviceInfo(String luid) {
  119. HashMap<String, String> map = new HashMap<>();
  120. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  121. map.put("luid", luid);//"80A036AEA1D3"
  122. String jsonContent = JSONObject.toJSONString(map);
  123. try {
  124. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Device_Info.getUrl());
  125. JSONObject data = jsonObject.getJSONObject("data");
  126. // 电量
  127. String battery = data.getString("battery");
  128. return battery;
  129. } catch (Exception e) {
  130. e.printStackTrace();
  131. }
  132. return null;
  133. }
  134. /**
  135. * 获取设备详情
  136. */
  137. public JSONObject particular(String luid) {
  138. HashMap<String, String> map = new HashMap<>();
  139. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  140. map.put("luid", luid);//"80A036AEA1D3"
  141. String jsonContent = JSONObject.toJSONString(map);
  142. try {
  143. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Device_Info.getUrl());
  144. JSONObject data = jsonObject.getJSONObject("data");
  145. return data;
  146. } catch (Exception e) {
  147. e.printStackTrace();
  148. }
  149. return null;
  150. }
  151. /**
  152. * 时效性 添加卡片
  153. */
  154. public Unlocking addCardInfo(CardInfoDto ciq) {
  155. HashMap<String, Object> map = new HashMap<>();
  156. map.put("luid", ciq.getLuid());//"80A036AEA1D3");
  157. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  158. map.put("card", ciq.getCard());//"0F8A50A9");
  159. map.put("cardType", ciq.getCardType());
  160. map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  161. map.put("type", 4);
  162. map.put("startTime", ciq.getStartTime());//"1686067200000");
  163. map.put("endTime", ciq.getEndTime());//"1686204000000");
  164. String jsonContent = JSONObject.toJSONString(map);
  165. try {
  166. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Card_Info.getUrl());
  167. JSONObject data = jsonObject.getJSONObject("data");
  168. Unlocking unlocking = new Unlocking();
  169. // 锁用户id
  170. String id = data.getString("id");
  171. unlocking.setLockUserId(id);
  172. if (0 == ciq.getCardType()) {
  173. unlocking.setLockStatus("2");
  174. } else {
  175. unlocking.setLockStatus("4");
  176. }
  177. unlocking.setLuid(ciq.getLuid());
  178. unlocking.setHouseNumberId(ciq.houseNumberId);
  179. unlocking.setOrderNumber(ciq.orderNumber);
  180. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  181. String start = sdf.format(Long.valueOf(ciq.getStartTime()));
  182. String end = sdf.format(Long.valueOf(ciq.getEndTime()));
  183. unlocking.setStartTime(start);
  184. unlocking.setEndTime(end);
  185. // unlocking.setType("4");
  186. return unlocking;
  187. } catch (Exception e) {
  188. e.printStackTrace();
  189. }
  190. return null;
  191. }
  192. /**
  193. * 时效性下发指纹
  194. */
  195. public Unlocking addFingerprintData(FingerprintDataDto fd) {
  196. HashMap<String, Object> map = new HashMap<>();
  197. map.put("luid", fd.getLuid());//"80A036AEA1D3");
  198. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  199. map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  200. map.put("fingerprintData", fd.getFingerprintData());//"544D520004001100370C5417000B000040CF0203000B000031CF0491000B00004750F4EB000B000040D38406000B00004994E200000B00004395947E000B00004F906471000B00004B0AD2CE00090000454CE2EA0009000041CB220000090000320D221C000900003915740D000900003256620C000700003E56A2050007000030974484000700004388C4AF0007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F0000801F0000E01F0000F01F0000F81F0000F81F0000F81F0000FC1F0000FC3F0000FC3F0000FC3F0000FE3F0000FE3F0000FC3F0000FC3F0000FC3F0000F007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D29");//指纹特征值
  201. map.put("type", 4);
  202. map.put("startTime", fd.getStartTime());//"1686067200000");
  203. map.put("endTime", fd.getEndTime());//"1686204000000");
  204. String jsonContent = JSONObject.toJSONString(map);
  205. try {
  206. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Fingerprint_Data.getUrl());
  207. JSONObject data = jsonObject.getJSONObject("data");
  208. Unlocking unlocking = new Unlocking();
  209. // 锁用户id
  210. String id = data.getString("id");
  211. unlocking.setLockUserId(id);
  212. unlocking.setLockStatus("3");
  213. unlocking.setLuid(fd.getLuid());
  214. unlocking.setHouseNumberId(fd.houseNumberId);
  215. unlocking.setOrderNumber(fd.orderNumber);
  216. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  217. String start = sdf.format(Long.valueOf(fd.getStartTime()));
  218. String end = sdf.format(Long.valueOf(fd.getEndTime()));
  219. unlocking.setStartTime(start);
  220. unlocking.setEndTime(end);
  221. unlocking.setType("4");
  222. return unlocking;
  223. } catch (Exception e) {
  224. e.printStackTrace();
  225. }
  226. return null;
  227. }
  228. /**
  229. * 时效性下发密码
  230. */
  231. public Unlocking addPassword(PasswordDto pr) {
  232. HashMap<String, Object> map = new HashMap<>();
  233. map.put("luid", pr.getLuid());//"80A036AEA1D3");
  234. System.out.println("doorLockConfig = " + doorLockConfig);
  235. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  236. map.put("startTime", pr.getStartTime());//"1686067200000");
  237. map.put("endTime", pr.getEndTime());//"1686204000000");
  238. map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  239. map.put("type", 4);
  240. String jsonContent = JSONObject.toJSONString(map);
  241. try {
  242. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Password.getUrl());
  243. JSONObject data = jsonObject.getJSONObject("data");
  244. String temporaryPassword = data.getString("temporaryPassword");
  245. String passWord = AesUtils.decrypt(temporaryPassword, pr.getLuid());
  246. Unlocking unlocking = new Unlocking();
  247. unlocking.setPassWord(passWord);
  248. // 锁用户id
  249. String id = data.getString("id");
  250. unlocking.setLockUserId(id);
  251. unlocking.setLockStatus("1");
  252. unlocking.setLuid(pr.getLuid());
  253. unlocking.setHouseNumberId(pr.houseNumberId);
  254. unlocking.setOrderNumber(pr.orderNumber);
  255. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  256. String start = sdf.format(Long.valueOf(pr.getStartTime()));
  257. String end = sdf.format(Long.valueOf(pr.getEndTime()));
  258. unlocking.setStartTime(start);
  259. unlocking.setEndTime(end);
  260. unlocking.setType("4");
  261. return unlocking;
  262. } catch (Exception e) {
  263. e.printStackTrace();
  264. }
  265. return null;
  266. }
  267. /**
  268. * 密码下发
  269. */
  270. public UnlockingAdmin savePassWord(KeyPassWordDto keyPassWordDto) {
  271. // 将时间转成时间戳
  272. String startTime = keyPassWordDto.getStartTime();
  273. String endTime = keyPassWordDto.getEndTime();
  274. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  275. long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  276. long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  277. // 将密码加密
  278. String passWord = keyPassWordDto.getPassWord();
  279. String luid = keyPassWordDto.getEquipmentType();
  280. String encryptPassWord = AesUtils.encrypt(passWord, luid);
  281. HashMap<String, Object> map = new HashMap<>();
  282. map.put("luid", luid);//"80A036AEA1D3");
  283. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  284. map.put("startTime", start);//"1686067200000");
  285. map.put("endTime", end);//"1686204000000");
  286. map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  287. map.put("type", keyPassWordDto.getType());
  288. map.put("password", encryptPassWord);
  289. String jsonContent = JSONObject.toJSONString(map);
  290. try {
  291. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Password.getUrl());
  292. JSONObject data = jsonObject.getJSONObject("data");
  293. String temporaryPassword = data.getString("temporaryPassword");
  294. String passWord2 = AesUtils.decrypt(temporaryPassword, luid);
  295. UnlockingAdmin unlocking = new UnlockingAdmin();
  296. unlocking.setPassWord(passWord);
  297. // 锁用户id
  298. String id = data.getString("id");
  299. unlocking.setLockUserId(id);
  300. unlocking.setLockStatus("1");
  301. unlocking.setLuid(luid);
  302. unlocking.setHouseNumberId(keyPassWordDto.getHouseNumberId());
  303. unlocking.setStartTime(startTime);
  304. unlocking.setEndTime(endTime);
  305. unlocking.setType(keyPassWordDto.getType());
  306. return unlocking;
  307. } catch (Exception e) {
  308. e.printStackTrace();
  309. }
  310. return null;
  311. }
  312. /**
  313. * 添加卡片
  314. */
  315. public UnlockingAdmin addCard(KeyCardDto keyCardDto) {
  316. // 将时间转成时间戳
  317. String startTime = keyCardDto.getStartTime();
  318. String endTime = keyCardDto.getEndTime();
  319. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  320. long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  321. long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  322. HashMap<String, Object> map = new HashMap<>();
  323. map.put("luid", keyCardDto.getLuid());//"80A036AEA1D3");
  324. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  325. map.put("card", keyCardDto.getCard());//"0F8A50A9");
  326. map.put("cardType", keyCardDto.getCardType());
  327. map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  328. map.put("type", keyCardDto.getType());
  329. map.put("startTime", start);//"1686067200000"
  330. map.put("endTime", end);//"1686204000000"
  331. String jsonContent = JSONObject.toJSONString(map);
  332. try {
  333. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Card_Info.getUrl());
  334. JSONObject data = jsonObject.getJSONObject("data");
  335. UnlockingAdmin unlocking = new UnlockingAdmin();
  336. // 锁用户id
  337. String id = data.getString("id");
  338. unlocking.setLockUserId(id);
  339. int cardType = keyCardDto.getCardType();
  340. if (0 == cardType) {
  341. unlocking.setLockStatus("2");
  342. } else {
  343. unlocking.setLockStatus("4");
  344. }
  345. unlocking.setLuid(keyCardDto.getLuid());
  346. unlocking.setHouseNumberId(keyCardDto.getHouseNumberId());
  347. unlocking.setStartTime(startTime);
  348. unlocking.setEndTime(endTime);
  349. unlocking.setType(keyCardDto.getType());
  350. return unlocking;
  351. } catch (Exception e) {
  352. e.printStackTrace();
  353. }
  354. return null;
  355. }
  356. /**
  357. * 添加指纹
  358. */
  359. public UnlockingAdmin addFingerprintDto(KeyFingerprintDto keyFingerprintDto) {
  360. // 将时间转成时间戳
  361. String startTime = keyFingerprintDto.getStartTime();
  362. String endTime = keyFingerprintDto.getEndTime();
  363. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  364. long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  365. long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  366. HashMap<String, Object> map = new HashMap<>();
  367. map.put("luid", keyFingerprintDto.getLuid());//"80A036AEA1D3");
  368. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  369. map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  370. map.put("fingerprintData", keyFingerprintDto.getFingerprintData());//"544D520004001100370C5417000B000040CF0203000B000031CF0491000B00004750F4EB000B000040D38406000B00004994E200000B00004395947E000B00004F906471000B00004B0AD2CE00090000454CE2EA0009000041CB220000090000320D221C000900003915740D000900003256620C000700003E56A2050007000030974484000700004388C4AF00070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);//指纹特征值
  371. map.put("type", keyFingerprintDto.getType());
  372. map.put("startTime", start);
  373. map.put("endTime", end);
  374. String jsonContent = JSONObject.toJSONString(map);
  375. try {
  376. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Fingerprint_Data.getUrl());
  377. JSONObject data = jsonObject.getJSONObject("data");
  378. UnlockingAdmin unlocking = new UnlockingAdmin();
  379. // 锁用户id
  380. String id = data.getString("id");
  381. unlocking.setLockUserId(id);
  382. unlocking.setLockStatus("3");
  383. unlocking.setLuid(keyFingerprintDto.getLuid());
  384. unlocking.setHouseNumberId(keyFingerprintDto.getHouseNumberId());
  385. unlocking.setStartTime(startTime);
  386. unlocking.setEndTime(endTime);
  387. unlocking.setType(keyFingerprintDto.getType());
  388. return unlocking;
  389. } catch (Exception e) {
  390. e.printStackTrace();
  391. }
  392. return null;
  393. }
  394. /**
  395. * 远程开锁
  396. *
  397. * @param luid
  398. * @return
  399. */
  400. public Boolean remoteUnlocking(String luid) {
  401. HashMap<String, Object> map = new HashMap<>();
  402. map.put("luid", luid);//"80A036AEA1D3");
  403. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  404. String jsonContent = JSONObject.toJSONString(map);
  405. try {
  406. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.RemoteOpen.getUrl());
  407. Integer result = jsonObject.getInteger("result");
  408. if (result == 1) {
  409. return true;
  410. } else {
  411. return false;
  412. }
  413. } catch (Exception e) {
  414. e.printStackTrace();
  415. }
  416. return false;
  417. }
  418. /**
  419. * 删除锁用户
  420. *
  421. * @param luid
  422. * @param id
  423. * @return
  424. */
  425. public void deleteLockUser(String luid, String id) {
  426. HashMap<String, Object> map = new HashMap<>();
  427. map.put("categoryId", doorLockConfig.getCategoryId());
  428. map.put("luid", luid);
  429. map.put("id", id);
  430. String jsonContent = JSONObject.toJSONString(map);
  431. try {
  432. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.DeleteLockUser.getUrl());
  433. // System.out.println("jsonObject = " + jsonObject);
  434. // return jsonObject;
  435. } catch (Exception e) {
  436. e.printStackTrace();
  437. }
  438. // return null;
  439. }
  440. /**
  441. * 请求数据
  442. *
  443. * @param content 请求参数
  444. * @param path 请求接口
  445. */
  446. public JSONObject queryData(String content, String path) throws Exception {
  447. String sign = MD5.getMD5(doorLockConfig.getAppId() + doorLockConfig.getAppSecret());
  448. String appId = doorLockConfig.getAppId();
  449. String jsonStr = AesUtils.encrypt(content, doorLockConfig.getAppSecret());
  450. /*执行请求,使用可以附加token的doPost方*/
  451. HttpClientHelper instance = HttpClientHelper.getInstance();
  452. String result = instance.doPostJson(doorLockConfig.getServiceHost() + (path.startsWith("/") ? path : ("/" + path)), jsonStr, sign, appId);
  453. if (ObjectUtils.isEmpty(result)) {
  454. return null;
  455. }
  456. /*解析数据 start*/
  457. JSONObject jsonObject = JSON.parseObject(result);
  458. // System.out.println("jsonObject = " + jsonObject);
  459. return jsonObject;
  460. }
  461. public static void main(String[] args) {
  462. String startTime = "2024-03-22 15:50:00";
  463. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  464. long l = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  465. System.out.println("l = " + l);
  466. }
  467. public UnlockingCustom saveCustomPassWord(CustomKeyPassWordDto dto) {
  468. // 将时间转成时间戳
  469. String startTime = dto.getStartTime();
  470. String endTime = dto.getEndTime();
  471. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  472. long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  473. long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  474. // 将密码加密
  475. String passWord = dto.getPassWord();
  476. String luid = dto.getEquipmentType();
  477. String encryptPassWord = AesUtils.encrypt(passWord, luid);
  478. HashMap<String, Object> map = new HashMap<>();
  479. map.put("luid", luid);//"80A036AEA1D3");
  480. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  481. map.put("startTime", start);//"1686067200000");
  482. map.put("endTime", end);//"1686204000000");
  483. map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  484. map.put("type", dto.getType());
  485. map.put("password", encryptPassWord);
  486. String jsonContent = JSONObject.toJSONString(map);
  487. try {
  488. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Password.getUrl());
  489. JSONObject data = jsonObject.getJSONObject("data");
  490. String temporaryPassword = data.getString("temporaryPassword");
  491. String passWord2 = AesUtils.decrypt(temporaryPassword, luid);
  492. UnlockingCustom unlocking = new UnlockingCustom();
  493. unlocking.setPassWord(passWord);
  494. // 锁用户id
  495. String id = data.getString("id");
  496. unlocking.setLockUserId(id);
  497. unlocking.setLockStatus("1");
  498. unlocking.setLuid(luid);
  499. unlocking.setHouseNumberId(dto.getHouseNumberId());
  500. unlocking.setStartTime(startTime);
  501. unlocking.setEndTime(endTime);
  502. unlocking.setType(dto.getType());
  503. return unlocking;
  504. } catch (Exception e) {
  505. e.printStackTrace();
  506. }
  507. return null;
  508. }
  509. public UnlockingCustom addCustomCard(CustomKeyCardDto dto) {
  510. // 将时间转成时间戳
  511. String startTime = dto.getStartTime();
  512. String endTime = dto.getEndTime();
  513. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  514. long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  515. long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  516. HashMap<String, Object> map = new HashMap<>();
  517. map.put("luid", dto.getLuid());//"80A036AEA1D3");
  518. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  519. map.put("card", dto.getCard());//"0F8A50A9");
  520. map.put("cardType", dto.getCardType());
  521. map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  522. map.put("type", dto.getType());
  523. map.put("startTime", start);//"1686067200000"
  524. map.put("endTime", end);//"1686204000000"
  525. String jsonContent = JSONObject.toJSONString(map);
  526. try {
  527. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Card_Info.getUrl());
  528. JSONObject data = jsonObject.getJSONObject("data");
  529. UnlockingCustom unlocking = new UnlockingCustom();
  530. // 锁用户id
  531. String id = data.getString("id");
  532. unlocking.setLockUserId(id);
  533. if (0 == dto.getCardType()) {
  534. unlocking.setLockStatus("2");
  535. } else {
  536. unlocking.setLockStatus("4");
  537. }
  538. unlocking.setLuid(dto.getLuid());
  539. unlocking.setHouseNumberId(dto.getHouseNumberId());
  540. unlocking.setStartTime(startTime);
  541. unlocking.setEndTime(endTime);
  542. unlocking.setType(dto.getType());
  543. return unlocking;
  544. } catch (Exception e) {
  545. e.printStackTrace();
  546. }
  547. return null;
  548. }
  549. public UnlockingCustom addCustomFingerprintDto(CustomKeyFingerprintDto dto) {
  550. // 将时间转成时间戳
  551. String startTime = dto.getStartTime();
  552. String endTime = dto.getEndTime();
  553. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  554. long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  555. long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  556. HashMap<String, Object> map = new HashMap<>();
  557. map.put("luid", dto.getLuid());//"80A036AEA1D3");
  558. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  559. map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
  560. map.put("fingerprintData", dto.getFingerprintData());//"544D520004001100370C5417000B000040CF0203000B000031CF0491000B00004750F4EB000B000040D38406000B00004994E200000B00004395947E000B00004F906471000B00004B0AD2CE00090000454CE2EA0009000041CB220000090000320D221C000900003915740D000900003256620C000700003E56A2050007000030974484000700004388C4AF0007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F0000801F0000E01F0000F01F0000F81F0000F81F0000F81F0000FC1F0000FC3F0000FC3F0000FC3F0000FE3F0000FE3F0000FC3F0000FC3F0000FC3F0000F007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D29");//指纹特征值
  561. map.put("type", dto.getType());
  562. map.put("startTime", start);
  563. map.put("endTime", end);
  564. String jsonContent = JSONObject.toJSONString(map);
  565. try {
  566. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Fingerprint_Data.getUrl());
  567. JSONObject data = jsonObject.getJSONObject("data");
  568. UnlockingCustom unlocking = new UnlockingCustom();
  569. // 锁用户id
  570. String id = data.getString("id");
  571. unlocking.setLockUserId(id);
  572. unlocking.setLockStatus("3");
  573. unlocking.setLuid(dto.getLuid());
  574. unlocking.setHouseNumberId(dto.getHouseNumberId());
  575. unlocking.setStartTime(startTime);
  576. unlocking.setEndTime(endTime);
  577. unlocking.setType(dto.getType());
  578. return unlocking;
  579. } catch (Exception e) {
  580. e.printStackTrace();
  581. }
  582. return null;
  583. }
  584. public void nfcFunction(Integer nfcFunction, String luid) {
  585. HashMap<String, Object> map = new HashMap<>();
  586. map.put("luid", luid);//"80A036AEA1D3");
  587. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  588. map.put("enable", nfcFunction);
  589. String jsonContent = JSONObject.toJSONString(map);
  590. try {
  591. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.SetNFC.getUrl());
  592. String data = jsonObject.getString("data");
  593. System.out.println("data = " + data);
  594. } catch (Exception e) {
  595. throw new RuntimeException(e);
  596. }
  597. }
  598. public void updateLock(String lockUserId, String luid, String startTime, String endTime) {
  599. DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  600. long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  601. long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
  602. HashMap<String, Object> map = new HashMap<>();
  603. map.put("luid", luid);//"80A036AEA1D3");
  604. map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
  605. map.put("id", lockUserId);// 用户名 也就是管理锁的账号
  606. map.put("startTime", start);
  607. map.put("endTime", end);
  608. String jsonContent = JSONObject.toJSONString(map);
  609. try {
  610. JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.ModifyPassword.getUrl());
  611. JSONObject data = jsonObject.getJSONObject("data");
  612. System.out.println("data = " + data);
  613. } catch (Exception e) {
  614. e.printStackTrace();
  615. }
  616. }
  617. }