简体   繁体   English

j8583库 - 如何将值转换为十六进制

[英]j8583 library - how to convert value into hex

I am using j8583 library to build iso8583 message. 我正在使用j8583库来构建iso8583消息。 I want to set DE96 element value as hexadecimals of binary data. 我想将DE96元素值设置为二进制数据的十六进制。 As per my understanding, the value should be converted to binary and then to hexadecimal. 根据我的理解,该值应转换为二进制,然后转换为十六进制。 Much like the BitMap value. 很像BitMap值。 I am not finding any way on achieving this using j8583 API. 我没有找到使用j8583 API实现这一目标的任何方法。 I have tried ISOType.BINARY type but that does not give the required value. 我尝试过ISOType.BINARY类型,但是没有提供所需的值。

Please see the following code 请参阅以下代码

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();
    }
}

} }

The above code prints the following iso message 上面的代码打印以下iso消息

08008200000000000800040000010000000002190926080000000000000000000123456000000

Please see the last 12 bytes, produced by msg.setValue(96, "123456", IsoType.BINARY, 6); 请查看msg.setValue(96, "123456", IsoType.BINARY, 6);生成的最后12个字节msg.setValue(96, "123456", IsoType.BINARY, 6); , instead of above message I want to build the following message ,而不是上面的消息,我想构建以下消息

08008200000000000800040000010000000002190926080000000000000000000313233343536

The last 6 bytes are hex encoded value. 最后6个字节是十六进制编码值。

The ISO.BINAY also appending additional '0' ie with msg.setValue(96, "123456", IsoType.BINARY, 6); ISO.BINAY还附加了额外的'0',即msg.setValue(96, "123456", IsoType.BINARY, 6); , it produces 123456000000 instead of 123456 ,它产生123456000000而不是123456

I am wondering if anyone has done it using this API. 我想知道是否有人使用此API完成了它。 Otherwise I have to add some sort of wrapper on it to add this functionality. 否则我必须在其上添加某种包装来添加此功能。

Following is the xml configuration 以下是xml配置

<template type="0800">
<field num="53" type="NUMERIC" length="16">00</field>
<field num="70" type="NUMERIC" length="3">000</field>
</template>

I am quite new to library. 我对图书馆很新。 Can anyone please help me understand. 任何人都可以帮助我理解。

Thanks 谢谢

对于IsoType.BINARY,提供的值应为byte [],然后在写入操作期间将该字节数组转换为十六进制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM