Java tutorial
package cmcc.gz.adc.message; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import cmcc.gz.adc.service.Constants; import cmcc.gz.adc.util.SecurityTool; public class CorpBindRsp { private MsgHeader header; private String resultcode; private String resultmsg; private String url; public CorpBindRsp(MsgHeader header, int resultcode) { this.header = header; /** * resultcode ? 0:?; 1:??; 401:??; 402:?; 403:License?; 404:? */ switch (resultcode) { case Constants.HEADER_SERVICEID_ISNULL: this.resultcode = "1"; this.resultmsg = "SERVICEID?"; break; case Constants.CORP_ACCOUNT_ISNULL: this.resultcode = "1"; this.resultmsg = "??CORPACCOUNT?"; break; case Constants.CORP_NAME_ISNULL: this.resultcode = "1"; this.resultmsg = "???CORPNAME?"; break; case Constants.CORP_POINT_ISNULL: this.resultcode = "401"; this.resultmsg = "?POINTLIST"; break; case Constants.CORP_OPTYPE_ISNULL: this.resultcode = "1"; this.resultmsg = "?OPTYPE?"; break; case Constants.CORP_OPTYPE_FAIL: this.resultcode = "1"; this.resultmsg = "?OPTYPE"; break; case Constants.CORP_ORDER_SUCCESS: this.resultcode = "0"; this.resultmsg = "EC??"; break; case Constants.CORP_ORDER_FAIL: this.resultcode = "402"; this.resultmsg = "EC?"; break; case Constants.CORP_ORDER_NOTFOUND: this.resultcode = "402"; this.resultmsg = "SI?EC"; break; case Constants.CORP_PARAM_FAIL: this.resultcode = String.valueOf(Constants.CORP_PARAM_FAIL); this.resultmsg = "EC??"; break; case Constants.CORP_ORDER_EXISTS: this.resultcode = "402"; this.resultmsg = "SIEC???"; break; case Constants.CORP_STATUS_CHANGE_SUCCESS: this.resultcode = "0"; this.resultmsg = "EC???"; break; case Constants.CORP_INFO_CHANGE_SUCCESS: this.resultcode = "0"; this.resultmsg = "EC????"; break; case Constants.CORP_UNORDER_SUCCESS: this.resultcode = "0"; this.resultmsg = "EC??"; break; case Constants.CORP_STATUS_UNORDER: this.resultcode = "1"; this.resultmsg = "EC???"; break; default: this.resultcode = "404"; this.resultmsg = "?"; break; } this.url = "http://10086.cn"; } public String toString() { try { Document document = DocumentHelper.createDocument(); Element root = document.addElement("CorpBindRsp"); Element head = root.addElement("HEAD"); head.addElement("CODE").addText(header.getCode()); head.addElement("SID").addText(header.getSid()); head.addElement("TIMESTAMP").addText(header.getTimestamp()); head.addElement("SERVICEID").addText(header.getServiceId()); root.addElement("BODY").setText(encodeBody()); return root.asXML(); } catch (Exception ex) { ex.printStackTrace(); } return null; } private String encodeBody() { Document document = DocumentHelper.createDocument(); try { Element root = document.addElement("BODY"); root.addElement("RESULTCODE").addText(resultcode); root.addElement("RESULTMSG").addText(resultmsg); root.addElement("URL").addText(url); return SecurityTool.encrypt(root.asXML()); } catch (Exception ex) { ex.printStackTrace(); } return null; } }