左晓为主开发手持机充值管理机
zuoxiao
2024-06-26 ddafb0f0951e68b4e56bfceef43cf78559f5161f
henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java
@@ -172,13 +172,13 @@
        public byte[] toByte() {
            byte[] data = new byte[16];
            data[0] = HexUtil.hexToByte(cardType);
            domainLength = domainName.length();
//            域名卡新乡C1后有01==0,鹿邑没有01==1
            if (type == 0) {
                if (domainNumber != null) {
                    byte[] domainNumbers = BcdUtil.strToBcd(domainNumber);
                    data[1] = domainNumbers[0];
                }
                domainLength = domainName.length();
                data[2] = HexUtil.hexToByte(HexUtil.get10to16(domainLength));
                String portStr = String.valueOf(port);
                int lenght = portStr.length();
@@ -187,11 +187,7 @@
                }
                String ascii = IDN.toASCII(domainName + "," + portStr + "#");
                asciiByte = ascii.getBytes();
                if (asciiByte.length < 12) {
                    System.arraycopy(asciiByte, 0, data, 3, asciiByte.length);
                } else {
                    System.arraycopy(asciiByte, 0, data, 3, 12);
                }
                System.arraycopy(asciiByte, 0, data, 3, Math.min(asciiByte.length, 12));
            } else {
                data[1] = HexUtil.hexToByte(HexUtil.get10to16(domainLength));
                String portStr = String.valueOf(port);
@@ -201,13 +197,7 @@
                }
                String ascii = IDN.toASCII(domainName + "," + portStr + "#");
                asciiByte = ascii.getBytes();
                if (asciiByte.length < 13) {
                    System.arraycopy(asciiByte, 0, data, 1, asciiByte.length);
                } else {
                    System.arraycopy(asciiByte, 0, data, 1, 13);
                }
                System.arraycopy(asciiByte, 0, data, 2, Math.min(asciiByte.length, 13));
            }
@@ -224,22 +214,10 @@
        public byte[] toBytes() {
            byte[] data = new byte[16];
            if (type==0){
                if (asciiByte.length > 12) {
                    if (asciiByte.length - 12 < 15) {
                        System.arraycopy(asciiByte, 12, data, 0, asciiByte.length - 12);
                    } else {
                        System.arraycopy(asciiByte, 12, data, 0, 15);
                    }
                }
            }else {
                if (asciiByte.length > 13) {
                    if (asciiByte.length - 13 < 15) {
                        System.arraycopy(asciiByte, 13, data, 0, asciiByte.length - 12);
                    } else {
                        System.arraycopy(asciiByte, 13, data, 0, 15);
                    }
                }
            int offset = (type == 0) ? 12 : 13;
            if (asciiByte.length > offset) {
                System.arraycopy(asciiByte, offset, data, 0, Math.min(asciiByte.length - offset, 15));
            }
            data[15] = getByteSum(data);
@@ -255,24 +233,11 @@
    public class Two extends BaseCard {
        public byte[] toBytes() {
            byte[] data = new byte[16];
            if (type==0){
                if (asciiByte.length > (12 + 15)) {
                    if (asciiByte.length - (12 + 15) < 15) {
                        System.arraycopy(asciiByte, 12 + 15, data, 0, asciiByte.length - (12 + 15));
                    } else {
                        System.arraycopy(asciiByte, 12 + 15, data, 0, 15);
                    }
                }
            }else {
                if (asciiByte.length > (13 + 15)) {
                    if (asciiByte.length - (13 + 15) < 15) {
                        System.arraycopy(asciiByte, 13 + 15, data, 0, asciiByte.length - (12 + 15));
                    } else {
                        System.arraycopy(asciiByte, 13 + 15, data, 0, 15);
                    }
                }
            int offset = (type == 0) ? 27 : 28; // 12 + 15 and 13 + 15
            if (asciiByte.length > offset) {
                int lengthToCopy = Math.min(asciiByte.length - offset, 15);
                System.arraycopy(asciiByte, offset, data, 0, lengthToCopy);
            }
            data[15] = getByteSum(data);
            return data;
        }