如何解析十六进制iso8583行?

Ale*_*est 4 java iso8583

这是代码:

import org.jpos.iso.packager.ISO87BPackager;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;

public class ParseISOMsg {
    public static void main(String[] args) throws ISOException {
        String hexmsg = "3038313082200000020000000400000000000000111312532012345630300301";
        // convert hex string to byte array
        byte[] bmsg =ISOUtil.hex2byte(hexmsg);
        ISOMsg m = new ISOMsg();
        // set packager, change ISO87BPackager for the matching one.
        m.setPackager(new ISO87BPackager());
        //unpack the message using the packager
        m.unpack(bmsg);
        //dump the message to standar output
        m.dump(System.out, "");
    }
}
Run Code Online (Sandbox Code Playgroud)

现在发出异常:

Exception in thread "main" org.jpos.iso.ISOException: org.jpos.iso.IFB_NUMERIC: Problem unpacking field 23 (java.lang.ArrayIndexOutOfBoundsException: 32) unpacking field=23, consumed=31
    at org.jpos.iso.ISOBasePackager.unpack(ISOBasePackager.java:340)
    at org.jpos.iso.ISOMsg.unpack(ISOMsg.java:468)
    at ParseISOMsg.main(ParseISOMsg.java:17)
Run Code Online (Sandbox Code Playgroud)

告诉我为什么我不能分发这条线 - 3038313082200000020000000400000000000000111312532012345630300301 ?

小智 5

这似乎是一个奇怪的打包程序,它使用 BCD 对大多数字段进行编码,但使用 ASCII 对 MTI 进行编码。我建议您基于 iso87binary.xml 创建自己的字段打包程序。您想将字段 0 定义从 更改IFB_NUMERICIFA_NUMERIC,然后您会得到如下内容:

<isomsg>
  <field id="0" value="0810"/>
  <field id="7" value="1113125320"/>
  <field id="11" value="123456"/>
  <field id="39" value="00"/>
  <field id="70" value="301"/>
</isomsg>
Run Code Online (Sandbox Code Playgroud)

为了创建您的打包程序,您需要使用如下代码:

ISOPackager p = new GenericPackager("yourpackager.xml");
Run Code Online (Sandbox Code Playgroud)