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;
}

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM