From bd4891e2fd6b773cbb0ec387f6db4bc944fdf51a Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期一, 31 三月 2025 18:07:51 +0800 Subject: [PATCH] feat(generallibrary): 添加卡片列表功能并优化登录逻辑 --- baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcWriteHelper.java | 38 +++++++++++++++++++++++++++----------- 1 files changed, 27 insertions(+), 11 deletions(-) diff --git a/baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcWriteHelper.java b/baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcWriteHelper.java index 525b5aa..c427898 100644 --- a/baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcWriteHelper.java +++ b/baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcWriteHelper.java @@ -24,6 +24,9 @@ private static NativeNfcWriteHelper helper; public NativeNfcWriteHelper(Intent intent, Activity activity) { + } + + public void setIntent(Intent intent) { this.tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); } @@ -37,6 +40,7 @@ if (helper == null) { helper = new NativeNfcWriteHelper(intent, activity); } + helper.setIntent(intent); return helper; } @@ -48,9 +52,9 @@ * @param */ @Override - public boolean writeUserData(BaseUserCardCard userCard) { + public boolean writeUserData(BaseUserCardCard userCard, int sector) { if (userCard != null) { - int a = 1; + int a = sector; try { MifareClassic mfc = MifareClassic.get(tag); if (null != mfc) { @@ -121,14 +125,21 @@ @Override public boolean writeData(byte[] str, int a, int b, NFCCallBack callBack) { + return writeData(str, a, b, true,null); + } + + @Override + public boolean writeData(byte[] str, int a, int b, boolean isConnect, NFCCallBack callBack) { Log.i("NFCWreatActivity", "writeData: a=" + a + " b=" + b); - if (str.length <= 16) { + if (str.length == 16) { try { MifareClassic mfc = MifareClassic.get(tag); if (null != mfc) { try { //杩炴帴NFC - mfc.connect(); + if (isConnect){ + mfc.connect(); + } //鑾峰彇鎵囧尯鏁伴噺 int count = mfc.getSectorCount(); //濡傛灉浼犺繘鏉ョ殑鎵囧尯澶т簡鎴栬�呭皬浜嗙洿鎺ラ��鍑烘柟娉� @@ -161,16 +172,14 @@ } } } else if (listA_PS.size() != 0 && listA_PS.size() > a) { - if (mfc.authenticateSectorWithKeyA(0, listA_PS.get(a))) { + if (mfc.authenticateSectorWithKeyA(a, defauleKey)){ + changePasword(a, mfc); isOpen = true; - if (listKeyA.get(a).equals(defauleKey)) { - //褰撳墠涓洪粯璁ょ櫧鍗″瘑鐮佹椂鍐欏崱鏃朵慨鏀瑰瘑鐮� - changePasword(a, mfc); - } + + }else if (mfc.authenticateSectorWithKeyA(a, listA_PS.get(a))) { + isOpen = true; } } - - if (isOpen) { int bIndex = mfc.sectorToBlock(a); //鍐欏崱 @@ -225,8 +234,15 @@ } } catch (Exception e) { e.printStackTrace(); + if (callBack != null) { + callBack.isSusses(false, a + "鎵囧尯鍐欏崱鎶ラ敊" + e.getMessage()); + } return false; } + } else { + if (callBack != null) { + callBack.isSusses(false, a + "鎵囧尯鍐欏崱鎶ラ敊锛宐yte鏁扮粍澶у皬涓嶄负16"); + } } return false; } -- Gitblit v1.8.0