packagecom.landimc.wxpay.utils;importcom.github.wxpay.sdk.WXPayConstants;importcom.github.wxpay.sdk.WXPayConstants.SignType;importcom.landimc.compoent.pay.WxPayCompoent;importcom.landimc.tools.MD5;importcom.landimc.tools.SysConfig;importcom.landimc.wxpay.model.WxPayConfig;importorg.apache.commons.codec.digest.DigestUtils;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.w3c.dom.Node;importorg.w3c.dom.NodeList;importjavax.annotation.Resource;importjavax.crypto.Mac;importjavax.crypto.spec.SecretKeySpec;importjavax.xml.parsers.DocumentBuilder;importjavax.xml.transform.OutputKeys;importjavax.xml.transform.Transformer;importjavax.xml.transform.TransformerFactory;importjavax.xml.transform.dom.DOMSource;importjavax.xml.transform.stream.StreamResult;importjava.io.ByteArrayInputStream;importjava.io.InputStream;importjava.io.StringWriter;importjava.io.UnsupportedEncodingException;importjava.security.MessageDigest;importjava.security.SecureRandom;import java.util.*;public classWXPayUtil {private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";private static final Random RANDOM = newSecureRandom();
@ResourceprivateWxPayCompoent wxPayCompoent;/*** XML格式字符串转换为Map
*
*@paramstrXML XML字符串
*@returnXML数据转换后的Map
*@throwsException*/
public static Map xmlToMap(String strXML) throwsException {try{
Map data = new HashMap();
DocumentBuilder documentBuilder=WXPayXmlUtil.newDocumentBuilder();
InputStream stream= new ByteArrayInputStream(strXML.getBytes("UTF-8"));
org.w3c.dom.Document doc=documentBuilder.parse(stream);
doc.getDocumentElement().normalize();
NodeList nodeList=doc.getDocumentElement().getChildNodes();for (int idx = 0; idx < nodeList.getLength(); ++idx) {
Node node=nodeList.item(idx);if (node.getNodeType() ==Node.ELEMENT_NODE) {
org.w3c.dom.Element element=(org.w3c.dom.Element) node;
data.put(element.getNodeName(), element.getTextContent());
}
}t