[英]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.