package com.template.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.template.common.utils.AesUtils; import com.template.common.utils.HttpClientHelper; import com.template.common.utils.MD5; import com.template.config.DoorLockConfig; import com.template.model.dto.*; import com.template.model.enumModel.PasswordUrlEnum; import com.template.model.pojo.Unlocking; import com.template.model.pojo.UnlockingAdmin; import com.template.model.pojo.UnlockingCustom; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.HashMap; /** * 门锁 */ @RestController public class PasswordIssController { @Autowired DoorLockConfig doorLockConfig; // @Scheduled(cron = "0 0/1 * * * ?") public void test() { // 密码下发,后续需通过luid(设备id)通过aes解码 HashMap map = new HashMap<>(); map.put("luid", "047863CA78E0");//"80A036AEA1D3"); // map.put("categoryId", "d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("categoryId", doorLockConfig.getCategoryId());//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("startTime", "1710753635000"); map.put("endTime", "1713432035000"); map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 map.put("type", 4); String jsonContent = JSONObject.toJSONString(map); try { // Object data = queryData(jsonContent, PasswordUrlEnum.Password.getUrl()); JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Password.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); String temporaryPassword = data.getString("temporaryPassword"); String decryptString = AesUtils.decrypt(temporaryPassword, "047863CA78E0"); String passWord = AesUtils.decrypt(temporaryPassword, "047863CA78E0"); System.out.println("passWord = " + passWord); } catch (Exception e) { e.printStackTrace(); } // 添加卡片 // HashMap map = new HashMap<>(); // map.put("luid", "047863CA78E0");//"80A036AEA1D3"); // map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 // map.put("card", "70109262");//"0F8A50A9"); // map.put("cardType", 0); //卡类型 0 卡片 1 身份证 // map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 // map.put("type", 4); // map.put("startTime", "1700031770000");//"1686067200000"); // map.put("endTime", "1700035370000");//"1686204000000"); // // String jsonContent = JSONObject.toJSONString(map); // // try { // queryData(jsonContent, PasswordUrlEnum.Card_Info.getUrl()); // } catch (Exception e) { // e.printStackTrace(); // } // 指纹下发 // HashMap map = new HashMap<>(); // map.put("luid", "047863CA78E0");//"80A036AEA1D3"); // map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 // map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 // map.put("fingerprintData", "544D520104001C0040CA92DD000D000044CD52E2000D00003DCE5263000D0000574DA47A00090000465382E1000D000058D3C20100090000478DF2E8000D000057CED27900090000398EE2DA000D00003E12525F000D00003FD3B262000D00003D93A2DB000D00004DD4A26A0009000034CE02D4000B0000341362CE000B000036CFB25B000B000050C822EB000700004A49F4E3000500005D8ED207000700005895C205000700002ECB42D00009000027CC125B00050000228D14D0000700002D4D845A000900002A4ED4D0000900002A105459000900002893F458000900003857F4D00007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FC3F0000FC3F0000FF7F0000FF7F0080FFFF0080FFFF0080FFFF0000FFFF0000FFFF0000FFFF0180FFFF0180FFFF0100FFFF0100FFFF0180FFFF0000FF030000FE010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005911"); // // map.put("type", 4); // map.put("startTime", "1700030758000");//"1686067200000"); // map.put("endTime", "1700034358000");//"1686204000000"); // // String jsonContent = JSONObject.toJSONString(map); // // try { // queryData(jsonContent, PasswordUrlEnum.Fingerprint_Data.getUrl()); // } catch (Exception e) { // e.printStackTrace(); // } } /** * 获取设备详情 */ public String getDeviceInfo(String luid) { HashMap map = new HashMap<>(); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("luid", luid);//"80A036AEA1D3" String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Device_Info.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); // 电量 String battery = data.getString("battery"); return battery; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 获取设备详情 */ public JSONObject particular(String luid) { HashMap map = new HashMap<>(); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("luid", luid);//"80A036AEA1D3" String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Device_Info.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); return data; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 时效性 添加卡片 */ public Unlocking addCardInfo(CardInfoDto ciq) { HashMap map = new HashMap<>(); map.put("luid", ciq.getLuid());//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("card", ciq.getCard());//"0F8A50A9"); map.put("cardType", ciq.getCardType()); map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 map.put("type", 4); map.put("startTime", ciq.getStartTime());//"1686067200000"); map.put("endTime", ciq.getEndTime());//"1686204000000"); String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Card_Info.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); Unlocking unlocking = new Unlocking(); // 锁用户id String id = data.getString("id"); unlocking.setLockUserId(id); if (0==ciq.getCardType()) { unlocking.setLockStatus("2"); }else { unlocking.setLockStatus("4"); } unlocking.setLuid(ciq.getLuid()); unlocking.setHouseNumberId(ciq.houseNumberId); unlocking.setOrderNumber(ciq.orderNumber); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String start = sdf.format(Long.valueOf(ciq.getStartTime())); String end = sdf.format(Long.valueOf(ciq.getEndTime())); unlocking.setStartTime(start); unlocking.setEndTime(end); unlocking.setType("4"); return unlocking; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 时效性下发指纹 */ public Unlocking addFingerprintData(FingerprintDataDto fd) { HashMap map = new HashMap<>(); map.put("luid", fd.getLuid());//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 map.put("fingerprintData", fd.getFingerprintData());//"544D520004001100370C5417000B000040CF0203000B000031CF0491000B00004750F4EB000B000040D38406000B00004994E200000B00004395947E000B00004F906471000B00004B0AD2CE00090000454CE2EA0009000041CB220000090000320D221C000900003915740D000900003256620C000700003E56A2050007000030974484000700004388C4AF0007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F0000801F0000E01F0000F01F0000F81F0000F81F0000F81F0000FC1F0000FC3F0000FC3F0000FC3F0000FE3F0000FE3F0000FC3F0000FC3F0000FC3F0000F007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D29");//指纹特征值 map.put("type", 4); map.put("startTime", fd.getStartTime());//"1686067200000"); map.put("endTime", fd.getEndTime());//"1686204000000"); String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Fingerprint_Data.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); Unlocking unlocking = new Unlocking(); // 锁用户id String id = data.getString("id"); unlocking.setLockUserId(id); unlocking.setLockStatus("3"); unlocking.setLuid(fd.getLuid()); unlocking.setHouseNumberId(fd.houseNumberId); unlocking.setOrderNumber(fd.orderNumber); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String start = sdf.format(Long.valueOf(fd.getStartTime())); String end = sdf.format(Long.valueOf(fd.getEndTime())); unlocking.setStartTime(start); unlocking.setEndTime(end); unlocking.setType("4"); return unlocking; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 时效性下发密码 */ public Unlocking addPassword(PasswordDto pr) { HashMap map = new HashMap<>(); map.put("luid", pr.getLuid());//"80A036AEA1D3"); System.out.println("doorLockConfig = " + doorLockConfig); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("startTime", pr.getStartTime());//"1686067200000"); map.put("endTime", pr.getEndTime());//"1686204000000"); map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 map.put("type", 4); String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Password.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); String temporaryPassword = data.getString("temporaryPassword"); String passWord = AesUtils.decrypt(temporaryPassword, pr.getLuid()); Unlocking unlocking = new Unlocking(); unlocking.setPassWord(passWord); // 锁用户id String id = data.getString("id"); unlocking.setLockUserId(id); unlocking.setLockStatus("1"); unlocking.setLuid(pr.getLuid()); unlocking.setHouseNumberId(pr.houseNumberId); unlocking.setOrderNumber(pr.orderNumber); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String start = sdf.format(Long.valueOf(pr.getStartTime())); String end = sdf.format(Long.valueOf(pr.getEndTime())); unlocking.setStartTime(start); unlocking.setEndTime(end); unlocking.setType("4"); return unlocking; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 密码下发 */ public UnlockingAdmin savePassWord(KeyPassWordDto keyPassWordDto) { // 将时间转成时间戳 String startTime = keyPassWordDto.getStartTime(); String endTime = keyPassWordDto.getEndTime(); DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); // 将密码加密 String passWord = keyPassWordDto.getPassWord(); String luid = keyPassWordDto.getEquipmentType(); String encryptPassWord = AesUtils.encrypt(passWord, luid); HashMap map = new HashMap<>(); map.put("luid", luid);//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("startTime", start);//"1686067200000"); map.put("endTime", end);//"1686204000000"); map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 map.put("type", keyPassWordDto.getType()); map.put("password", encryptPassWord); String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Password.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); String temporaryPassword = data.getString("temporaryPassword"); String passWord2 = AesUtils.decrypt(temporaryPassword, luid); UnlockingAdmin unlocking = new UnlockingAdmin(); unlocking.setPassWord(passWord); // 锁用户id String id = data.getString("id"); unlocking.setLockUserId(id); unlocking.setLockStatus("1"); unlocking.setLuid(luid); unlocking.setHouseNumberId(keyPassWordDto.getHouseNumberId()); unlocking.setStartTime(startTime); unlocking.setEndTime(endTime); unlocking.setType(keyPassWordDto.getType()); return unlocking; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 添加卡片 */ public UnlockingAdmin addCard(KeyCardDto keyCardDto) { // 将时间转成时间戳 String startTime = keyCardDto.getStartTime(); String endTime = keyCardDto.getEndTime(); DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); HashMap map = new HashMap<>(); map.put("luid", keyCardDto.getLuid());//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("card", keyCardDto.getCard());//"0F8A50A9"); map.put("cardType", keyCardDto.getCardType()); map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 map.put("type", keyCardDto.getType()); map.put("startTime", start);//"1686067200000" map.put("endTime", end);//"1686204000000" String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Card_Info.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); UnlockingAdmin unlocking = new UnlockingAdmin(); // 锁用户id String id = data.getString("id"); unlocking.setLockUserId(id); int cardType = keyCardDto.getCardType(); if (0==cardType) { unlocking.setLockStatus("2"); }else { unlocking.setLockStatus("4"); } unlocking.setLuid(keyCardDto.getLuid()); unlocking.setHouseNumberId(keyCardDto.getHouseNumberId()); unlocking.setStartTime(startTime); unlocking.setEndTime(endTime); unlocking.setType(keyCardDto.getType()); return unlocking; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 添加指纹 */ public UnlockingAdmin addFingerprintDto(KeyFingerprintDto keyFingerprintDto) { // 将时间转成时间戳 String startTime = keyFingerprintDto.getStartTime(); String endTime = keyFingerprintDto.getEndTime(); DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); HashMap map = new HashMap<>(); map.put("luid", keyFingerprintDto.getLuid());//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 map.put("fingerprintData", keyFingerprintDto.getFingerprintData());//"544D520004001100370C5417000B000040CF0203000B000031CF0491000B00004750F4EB000B000040D38406000B00004994E200000B00004395947E000B00004F906471000B00004B0AD2CE00090000454CE2EA0009000041CB220000090000320D221C000900003915740D000900003256620C000700003E56A2050007000030974484000700004388C4AF0007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F0000801F0000E01F0000F01F0000F81F0000F81F0000F81F0000FC1F0000FC3F0000FC3F0000FC3F0000FE3F0000FE3F0000FC3F0000FC3F0000FC3F0000F007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D29");//指纹特征值 map.put("type", keyFingerprintDto.getType()); map.put("startTime", start); map.put("endTime", end); String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Fingerprint_Data.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); UnlockingAdmin unlocking = new UnlockingAdmin(); // 锁用户id String id = data.getString("id"); unlocking.setLockUserId(id); unlocking.setLockStatus("3"); unlocking.setLuid(keyFingerprintDto.getLuid()); unlocking.setHouseNumberId(keyFingerprintDto.getHouseNumberId()); unlocking.setStartTime(startTime); unlocking.setEndTime(endTime); unlocking.setType(keyFingerprintDto.getType()); return unlocking; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 远程开锁 * * @param luid * @return */ public void remoteUnlocking(String luid) { HashMap map = new HashMap<>(); map.put("luid", luid);//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.RemoteOpen.getUrl()); } catch (Exception e) { e.printStackTrace(); } // return null; } /** * 删除锁用户 * * @param luid * @param id * @return */ public void deleteLockUser(String luid, String id) { HashMap map = new HashMap<>(); map.put("categoryId", doorLockConfig.getCategoryId()); map.put("luid", luid); map.put("id", id); String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.DeleteLockUser.getUrl()); System.out.println("jsonObject = " + jsonObject); // return jsonObject; } catch (Exception e) { e.printStackTrace(); } // return null; } /** * 请求数据 * * @param content 请求参数 * @param path 请求接口 */ public JSONObject queryData(String content, String path) throws Exception { String sign = MD5.getMD5(doorLockConfig.getAppId() + doorLockConfig.getAppSecret()); String appId = doorLockConfig.getAppId(); String jsonStr = AesUtils.encrypt(content, doorLockConfig.getAppSecret()); /*执行请求,使用可以附加token的doPost方*/ HttpClientHelper instance = HttpClientHelper.getInstance(); String result = instance.doPostJson(doorLockConfig.getServiceHost() + (path.startsWith("/") ? path : ("/" + path)), jsonStr, sign, appId); if (ObjectUtils.isEmpty(result)) { return null; } /*解析数据 start*/ JSONObject jsonObject = JSON.parseObject(result); System.out.println("jsonObject = " + jsonObject); return jsonObject; } public static void main(String[] args) { String startTime = "2024-03-22 15:50:00"; DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); long l = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); System.out.println("l = " + l); } public UnlockingCustom saveCustomPassWord(CustomKeyPassWordDto dto) { // 将时间转成时间戳 String startTime = dto.getStartTime(); String endTime =dto.getEndTime(); DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); // 将密码加密 String passWord = dto.getPassWord(); String luid =dto.getEquipmentType(); String encryptPassWord = AesUtils.encrypt(passWord, luid); HashMap map = new HashMap<>(); map.put("luid", luid);//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("startTime", start);//"1686067200000"); map.put("endTime", end);//"1686204000000"); map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 map.put("type", dto.getType()); map.put("password", encryptPassWord); String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Password.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); String temporaryPassword = data.getString("temporaryPassword"); String passWord2 = AesUtils.decrypt(temporaryPassword, luid); UnlockingCustom unlocking = new UnlockingCustom(); unlocking.setPassWord(passWord); // 锁用户id String id = data.getString("id"); unlocking.setLockUserId(id); unlocking.setLockStatus("1"); unlocking.setLuid(luid); unlocking.setHouseNumberId(dto.getHouseNumberId()); unlocking.setStartTime(startTime); unlocking.setEndTime(endTime); unlocking.setType(dto.getType()); return unlocking; } catch (Exception e) { e.printStackTrace(); } return null; } public UnlockingCustom addCustomCard(CustomKeyCardDto dto) { // 将时间转成时间戳 String startTime = dto.getStartTime(); String endTime = dto.getEndTime(); DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); HashMap map = new HashMap<>(); map.put("luid", dto.getLuid());//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("card", dto.getCard());//"0F8A50A9"); map.put("cardType", dto.getCardType()); map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 map.put("type", dto.getType()); map.put("startTime", start);//"1686067200000" map.put("endTime", end);//"1686204000000" String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Card_Info.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); UnlockingCustom unlocking = new UnlockingCustom(); // 锁用户id String id = data.getString("id"); unlocking.setLockUserId(id); if (0==dto.getCardType()) { unlocking.setLockStatus("2"); }else { unlocking.setLockStatus("4"); } unlocking.setLuid(dto.getLuid()); unlocking.setHouseNumberId(dto.getHouseNumberId()); unlocking.setStartTime(startTime); unlocking.setEndTime(endTime); unlocking.setType(dto.getType()); return unlocking; } catch (Exception e) { e.printStackTrace(); } return null; } public UnlockingCustom addCustomFingerprintDto(CustomKeyFingerprintDto dto) { // 将时间转成时间戳 String startTime = dto.getStartTime(); String endTime = dto.getEndTime(); DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); HashMap map = new HashMap<>(); map.put("luid", dto.getLuid());//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("userName", "13097286670");// 用户名 也就是管理锁的账号 map.put("fingerprintData", dto.getFingerprintData());//"544D520004001100370C5417000B000040CF0203000B000031CF0491000B00004750F4EB000B000040D38406000B00004994E200000B00004395947E000B00004F906471000B00004B0AD2CE00090000454CE2EA0009000041CB220000090000320D221C000900003915740D000900003256620C000700003E56A2050007000030974484000700004388C4AF0007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F0000801F0000E01F0000F01F0000F81F0000F81F0000F81F0000FC1F0000FC3F0000FC3F0000FC3F0000FE3F0000FE3F0000FC3F0000FC3F0000FC3F0000F007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D29");//指纹特征值 map.put("type", dto.getType()); map.put("startTime", start); map.put("endTime", end); String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Fingerprint_Data.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); UnlockingCustom unlocking = new UnlockingCustom(); // 锁用户id String id = data.getString("id"); unlocking.setLockUserId(id); unlocking.setLockStatus("3"); unlocking.setLuid(dto.getLuid()); unlocking.setHouseNumberId(dto.getHouseNumberId()); unlocking.setStartTime(startTime); unlocking.setEndTime(endTime); unlocking.setType(dto.getType()); return unlocking; } catch (Exception e) { e.printStackTrace(); } return null; } public void nfcFunction(Integer nfcFunction,String luid) { HashMap map = new HashMap<>(); map.put("luid", luid);//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("enable", nfcFunction); String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.SetNFC.getUrl()); String data = jsonObject.getString("data"); System.out.println("data = " + data); } catch (Exception e) { throw new RuntimeException(e); } } public void updateLock(String lockUserId, String luid, String startTime, String endTime) { DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); long start = LocalDateTime.parse(startTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); long end = LocalDateTime.parse(endTime, dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); HashMap map = new HashMap<>(); map.put("luid", luid);//"80A036AEA1D3"); map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值 map.put("id", lockUserId);// 用户名 也就是管理锁的账号 map.put("startTime", start); map.put("endTime", end); String jsonContent = JSONObject.toJSONString(map); try { JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.ModifyPassword.getUrl()); JSONObject data = jsonObject.getJSONObject("data"); System.out.println("data = " + data); } catch (Exception e) { e.printStackTrace(); } } }