| | |
| | | */ |
| | | public static UserCard getBean(List<byte[]> data) { |
| | | try { |
| | | UserCard userCard = new UserCard(); |
| | | |
| | | if (data != null) { |
| | | byte[] zero = data.get(0); |
| | | byte[] one = data.get(1); |
| | | byte[] two = data.get(2); |
| | | userCard.cardType = HexUtil.byteToHex(zero[0]); |
| | | userCard.rechargeTimes = HexUtil.get16to10(HexUtil.byteToHex(zero[1])); |
| | | byte[] swipeNumberBytes = new byte[2]; |
| | | System.arraycopy(zero,2,swipeNumberBytes,0,swipeNumberBytes.length); |
| | | String swipeNumberHex = HexUtil.bytesToHex(swipeNumberBytes); |
| | | userCard.swipeNumber = (short) HexUtil.get16to10(swipeNumberHex); |
| | | byte[] electricityPriceBytes = new byte[4]; |
| | | System.arraycopy(zero,4,electricityPriceBytes,0,electricityPriceBytes.length); |
| | | if (zero != null && zero.length == 16) { |
| | | UserCard userCard = new UserCard(); |
| | | userCard.cardType = HexUtil.byteToHex(zero[0]); |
| | | userCard.rechargeTimes = HexUtil.get16to10(HexUtil.byteToHex(zero[1])); |
| | | byte[] swipeNumberBytes = new byte[2]; |
| | | System.arraycopy(zero, 2, swipeNumberBytes, 0, swipeNumberBytes.length); |
| | | String swipeNumberHex = HexUtil.bytesToHex(swipeNumberBytes); |
| | | userCard.swipeNumber = (short) HexUtil.get16to10(swipeNumberHex); |
| | | byte[] electricityPriceBytes = new byte[4]; |
| | | System.arraycopy(zero, 4, electricityPriceBytes, 0, electricityPriceBytes.length); |
| | | |
| | | userCard.electricityPrice = HexUtil.hexToFloat(HexUtil.bytesToHex(electricityPriceBytes)); |
| | | userCard.state = BcdUtil.bcdToStr(zero[8]); |
| | | byte[] balanceBytes = new byte[4]; |
| | | System.arraycopy(zero,9,balanceBytes,0,balanceBytes.length); |
| | | userCard.electricityPrice = HexUtil.hexToFloat(HexUtil.bytesToHex(electricityPriceBytes)); |
| | | userCard.state = BcdUtil.bcdToStr(zero[8]); |
| | | byte[] balanceBytes = new byte[4]; |
| | | System.arraycopy(zero, 9, balanceBytes, 0, balanceBytes.length); |
| | | |
| | | userCard.balance = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(balanceBytes)); |
| | | userCard.balance = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(balanceBytes)); |
| | | byte[] addressCodeBytes = new byte[6]; |
| | | System.arraycopy(zero, 13, addressCodeBytes, 0, 2); |
| | | System.arraycopy(two, 11, addressCodeBytes, 2, 4); |
| | | userCard.addressCode = BcdUtil.bcdToStr(addressCodeBytes); |
| | | |
| | | byte[] addressCodeBytes = new byte[6]; |
| | | System.arraycopy(zero,13,addressCodeBytes,0,2); |
| | | System.arraycopy(two,11,addressCodeBytes,0,4); |
| | | userCard.addressCode = BcdUtil.bcdToStr(addressCodeBytes); |
| | | |
| | | int year = 0; |
| | | int month = 0; |
| | | int day = 0; |
| | | int hour = 0; |
| | | int minute = 0; |
| | | int second = 0; |
| | | for (int i = 0; i < 6; i++) { |
| | | byte byteData = one[i + 4]; |
| | | switch (i) { |
| | | case 0: |
| | | year = getBcdToInt(byteData); |
| | | break; |
| | | case 1: |
| | | month = getBcdToInt(byteData); |
| | | break; |
| | | case 2: |
| | | day = getBcdToInt(byteData); |
| | | break; |
| | | case 3: |
| | | hour = getBcdToInt(byteData); |
| | | break; |
| | | case 4: |
| | | minute = getBcdToInt(byteData); |
| | | break; |
| | | case 5: |
| | | second = getBcdToInt(byteData); |
| | | break; |
| | | int year = 0; |
| | | int month = 0; |
| | | int day = 0; |
| | | int hour = 0; |
| | | int minute = 0; |
| | | int second = 0; |
| | | for (int i = 0; i < 6; i++) { |
| | | byte byteData = one[i + 4]; |
| | | switch (i) { |
| | | case 0: |
| | | year = getBcdToInt(byteData); |
| | | break; |
| | | case 1: |
| | | month = getBcdToInt(byteData); |
| | | break; |
| | | case 2: |
| | | day = getBcdToInt(byteData); |
| | | break; |
| | | case 3: |
| | | hour = getBcdToInt(byteData); |
| | | break; |
| | | case 4: |
| | | minute = getBcdToInt(byteData); |
| | | break; |
| | | case 5: |
| | | second = getBcdToInt(byteData); |
| | | break; |
| | | } |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(2000 + year, month, day, hour, minute, second); |
| | | byte[] initPeasantCodeBytes = new byte[16]; |
| | | System.arraycopy(one, 10, initPeasantCodeBytes, 0, 5); |
| | | System.arraycopy(two, 0, initPeasantCodeBytes, 5, 11); |
| | | userCard.initPeasantCode = HexUtil.bytesToHex(initPeasantCodeBytes); |
| | | return userCard; |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(2000 + year, month, day, hour, minute, second); |
| | | byte[] initPeasantCodeBytes = new byte[16]; |
| | | System.arraycopy(one,10,initPeasantCodeBytes,0,5); |
| | | System.arraycopy(two,0,initPeasantCodeBytes,0,11); |
| | | userCard.initPeasantCode = HexUtil.bytesToHex(initPeasantCodeBytes); |
| | | return userCard; |
| | | |
| | | return null; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | /** |
| | | * 用户卡0块 |
| | | */ |
| | | public class Zero { |
| | | public class Zero { |
| | | public byte[] toByte() { |
| | | byte[] data = new byte[16]; |
| | | data[0] = HexUtil.hexToByte(cardType); |
| | |
| | | /** |
| | | * 用户卡1块 |
| | | */ |
| | | public class One { |
| | | public class One { |
| | | |
| | | public byte[] toBytes() { |
| | | byte[] data = new byte[16]; |
| | |
| | | data[9] = bcdSecond; |
| | | } |
| | | byte[] initPeasantCodes = HexUtil.hexToByteArray(initPeasantCode); |
| | | System.arraycopy(initPeasantCodes, 5, data, 0, 5); |
| | | System.arraycopy(initPeasantCodes, 0, data, 10, 5); |
| | | data[15] = getByteSum(data); |
| | | return data; |
| | | } |
| | |
| | | /** |
| | | * 用户卡2块 |
| | | */ |
| | | public class Two { |
| | | public class Two { |
| | | public byte[] toBytes() { |
| | | byte[] data = new byte[16]; |
| | | byte[] initPeasantCodes = HexUtil.hexToByteArray(initPeasantCode); |