From 15d9aae9a65c3385aaea29cb6d9810e4a8e8bd27 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期二, 07 五月 2024 11:04:45 +0800
Subject: [PATCH] 1.修复开卡列表显示异常bug 2.实现读卡界面相关功能 3.所有Activity去掉齐河后缀

---
 qihealonelibrary/src/main/java/com/dayu/qihealonelibrary/tools/NfcReadHelper.java |  130 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 124 insertions(+), 6 deletions(-)

diff --git a/qihealonelibrary/src/main/java/com/dayu/qihealonelibrary/tools/NfcReadHelper.java b/qihealonelibrary/src/main/java/com/dayu/qihealonelibrary/tools/NfcReadHelper.java
index 2c8542f..dff0d49 100644
--- a/qihealonelibrary/src/main/java/com/dayu/qihealonelibrary/tools/NfcReadHelper.java
+++ b/qihealonelibrary/src/main/java/com/dayu/qihealonelibrary/tools/NfcReadHelper.java
@@ -8,12 +8,14 @@
 import android.util.Log;
 
 import com.dayu.baselibrary.tools.HexUtil;
+import com.dayu.baselibrary.utils.BaseCommon;
 import com.dayu.qihealonelibrary.card.UserCard;
 import com.dayu.qihealonelibrary.utils.CardCommon;
 
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -113,13 +115,74 @@
         return null;
     }
 
-    public String getCradType() {
+    /**
+     * 鑾峰彇鍗″彿
+     *
+     * @return
+     */
+    public String getCardNumber() {
+        MifareClassic mfc = MifareClassic.get(tag);
+        if (null != mfc) {
+            try {
+                mfc.connect();
+                //鑾峰彇褰撳墠鍗″彿
+                boolean isOpen = mfc.authenticateSectorWithKeyA(0, defauleKey);
+                if (!isOpen) {
+                    isOpen = mfc.authenticateSectorWithKeyA(0, companyKey);
+                }
+                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));
+                        Log.i("NFCWreatActivity", "hex===" + hex);
+                        return hex;
+                    }
+                }
+
+            } catch (IOException e) {
+                return BaseCommon.CARD_TYPE_ERROR1;
+            } finally {
+                try {
+                    mfc.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return "";
+    }
+
+
+    /**
+     * 鑾峰彇鍗$墖绫诲瀷鍜屽崱鍙�
+     *
+     * @return
+     */
+    public String getCradTypeAndCardNumber() {
 
         MifareClassic mfc = MifareClassic.get(tag);
         if (null != mfc) {
             try {
                 mfc.connect();
-                boolean isOpen = mfc.authenticateSectorWithKeyA(1, defauleKey);
+                StringBuilder strData = new StringBuilder();
+                //鑾峰彇褰撳墠鍗″彿
+                boolean isOpen = mfc.authenticateSectorWithKeyA(0, defauleKey);
+                if (!isOpen) {
+                    isOpen = mfc.authenticateSectorWithKeyA(0, companyKey);
+                }
+                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));
+                        strData.append(hex);
+                        strData.append(",");
+                        Log.i("NFCWreatActivity", "hex===" + hex);
+                    }
+                }
+                //鑾峰彇鍗$墖绫诲瀷
+                isOpen = mfc.authenticateSectorWithKeyA(1, defauleKey);
                 if (!isOpen) {
                     isOpen = mfc.authenticateSectorWithKeyA(1, companyKey);
                 }
@@ -128,16 +191,16 @@
                     byte[] data = mfc.readBlock(bIndex + 0);
                     if (data != null && data.length > 0) {
                         String hex = HexUtil.byteToHex(data[0]);
+                        strData.append(hex);
                         Log.i("NFCWreatActivity", "hex===" + hex);
-                        return hex;
+                        return strData.toString();
                     }
-
                 } else {
                     Log.i("NFCWreatActivity", "isOpen===" + isOpen);
-                    return "-1";
+                    return BaseCommon.CARD_TYPE_ERROR2;
                 }
             } catch (IOException e) {
-                return "-1";
+                return BaseCommon.CARD_TYPE_ERROR1;
             } finally {
                 try {
                     mfc.close();
@@ -217,6 +280,61 @@
     }
 
 
+    public List<byte[]> getOnesectorData() {
+        MifareClassic mfc = null;
+        try {
+            mfc = MifareClassic.get(tag);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        List<byte[]> list = new ArrayList<>();
+        if (null != mfc) {
+            try {
+                //閾炬帴NFC
+                mfc.connect();
+                //鐢ㄤ簬鍒ゆ柇鏃跺�欐湁鍐呭璇诲彇鍑烘潵
+                boolean flag = false;
+
+                //楠岃瘉鎵囧尯瀵嗙爜锛屽惁鍒欎細鎶ラ敊锛堥摼鎺ュけ璐ラ敊璇級
+                boolean isOpen = mfc.authenticateSectorWithKeyA(1, companyKey);
+                if (!isOpen) {
+                    isOpen = mfc.authenticateSectorWithKeyA(1, defauleKey);
+                }
+                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();
+                        }
+                    }
+                }
+
+            } catch (IOException e) {
+                e.printStackTrace();
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                try {
+                    mfc.close();
+                    return list;
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return null;
+    }
+
     /**
      * 鑾峰彇1鎵囧尯淇℃伅
      *

--
Gitblit v1.8.0