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
16
17 public class EncryptMessageTest extends MessagePush {
18 StringBuilder xmlSb = new StringBuilder();
19
20
21
22
23
24
25 @Test
26 public void testValidate() throws IOException {
27 String echostr = "9104940990866104523";
28 String para = "?signature=6ea29ec4c087868f960a20f28b7ac3edef7e444e&echostr="
29 + echostr + "×tamp=1433903307&nonce=1961697383";
30 xmlSb.delete(0, xmlSb.length());
31 String response = get(para);
32 Assert.assertEquals(echostr, response);
33 }
34
35
36
37
38
39
40 @Test
41 public void testType1() throws IOException {
42 String para = "?signature=d919cc8a6361597afa536e906156262cc9cd93df×tamp=1433903433&nonce=518016546";
43 xmlSb.delete(0, xmlSb.length());
44 xmlSb.append("<xml>");
45 xmlSb.append("<ToUserName><![CDATA[gh_22b350df957b]]></ToUserName>");
46 xmlSb.append("<FromUserName><![CDATA[owGBft_vbBbOaQOmpEUE4xDLeRSU]]></FromUserName>");
47 xmlSb.append("<CreateTime>1433903433</CreateTime>");
48 xmlSb.append("<MsgType><![CDATA[text]]></MsgType>");
49 xmlSb.append("<Content><![CDATA[text]]></Content>");
50 xmlSb.append("</xml>");
51 String response = push(para, xmlSb.toString());
52 Assert.assertNotNull(response);
53 System.err.println(response);
54 }
55
56
57
58
59
60
61 @Test
62 public void testType2() throws IOException {
63 String para = "/?signature=b4343f727d6e9b1072f6f72d28b0d0cf38986dce×tamp=1430926116&nonce=1801492986&encrypt_type=aes&msg_signature=af1868ffe3058db89643c6c546e49cd40d717ac9";
64 xmlSb.delete(0, xmlSb.length());
65 xmlSb.append("<xml>");
66 xmlSb.append("<ToUserName><![CDATA[gh_248c6f91d64f]]></ToUserName>");
67 xmlSb.append("<FromUserName><![CDATA[oyFLst1bqtuTcxK-ojF8hOGtLQao]]></FromUserName>");
68 xmlSb.append("<CreateTime>1415980001</CreateTime>");
69 xmlSb.append("<MsgType><![CDATA[event]]></MsgType>");
70 xmlSb.append("<Event><![CDATA[CLICK]]></Event>");
71 xmlSb.append("<EventKey><![CDATA[CHECKIN]]></EventKey>");
72 xmlSb.append("<Encrypt><![CDATA[TDlZ8S/dhpElqvh4Nd4esnSk6Z6jIF65S3OIXiDWdwRMw+B7uzRcoJDZcETYw3b5ZE1eB9zyt4qHyJdjiBazUeN/ZkG6PVPHaprE0q0yBs2YCGLesAsbQ8rFyMtDazsOzug7pu/PM3RI886PnJ1QAcnPDT7xj4lRmKasWziZ3Ta45FH4vNkaozKNluzpUpq43PGzlOfa1ITvx22ScBcWmdaKnEBFAH/sGwpJ6IaKzHo5DDGyD0gmQ/QNiSh/swMzZewKG6VU0rRWms1rMXOXgP5ttxH0d7wIYMeqbXwwqRh4lh93CxVs2pJGrxTpI48ZnytWSSBBWfMSgchdxvHGd4auBnYWPizIoeQjb7/zJkXnnfru8/TiSQHXujLQuETV78I1jbvNeDJ7dMVsYbpANzfNa5VtJSZCorucCHgK15k=]]></Encrypt>");
73 xmlSb.append("</xml>");
74 String response = push(para, xmlSb.toString());
75 Assert.assertNotNull(response);
76 System.err.println(response);
77 }
78
79
80
81
82
83
84 @Test
85 public void testType3() throws IOException {
86 String para = "?signature=ad05f836772d1cbba1ff2edb7be4b9c9fb3a43d5×tamp=1415980001&nonce=1803216865&encrypt_type=aes&msg_signature=c0d38e9ca00548f7142627ec2908a4fe8481025e";
87 xmlSb.delete(0, xmlSb.length());
88 xmlSb.append("<xml>");
89 xmlSb.append("<ToUserName><![CDATA[gh_248c6f91d64f]]></ToUserName>");
90 xmlSb.append("<Encrypt><![CDATA[R6VQIWDR14XgSRLm25zc7V/WJYqK15gsUiMh0u/5GTMZME6jGtHkyfVN079ZPL065b+ZDq3TnoFKKtjtZlzcodY6Fm8+EujvtbTdVMMFSwdo8AwqVViAn09+DDfqPaNvbHUSiYsL3qlxArs1MH6APRUHFo7MU/piY1x2stJc8+kv28xtF+K8Aou0RuPO7PeQ18Zu/GkLnYNiI1E7UG31UYfOgVKcRjeE0PXa18iF5LBS8G/ce/l+/pH/DJWUBw5uXaqSOlo21tctlgLXu3bYUUkIu8tT49QwhHvRZILtO9icoyCNuTA7iTcHIdlAe1bD1S0ncmopIQCGmoU2/AXC2CCi6trONf3EPNKKKfDeQYHadnVZOg6kTX2cnYmHZLviYeLzjCKFSqSNkimoSKQ/Dcutpsq1D82NCwiExUZW4oo=]]></Encrypt>");
91 xmlSb.append("</xml>");
92 String response = push(para, xmlSb.toString());
93 Assert.assertNotNull(response);
94 System.err.println(response);
95 }
96 }