From eb53d9c4837b5a0df0db1ca153e05bf305ce498a Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期二, 08 四月 2025 15:32:01 +0800
Subject: [PATCH] feat(generallibrary): 新增用户开卡功能
---
baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcReadHelper.java | 75 +++++++++++++++++++++++++++++++++++--
1 files changed, 70 insertions(+), 5 deletions(-)
diff --git a/baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcReadHelper.java b/baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcReadHelper.java
index bcad792..4c8aa09 100644
--- a/baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcReadHelper.java
+++ b/baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcReadHelper.java
@@ -32,8 +32,14 @@
public NativeNfcReadHelper(Intent intent, Activity activity) {
+ }
+
+
+ @Override
+ public void setIntent(Intent intent) {
this.tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
}
+
/**
* 鍗曚緥鍒濆鍖�
@@ -45,6 +51,7 @@
if (helper == null) {
helper = new NativeNfcReadHelper(intent, activity);
}
+ helper.setIntent(intent);
return helper;
}
@@ -53,8 +60,9 @@
*
* @return
*/
+ @Override
public BaseUserCardCard getUserCardData(BaseUserCardCard userCardCard) {
- if (userCardCard!=null){
+ if (userCardCard != null) {
BaseUserCardCard userCard = null;
Map<String, List<byte[]>> map = new HashMap<>();
MifareClassic mfc = MifareClassic.get(tag);
@@ -117,8 +125,9 @@
return null;
}
- public String getCradType() {
+ @Override
+ public String getCradType() {
MifareClassic mfc = MifareClassic.get(tag);
if (null != mfc) {
try {
@@ -161,6 +170,7 @@
*
* @param callback
*/
+ @Override
public void getAllData(final NFCCallMapback callback) {
Map<String, List<byte[]>> map = new HashMap<>();
MifareClassic mfc = MifareClassic.get(tag);
@@ -232,6 +242,7 @@
*
* @param callback
*/
+ @Override
public void getOneSectorData(NFCCallListback callback) {
@@ -305,6 +316,7 @@
* @param b 鍧�
* @param callback
*/
+ @Override
public void getData(final int a, final int b, final NFCCallByteback callback) {
new Thread(new Runnable() {
@Override
@@ -381,12 +393,21 @@
mfc.connect();
//鑾峰彇褰撳墠鍗″彿
boolean isOpen = false;
- for (int i = 0; i < listKeyA.size(); i++) {
- if (mfc.authenticateSectorWithKeyA(0, listKeyA.get(i))) {
+ if (!listKeyA.isEmpty()) {
+ for (int i = 0; i < listKeyA.size(); i++) {
+ if (mfc.authenticateSectorWithKeyA(0, listKeyA.get(i))) {
+ isOpen = true;
+ break;
+ }
+ }
+ } else if (!listA_PS.isEmpty()) {
+ if (mfc.authenticateSectorWithKeyA(0, defauleKey)) {
isOpen = true;
- break;
+ } else if (mfc.authenticateSectorWithKeyA(0, listA_PS.get(0))) {
+ isOpen = true;
}
}
+
if (isOpen) {
int bIndex = mfc.sectorToBlock(0);
byte[] data = mfc.readBlock(bIndex + 0);
@@ -407,6 +428,49 @@
} catch (IOException e) {
e.printStackTrace();
}
+ }
+ }
+ return "";
+ }
+
+
+ public String getCardNumberNoClose() {
+ MifareClassic mfc = MifareClassic.get(tag);
+ if (null != mfc) {
+ try {
+ mfc.connect();
+ //鑾峰彇褰撳墠鍗″彿
+ boolean isOpen = false;
+ if (!listKeyA.isEmpty()) {
+ for (int i = 0; i < listKeyA.size(); i++) {
+ if (mfc.authenticateSectorWithKeyA(0, listKeyA.get(i))) {
+ isOpen = true;
+ break;
+ }
+ }
+ } else if (!listA_PS.isEmpty()) {
+ if (mfc.authenticateSectorWithKeyA(0, defauleKey)) {
+ isOpen = true;
+ } else if (mfc.authenticateSectorWithKeyA(0, listA_PS.get(0))) {
+ isOpen = true;
+ }
+ }
+
+ if (isOpen) {
+ int bIndex = mfc.sectorToBlock(0);
+ 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);
+ Log.i("NFCWreatActivity", "hex===" + hex);
+ return hex.toUpperCase();
+ }
+ }
+
+ } catch (IOException e) {
+ Log.i("NFCWreatActivity", e.toString());
+ return BaseCommon.CARD_TYPE_ERROR1;
}
}
return "";
@@ -543,6 +607,7 @@
*
* @return
*/
+ @Override
public BaseManagerToUserCard getManagerToUserCardData(BaseManagerToUserCard baseManagerToUserCard) {
BaseManagerToUserCard managerToUserCard = null;
--
Gitblit v1.8.0