#651 WxMpXmlMessage增加allFieldsMap属性, 用于存放所有xml属性和值。

This commit is contained in:
Binary Wang
2018-11-04 17:03:20 +08:00
parent 4a62a3f70e
commit 84aa3cf1c0
2 changed files with 97 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.bean.message;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Map;
import org.apache.commons.io.IOUtils;
@@ -11,6 +12,7 @@ import com.thoughtworks.xstream.annotations.XStreamConverter;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.XmlUtils;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.util.crypto.WxMpCryptUtil;
@@ -33,6 +35,11 @@ import me.chanjar.weixin.mp.util.xml.XStreamTransformer;
public class WxMpXmlMessage implements Serializable {
private static final long serialVersionUID = -3586245291677274914L;
/**
* 使用dom4j解析的存放所有xml属性和值的map.
*/
private Map<String, Object> allFieldsMap;
///////////////////////
// 以下都是微信推送过来的消息的xml的element所对应的属性
///////////////////////
@@ -562,7 +569,9 @@ public class WxMpXmlMessage implements Serializable {
public static WxMpXmlMessage fromXml(String xml) {
//修改微信变态的消息内容格式,方便解析
xml = xml.replace("</PicList><PicList>", "");
return XStreamTransformer.fromXml(WxMpXmlMessage.class, xml);
final WxMpXmlMessage xmlMessage = XStreamTransformer.fromXml(WxMpXmlMessage.class, xml);
xmlMessage.setAllFieldsMap(XmlUtils.xml2Map(xml));
return xmlMessage;
}
public static WxMpXmlMessage fromXml(InputStream is) {