左晓为主开发手持机充值管理机
zuoxiao
2025-03-31 bd4891e2fd6b773cbb0ec387f6db4bc944fdf51a
henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java
@@ -168,17 +168,17 @@
    /**
     * 用户卡0块
     */
    public class Zero extends BaseCard {
    public class Zero extends HNBaseCard {
        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));
            }
@@ -220,26 +210,14 @@
    /**
     * 用户卡1块
     */
    public class One extends BaseCard {
    public class One extends HNBaseCard {
        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);
@@ -252,27 +230,14 @@
    /**
     * 用户卡2块
     */
    public class Two extends BaseCard {
    public class Two extends HNBaseCard {
        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;
        }