[英]j8583 library - how to convert value into hex
我正在使用j8583库来构建iso8583消息。 我想将DE96元素值设置为二进制数据的十六进制。 根据我的理解,该值应转换为二进制,然后转换为十六进制。 很像BitMap值。 我没有找到使用j8583 API实现这一目标的任何方法。 我尝试过ISOType.BINARY类型,但是没有提供所需的值。
请参阅以下代码
package j8583.example;
import java.io.IOException;
import java.util.Date;
import com.solab.iso8583.IsoMessage;
import com.solab.iso8583.IsoType;
import com.solab.iso8583.MessageFactory;
import com.solab.iso8583.parse.ConfigParser;
import com.solab.iso8583.util.HexCodec;
public class MsgSender0800 {
public static void main(String[] args) {
try {
MessageFactory mfact = ConfigParser.createFromClasspathConfig("j8583/example/config.xml");
IsoMessage msg = mfact.newMessage(0x800);
msg.setValue(7, new Date(), IsoType.DATE10, 10);
msg.setValue(96, "123456", IsoType.BINARY, 6);
/* I want DE 96 value similar to the output of this code
String test = "123456";
String encoded = HexCodec.hexEncode(test.getBytes(), 0, test.length());
System.out.println(encoded);
System.out.println(new String(HexCodec.hexDecode(encoded)));
*/
String strMsg = new String(msg.writeData());
System.out.println(strMsg);
} catch (IOException e) {
e.printStackTrace();
}
}
}
上面的代码打印以下iso消息
08008200000000000800040000010000000002190926080000000000000000000123456000000
请查看msg.setValue(96, "123456", IsoType.BINARY, 6);
生成的最后12个字节msg.setValue(96, "123456", IsoType.BINARY, 6);
,而不是上面的消息,我想构建以下消息
08008200000000000800040000010000000002190926080000000000000000000313233343536
最后6个字节是十六进制编码值。
ISO.BINAY还附加了额外的'0',即msg.setValue(96, "123456", IsoType.BINARY, 6);
,它产生123456000000
而不是123456
我想知道是否有人使用此API完成了它。 否则我必须在其上添加某种包装来添加此功能。
以下是xml配置
<template type="0800">
<field num="53" type="NUMERIC" length="16">00</field>
<field num="70" type="NUMERIC" length="3">000</field>
</template>
我对图书馆很新。 任何人都可以帮助我理解。
谢谢
对于IsoType.BINARY,提供的值应为byte [],然后在写入操作期间将该字节数组转换为十六进制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.