PasswordIssController.java 36 KB

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