[英]how to prepend ISO8583 message length to an ISO8583 message using j8583 library
我正在嘗試使用 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
另外,我如何查看從我的終端發送到服務器的原始消息?
好吧,您已經使用IsoMessage.write(outputStream, 2)
將消息寫入流,其長度作為 2 字節標頭。 換句話說,該方法完全符合您的要求,但您已經在使用它,所以我不確定問題是什么; 對方收到的消息不是財產嗎? 也許您應該將套接字的 outputStream 包裝在BufferedOutputStream
; IsoMessage.write
將在寫入消息后刷新流。
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.