左晓为主开发手持机充值管理机
app/src/main/java/com/dayu/recharge/card/DomainCard.java
@@ -23,7 +23,24 @@
    //端口号为5个字节,不足5位高位补0。端口号与域名之间用”,”隔开。端口号最后以”#”结束
    public String domainName;//域名
    public String port;//端口
    public int port;//端口
    public String getDomainName() {
        return domainName;
    }
    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }
    public int getPort() {
        return port;
    }
    public void setPort(int port) {
        this.port = port;
    }
    private byte[] asciiByte;//当前域名和端口号数组
@@ -50,10 +67,18 @@
        public byte[] toByte() {
            byte[] data = new byte[16];
            data[0] = HexUtil.hexToByte(cardType);
            byte[] domainNumbers = BcdUtil.strToBcd(domainNumber);
            data[1] = domainNumbers[0];
            if (domainNumber != null) {
                byte[] domainNumbers = BcdUtil.strToBcd(domainNumber);
                data[1] = domainNumbers[0];
            }
            domainLength = domainName.length();
            data[2] = HexUtil.hexToByte(HexUtil.get10to16(domainLength));
            String ascii = IDN.toASCII(domainName + "," + port + "#");
            String portStr = String.valueOf(port);
            int lenght = portStr.length();
            for (int i = 0; i < 5 - lenght; i++) {
                portStr = "0" + portStr;
            }
            String ascii = IDN.toASCII(domainName + "," + portStr + "#");
            asciiByte = ascii.getBytes();
            if (asciiByte.length < 12) {
                System.arraycopy(asciiByte, 0, data, 3, asciiByte.length);
@@ -75,9 +100,9 @@
            byte[] data = new byte[16];
            if (asciiByte.length > 12) {
                if (asciiByte.length - 12 < 15) {
                    System.arraycopy(asciiByte, 12, data, 3, asciiByte.length - 12);
                    System.arraycopy(asciiByte, 12, data, 0, asciiByte.length - 12);
                } else {
                    System.arraycopy(asciiByte, 12, data, 3, 15);
                    System.arraycopy(asciiByte, 12, data, 0, 15);
                }
            }
            data[15] = getByteSum(data);
@@ -95,9 +120,9 @@
            byte[] data = new byte[16];
            if (asciiByte.length > (12 + 15)) {
                if (asciiByte.length - (12 + 15) < 15) {
                    System.arraycopy(asciiByte, 12, data, 3, asciiByte.length - (12 + 15));
                    System.arraycopy(asciiByte, 12, data, 0, asciiByte.length - (12 + 15));
                } else {
                    System.arraycopy(asciiByte, 12, data, 3, 15);
                    System.arraycopy(asciiByte, 12, data, 0, 15);
                }
            }
            data[15] = getByteSum(data);