package com.dayu.recharge.socketBean; import com.dayu.recharge.tools.ArraysUtil; import com.dayu.recharge.tools.BcdUtil; import com.dayu.recharge.utils.CRC8; /** * Copyright (C), 2022, * Author: zuo * Date: 2022/2/7 12:22 * Description:开卡报文 */ public class InitCardRequestBean extends BaseSocketBean { String control = "01";//控制域 String initCode;//设备注册号 String machineCode;//充值管理机序列号 String AFN = "93"; String orderId;//= new String[8];//订单号 String name;// = new String[13];//姓名 String phone;//= new String[6]; String idCard;//= new String[18]; @Override public byte[] toByte() { byte[] data = new byte[65]; data[0] = CRC8.hexStrToBinaryStr(control)[0]; byte[] initCodeBytes = CRC8.hexStrToBinaryStr(initCode); ArraysUtil.copyof(data, initCodeBytes, 1); byte[] machineCodeByte = CRC8.hexStrToBinaryStr(machineCode); ArraysUtil.copyof(data, machineCodeByte, 17); ArraysUtil.copyof(data, CRC8.hexStrToBinaryStr(AFN)[0], 20); byte[] orderIdByte = BcdUtil.strToBcd(this.orderId); ArraysUtil.copyof(data, orderIdByte, 21); byte[] myNameByte = new byte[12]; byte[] nameByte = CRC8.hexStrToBinaryStr(this.name); if (nameByte.length != 12) { ArraysUtil.copyof(myNameByte, nameByte, 0); } else { myNameByte = nameByte; } ArraysUtil.copyof(data, myNameByte, 29); byte[] phoneByte = BcdUtil.strToBcd(this.phone); ArraysUtil.copyof(data, phoneByte, 41); byte[] idCardByte = CRC8.hexStrToBinaryStr(this.idCard); ArraysUtil.copyof(data, idCardByte, 47); return data; } @Override public String toString() { return control + initCode + machineCode + AFN + orderId + name + phone + idCard; } public String getControl() { return control; } public void setControl(String control) { this.control = control; } public String getInitCode() { return initCode; } public void setInitCode(String initCode) { this.initCode = initCode; } public String getMachineCode() { return machineCode; } public void setMachineCode(String machineCode) { this.machineCode = machineCode; } public String getAFN() { return AFN; } public void setAFN(String AFN) { this.AFN = AFN; } public String getOrderId() { return orderId; } public void setOrderId(String orderId) { this.orderId = orderId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getIdCard() { return idCard; } public void setIdCard(String idCard) { this.idCard = idCard; } }