|
12 | 12 | public class WxMaMessageTest { |
13 | 13 |
|
14 | 14 | 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>"; |
59 | 32 | WxMaMessage wxMessage = WxMaMessage.fromXml(xml); |
60 | 33 | assertEquals(wxMessage.getToUser(), "toUser"); |
61 | 34 | assertEquals(wxMessage.getFromUser(), "fromUser"); |
62 | | - assertEquals(wxMessage.getCreateTime(), new Long(1348831860L)); |
| 35 | + assertEquals(wxMessage.getCreateTime(),new Integer(1482048670)); |
63 | 36 | assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.TEXT); |
64 | 37 | assertEquals(wxMessage.getContent(), "this is a test"); |
65 | 38 | assertEquals(wxMessage.getMsgId(), new Long(1234567890123456L)); |
66 | 39 | assertEquals(wxMessage.getPicUrl(), "this is a url"); |
67 | 40 | 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"); |
127 | 48 | } |
128 | 49 |
|
129 | 50 | } |
0 commit comments