1 package com.foxinmy.weixin4j.server.test;
2
3 import java.io.IOException;
4
5 import org.junit.Assert;
6 import org.junit.Test;
7
8
9
10
11
12
13
14
15 public class EventMessageRequestTest extends MessagePush {
16
17 private StringBuilder xmlSb = new StringBuilder();
18
19
20 @Test
21 public void scribe() throws IOException {
22 String para = "?signature=d919cc8a6361597afa536e906156262cc9cd93df×tamp=1433903433&nonce=518016546";
23 xmlSb.delete(0, xmlSb.length());
24 xmlSb.append("<xml>");
25 xmlSb.append("<ToUserName><![CDATA[toUser]]></ToUserName>");
26 xmlSb.append("<FromUserName><![CDATA[FromUser]]></FromUserName>");
27 xmlSb.append("<CreateTime>123456789</CreateTime>");
28 xmlSb.append("<MsgType><![CDATA[event]]></MsgType>");
29 xmlSb.append("<Event><![CDATA[subscribe]]></Event>");
30 xmlSb.append("</xml>");
31 String response = push(para, xmlSb.toString());
32 Assert.assertNotNull(response);
33 System.out.println(response);
34 }
35
36 @Test
37 public void scan() throws IOException {
38 String para = "?signature=d919cc8a6361597afa536e906156262cc9cd93df×tamp=1433903433&nonce=518016546";
39 xmlSb.delete(0, xmlSb.length());
40 xmlSb.append("<xml>");
41 xmlSb.append("<ToUserName><![CDATA[toUser]]></ToUserName>");
42 xmlSb.append("<FromUserName><![CDATA[FromUser]]></FromUserName>");
43 xmlSb.append("<CreateTime>123456789</CreateTime>");
44 xmlSb.append("<MsgType><![CDATA[event]]></MsgType>");
45 xmlSb.append("<Event><![CDATA[SCAN]]></Event>");
46 xmlSb.append("<EventKey><![CDATA[SCENE_VALUE]]></EventKey>");
47 xmlSb.append("<Ticket><![CDATA[TICKET]]></Ticket>");
48 xmlSb.append("</xml>");
49 String response = push(para, xmlSb.toString());
50 Assert.assertNotNull(response);
51 System.out.println(response);
52 }
53
54 @Test
55 public void scan_scribe() throws IOException {
56 String para = "?signature=d919cc8a6361597afa536e906156262cc9cd93df×tamp=1433903433&nonce=518016546";
57 xmlSb.delete(0, xmlSb.length());
58 xmlSb.append("<xml><ToUserName><![CDATA[toUser]]></ToUserName>");
59 xmlSb.append("<FromUserName><![CDATA[FromUser]]></FromUserName>");
60 xmlSb.append("<CreateTime>123456789</CreateTime>");
61 xmlSb.append("<MsgType><![CDATA[event]]></MsgType>");
62 xmlSb.append("<Event><![CDATA[subscribe]]></Event>");
63 xmlSb.append("<EventKey><![CDATA[qrscene_123123]]></EventKey>");
64 xmlSb.append("<Ticket><![CDATA[TICKET]]></Ticket>");
65 xmlSb.append("</xml>");
66 String response = push(para, xmlSb.toString());
67 Assert.assertNotNull(response);
68 System.out.println(response);
69 }
70
71 @Test
72 public void location() throws IOException {
73 String para = "?signature=d919cc8a6361597afa536e906156262cc9cd93df×tamp=1433903433&nonce=518016546";
74 xmlSb.delete(0, xmlSb.length());
75 xmlSb.append("<xml>");
76 xmlSb.append("<ToUserName><![CDATA[toUser]]></ToUserName>");
77 xmlSb.append("<FromUserName><![CDATA[fromUser]]></FromUserName>");
78 xmlSb.append("<CreateTime>123456789</CreateTime>");
79 xmlSb.append("<MsgType><![CDATA[event]]></MsgType>");
80 xmlSb.append("<Event><![CDATA[LOCATION]]></Event>");
81 xmlSb.append("<Latitude>23.137466</Latitude>");
82 xmlSb.append("<Longitude>113.352425</Longitude>");
83 xmlSb.append("<Precision>119.385040</Precision>");
84 xmlSb.append("</xml>");
85 String response = push(para, xmlSb.toString());
86 Assert.assertNotNull(response);
87 System.out.println(response);
88 }
89
90 @Test
91 public void menu_click() throws IOException {
92 String para = "?signature=d919cc8a6361597afa536e906156262cc9cd93df×tamp=1433903433&nonce=518016546";
93 xmlSb.delete(0, xmlSb.length());
94 xmlSb.append("<xml>");
95 xmlSb.append("<ToUserName><![CDATA[toUser]]></ToUserName>");
96 xmlSb.append("<FromUserName><![CDATA[FromUser]]></FromUserName>");
97 xmlSb.append("<CreateTime>123456789</CreateTime>");
98 xmlSb.append("<MsgType><![CDATA[event]]></MsgType>");
99 xmlSb.append("<Event><![CDATA[CLICK]]></Event>");
100 xmlSb.append("<EventKey><![CDATA[EVENTKEY]]></EventKey>");
101 xmlSb.append("</xml>");
102 String response = push(para, xmlSb.toString());
103 Assert.assertNotNull(response);
104 System.out.println(response);
105 }
106
107 @Test
108 public void menu_link() throws IOException {
109 String para = "?signature=d919cc8a6361597afa536e906156262cc9cd93df×tamp=1433903433&nonce=518016546";
110 xmlSb.delete(0, xmlSb.length());
111 xmlSb.append("<xml>");
112 xmlSb.append("<ToUserName><![CDATA[toUser]]></ToUserName>");
113 xmlSb.append("<FromUserName><![CDATA[FromUser]]></FromUserName>");
114 xmlSb.append("<CreateTime>123456789</CreateTime>");
115 xmlSb.append("<MsgType><![CDATA[event]]></MsgType>");
116 xmlSb.append("<Event><![CDATA[VIEW]]></Event>");
117 xmlSb.append("<EventKey><![CDATA[www.qq.com]]></EventKey>");
118 xmlSb.append("</xml>");
119 String response = push(para, xmlSb.toString());
120 Assert.assertNotNull(response);
121 System.out.println(response);
122 }
123
124 @Test
125 public void menu_scan() throws IOException {
126 String para = "?signature=d919cc8a6361597afa536e906156262cc9cd93df×tamp=1433903433&nonce=518016546";
127 xmlSb.delete(0, xmlSb.length());
128 xmlSb.append("<xml>");
129 xmlSb.append("<ToUserName><![CDATA[toUser]]></ToUserName>");
130 xmlSb.append("<FromUserName><![CDATA[FromUser]]></FromUserName>");
131 xmlSb.append("<CreateTime>123456789</CreateTime>");
132 xmlSb.append("<MsgType><![CDATA[event]]></MsgType>");
133 xmlSb.append("<Event><![CDATA[scancode_waitmsg]]></Event>");
134 xmlSb.append("<EventKey><![CDATA[www.qq.com]]></EventKey>");
135 xmlSb.append("<ScanCodeInfo><ScanType><![CDATA[qrcode]]></ScanType>");
136 xmlSb.append("<ScanResult><![CDATA[1]]></ScanResult>");
137 xmlSb.append("</ScanCodeInfo>");
138
139 xmlSb.append("</xml>");
140 String response = push(para, xmlSb.toString());
141 Assert.assertNotNull(response);
142 System.out.println(response);
143 }
144
145 @Test
146 public void menu_photo() throws IOException {
147 String para = "?signature=d919cc8a6361597afa536e906156262cc9cd93df×tamp=1433903433&nonce=518016546";
148 xmlSb.delete(0, xmlSb.length());
149 xmlSb.append("<xml>");
150 xmlSb.append("<ToUserName><![CDATA[toUser]]></ToUserName>");
151 xmlSb.append("<FromUserName><![CDATA[FromUser]]></FromUserName>");
152 xmlSb.append("<CreateTime>123456789</CreateTime>");
153 xmlSb.append("<MsgType><![CDATA[event]]></MsgType>");
154 xmlSb.append("<Event><![CDATA[pic_weixin]]></Event>");
155 xmlSb.append("<EventKey><![CDATA[www.qq.com]]></EventKey>");
156 xmlSb.append("<SendPicsInfo><Count>1</Count>");
157 xmlSb.append("<PicList><item><PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>");
158 xmlSb.append("</item></PicList></SendPicsInfo>");
159 xmlSb.append("</xml>");
160 String response = push(para, xmlSb.toString());
161 Assert.assertNotNull(response);
162 System.out.println(response);
163 }
164
165 @Test
166 public void menu_location() throws IOException {
167 String para = "?signature=d919cc8a6361597afa536e906156262cc9cd93df×tamp=1433903433&nonce=518016546";
168 xmlSb.delete(0, xmlSb.length());
169 xmlSb.append("<xml>");
170 xmlSb.append("<ToUserName><![CDATA[toUser]]></ToUserName>");
171 xmlSb.append("<FromUserName><![CDATA[FromUser]]></FromUserName>");
172 xmlSb.append("<CreateTime>123456789</CreateTime>");
173 xmlSb.append("<MsgType><![CDATA[event]]></MsgType>");
174 xmlSb.append("<Event><![CDATA[location_select]]></Event>");
175 xmlSb.append("<EventKey><![CDATA[www.qq.com]]></EventKey>");
176 xmlSb.append("<SendLocationInfo><Location_X><![CDATA[23]]></Location_X>");
177 xmlSb.append("<Location_Y><![CDATA[113]]></Location_Y>");
178 xmlSb.append("<Scale><![CDATA[15]]></Scale>");
179 xmlSb.append("<Label><![CDATA[ 广州市海珠区客村艺苑路 106号]]></Label>");
180 xmlSb.append("<Poiname><![CDATA[]]></Poiname></SendLocationInfo>");
181 xmlSb.append("</xml>");
182 String response = push(para, xmlSb.toString());
183 Assert.assertNotNull(response);
184 System.out.println(response);
185 }
186 }