| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- 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() {
- HashMap<String, String> map = new HashMap<>();
- map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
- map.put("luid", "80A036AE25AB");//"80A036AEA1D3"
- String jsonContent = JSONObject.toJSONString(map);
- try {
- JSONObject jsonObject = queryData(jsonContent, PasswordUrlEnum.Device_Info.getUrl());
- JSONObject data = jsonObject.getJSONObject("data");
- } catch (Exception e) {
- e.printStackTrace();
- }
- // 密码下发,后续需通过luid(设备id)通过aes解码
- // HashMap<String, Object> 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<String, Object> 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<String, Object> map = new HashMap<>();
- // map.put("luid", "047863CA78E0");//"80A036AEA1D3");
- // map.put("categoryId", doorLockConfig.getCategoryId());//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
- // // map.put("categoryId", "d0c248256f8346d2a19afa296562b319");//"d0c248256f8346d2a19afa296562b319");//设备分类ID 所有蓝牙wifi锁默认统一值
- // map.put("userName", "13097286670");// 用户名 也就是管理锁的账号
- // map.put("fingerprintData","544D520204001700484AA20800050000400C0280000500003E0D620C00070000434E848A000B0000390E427B000B0000554F348C0007000044503280000B000053912487000700003DD2E477000B00004D93020F000500005D13F21200070000358A227B00010000300D827300050000268D6472000500002311C2600005000038D5E467000100002DD5A2E2000500003D49D20D0003000036CAD28300030000229652CD0003000036D66266000300002716C455000300003057845500030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080010000E0070000F00F0000F8070000FC0F0000FE1F0000FE7F0000FF7F0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FF7F0000FF070000FF0700007E000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003AEA");
- // map.put("type", 4);
- // map.put("startTime", "1724315400000");//"1686067200000");
- // map.put("endTime", "1724322600000");//"1686204000000");
- //
- // String jsonContent = JSONObject.toJSONString(map);
- //
- // try {
- // queryData(jsonContent, PasswordUrlEnum.Fingerprint_Data.getUrl());
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- // 删除
- // HashMap<String, Object> map = new HashMap<>();
- // map.put("categoryId", doorLockConfig.getCategoryId());
- // map.put("luid", "047863CA78E0");
- //// map.put("id", "12ea7b0761b040e18ab95348287d6bae");
- // map.put("id", "66336c9de4fa47b6aeb9e4216937f904");
- // 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();
- // }
- }
- /**
- * 获取设备详情
- */
- public String getDeviceInfo(String luid) {
- HashMap<String, String> 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<String, String> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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());//"544D520004001100370C5417000B000040CF0203000B000031CF0491000B00004750F4EB000B000040D38406000B00004994E200000B00004395947E000B00004F906471000B00004B0AD2CE00090000454CE2EA0009000041CB220000090000320D221C000900003915740D000900003256620C000700003E56A2050007000030974484000700004388C4AF00070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);//指纹特征值
- 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 Boolean remoteUnlocking(String luid) {
- HashMap<String, Object> 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());
- Integer result = jsonObject.getInteger("result");
- if (result == 1) {
- return true;
- } else {
- return false;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- /**
- * 删除锁用户
- *
- * @param luid
- * @param id
- * @return
- */
- public void deleteLockUser(String luid, String id) {
- HashMap<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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();
- }
- }
- }
|