Skip to content

Commit 0919205

Browse files
committed
🎨 修改XML消息解析类里的agentId为字符串类型,避免为空值时导致的异常
1 parent bbb5269 commit 0919205

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
1717
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
1818
import org.apache.commons.io.IOUtils;
19+
import org.apache.commons.lang3.StringUtils;
1920

2021
import java.io.IOException;
2122
import java.io.InputStream;
@@ -51,7 +52,7 @@ public class WxCpXmlMessage implements Serializable {
5152
///////////////////////
5253

5354
@XStreamAlias("AgentID")
54-
private Integer agentId;
55+
private String agentId;
5556

5657
@XStreamAlias("ToUserName")
5758
@XStreamConverter(value = XStreamCDataConverter.class)
@@ -476,7 +477,7 @@ protected static WxCpXmlMessage fromXml(String xml) {
476477
return xmlMessage;
477478
}
478479

479-
public static WxCpXmlMessage fromXml(String xml, Integer agentId) {
480+
public static WxCpXmlMessage fromXml(String xml, String agentId) {
480481
//修改微信变态的消息内容格式,方便解析
481482
xml = xml.replace("</PicList><PicList>", "");
482483
final WxCpXmlMessage xmlMessage = fromXml(xml);
@@ -497,7 +498,7 @@ public static WxCpXmlMessage fromEncryptedXml(String encryptedXml, WxCpConfigSto
497498
WxCpXmlMessage wxCpXmlMessage = fromXml(encryptedXml);
498499
String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, encryptedXml);
499500
log.debug("解密后的原始xml消息内容:{}", plainText);
500-
if (null != wxCpXmlMessage.getAgentId()) {
501+
if (StringUtils.isNotEmpty(wxCpXmlMessage.getAgentId())) {
501502
return fromXml(plainText, wxCpXmlMessage.getAgentId());
502503
} else {
503504
return fromXml(plainText);

0 commit comments

Comments
 (0)