- ISOMsg m = new ISOMsg();
- m.setDirection(2);
- m.set(0,"0800");
- m.set(3, "000000");
- m.set(7,ISODate.getDateTime(new Date()));
- m.set(11,"流水号(如:123456)");
- m.set(22,"010");
- m.set(41,"终端号");
- m.set(42,"商户号");
- ISOPackager p = new GenericPackager("src/jpos/test/iso8583.xml");
- m.setPackager(p);
-
- byte[] b = m.pack();
-
- Logger logger = new Logger();
- logger.addListener (new SimpleLogListener (System.out));
- JPosTest jt = new JPosTest(logger,"AAAA");
- LogEvent evt = new LogEvent (jt, "Test");
- evt.addMessage(ISOUtil.hexString(b));
- evt.addMessage(m);
-
- ISOChannel channel = new PostChannel("IP地址", 端口, p);
- channel.connect();
- channel.send(m);
- ISOMsg r = channel.receive();
- evt.addMessage(r);
- Logger.log (evt);
- channel.disconnect();
- 如果运行中遇到异常,比如EOFException,则说明,传入的数据格式有误,请检查,并保证与你相应的服务器指定格式保持一致。。此例仅供参考……
API的参考网址:http://jpos.org/doc/javadoc/index.html