//加密body字符串
DESPlus des = new DESPlus("tanglu");//密钥
base64=Base64.encode(des.encrypt(body.getBytes()));
md5=MD5Util.getMD5String(base64);//只做校验用
DESPlus des = new DESPlus("tanglu");//密钥
base64=Base64.encode(des.encrypt(body.getBytes()));
md5=MD5Util.getMD5String(base64);//只做校验用
/**
* 组装发送的数据
* @param command:命令码
* @param encryptionType:加密格式,0:不加密,1:DES+base64
* @param body:xml格式数据体
* @return
*/
public static String toMessage(String command,String encryptionType,String body){
String md5="";
String base64="";
StringBuffer xml=new StringBuffer();
xml.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
xml.append("<message>");
xml.append("<head>");
xml.append("<version>"+Constants.VERSION+"</version>");//协议版本
xml.append("<command>"+command+"</command>");//命令码
xml.append("<clientId>"+Constants.CLIENT_ID+"</clientId>");//LBC编号
xml.append("<messageId>"+DateUtil.getCurrentDate("yyyyMMddHHmmssSSS")+"</messageId>");//消息流水号(不可重复)
if("0".equals(encryptionType)){//不加密
xml.append("<encryptionType>0</encryptionType>");//加密格式0不加密,1DES base64
byte[] b=null;
try {
b=body.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
md5=MD5Util.getMD5String(b);
}else{
xml.append("<encryptionType>1</encryptionType>");//加密格式0不加密,1DES base64
try {
DESPlus des = new DESPlus("tanglu");
base64=Base64.encode(des.encrypt(body.getBytes()));
md5=MD5Util.getMD5String(base64);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
xml.append("<md>"+md5+"</md>");//校验码
xml.append("</head>");
xml.append("<body>");
if("0".equals(encryptionType)){//不加密
xml.append(body);
}else{
xml.append(base64);
}
xml.append("</body>");
xml.append("</message>");
return xml.toString();
}