| | |
| | | return helper; |
| | | } |
| | | |
| | | |
| | | public BaseUserCardCard getUserCardData( BaseUserCardCard userCardCard) { |
| | | return getUserCardData(1, userCardCard); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户卡信息 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public BaseUserCardCard getUserCardData(BaseUserCardCard userCardCard) { |
| | | public BaseUserCardCard getUserCardData(int sectorIndex, BaseUserCardCard userCardCard) { |
| | | if (userCardCard != null) { |
| | | BaseUserCardCard userCard = null; |
| | | Map<String, List<byte[]>> map = new HashMap<>(); |
| | |
| | | try { |
| | | //链接NFC |
| | | mfc.connect(); |
| | | //获取扇区数量 |
| | | int count = mfc.getSectorCount(); |
| | | //存储空间 |
| | | int size = mfc.getSize(); |
| | | |
| | | //用于判断时候有内容读取出来 |
| | | boolean flag = false; |
| | | List<byte[]> list = new ArrayList<>(); |
| | | //验证扇区密码,否则会报错(链接失败错误) |
| | | boolean isOpen = false; |
| | | for (int i = 0; i < listKeyA.size(); i++) { |
| | | if (mfc.authenticateSectorWithKeyA(1, listKeyA.get(i))) { |
| | | if (!listKeyA.isEmpty()) { |
| | | for (int i = 0; i < listKeyA.size(); i++) { |
| | | if (mfc.authenticateSectorWithKeyA(sectorIndex, listKeyA.get(i))) { |
| | | isOpen = true; |
| | | break; |
| | | } |
| | | } |
| | | } else if (!listA_PS.isEmpty()) { |
| | | if (mfc.authenticateSectorWithKeyA(sectorIndex, defauleKey)) { |
| | | isOpen = true; |
| | | break; |
| | | } else if (mfc.authenticateSectorWithKeyA(sectorIndex, listA_PS.get(sectorIndex))) { |
| | | isOpen = true; |
| | | } |
| | | } |
| | | if (isOpen) { |
| | | //获取扇区里面块的数量 |
| | | int bCount = mfc.getBlockCountInSector(1); |
| | | int bCount = mfc.getBlockCountInSector(sectorIndex); |
| | | //获取扇区第一个块对应芯片存储器的位置(我是这样理解的,因为第0扇区的这个值是4而不是0) |
| | | int bIndex = mfc.sectorToBlock(1); |
| | | int bIndex = mfc.sectorToBlock(sectorIndex); |
| | | //String data1 = ""; |
| | | for (int j = 0; j < bCount; j++) { |
| | | //读取数据 |
| | |
| | | |
| | | @Override |
| | | public String getCradTypeAndCardNumber() { |
| | | return getCradTypeAndCardNumber(1); |
| | | return getCradTypeAndCardNumber(1, 0, 0); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | |
| | | public String getCradTypeAndCardNumber(int sectorIndex) { |
| | | public String getCradTypeAndCardNumber(int sectorIndex, int blockIndex, int cardTypeIndex) { |
| | | |
| | | MifareClassic mfc = MifareClassic.get(tag); |
| | | if (null != mfc) { |
| | |
| | | } |
| | | if (isOpen) { |
| | | int bIndex = mfc.sectorToBlock(sectorIndex); |
| | | byte[] data = mfc.readBlock(bIndex + sectorIndex); |
| | | byte[] data = mfc.readBlock(bIndex + 0); |
| | | if (data != null && data.length > 0) { |
| | | String hex = HexUtil.byteToHex(data[0]); |
| | | String hex = HexUtil.byteToHex(data[cardTypeIndex]); |
| | | strData.append(hex); |
| | | Log.i("NFCWreatActivity", "hex===" + hex); |
| | | return strData.toString().toUpperCase(); |
| | |
| | | return BaseCommon.CARD_TYPE_ERROR2; |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | return BaseCommon.CARD_TYPE_ERROR1; |
| | | } finally { |
| | | try { |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |