| | |
| | | import com.dayu.recharge.tools.BcdUtil; |
| | | import com.dayu.recharge.tools.HexUtil; |
| | | import com.dayu.recharge.utils.MornyUtil; |
| | | import com.dayu.recharge.utils.MyCommon; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Calendar; |
| | |
| | | * Description: 用户卡结构 |
| | | */ |
| | | public class UserCard implements Serializable { |
| | | public String cardType = "A1";//写卡标志 A1刷卡开泵前 A8刷卡开泵后 A2叠加充值 |
| | | public String cardType = MyCommon.USER_CARD_TYPE_1;//写卡标志 A1刷卡开泵前 A8刷卡开泵后 A2叠加充值 |
| | | |
| | | public int rechargeTimes;//充值次数 |
| | | |
| | |
| | | * @param data |
| | | */ |
| | | public static UserCard getBean(List<byte[]> data) { |
| | | 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]; |
| | | swipeNumberBytes[0] = zero[2]; |
| | | swipeNumberBytes[1] = zero[3]; |
| | | String swipeNumberHex = HexUtil.bytesToHex(swipeNumberBytes); |
| | | userCard.swipeNumber = (short) HexUtil.get16to10(swipeNumberHex); |
| | | byte[] electricityPriceBytes = new byte[4]; |
| | | for (int i = 0; i < 4; i++) { |
| | | electricityPriceBytes[i] = zero[i + 4]; |
| | | } |
| | | userCard.electricityPrice = HexUtil.hexToFloat(HexUtil.bytesToHex(electricityPriceBytes)); |
| | | userCard.state = BcdUtil.bcdToStr(zero[8]); |
| | | byte[] balanceBytes = new byte[4]; |
| | | for (int i = 0; i < 4; i++) { |
| | | balanceBytes[i] = zero[i + 9]; |
| | | } |
| | | userCard.balance = HexUtil.get16to10(HexUtil.bytesToHex(balanceBytes)); |
| | | |
| | | byte[] addressCodeBytes = new byte[6]; |
| | | addressCodeBytes[0] = zero[13]; |
| | | addressCodeBytes[1] = zero[14]; |
| | | addressCodeBytes[2] = two[11]; |
| | | addressCodeBytes[3] = two[12]; |
| | | addressCodeBytes[4] = two[13]; |
| | | addressCodeBytes[5] = two[14]; |
| | | 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; |
| | | 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]; |
| | | swipeNumberBytes[0] = zero[2]; |
| | | swipeNumberBytes[1] = zero[3]; |
| | | String swipeNumberHex = HexUtil.bytesToHex(swipeNumberBytes); |
| | | userCard.swipeNumber = (short) HexUtil.get16to10(swipeNumberHex); |
| | | byte[] electricityPriceBytes = new byte[4]; |
| | | for (int i = 0; i < 4; i++) { |
| | | electricityPriceBytes[i] = zero[i + 4]; |
| | | } |
| | | userCard.electricityPrice = HexUtil.hexToFloat(HexUtil.bytesToHex(electricityPriceBytes)); |
| | | userCard.state = BcdUtil.bcdToStr(zero[8]); |
| | | byte[] balanceBytes = new byte[4]; |
| | | for (int i = 0; i < 4; i++) { |
| | | balanceBytes[i] = zero[i + 9]; |
| | | } |
| | | userCard.balance = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(balanceBytes)); |
| | | |
| | | byte[] addressCodeBytes = new byte[6]; |
| | | addressCodeBytes[0] = zero[13]; |
| | | addressCodeBytes[1] = zero[14]; |
| | | addressCodeBytes[2] = two[11]; |
| | | addressCodeBytes[3] = two[12]; |
| | | addressCodeBytes[4] = two[13]; |
| | | addressCodeBytes[5] = two[14]; |
| | | 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; |
| | | } |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(2000 + year, month, day, hour, minute, second); |
| | | byte[] initPeasantCodeBytes = new byte[16]; |
| | | initPeasantCodeBytes[0] = one[10]; |
| | | initPeasantCodeBytes[1] = one[11]; |
| | | initPeasantCodeBytes[2] = one[12]; |
| | | initPeasantCodeBytes[3] = one[13]; |
| | | initPeasantCodeBytes[4] = one[14]; |
| | | initPeasantCodeBytes[5] = two[0]; |
| | | initPeasantCodeBytes[6] = two[1]; |
| | | initPeasantCodeBytes[7] = two[2]; |
| | | initPeasantCodeBytes[8] = two[3]; |
| | | initPeasantCodeBytes[9] = two[4]; |
| | | initPeasantCodeBytes[10] = two[5]; |
| | | initPeasantCodeBytes[11] = two[6]; |
| | | initPeasantCodeBytes[12] = two[7]; |
| | | initPeasantCodeBytes[13] = two[8]; |
| | | initPeasantCodeBytes[14] = two[9]; |
| | | initPeasantCodeBytes[15] = two[10]; |
| | | 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]; |
| | | initPeasantCodeBytes[0] = one[10]; |
| | | initPeasantCodeBytes[1] = one[11]; |
| | | initPeasantCodeBytes[2] = one[12]; |
| | | initPeasantCodeBytes[3] = one[13]; |
| | | initPeasantCodeBytes[4] = one[14]; |
| | | initPeasantCodeBytes[5] = two[0]; |
| | | initPeasantCodeBytes[6] = two[1]; |
| | | initPeasantCodeBytes[7] = two[2]; |
| | | initPeasantCodeBytes[8] = two[3]; |
| | | initPeasantCodeBytes[9] = two[4]; |
| | | initPeasantCodeBytes[10] = two[5]; |
| | | initPeasantCodeBytes[11] = two[6]; |
| | | initPeasantCodeBytes[12] = two[7]; |
| | | initPeasantCodeBytes[13] = two[8]; |
| | | initPeasantCodeBytes[14] = two[9]; |
| | | initPeasantCodeBytes[15] = two[10]; |
| | | userCard.initPeasantCode = HexUtil.bytesToHex(initPeasantCodeBytes); |
| | | return userCard; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | return null; |
| | | } |