How to fix Java ISO8583 socket error: TRANSMISSION ERROR
How to fix Java ISO8583 socket error: TRANSMISSION ERROR
我正在做一个项目,这个错误一直让我很头疼。我正在使用 Java J8583 库来构建 ISO8583 消息并发送到远程服务器。服务器的响应是一个十六进制值:5452414E53414354494F4E204552524F52,转换为 ASCII 时:传输错误。
// function to construct Message
public IsoMessage createLoadRequest(String tag) {
IsoMessage nManagementMsg = messageFactory.newMessage(0x0800);
Date date = new Date();
String terminalID = new Utils().retrieveTerminalID();
nManagementMsg.setField(3, new IsoValue<Object>(IsoType.ALPHA, tag, 6));
nManagementMsg.setField(7, new IsoValue<Object>(IsoType.NUMERIC, utcTime.format(date), 10));
lastTransactionAuditCode = Utils.randomAlphaNumeric(6);
nManagementMsg.setField(11, new IsoValue<Object>(IsoType.NUMERIC, lastTransactionAuditCode, 6)); // System Trace Audit Number
nManagementMsg.setField(12, new IsoValue<>(IsoType.NUMERIC, localTime.format(date), 6));
nManagementMsg.setField(13, new IsoValue<>(IsoType.DATE_EXP, localDate.format(date), 4));
nManagementMsg.setField(41, new IsoValue<Object>(IsoType.ALPHA, terminalID, 8));
return nManagementMsg;
}
//function to make send Message to server
public boolean retrieveData() throws UnsupportedEncodingException {
IsoMessage networkManagementMsg = this.createLoadRequest("567YUY");
String strToSend = new String(networkManagementMsg.writeData());
if (!start()) {
return false;
}
try {
logger.info(strToSend);
outputStream.writeUTF(strToSend);
IsoMessage response = readMessage();
final String result = response.getAt(39).toString();
if (!result.equals("00")) {
logger.log(Level.WARNING, "Network Management Response contains a non-zero result code {0}", result);
return false;
}
// parse and get required data
String value = response.getAt(62).toString();
System.out.println(value);
return true;
} catch (Exception ex) {
logger.severe("Exception while loading terminal info");
ex.printStackTrace();
return false;
} finally {
stop();
}
}
我期待 ISOMessage 返回错误:
INFO: 08002238000000800000567YUY0515135835Q56U46135835051520390013
INFO: Received response: 5452414E53414354494F4E204552524F52
INFO: IsoMessage: null
java.io.IOException: Failed to parse iso message string:
5452414E53414354494F4E204552524F52
如果没有更大的项目上下文和要打包的每个字段的值,很难说,但您的请求看起来很奇怪。 STAN(字段 11)应该是数字,但包含 alpha。此外,您应该检查终端 ID(字段 41)的编码,因为它可能是 8 个字节,就像您构建它时一样,但在某些系统中,我看到使用十六进制编码的 16 个字节。
我正在做一个项目,这个错误一直让我很头疼。我正在使用 Java J8583 库来构建 ISO8583 消息并发送到远程服务器。服务器的响应是一个十六进制值:5452414E53414354494F4E204552524F52,转换为 ASCII 时:传输错误。
// function to construct Message
public IsoMessage createLoadRequest(String tag) {
IsoMessage nManagementMsg = messageFactory.newMessage(0x0800);
Date date = new Date();
String terminalID = new Utils().retrieveTerminalID();
nManagementMsg.setField(3, new IsoValue<Object>(IsoType.ALPHA, tag, 6));
nManagementMsg.setField(7, new IsoValue<Object>(IsoType.NUMERIC, utcTime.format(date), 10));
lastTransactionAuditCode = Utils.randomAlphaNumeric(6);
nManagementMsg.setField(11, new IsoValue<Object>(IsoType.NUMERIC, lastTransactionAuditCode, 6)); // System Trace Audit Number
nManagementMsg.setField(12, new IsoValue<>(IsoType.NUMERIC, localTime.format(date), 6));
nManagementMsg.setField(13, new IsoValue<>(IsoType.DATE_EXP, localDate.format(date), 4));
nManagementMsg.setField(41, new IsoValue<Object>(IsoType.ALPHA, terminalID, 8));
return nManagementMsg;
}
//function to make send Message to server
public boolean retrieveData() throws UnsupportedEncodingException {
IsoMessage networkManagementMsg = this.createLoadRequest("567YUY");
String strToSend = new String(networkManagementMsg.writeData());
if (!start()) {
return false;
}
try {
logger.info(strToSend);
outputStream.writeUTF(strToSend);
IsoMessage response = readMessage();
final String result = response.getAt(39).toString();
if (!result.equals("00")) {
logger.log(Level.WARNING, "Network Management Response contains a non-zero result code {0}", result);
return false;
}
// parse and get required data
String value = response.getAt(62).toString();
System.out.println(value);
return true;
} catch (Exception ex) {
logger.severe("Exception while loading terminal info");
ex.printStackTrace();
return false;
} finally {
stop();
}
}
我期待 ISOMessage 返回错误:
INFO: 08002238000000800000567YUY0515135835Q56U46135835051520390013
INFO: Received response: 5452414E53414354494F4E204552524F52
INFO: IsoMessage: null
java.io.IOException: Failed to parse iso message string:
5452414E53414354494F4E204552524F52
如果没有更大的项目上下文和要打包的每个字段的值,很难说,但您的请求看起来很奇怪。 STAN(字段 11)应该是数字,但包含 alpha。此外,您应该检查终端 ID(字段 41)的编码,因为它可能是 8 个字节,就像您构建它时一样,但在某些系统中,我看到使用十六进制编码的 16 个字节。