From 6a5879320dfac43155d024814a0a4d794a612696 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期三, 21 八月 2024 13:52:14 +0800 Subject: [PATCH] 齐河联网版程序除补卡相关逻辑 --- qiheonlinelibrary/src/main/java/com/dayu/qiheonlinelibrary/tools/NfcReadHelper.java | 72 +++++++++++++++++++++++++++++++++++- 1 files changed, 70 insertions(+), 2 deletions(-) diff --git a/qiheonlinelibrary/src/main/java/com/dayu/qiheonlinelibrary/tools/NfcReadHelper.java b/qiheonlinelibrary/src/main/java/com/dayu/qiheonlinelibrary/tools/NfcReadHelper.java index 5d89eeb..424c0d1 100644 --- a/qiheonlinelibrary/src/main/java/com/dayu/qiheonlinelibrary/tools/NfcReadHelper.java +++ b/qiheonlinelibrary/src/main/java/com/dayu/qiheonlinelibrary/tools/NfcReadHelper.java @@ -9,6 +9,7 @@ import com.dayu.baselibrary.tools.HexUtil; import com.dayu.baselibrary.utils.BaseCommon; +import com.dayu.qiheonlinelibrary.card.ManagerToUserCard; import com.dayu.qiheonlinelibrary.card.UserCard; import com.dayu.qiheonlinelibrary.utils.CardCommon; @@ -135,8 +136,8 @@ byte[] data = mfc.readBlock(bIndex + 0); if (data != null && data.length > 0) { String hex = HexUtil.bytesToHex(Arrays.copyOfRange(data, 0, 4)); -// hex = HexUtil.spaceHex(hex); -// hex = HexUtil.HighLowHex(hex); + hex = HexUtil.spaceHex(hex); + hex = HexUtil.HighLowHex(hex); Log.i("NFCWreatActivity", "hex===" + hex); return hex.toUpperCase(); } @@ -178,6 +179,8 @@ byte[] data = mfc.readBlock(bIndex + 0); if (data != null && data.length > 0) { String hex = HexUtil.bytesToHex(Arrays.copyOfRange(data, 0, 4)); + hex = HexUtil.spaceHex(hex); + hex = HexUtil.HighLowHex(hex); strData.append(hex); strData.append(","); Log.i("NFCWreatActivity", "hex===" + hex); @@ -476,6 +479,71 @@ }).start(); } + + /** + * 鑾峰彇鐢ㄦ埛鍗′俊鎭� + * + * @return + */ + public ManagerToUserCard getManagerToUserCardData() { + ManagerToUserCard managerToUserCard = null; + Map<String, List<byte[]>> map = new HashMap<>(); + MifareClassic mfc = MifareClassic.get(tag); + if (null != mfc) { + try { + //閾炬帴NFC + mfc.connect(); + //鑾峰彇鎵囧尯鏁伴噺 + int count = mfc.getSectorCount(); + //瀛樺偍绌洪棿 + int size = mfc.getSize(); + //鐢ㄤ簬鍒ゆ柇鏃跺�欐湁鍐呭璇诲彇鍑烘潵 + boolean flag = false; + List<byte[]> list = new ArrayList<>(); + //楠岃瘉鎵囧尯瀵嗙爜锛屽惁鍒欎細鎶ラ敊锛堥摼鎺ュけ璐ラ敊璇級 + boolean isOpen = mfc.authenticateSectorWithKeyA(1, defauleKey); + if (!isOpen) { + isOpen = mfc.authenticateSectorWithKeyA(1, companyKey); + } + if (isOpen) { + //鑾峰彇鎵囧尯閲岄潰鍧楃殑鏁伴噺 + int bCount = mfc.getBlockCountInSector(1); + //鑾峰彇鎵囧尯绗竴涓潡瀵瑰簲鑺墖瀛樺偍鍣ㄧ殑浣嶇疆锛堟垜鏄繖鏍风悊瑙g殑锛屽洜涓虹0鎵囧尯鐨勮繖涓�兼槸4鑰屼笉鏄�0锛� + int bIndex = mfc.sectorToBlock(1); + //String data1 = ""; + for (int j = 0; j < bCount; j++) { + //璇诲彇鏁版嵁 + byte[] data = null; + try { + data = mfc.readBlock(bIndex); + bIndex++; + list.add(data); + } catch (Exception e) { + e.printStackTrace(); + } + } + flag = true; + } + + if (flag) { + managerToUserCard = ManagerToUserCard.getBean(list); + return managerToUserCard; + } + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + mfc.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return null; + } + /** * 杩斿洖鐩戝惉绫� */ -- Gitblit v1.8.0