ISO8583报文格式的生产java代码
package iso;
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
import objects.ISO8583Bean;
public class ISO8583 { @SuppressWarnings("unchecked") public static void main(String[] args) throws IOException { // 报文包含哪几个域 // 卡号第2域 LLVAR BCD 5309987876545342 // 交易类型 第3域 长度6 BCD 900000 // 金额 第4域 长度12 BCD 100分 // 时间 第7域 长度8 BCD 20030802 // 2磁道信息 第35域 LLVAR ASCII 123456 // 3磁道信息 第36域 LLLVAR BCD 123456001 // 商户号 第41域 LLVAR ASCII 98765432
/* * //String str1 = * "720000003080000016530998787654534290000000000000010020030802063132333435360009123456001083938373635343332" * ; int length = str.length(); String s1 = str.substring(0, 2); String * s2 = str.substring(2, 4); int x1 = Integer.parseInt(s2); * System.out.println(x1); System.out.println(s1); * System.out.println(s2); System.out.println(length); */ Map hexmap = new HashMap(); hexmap.put("0000", "0"); hexmap.put("0001", "1"); hexmap.put("0010", "2"); hexmap.put("0011", "3"); hexmap.put("0100", "4"); hexmap.put("0101", "5"); hexmap.put("0110", "6"); hexmap.put("0111", "7"); hexmap.put("1000", "8"); hexmap.put("1001", "9"); hexmap.put("1010", "A"); hexmap.put("1011", "B"); hexmap.put("1100", "C"); hexmap.put("1101", "D"); hexmap.put("1110", "E"); hexmap.put("1111", "F"); // 报文包里的内容7200000030800000165309987876545342900000000000000100 // 20030802063132333435360009123456001083938373635343332 File file = new File("ISO8583.txt"); List list = new ArrayList(); StringBuffer sb = new StringBuffer(); StringBuffer sb2 = new StringBuffer(); sb.append("0000000000000000000000000000000000000000000000000000000000000000"); String str = ""; BufferedReader br = new BufferedReader(new FileReader(file)); while ((str = br.readLine()) != null) { System.out.println(str); ISO8583Bean iso = new ISO8583Bean(); String[] s = str.split(","); iso.setIndex(Integer.parseInt(s[0])); iso.setLength(s[1]); iso.setType(s[2]); iso.setContent(s[3]); list.add(iso); } for (int i = 0; i < list.size(); i++) { ISO8583Bean iso = (ISO8583Bean) list.get(i); sb.setCharAt(iso.getIndex() - 1, '1'); /* sb.replace(iso.getIndex() - 1, iso.getIndex(), "1"); */ System.out.println(sb.toString()); } for (int i = 0; i < sb.toString().length() / 4; i++) { String str1 = sb.toString().substring(4 * i, 4 * (i + 1)); sb2.append((String) hexmap.get(str1)); System.out.println(sb2); } for (int i = 0; i < list.size(); i++) { ISO8583Bean iso = (ISO8583Bean) list.get(i); if (iso.getLength().equals("LLVAR")) { System.out.println(list.get(0)); if (iso.getContent().length() < 10) { sb2.append("0").append(iso.getContent().length()); } else if (iso.getContent().length() >10) { sb.append(iso.getContent().length()).append( iso.getContent()); } } else if (iso.getLength().equals("LLLVAR")) { if (iso.getContent().length() < 10) { sb2.append("000").append(iso.getContent().length()).append( iso.getContent()); } else if (Integer.parseInt(iso.getLength()) < 100 && Integer.parseInt(iso.getLength()) > 10) { sb2.append("00").append(iso.getLength()).append( iso.getContent()); } } /* * if (iso.getIndex() == 4) { * * } if (iso.getType().equals("ASCII")) { String s = * iso.getContent(); int sum = 0; for (int j = s.length(); j > 0; * j--) { sum = sum + 16 * j; } } */ } System.out.println("解析出来的报文为:" + sb2.toString()); } }

浙公网安备 33010602011771号