我正在尝试使用 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);
下面是配置
<?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>
下面是 ISO 消息的字符串表示(输出):
Connecting to server
ISO026000073
Sending request 008386
ISO0260000730200B23A800128A180180000000014000000650000000000002050021112445800838612445802110211021103456174591700012340000=0000008984011234567890 SOLABTEST TEST-3 DF MX010abcdefghij484012B456PRO1+000013 1234P0399904ABCD
另外,我如何查看从终端发送到服务器的原始消息?