如何使用 j8583 库将 ISO8583 消息长度添加到 ISO8583 消息中

AJA*_*JAY 4 java iso8583 j8583

我正在尝试使用 j8583 向服务器发送 ISO8583 消息。我在 config.xml 文件中设置标头并设置其中的字段。现在,服务器配置要求在传入 ISO8583 消息之前发送 2 字节长度(以字节形式发送的十六进制长度)。所以我的问题是:

1)如何计算消息的长度,即ISO消息的字节表示以及如何计算字节表示的长度。

2)如何在ISO8583消息之前将消息的长度发送到服务器,即添加在标头前面。

以下是一些代码摘录

Client client = new Client(sock);
    Thread reader = new Thread(client, "j8583-client");
    reader.start();

        IsoMessage req = mfact.newMessage(0x200);
        req.setValue(4, amounts[rng.nextInt(amounts.length)],
                IsoType.AMOUNT, 0);
        req.setValue(12, req.getObjectValue(7), IsoType.TIME, 0);
        req.setValue(13, req.getObjectValue(7), IsoType.DATE4, 0);
        req.setValue(15, req.getObjectValue(7), IsoType.DATE4, 0);
        req.setValue(17, req.getObjectValue(7), IsoType.DATE4, 0);
        req.setValue(37, System.currentTimeMillis() % 1000000,
                IsoType.NUMERIC, 12);
        req.setValue(41, data[rng.nextInt(data.length)], IsoType.ALPHA, 16);
        req.setValue(48, data[rng.nextInt(data.length)], IsoType.LLLVAR, 0);
        pending.put(req.getField(11).toString(), req);
        System.err.println(String.format("Sending request %s", req.getField(11)));
                    System.out.println(req.getIsoHeader());
                    System.out.println(req.debugString());

        req.write(sock.getOutputStream(), 2);
Run Code Online (Sandbox Code Playgroud)

下面是配置

    <?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>

<!-- These are the ISO headers to be prepended to the message types specified -->
<header type="0200">ISO026000073</header>
<header type="0210">ISO015000055</header>
<header type="0400">ISO015000050</header>
<header type="0410">ISO015000055</header>
<header type="0800">ISO015000015</header>
<header type="0810">ISO015000015</header>

<!-- The client example uses this to create requests -->
<template type="0200">
    <field num="3" type="NUMERIC" length="6">650000</field>
    <field num="32" type="LLVAR">456</field>
    <field num="35" type="LLVAR">4591700012340000=</field>
    <field num="43" type="ALPHA" length="40">SOLABTEST             TEST-3       DF MX</field>
    <field num="49" type="ALPHA" length="3">484</field>
    <field num="60" type="LLLVAR">B456PRO1+000</field>
    <field num="61" type="LLLVAR">        1234P</field>
    <field num="100" type="LLVAR">999</field>
    <field num="102" type="LLVAR">ABCD</field>
</template>
Run Code Online (Sandbox Code Playgroud)

下面是 ISO 消息(输出)的字符串表示形式:

    Connecting to server
ISO026000073
Sending request 008386
ISO0260000730200B23A800128A180180000000014000000650000000000002050021112445800838612445802110211021103456174591700012340000=0000008984011234567890      SOLABTEST             TEST-3       DF MX010abcdefghij484012B456PRO1+000013        1234P0399904ABCD
Run Code Online (Sandbox Code Playgroud)

另外,我如何查看从我的终端发送到服务器的原始消息?

Cho*_*hos 6

好吧,您已经使用过IsoMessage.write(outputStream, 2)将消息写入流,其长度作为 2 字节标头预先添加。换句话说,该方法完全符合您的要求,但您已经在使用它,所以我不确定问题是什么;对方收到的消息不是财产吗?也许您应该将套接字的输出流包装在BufferedOutputStream;中 IsoMessage.write写入消息后将刷新流。

IsoMessage.writeData()为您提供没有任何长度标头的字节数组。