🎨 #3715 企业微信回调消息中的MsgId改为字符串类型

This commit is contained in:
Copilot
2025-09-24 21:40:27 +08:00
committed by GitHub
parent e6a844ab70
commit 1788d9071e
2 changed files with 31 additions and 2 deletions

View File

@@ -92,7 +92,7 @@ public class WxCpXmlMessage implements Serializable {
private String content;
@XStreamAlias("MsgId")
private Long msgId;
private String msgId;
@XStreamAlias("PicUrl")
@XStreamConverter(value = XStreamCDataConverter.class)

View File

@@ -72,7 +72,7 @@ public class WxCpXmlMessageTest {
assertEquals(wxMessage.getCreateTime(), Long.valueOf(1348831860));
assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.TEXT);
assertEquals(wxMessage.getContent(), "this is a test");
assertEquals(wxMessage.getMsgId(), Long.valueOf(1234567890123456L));
assertEquals(wxMessage.getMsgId(), "1234567890123456");
assertEquals(wxMessage.getPicUrl(), "this is a url");
assertEquals(wxMessage.getMediaId(), "media_id");
assertEquals(wxMessage.getFormat(), "Format");
@@ -442,4 +442,33 @@ public class WxCpXmlMessageTest {
assertThat(wxCpXmlMessage.getJobId()).isEqualTo("jobid_S0MrnndvRG5fadSlLwiBqiDDbM143UqTmKP3152FZk4");
assertThat(wxCpXmlMessage.getEvent()).isEqualTo(UPLOAD_MEDIA_JOB_FINISH);
}
/**
* Test both numeric and string msgId formats to ensure backward compatibility
*/
public void testMsgIdStringAndNumericFormats() {
// Test with numeric msgId (old format)
String xmlWithNumeric = "<xml>"
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
+ "<CreateTime>1348831860</CreateTime>"
+ "<MsgType><![CDATA[text]]></MsgType>"
+ "<Content><![CDATA[this is a test]]></Content>"
+ "<MsgId>1234567890123456</MsgId>"
+ "</xml>";
WxCpXmlMessage wxMessageNumeric = WxCpXmlMessage.fromXml(xmlWithNumeric);
assertEquals(wxMessageNumeric.getMsgId(), "1234567890123456");
// Test with string msgId (new format - the actual issue case)
String xmlWithString = "<xml>"
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
+ "<CreateTime>1348831860</CreateTime>"
+ "<MsgType><![CDATA[text]]></MsgType>"
+ "<Content><![CDATA[this is a test]]></Content>"
+ "<MsgId>CAIQg/PKxgYY2sC9tpuAgAMg9/zKaw==</MsgId>"
+ "</xml>";
WxCpXmlMessage wxMessageString = WxCpXmlMessage.fromXml(xmlWithString);
assertEquals(wxMessageString.getMsgId(), "CAIQg/PKxgYY2sC9tpuAgAMg9/zKaw==");
}
}