public class ISO8583Util {
/**
* 8583报文拼装
* 1_HEAD(不传)
* 4_BITMAP(计算得到)
* @param treeMap
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static TreeMap encISO8583(TreeMap dataMap) {
try {
String bitMap = getBitmap();
Map tlMap = valueTypeAndLen();
if(dataMap != null) {
Iterator it = dataMap.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
String value = (String) dataMap.get(key);
String yuNoStr = key.substring(2);
int yuNo = Integer.parseInt(yuNoStr);
bitMap = changeBitmapFlag(yuNo, bitMap);
String typeLenVal = (String) tlMap.get(key);
String[] typeLen = typeLenVal.split(",");
int mLen = Integer.valueOf(typeLen[2]);
String type = typeLen[1];
String mode = typeLen[0];
//System.out.println(key + ":域类型:" +mode + ";格式"+ type + ";长度" + mLen);
//System.out.println(key + ":域内容:" + value);
if(value != null) {
if(mode.indexOf("VAR") > 0) {//变长判断
if(type.equals("ASCII")) {//数据格式
byte[] bytes = value.getBytes("utf-8");
String vLen = bytes.length + "";
String mHea = refFixZreo(mLen, vLen);
if(mLen % 2 > 0) {
if(mHea.equals("016")){
mHea = "00" + mHea;
}else{
mHea = "0" + mHea;
}
}
if(mHea != null) {
String yuValue = mHea + CrbUtil.ba2HexString(bytes);