简体   繁体   English

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

[英]how to prepend ISO8583 message length to an ISO8583 message using j8583 library

I am trying to send an ISO8583 message to a server using j8583.我正在尝试使用 j8583 向服务器发送 ISO8583 消息。 I am setting the header in the config.xml file and setting the fields from the same.我在 config.xml 文件中设置标题并设置相同的字段。 Now the server configuration requires that 2byte length(Length in hex sent as bytes) should be sent before the incoming ISO8583 message.现在服务器配置要求在传入 ISO8583 消息之前发送 2 字节长度(以字节形式发送的十六进制长度)。 So my question is :所以我的问题是:

1)How to calculate the length of the message ie the byte representation of the ISO message and how to calculate the length of the byte representation. 1)如何计算报文的长度即ISO报文的字节表示以及如何计算字节表示的长度。

2)How to send the length of the message to the server before the ISO8583 message ie prepended in front of the header. 2) 如何在 ISO8583 消息之前将消息的长度发送到服务器,即在标头前面。

Here are some of the code excerpts以下是部分代码摘录

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);

and below is the config下面是配置

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

the below is the string representation of the ISO message (the output) :下面是 ISO 消息(输出)的字符串表示:

    Connecting to server
ISO026000073
Sending request 008386
ISO0260000730200B23A800128A180180000000014000000650000000000002050021112445800838612445802110211021103456174591700012340000=0000008984011234567890      SOLABTEST             TEST-3       DF MX010abcdefghij484012B456PRO1+000013        1234P0399904ABCD

Also how can I see what raw message is being sent from my terminal to the server?另外,我如何查看从我的终端发送到服务器的原始消息?

Well you already use IsoMessage.write(outputStream, 2) to write a message to a stream, with its length prepended as a 2-byte header.好吧,您已经使用IsoMessage.write(outputStream, 2)将消息写入流,其长度作为 2 字节标头。 In other words, that method does exactly what you're asking for, but you're already using it, so I'm not sure what the problem is;换句话说,该方法完全符合您的要求,但您已经在使用它,所以我不确定问题是什么; is the message not property received on the other side?对方收到的消息不是财产吗? Perhaps you should wrap the socket's outputStream in a BufferedOutputStream ;也许您应该将套接字的 outputStream 包装在BufferedOutputStream IsoMessage.write will flush the stream after writing the message. IsoMessage.write将在写入消息后刷新流。

IsoMessage.writeData() gives you the byte array without any length headers. IsoMessage.writeData()为您提供没有任何长度标头的字节数组。

/* Handel a hexidecimal header in j8583 */
String header = "6000888000"; 
long it = Long.parseLong(header.trim(), 16); 
BigInteger bigInt = BigInteger.valueOf(it);
Log.i(TAG, "value of heder " + bigInt.toString());
byte[] bytearray = (bigInt.toByteArray());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM