From ddafb0f0951e68b4e56bfceef43cf78559f5161f Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 26 六月 2024 14:52:27 +0800
Subject: [PATCH] 1.修复河南版本域名卡结构不同问题 2.修复齐河版本最终购水日期的bug

---
 henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java |   57 +++++++++++----------------------------------------------
 1 files changed, 11 insertions(+), 46 deletions(-)

diff --git a/henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java b/henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java
index 977ad1b..4c3e93d 100644
--- a/henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java
+++ b/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();
 //            鍩熷悕鍗℃柊涔1鍚庢湁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;
         }

--
Gitblit v1.8.0