11package me .chanjar .weixin .cp .bean ;
22
3- import me .chanjar .weixin .common .api .WxConsts ;
43import me .chanjar .weixin .cp .bean .article .MpnewsArticle ;
54import me .chanjar .weixin .cp .bean .article .NewArticle ;
65import org .testng .annotations .*;
109@ Test
1110public class WxCpMessageTest {
1211
13- public void testTextReply () {
14- WxCpMessage reply = new WxCpMessage ();
15- reply .setToUser ("OPENID" );
16- reply .setMsgType (WxConsts .CUSTOM_MSG_TEXT );
17- reply .setContent ("sfsfdsdf" );
18- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" text\" ,\" text\" :{\" content\" :\" sfsfdsdf\" }}" );
19- }
20-
2112 public void testTextBuild () {
2213 WxCpMessage reply = WxCpMessage .TEXT ().toUser ("OPENID" ).content ("sfsfdsdf" ).build ();
23- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" text\" ,\" text\" :{\" content\" :\" sfsfdsdf\" }}" );
14+ assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" text\" ,\" text\" :{\" content\" :\" sfsfdsdf\" }, \" safe \" : \" 0 \" }" );
2415 }
2516
26- public void testImageReply () {
27- WxCpMessage reply = new WxCpMessage ();
28- reply . setToUser ( "OPENID" );
29- reply . setMsgType ( WxConsts . CUSTOM_MSG_IMAGE );
30- reply . setMediaId ( "MEDIA_ID" );
31- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" image \" ,\" image \" :{\" media_id \" :\" MEDIA_ID \" } }" );
17+ public void testTextCardBuild () {
18+ WxCpMessage reply = WxCpMessage . TEXTCARD (). toUser ( "OPENID" )
19+ . title ( "领奖通知" )
20+ . description ( "<div class= \" gray \" >2016年9月26日</div> <div class= \" normal \" >恭喜你抽中iPhone 7一台,领奖码:xxxx</div><div class= \" highlight \" >请于2016年10月10日前联系行政同事领取</div>" )
21+ . url ( "http://www.qq.com" ). build ( );
22+ assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" textcard \" ,\" textcard \" :{\" title \" :\" 领奖通知 \" , \" description \" : \" <div class= \\ \" gray \\ \" >2016年9月26日</div> <div class= \\ \" normal \\ \" >恭喜你抽中iPhone 7一台,领奖码:xxxx</div><div class= \\ \" highlight \\ \" >请于2016年10月10日前联系行政同事领取</div> \" , \" url \" : \" http://www.qq.com \" }, \" safe \" : \" 0 \" }" );
3223 }
3324
3425 public void testImageBuild () {
3526 WxCpMessage reply = WxCpMessage .IMAGE ().toUser ("OPENID" ).mediaId ("MEDIA_ID" ).build ();
36- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" image\" ,\" image\" :{\" media_id\" :\" MEDIA_ID\" }}" );
37- }
38-
39- public void testVoiceReply () {
40- WxCpMessage reply = new WxCpMessage ();
41- reply .setToUser ("OPENID" );
42- reply .setMsgType (WxConsts .CUSTOM_MSG_VOICE );
43- reply .setMediaId ("MEDIA_ID" );
44- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" voice\" ,\" voice\" :{\" media_id\" :\" MEDIA_ID\" }}" );
27+ assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" image\" ,\" image\" :{\" media_id\" :\" MEDIA_ID\" },\" safe\" :\" 0\" }" );
4528 }
4629
4730 public void testVoiceBuild () {
4831 WxCpMessage reply = WxCpMessage .VOICE ().toUser ("OPENID" ).mediaId ("MEDIA_ID" ).build ();
49- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" voice\" ,\" voice\" :{\" media_id\" :\" MEDIA_ID\" }}" );
50- }
51-
52- public void testVideoReply () {
53- WxCpMessage reply = new WxCpMessage ();
54- reply .setToUser ("OPENID" );
55- reply .setMsgType (WxConsts .CUSTOM_MSG_VIDEO );
56- reply .setMediaId ("MEDIA_ID" );
57- reply .setThumbMediaId ("MEDIA_ID" );
58- reply .setTitle ("TITLE" );
59- reply .setDescription ("DESCRIPTION" );
60- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" video\" ,\" video\" :{\" media_id\" :\" MEDIA_ID\" ,\" thumb_media_id\" :\" MEDIA_ID\" ,\" title\" :\" TITLE\" ,\" description\" :\" DESCRIPTION\" }}" );
32+ assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" voice\" ,\" voice\" :{\" media_id\" :\" MEDIA_ID\" },\" safe\" :\" 0\" }" );
6133 }
6234
6335 public void testVideoBuild () {
6436 WxCpMessage reply = WxCpMessage .VIDEO ().toUser ("OPENID" ).title ("TITLE" ).mediaId ("MEDIA_ID" ).thumbMediaId ("MEDIA_ID" ).description ("DESCRIPTION" ).build ();
65- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" video\" ,\" video\" :{\" media_id\" :\" MEDIA_ID\" ,\" thumb_media_id\" :\" MEDIA_ID\" ,\" title\" :\" TITLE\" ,\" description\" :\" DESCRIPTION\" }}" );
66- }
67-
68- public void testNewsReply () {
69- WxCpMessage reply = new WxCpMessage ();
70- reply .setToUser ("OPENID" );
71- reply .setMsgType (WxConsts .CUSTOM_MSG_NEWS );
72-
73- NewArticle article1 = new NewArticle ();
74- article1 .setUrl ("URL" );
75- article1 .setPicUrl ("PIC_URL" );
76- article1 .setDescription ("Is Really A Happy Day" );
77- article1 .setTitle ("Happy Day" );
78- reply .getArticles ().add (article1 );
79-
80- NewArticle article2 = new NewArticle ();
81- article2 .setUrl ("URL" );
82- article2 .setPicUrl ("PIC_URL" );
83- article2 .setDescription ("Is Really A Happy Day" );
84- article2 .setTitle ("Happy Day" );
85- reply .getArticles ().add (article2 );
86-
87-
88- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" news\" ,\" news\" :{\" articles\" :[{\" title\" :\" Happy Day\" ,\" description\" :\" Is Really A Happy Day\" ,\" url\" :\" URL\" ,\" picurl\" :\" PIC_URL\" },{\" title\" :\" Happy Day\" ,\" description\" :\" Is Really A Happy Day\" ,\" url\" :\" URL\" ,\" picurl\" :\" PIC_URL\" }]}}" );
37+ assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" video\" ,\" safe\" :\" 0\" ,\" video\" :{\" media_id\" :\" MEDIA_ID\" ,\" thumb_media_id\" :\" MEDIA_ID\" ,\" title\" :\" TITLE\" ,\" description\" :\" DESCRIPTION\" }}" );
8938 }
9039
9140 public void testNewsBuild () {
@@ -103,7 +52,7 @@ public void testNewsBuild() {
10352
10453 WxCpMessage reply = WxCpMessage .NEWS ().toUser ("OPENID" ).addArticle (article1 ).addArticle (article2 ).build ();
10554
106- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" news\" ,\" news\" :{\" articles\" :[{\" title\" :\" Happy Day\" ,\" description\" :\" Is Really A Happy Day\" ,\" url\" :\" URL\" ,\" picurl\" :\" PIC_URL\" },{\" title\" :\" Happy Day\" ,\" description\" :\" Is Really A Happy Day\" ,\" url\" :\" URL\" ,\" picurl\" :\" PIC_URL\" }]}}" );
55+ assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" news\" ,\" safe \" : \" 0 \" , \" news\" :{\" articles\" :[{\" title\" :\" Happy Day\" ,\" description\" :\" Is Really A Happy Day\" ,\" url\" :\" URL\" ,\" picurl\" :\" PIC_URL\" },{\" title\" :\" Happy Day\" ,\" description\" :\" Is Really A Happy Day\" ,\" url\" :\" URL\" ,\" picurl\" :\" PIC_URL\" }]}}" );
10756 }
10857
10958 public void testMpnewsBuild_with_articles () {
@@ -136,7 +85,7 @@ public void testMpnewsBuild_with_media_id() {
13685 WxCpMessage reply = WxCpMessage .MPNEWS ().toUser ("OPENID" ).mediaId ("mmm" ).build ();
13786
13887 assertEquals (reply .toJson (),
139- "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" mpnews\" ,\" mpnews\" :{\" media_id\" :\" mmm\" }}" );
88+ "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" mpnews\" ,\" safe \" : \" 0 \" , \" mpnews\" :{\" media_id\" :\" mmm\" }}" );
14089 }
14190
14291}
0 commit comments