Skip to content

Commit 75ca824

Browse files
committed
1 parent b47cd3a commit 75ca824

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public void setFromUserName(String fromUserName) {
382382
public static WxMpXmlMessage fromXml(String xml) {
383383
try {
384384
// 操蛋的微信,模板消息推送成功的消息是MsgID,其他消息推送过来是MsgId
385-
xml = xml.replaceAll("<MsgID>", "<MsgId>").replaceAll("</MsgID>", "</MsgID>");
385+
xml = xml.replaceAll("<MsgID>", "<MsgId>").replaceAll("</MsgID>", "</MsgId>");
386386
return XmlTransformer.fromXml(WxMpXmlMessage.class, xml);
387387
} catch (JAXBException e) {
388388
throw new RuntimeException(e);

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlMessageTest.java

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,86 @@ public void testFromXml() {
8787
Assert.assertEquals(wxMessage.getSendLocationInfo().getLabel(), " 广州市海珠区客村艺苑路 106号");
8888
Assert.assertEquals(wxMessage.getSendLocationInfo().getPoiname(), "wo de poi");
8989
}
90-
90+
91+
public void testFromXml2() {
92+
93+
String xml = "<xml>"
94+
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
95+
+ "<FromUserName><![CDATA[fromUser]]></FromUserName> "
96+
+ "<CreateTime>1348831860</CreateTime>"
97+
+ "<MsgType><![CDATA[text]]></MsgType>"
98+
+ "<Content><![CDATA[this is a test]]></Content>"
99+
+ "<MsgID>1234567890123456</MsgID>"
100+
+ "<PicUrl><![CDATA[this is a url]]></PicUrl>"
101+
+ "<MediaId><![CDATA[media_id]]></MediaId>"
102+
+ "<Format><![CDATA[Format]]></Format>"
103+
+ "<ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>"
104+
+ "<Location_X>23.134521</Location_X>"
105+
+ "<Location_Y>113.358803</Location_Y>"
106+
+ "<Scale>20</Scale>"
107+
+ "<Label><![CDATA[位置信息]]></Label>"
108+
+ "<Description><![CDATA[公众平台官网链接]]></Description>"
109+
+ "<Url><![CDATA[url]]></Url>"
110+
+ "<Title><![CDATA[公众平台官网链接]]></Title>"
111+
+ "<Event><![CDATA[subscribe]]></Event>"
112+
+ "<EventKey><![CDATA[qrscene_123123]]></EventKey>"
113+
+ "<Ticket><![CDATA[TICKET]]></Ticket>"
114+
+ "<Latitude>23.137466</Latitude>"
115+
+ "<Longitude>113.352425</Longitude>"
116+
+ "<Precision>119.385040</Precision>"
117+
+ "<ScanCodeInfo>"
118+
+ " <ScanType><![CDATA[qrcode]]></ScanType>"
119+
+ " <ScanResult><![CDATA[1]]></ScanResult>"
120+
+ "</ScanCodeInfo>"
121+
+ "<SendPicsInfo>"
122+
+ " <Count>1</Count>\n"
123+
+ " <PicList>"
124+
+ " <item>"
125+
+ " <PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>"
126+
+ " </item>"
127+
+ " </PicList>"
128+
+ "</SendPicsInfo>"
129+
+ "<SendLocationInfo>"
130+
+ " <Location_X><![CDATA[23]]></Location_X>\n"
131+
+ " <Location_Y><![CDATA[113]]></Location_Y>\n"
132+
+ " <Scale><![CDATA[15]]></Scale>\n"
133+
+ " <Label><![CDATA[ 广州市海珠区客村艺苑路 106号]]></Label>\n"
134+
+ " <Poiname><![CDATA[wo de poi]]></Poiname>\n"
135+
+ "</SendLocationInfo>"
136+
+ "</xml>";
137+
WxMpXmlMessage wxMessage = WxMpXmlMessage.fromXml(xml);
138+
Assert.assertEquals(wxMessage.getToUserName(), "toUser");
139+
Assert.assertEquals(wxMessage.getFromUserName(), "fromUser");
140+
Assert.assertEquals(wxMessage.getCreateTime(), new Long(1348831860l));
141+
Assert.assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT);
142+
Assert.assertEquals(wxMessage.getContent(), "this is a test");
143+
Assert.assertEquals(wxMessage.getMsgId(), new Long(1234567890123456l));
144+
Assert.assertEquals(wxMessage.getPicUrl(), "this is a url");
145+
Assert.assertEquals(wxMessage.getMediaId(), "media_id");
146+
Assert.assertEquals(wxMessage.getFormat(), "Format");
147+
Assert.assertEquals(wxMessage.getThumbMediaId(), "thumb_media_id");
148+
Assert.assertEquals(wxMessage.getLocationX(), new Double(23.134521d));
149+
Assert.assertEquals(wxMessage.getLocationY(), new Double(113.358803d));
150+
Assert.assertEquals(wxMessage.getScale(), new Double(20));
151+
Assert.assertEquals(wxMessage.getLabel(), "位置信息");
152+
Assert.assertEquals(wxMessage.getDescription(), "公众平台官网链接");
153+
Assert.assertEquals(wxMessage.getUrl(), "url");
154+
Assert.assertEquals(wxMessage.getTitle(), "公众平台官网链接");
155+
Assert.assertEquals(wxMessage.getEvent(), "subscribe");
156+
Assert.assertEquals(wxMessage.getEventKey(), "qrscene_123123");
157+
Assert.assertEquals(wxMessage.getTicket(), "TICKET");
158+
Assert.assertEquals(wxMessage.getLatitude(), new Double(23.137466));
159+
Assert.assertEquals(wxMessage.getLongitude(), new Double(113.352425));
160+
Assert.assertEquals(wxMessage.getPrecision(), new Double(119.385040));
161+
Assert.assertEquals(wxMessage.getScanCodeInfo().getScanType(), "qrcode");
162+
Assert.assertEquals(wxMessage.getScanCodeInfo().getScanResult(), "1");
163+
Assert.assertEquals(wxMessage.getSendPicsInfo().getCount(), new Long(1l));
164+
Assert.assertEquals(wxMessage.getSendPicsInfo().getPicList().get(0).getPicMd5Sum(), "1b5f7c23b5bf75682a53e7b6d163e185");
165+
Assert.assertEquals(wxMessage.getSendLocationInfo().getLocationX(), "23");
166+
Assert.assertEquals(wxMessage.getSendLocationInfo().getLocationY(), "113");
167+
Assert.assertEquals(wxMessage.getSendLocationInfo().getScale(), "15");
168+
Assert.assertEquals(wxMessage.getSendLocationInfo().getLabel(), " 广州市海珠区客村艺苑路 106号");
169+
Assert.assertEquals(wxMessage.getSendLocationInfo().getPoiname(), "wo de poi");
170+
}
171+
91172
}

0 commit comments

Comments
 (0)