有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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, "");
    }
}

现在发布了一个例外:

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)

告诉我为什么我不能分发此行-303831308220000000200000000000000111131253201234563030301


共 (1) 个答案

  1. # 1 楼答案

    这似乎是一个奇怪的打包程序,它使用BCD对大多数字段进行编码,而使用ASCII对MTI进行编码。我建议您基于iso87binary创建自己的field packager。xml。如果要将字段0定义从IFB_NUMERIC更改为IFA_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>
    

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

    ISOPackager p = new GenericPackager("yourpackager.xml");