瀏覽代碼

3.0 M1卡新增单独获取Uid

xwh 1 周之前
父節點
當前提交
dfed616358

+ 2 - 2
config.gradle

@@ -7,8 +7,8 @@ ext {
 //            minSdkVersion    : 24,
             minSdkVersion    : 21,
             targetSdkVersion : 22,
-            versionCode      : 82,
-            versionName      : "3.2.1.241219"
+            versionCode      : 83,
+            versionName      : "3.2.2.250102"
     ]
     //依赖 配置
     dependencies = [

+ 3 - 0
lib_base/src/main/java/com/hh/lib_base/Constants.java

@@ -149,6 +149,9 @@ public class Constants {
         //ampe event set
         public static final String EVENT_SET = "set";
 
+        //M1 ampe event getUid M1卡单独获取UID事件
+        public static final String EVENT_M1_GETUID = "getUid";
+
         // 二维码
         public static final String ACTION_QR = "getQRCode";
         // 二维码监听,app有消息,就推给小程序

+ 12 - 0
lib_nfc/lib_m1_card/src/main/java/com/hh/lib_m1_card/DxM1CardReader.java

@@ -7,6 +7,7 @@ import android.util.Log;
 
 import com.donsee.devices.CardReader;
 import com.donsee.devices.HexUtil;
+import com.hh.lib_base.Constants;
 import com.hh.lib_m1_card.bean.AmpeResultM1CardBean;
 import com.hh.lib_m1_card.bean.DxM1CardLoopResultBean;
 import com.hh.lib_m1_card.config.M1CardConfig;
@@ -141,6 +142,15 @@ public class DxM1CardReader {
         }else{
             Thread.sleep(20);
             String uidInfo = HexUtil.bytesToHex(uid, 4);
+            if(Constants.Ampe.EVENT_M1_GETUID.equals(m1CardLoopConfig.getEvent())){
+                DxM1CardLoopResultBean data=new DxM1CardLoopResultBean();
+                data.setEvent(m1CardLoopConfig.getEvent());
+                data.setUid(uidInfo);
+                if(m1CardReaderResultListener!=null){
+                    m1CardReaderResultListener.onJsonInfo(GsonUtils.getGson().toJson(data));
+                }
+                return;
+            }
             ret = cardReader.Donsee_M1VerifyPass(m1CardLoopConfig.getKeyMode(),
                     ((byte) m1CardLoopConfig.getSector()), HexUtil.hexToBytes(m1CardLoopConfig.getSecretKey()));
             if (ret != SUCCESS) {
@@ -182,8 +192,10 @@ public class DxM1CardReader {
 
                 }
                 DxM1CardLoopResultBean data=new DxM1CardLoopResultBean();
+                data.setEvent(m1CardLoopConfig.getEvent());
                 data.setUid(uidInfo);
                 data.setReadContent(cardStr.toString());
+
                 if(m1CardReaderResultListener!=null){
                     m1CardReaderResultListener.onJsonInfo(GsonUtils.getGson().toJson(data));
                 }

+ 10 - 0
lib_nfc/lib_m1_card/src/main/java/com/hh/lib_m1_card/bean/DxM1CardLoopResultBean.java

@@ -9,6 +9,7 @@ package com.hh.lib_m1_card.bean;
 public class DxM1CardLoopResultBean {
     private String uid;
     private String readContent;
+    private String event="";
 
     public String getUid() {
         return uid;
@@ -25,4 +26,13 @@ public class DxM1CardLoopResultBean {
     public void setReadContent(String readContent) {
         this.readContent = readContent;
     }
+
+
+    public String getEvent() {
+        return event;
+    }
+
+    public void setEvent(String event) {
+        this.event = event;
+    }
 }

+ 11 - 0
lib_nfc/lib_m1_card/src/main/java/com/hh/lib_m1_card/config/M1CardConfig.java

@@ -13,6 +13,7 @@ public class M1CardConfig {
     private String block="";  // 读取的块,可以多块"1,2,3"
     private String secretKey=""; //密钥
     private byte keyMode=0x60; //默认keyA, 0x61 KeyB
+    private String event="start";
 
 
     public int getSector() {
@@ -47,6 +48,15 @@ public class M1CardConfig {
         this.keyMode = keyMode;
     }
 
+
+    public String getEvent() {
+        return event;
+    }
+
+    public void setEvent(String event) {
+        this.event = event;
+    }
+
     public String[] getBlockList() {
         String[] list;
         if(TextUtils.isEmpty(block)){
@@ -66,6 +76,7 @@ public class M1CardConfig {
                 ", block='" + block + '\'' +
                 ", secretKey='" + secretKey + '\'' +
                 ", keyMode=" + keyMode +
+                ", event='" + event + '\'' +
                 '}';
     }
 }

+ 8 - 2
lib_nfc/src/main/java/com/lib_nfc/m1/M1CardInvoker.java

@@ -82,14 +82,20 @@ public class M1CardInvoker {
         initM1();
         boolean success = false;
 
-        if(Constants.Ampe.EVENT_START.equals(newBean.getEvent())){
+        if(Constants.Ampe.EVENT_START.equals(newBean.getEvent())){ //启动M1卡监听,读取块内容
             if(newBean.getParams()!=null){
+                newBean.setEvent(newBean.getEvent());
                 dxM1CardReader.setM1CardLoopConfig(newBean.getParams());
                 success = dxM1CardReader.startRead();
             }
 
-        } else if (Constants.Ampe.EVENT_STOP.equals(newBean.getEvent())) {
+        } else if (Constants.Ampe.EVENT_STOP.equals(newBean.getEvent())) { //停止阅读器
             success = dxM1CardReader.stopRead();
+        }else if((Constants.Ampe.EVENT_M1_GETUID.equals(newBean.getEvent()))){ //启动M1卡监听,读取Uid
+            M1CardConfig cardConfig=new M1CardConfig();
+            cardConfig.setEvent(newBean.getEvent());
+            dxM1CardReader.setM1CardLoopConfig(cardConfig);
+            success = dxM1CardReader.startRead();
         }
         BaseAmpeAppletResultBean ssConfigBean = new BaseAmpeAppletResultBean();
         ssConfigBean.setAction(Constants.Ampe.ACTION_DOM1LISTENER);