| | |
| | | import android.nfc.tech.MifareClassic; |
| | | import android.util.Log; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | |
| | | import com.dayu.baselibrary.bean.BaseManagerToUserCard; |
| | | import com.dayu.baselibrary.bean.BaseUserCardCard; |
| | | import com.dayu.baselibrary.tools.HexUtil; |
| | |
| | | private Tag tag; |
| | | // private NFCCallback callback; |
| | | private static NativeNfcReadHelper helper; |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public String getCardNumberNoClose() { |
| | | if (tag == null) { |
| | | return ""; |
| | |
| | | return ""; |
| | | } |
| | | |
| | | @Override |
| | | public String getCradTypeAndCardNumber() { |
| | | return getCradTypeAndCardNumber(1); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取卡片类型和卡号 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String getCradTypeAndCardNumber() { |
| | | |
| | | public String getCradTypeAndCardNumber(int sectorIndex) { |
| | | |
| | | MifareClassic mfc = MifareClassic.get(tag); |
| | | if (null != mfc) { |
| | |
| | | StringBuilder strData = new StringBuilder(); |
| | | //获取当前卡号 |
| | | 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, listA_PS.get(0))) { |
| | | isOpen = true; |
| | | } else if (mfc.authenticateSectorWithKeyA(0, defauleKey)) { |
| | | isOpen = true; |
| | | } |
| | | } |
| | | if (isOpen) { |
| | |
| | | } |
| | | } |
| | | //获取卡片类型 |
| | | if (!listKeyA.isEmpty()) { |
| | | for (int i = 0; i < listKeyA.size(); i++) { |
| | | if (mfc.authenticateSectorWithKeyA(1, listKeyA.get(i))) { |
| | | if (mfc.authenticateSectorWithKeyA(sectorIndex, listKeyA.get(i))) { |
| | | isOpen = true; |
| | | break; |
| | | } |
| | | } |
| | | } else if (!listA_PS.isEmpty()) { |
| | | if (mfc.authenticateSectorWithKeyA(sectorIndex, listA_PS.get(sectorIndex))) { |
| | | isOpen = true; |
| | | } else if (mfc.authenticateSectorWithKeyA(sectorIndex, defauleKey)) { |
| | | isOpen = true; |
| | | } |
| | | } |
| | | if (isOpen) { |
| | | int bIndex = mfc.sectorToBlock(1); |
| | | byte[] data = mfc.readBlock(bIndex + 0); |
| | | int bIndex = mfc.sectorToBlock(sectorIndex); |
| | | byte[] data = mfc.readBlock(bIndex + sectorIndex); |
| | | if (data != null && data.length > 0) { |
| | | String hex = HexUtil.byteToHex(data[0]); |
| | | strData.append(hex); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |