From a6fdb620fa48f6c78f066d8e01b69d2570d3baa7 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 22 十一月 2023 17:43:45 +0800
Subject: [PATCH] 修改初始密码 首页添加联网状态 调整联网loding动画

---
 app/src/main/java/com/dayu/recharge/tools/NfcReadHelper.java |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/app/src/main/java/com/dayu/recharge/tools/NfcReadHelper.java b/app/src/main/java/com/dayu/recharge/tools/NfcReadHelper.java
index 428cfd8..34cd956 100644
--- a/app/src/main/java/com/dayu/recharge/tools/NfcReadHelper.java
+++ b/app/src/main/java/com/dayu/recharge/tools/NfcReadHelper.java
@@ -4,6 +4,7 @@
 import android.nfc.NfcAdapter;
 import android.nfc.Tag;
 import android.nfc.tech.MifareClassic;
+import android.util.Log;
 
 import com.dayu.recharge.card.UserCard;
 import com.dayu.recharge.utils.MyCommon;
@@ -46,7 +47,11 @@
         return helper;
     }
 
-
+    /**
+     * 鑾峰彇鐢ㄦ埛鍗′俊鎭�
+     *
+     * @return
+     */
     public UserCard getUserCardData() {
         UserCard userCard = null;
         Map<String, List<byte[]>> map = new HashMap<>();
@@ -63,7 +68,10 @@
                 boolean flag = false;
                 List<byte[]> list = new ArrayList<>();
                 //楠岃瘉鎵囧尯瀵嗙爜锛屽惁鍒欎細鎶ラ敊锛堥摼鎺ュけ璐ラ敊璇級
-                boolean isOpen = mfc.authenticateSectorWithKeyA(1, bytes);
+                boolean isOpen = mfc.authenticateSectorWithKeyA(1, defauleKey);
+                if (!isOpen){
+                    isOpen=   mfc.authenticateSectorWithKeyA(1, companyKey);
+                }
                 if (isOpen) {
                     //鑾峰彇鎵囧尯閲岄潰鍧楃殑鏁伴噺
                     int bCount = mfc.getBlockCountInSector(1);
@@ -103,6 +111,41 @@
         return null;
     }
 
+    public String getCradType() {
+
+        MifareClassic mfc = MifareClassic.get(tag);
+        if (null != mfc) {
+            try {
+                mfc.connect();
+                boolean isOpen = mfc.authenticateSectorWithKeyA(1, defauleKey);
+                if (!isOpen){
+                    isOpen= mfc.authenticateSectorWithKeyA(1, companyKey);
+                }
+                if (isOpen) {
+                    int bIndex = mfc.sectorToBlock(1);
+                    byte[] data = mfc.readBlock(bIndex + 0);
+                    if (data != null && data.length > 0) {
+                        String hex = HexUtil.byteToHex(data[0]);
+                        Log.i("NFCWreatActivity", "hex===" + hex);
+                        return hex;
+                    }
+
+                } else {
+                    Log.i("NFCWreatActivity", "isOpen===" + isOpen);
+                    return "-1";
+                }
+            } catch (IOException e) {
+                return "-1";
+            } finally {
+                try {
+                    mfc.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return "";
+    }
 
     /**
      * 璇诲彇NFC鍗$殑鍏ㄩ儴淇℃伅
@@ -128,7 +171,10 @@
                         for (int i = 0; i < count; i++) {
                             List<byte[]> list = new ArrayList<>();
                             //楠岃瘉鎵囧尯瀵嗙爜锛屽惁鍒欎細鎶ラ敊锛堥摼鎺ュけ璐ラ敊璇級
-                            boolean isOpen = mfc.authenticateSectorWithKeyA(i, bytes);
+                            boolean isOpen = mfc.authenticateSectorWithKeyA(i, defauleKey);
+                            if (!isOpen){
+                                isOpen = mfc.authenticateSectorWithKeyA(i, companyKey);
+                            }
                             if (isOpen) {
                                 //鑾峰彇鎵囧尯閲岄潰鍧楃殑鏁伴噺
                                 int bCount = mfc.getBlockCountInSector(i);
@@ -216,7 +262,10 @@
                                 typeS = "TYPE_UNKNOWN";
                                 break;
                         }
-                        boolean isOpen = mfc.authenticateSectorWithKeyA(a, bytes);
+                        boolean isOpen = mfc.authenticateSectorWithKeyA(a, defauleKey);
+                        if (!isOpen){
+                            isOpen = mfc.authenticateSectorWithKeyA(a, companyKey);
+                        }
                         if (isOpen) {
                             int bIndex = mfc.sectorToBlock(a);
                             byte[] data = mfc.readBlock(bIndex + b);

--
Gitblit v1.8.0