Skip to content

Commit 61e3163

Browse files
committed
binarywang#531 小程序WxMaMessage类增加小程序卡片消息相关的几个属性
1 parent 8b30615 commit 61e3163

File tree

2 files changed

+50
-106
lines changed

2 files changed

+50
-106
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaMessage.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class WxMaMessage implements Serializable {
4242

4343
@SerializedName("CreateTime")
4444
@XStreamAlias("CreateTime")
45-
@XStreamConverter(value = XStreamCDataConverter.class)
4645
private Integer createTime;
4746

4847
@SerializedName("MsgType")
@@ -62,7 +61,6 @@ public class WxMaMessage implements Serializable {
6261

6362
@SerializedName("MsgId")
6463
@XStreamAlias("MsgId")
65-
@XStreamConverter(value = XStreamCDataConverter.class)
6664
private Long msgId;
6765

6866
@SerializedName("PicUrl")
@@ -80,6 +78,31 @@ public class WxMaMessage implements Serializable {
8078
@XStreamConverter(value = XStreamCDataConverter.class)
8179
private String event;
8280

81+
@SerializedName("Title")
82+
@XStreamAlias("Title")
83+
@XStreamConverter(value = XStreamCDataConverter.class)
84+
private String title;
85+
86+
@SerializedName("AppId")
87+
@XStreamAlias("AppId")
88+
@XStreamConverter(value = XStreamCDataConverter.class)
89+
private String appId;
90+
91+
@SerializedName("PagePath")
92+
@XStreamAlias("PagePath")
93+
@XStreamConverter(value = XStreamCDataConverter.class)
94+
private String pagePath;
95+
96+
@SerializedName("ThumbUrl")
97+
@XStreamAlias("ThumbUrl")
98+
@XStreamConverter(value = XStreamCDataConverter.class)
99+
private String thumbUrl;
100+
101+
@SerializedName("ThumbMediaId")
102+
@XStreamAlias("ThumbMediaId")
103+
@XStreamConverter(value = XStreamCDataConverter.class)
104+
private String thumbMediaId;
105+
83106
@SerializedName("SessionFrom")
84107
@XStreamAlias("SessionFrom")
85108
@XStreamConverter(value = XStreamCDataConverter.class)

weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaMessageTest.java

Lines changed: 25 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -12,118 +12,39 @@
1212
public class WxMaMessageTest {
1313

1414
public void testFromXml() {
15-
String xml = "<xml>"
16-
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
17-
+ "<FromUserName><![CDATA[fromUser]]></FromUserName> "
18-
+ "<CreateTime>1348831860</CreateTime>"
19-
+ "<MsgDataFormat><![CDATA[text]]></MsgDataFormat>"
20-
+ "<Content><![CDATA[this is a test]]></Content>"
21-
+ "<MsgId>1234567890123456</MsgId>"
22-
+ "<PicUrl><![CDATA[this is a url]]></PicUrl>"
23-
+ "<MediaId><![CDATA[media_id]]></MediaId>"
24-
+ "<Format><![CDATA[Format]]></Format>"
25-
+ "<ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>"
26-
+ "<Location_X>23.134521</Location_X>"
27-
+ "<Location_Y>113.358803</Location_Y>"
28-
+ "<Scale>20</Scale>"
29-
+ "<Label><![CDATA[位置信息]]></Label>"
30-
+ "<Description><![CDATA[公众平台官网链接]]></Description>"
31-
+ "<Url><![CDATA[url]]></Url>"
32-
+ "<Title><![CDATA[公众平台官网链接]]></Title>"
33-
+ "<Event><![CDATA[subscribe]]></Event>"
34-
+ "<EventKey><![CDATA[qrscene_123123]]></EventKey>"
35-
+ "<Ticket><![CDATA[TICKET]]></Ticket>"
36-
+ "<Latitude>23.137466</Latitude>"
37-
+ "<Longitude>113.352425</Longitude>"
38-
+ "<Precision>119.385040</Precision>"
39-
+ "<ScanCodeInfo>"
40-
+ " <ScanType><![CDATA[qrcode]]></ScanType>"
41-
+ " <ScanResult><![CDATA[1]]></ScanResult>"
42-
+ "</ScanCodeInfo>"
43-
+ "<SendPicsInfo>"
44-
+ " <Count>1</Count>\n"
45-
+ " <PicList>"
46-
+ " <item>"
47-
+ " <PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>"
48-
+ " </item>"
49-
+ " </PicList>"
50-
+ "</SendPicsInfo>"
51-
+ "<SendLocationInfo>"
52-
+ " <Location_X><![CDATA[23]]></Location_X>\n"
53-
+ " <Location_Y><![CDATA[113]]></Location_Y>\n"
54-
+ " <Scale><![CDATA[15]]></Scale>\n"
55-
+ " <Label><![CDATA[ 广州市海珠区客村艺苑路 106号]]></Label>\n"
56-
+ " <Poiname><![CDATA[wo de poi]]></Poiname>\n"
57-
+ "</SendLocationInfo>"
58-
+ "</xml>";
15+
String xml = "<xml>\n" +
16+
" <ToUserName><![CDATA[toUser]]></ToUserName>\n" +
17+
" <FromUserName><![CDATA[fromUser]]></FromUserName>\n" +
18+
" <CreateTime>1482048670</CreateTime>\n" +
19+
" <MsgType><![CDATA[text]]></MsgType>\n" +
20+
" <Content><![CDATA[this is a test]]></Content>\n" +
21+
" <MsgId>1234567890123456</MsgId>\n" +
22+
" <PicUrl><![CDATA[this is a url]]></PicUrl>\n" +
23+
" <MediaId><![CDATA[media_id]]></MediaId>\n" +
24+
" <Title><![CDATA[Title]]></Title>\n" +
25+
" <AppId><![CDATA[AppId]]></AppId>\n" +
26+
" <PagePath><![CDATA[PagePath]]></PagePath>\n" +
27+
" <ThumbUrl><![CDATA[ThumbUrl]]></ThumbUrl>\n" +
28+
" <ThumbMediaId><![CDATA[ThumbMediaId]]></ThumbMediaId>\n" +
29+
" <Event><![CDATA[user_enter_tempsession]]></Event>\n" +
30+
" <SessionFrom><![CDATA[sessionFrom]]></SessionFrom>\n" +
31+
"</xml>";
5932
WxMaMessage wxMessage = WxMaMessage.fromXml(xml);
6033
assertEquals(wxMessage.getToUser(), "toUser");
6134
assertEquals(wxMessage.getFromUser(), "fromUser");
62-
assertEquals(wxMessage.getCreateTime(), new Long(1348831860L));
35+
assertEquals(wxMessage.getCreateTime(),new Integer(1482048670));
6336
assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.TEXT);
6437
assertEquals(wxMessage.getContent(), "this is a test");
6538
assertEquals(wxMessage.getMsgId(), new Long(1234567890123456L));
6639
assertEquals(wxMessage.getPicUrl(), "this is a url");
6740
assertEquals(wxMessage.getMediaId(), "media_id");
68-
assertEquals(wxMessage.getEvent(), "subscribe");
69-
}
70-
71-
public void testFromXml2() {
72-
73-
String xml = "<xml>"
74-
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
75-
+ "<FromUserName><![CDATA[fromUser]]></FromUserName> "
76-
+ "<CreateTime>1348831860</CreateTime>"
77-
+ "<MsgDataFormat><![CDATA[text]]></MsgDataFormat>"
78-
+ "<Content><![CDATA[this is a test]]></Content>"
79-
+ "<MsgID>1234567890123456</MsgID>"
80-
+ "<PicUrl><![CDATA[this is a url]]></PicUrl>"
81-
+ "<MediaId><![CDATA[media_id]]></MediaId>"
82-
+ "<Format><![CDATA[Format]]></Format>"
83-
+ "<ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>"
84-
+ "<Location_X>23.134521</Location_X>"
85-
+ "<Location_Y>113.358803</Location_Y>"
86-
+ "<Scale>20</Scale>"
87-
+ "<Label><![CDATA[位置信息]]></Label>"
88-
+ "<Description><![CDATA[公众平台官网链接]]></Description>"
89-
+ "<Url><![CDATA[url]]></Url>"
90-
+ "<Title><![CDATA[公众平台官网链接]]></Title>"
91-
+ "<Event><![CDATA[subscribe]]></Event>"
92-
+ "<EventKey><![CDATA[qrscene_123123]]></EventKey>"
93-
+ "<Ticket><![CDATA[TICKET]]></Ticket>"
94-
+ "<Latitude>23.137466</Latitude>"
95-
+ "<Longitude>113.352425</Longitude>"
96-
+ "<Precision>119.385040</Precision>"
97-
+ "<ScanCodeInfo>"
98-
+ " <ScanType><![CDATA[qrcode]]></ScanType>"
99-
+ " <ScanResult><![CDATA[1]]></ScanResult>"
100-
+ "</ScanCodeInfo>"
101-
+ "<SendPicsInfo>"
102-
+ " <Count>1</Count>\n"
103-
+ " <PicList>"
104-
+ " <item>"
105-
+ " <PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>"
106-
+ " </item>"
107-
+ " </PicList>"
108-
+ "</SendPicsInfo>"
109-
+ "<SendLocationInfo>"
110-
+ " <Location_X><![CDATA[23]]></Location_X>\n"
111-
+ " <Location_Y><![CDATA[113]]></Location_Y>\n"
112-
+ " <Scale><![CDATA[15]]></Scale>\n"
113-
+ " <Label><![CDATA[ 广州市海珠区客村艺苑路 106号]]></Label>\n"
114-
+ " <Poiname><![CDATA[wo de poi]]></Poiname>\n"
115-
+ "</SendLocationInfo>"
116-
+ "</xml>";
117-
WxMaMessage wxMessage = WxMaMessage.fromXml(xml);
118-
assertEquals(wxMessage.getToUser(), "toUser");
119-
assertEquals(wxMessage.getFromUser(), "fromUser");
120-
assertEquals(wxMessage.getCreateTime(), new Integer(1348831860));
121-
assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.TEXT);
122-
assertEquals(wxMessage.getContent(), "this is a test");
123-
assertEquals(wxMessage.getMsgId(), new Long(1234567890123456L));
124-
assertEquals(wxMessage.getPicUrl(), "this is a url");
125-
assertEquals(wxMessage.getMediaId(), "media_id");
126-
assertEquals(wxMessage.getEvent(), "subscribe");
41+
assertEquals(wxMessage.getTitle(), "Title");
42+
assertEquals(wxMessage.getPagePath(), "PagePath");
43+
assertEquals(wxMessage.getThumbUrl(), "ThumbUrl");
44+
assertEquals(wxMessage.getThumbMediaId(), "ThumbMediaId");
45+
assertEquals(wxMessage.getAppId(), "AppId");
46+
assertEquals(wxMessage.getEvent(), "user_enter_tempsession");
47+
assertEquals(wxMessage.getSessionFrom(), "sessionFrom");
12748
}
12849

12950
}

0 commit comments

Comments
 (0)