我正在尝试解析ISO 8583消息并获取单个数据元素。
下面我到目前为止尝试过的代码

ISOResponse.java

public class ISOResponse {
private static final String TAG = "ISOResponse";
private static final String ISOResponseMessage = "60010203040210303800000E8002000000000000000031000046741306511212383334363133303034363734313330363534303036323730353532340012910A59218CDAFBBCD2520014";

public void parseISO8583(final Context context) throws ParseException, IOException {

    MessageFactory<IsoMessage> messageFactory = new MessageFactory<IsoMessage>();

    if (1 == 0) {
        ConfigParser.configureFromDefault(messageFactory);
    } else {

        PrintLog.log(TAG, "Messagefactory is done");

        InputStream inputData = context.getResources().openRawResource(R.raw.j8583_config);

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputData));

        ConfigParser.configureFromReader(messageFactory, bufferedReader);

    }

    messageFactory.setIgnoreLastMissingField(true);
    IsoMessage isoMessage = messageFactory.parseMessage(ISOResponseMessage.getBytes(),10);
    if (isoMessage != null) {
        PrintLog.log(TAG, "Message type: %04x%n" + isoMessage.getType());
        PrintLog.log(TAG, "FIELD TYPE VALUE");
        for (int i = 2; i <= 64; i++) {
            IsoValue<?> f = isoMessage.getField(i);
            if (f != null) {
                PrintLog.log(TAG, "%5d %-6s [" + i + f.getType());
                PrintLog.log(TAG, f.toString());
                PrintLog.log(TAG, "" + ']');
            }
        }
    }
}
}


j8583_config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE j8583-config PUBLIC "-//J8583//DTD CONFIG 1.0//EN"
"http://j8583.sourceforge.net/j8583.dtd">
<j8583-config>
<!-- This is a test config file -->

<!-- These are the ISO headers to be prepended to the message types specified -->
<header type="0800"/>

<template type="0280">
    <field num="3" type="NUMERIC" length="2">99</field>
</template>

<!-- The server example uses this to read the requests -->
<parse type="0200">
    <field num="3" type="NUMERIC" length="6" />
    <field num="4" type="AMOUNT" />
    <field num="7" type="DATE10" />
    <field num="11" type="NUMERIC" length="6" />
    <field num="12" type="TIME" />
    <field num="13" type="DATE4" />
    <field num="15" type="DATE4" />
    <field num="17" type="DATE_EXP" />
    <field num="32" type="LLVAR" />
    <field num="35" type="LLVAR" />
    <field num="37" type="NUMERIC" length="12" />
    <field num="41" type="ALPHA" length="16" />
    <field num="43" type="ALPHA" length="40" />
    <field num="48" type="LLLVAR" />
    <field num="49" type="ALPHA" length="3" />
    <field num="60" type="LLLVAR" />
    <field num="61" type="LLLVAR" />
    <field num="100" type="LLVAR" />
    <field num="102" type="LLVAR" />
</parse>


<!-- The client example uses this to read the responses -->
<parse type="0210">
    <field num="3" type="NUMERIC" length="6" />
    <field num="4" type="AMOUNT" length="12" />
    <field num="11" type="NUMERIC" length="6" />
    <field num="12" type="TIME" length="6" />
    <field num="13" type="DATE4" length="4" />
    <field num="37" type="NUMERIC" length="12" />
    <field num="38" type="NUMERIC" length="6" />
    <field num="39" type="NUMERIC" length="2" />
    <field num="41" type="ALPHA" length="8" />
    <field num="55" type="LLLVAR" length="255" />
</parse>

<!-- this is for binary tests (message encoding AND fields) -->
<parse type="0600">
    <field num="4" type="AMOUNT" />
    <field num="7" type="DATE10" />
    <field num="11" type="NUMERIC" length="6" />
    <field num="41" type="BINARY" length="8" />
    <field num="42" type="BINARY" length="4" />
    <field num="43" type="ALPHA" length="40" />
    <field num="62" type="LLBIN" />
    <field num="63" type="LLBIN" />
    <field num="64" type="LLLBIN" />
    <field num="65" type="LLLBIN" />
    <field num="102" type="LLLVAR" />
</parse>

<parse type="0800">
    <field num="3" type="ALPHA" length="6"/>
    <field num="12" type="DATE4" length="14"/>
    <field num="17" type="DATE4" length="8"/>
    <field num="11" type="NUMERIC" length="6"/>
    <field num="41" type="LLVAR" length="16"/>
</parse>

<parse type="0810" extends="0800">
    <field num="17" type="exclude"/>
    <field num="39" type="ALPHA" length="2"/>
</parse>

<parse type="0201">
    <field num="3" type="NUMERIC" length="19" />
</parse>
<parse type="0202">
    <field num="3" type="NUMERIC" length="22" />
</parse>
<parse type="0280">
    <field num="3" type="NUMERIC" length="2" />
</parse>




在此之后,我的代码将抛出


  无效的ISO 8583标头


例外。我尝试删除标头数据并使isoMessage中的标头长度为0,但仍给出相同的异常。

谁能帮我找到代码错误。
提前致谢。

最佳答案

我尝试解析您的消息,并得到以下信息:

<parse header="6001020304" type="0210" bitmap="303800000E800200">
    <field num="3" type="NUMERIC"  length="6"  value="000000" />
    <field num="4" type="AMOUNT"   length="12" value="000000003100" />
    <field num="11" type="NUMERIC" length="6"  value="004674" />
    <field num="12" type="TIME"    length="6"  value="130651" />
    <field num="13" type="DATE4"   length="4"  value="121238" />
    <field num="37" type="NUMERIC" length="12" value="346130046741" />
    <field num="38" type="NUMERIC" length="6"  value="306540" />
    <field num="39" type="NUMERIC" length="2"  value="06" />
    <field num="41" type="ALPHA"   length="8"  value="2705524\0" />
    <field num="55" type="LLLVAR"  length="12" value="910A59218CDAFBBCD2520014" />
</parse>


看来您的邮件标题长度是14(包括MTI)(或10(不含MTI))

08-26 00:39