XML报文解析
/** * XML报文解析 * @param docStr */ private Map<String, Object> analysisXmlStr(String xmlStr) { try { Map<String, Object> analysisResultMap = new HashMap<>(); if (StringUtils.isEmpty(xmlStr)) { return analysisResultMap; } org.dom4j.Document payResponseDoc = DocumentHelper.parseText(xmlStr); org.dom4j.Element rootElement = payResponseDoc.getRootElement(); // Header Node headerNode = rootElement.selectSingleNode("Header"); String status = headerNode.selectSingleNode("Status").getStringValue(); // Response Node responseNode = rootElement.selectSingleNode("Response"); if (null == responseNode) { return analysisResultMap; } Node orderStatusNode = responseNode.selectSingleNode("OrderStatus"); if (null == orderStatusNode) { return analysisResultMap; } String orderStatus = orderStatusNode.getStringValue(); String platformCode = responseNode.selectSingleNode("PlatformCode").getStringValue(); String payAmount = responseNode.selectSingleNode("PayAmount").getStringValue(); String realPayAmount = responseNode.selectSingleNode("RealPayAmount").getStringValue(); String orderId = responseNode.selectSingleNode("OrderId").getStringValue(); // Response - TradeList Node tradeListNode = responseNode.selectSingleNode("TradeList"); String batchNo = tradeListNode.selectSingleNode("TradeIfo").selectSingleNode("BatchDetailNo").getStringValue(); // 封装 analysisResultMap.put("status", status); analysisResultMap.put("orderStatus", orderStatus); analysisResultMap.put("platformCode", platformCode); analysisResultMap.put("payAmount", payAmount); analysisResultMap.put("realPayAmount", realPayAmount); analysisResultMap.put("orderId", orderId); analysisResultMap.put("batchNo", batchNo); return analysisResultMap; } catch (DocumentException e) { logger.error("报文解析异常!", e); } return null; }