1
1
package me .chanjar .weixin .mp .api ;
2
2
3
- import java .io .IOException ;
4
- import java .io .InputStream ;
5
-
6
- import org .testng .Assert ;
7
- import org .testng .annotations .DataProvider ;
8
- import org .testng .annotations .Guice ;
9
- import org .testng .annotations .Test ;
10
-
11
3
import com .google .inject .Inject ;
12
-
13
4
import me .chanjar .weixin .common .api .WxConsts ;
14
5
import me .chanjar .weixin .common .bean .result .WxMediaUploadResult ;
15
6
import me .chanjar .weixin .common .exception .WxErrorException ;
19
10
import me .chanjar .weixin .mp .bean .WxMpMassVideo ;
20
11
import me .chanjar .weixin .mp .bean .result .WxMpMassSendResult ;
21
12
import me .chanjar .weixin .mp .bean .result .WxMpMassUploadResult ;
13
+ import org .testng .Assert ;
14
+ import org .testng .annotations .DataProvider ;
15
+ import org .testng .annotations .Guice ;
16
+ import org .testng .annotations .Test ;
17
+
18
+ import java .io .IOException ;
19
+ import java .io .InputStream ;
22
20
23
21
/**
24
22
* 测试群发消息
25
- * @author chanjarster
26
23
*
24
+ * @author chanjarster
27
25
*/
28
- @ Test (groups = "massAPI" , dependsOnGroups = { "baseAPI" , "mediaAPI" , "groupAPI" })
26
+ @ Test (groups = "massAPI" , dependsOnGroups = {"baseAPI" , "mediaAPI" , "groupAPI" })
29
27
@ Guice (modules = ApiTestModule .class )
30
28
public class WxMpMassMessageAPITest {
31
29
@@ -36,60 +34,60 @@ public class WxMpMassMessageAPITest {
36
34
public void testTextMassOpenIdsMessageSend () throws WxErrorException {
37
35
// 发送群发消息
38
36
WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage ) this .wxService
39
- .getWxMpConfigStorage ();
37
+ .getWxMpConfigStorage ();
40
38
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage ();
41
39
massMessage .setMsgType (WxConsts .MASS_MSG_TEXT );
42
40
massMessage .setContent ("测试群发消息\n 欢迎欢迎,热烈欢迎\n 换行测试\n 超链接:<a href=\" http://www.baidu.com\" >Hello World</a>" );
43
41
massMessage .getToUsers ().add (configProvider .getOpenid ());
44
42
45
43
WxMpMassSendResult massResult = this .wxService
46
- .massOpenIdsMessageSend (massMessage );
44
+ .massOpenIdsMessageSend (massMessage );
47
45
Assert .assertNotNull (massResult );
48
46
Assert .assertNotNull (massResult .getMsgId ());
49
47
}
50
48
51
- @ Test (dataProvider = "massMessages" )
49
+ @ Test (dataProvider = "massMessages" )
52
50
public void testMediaMassOpenIdsMessageSend (String massMsgType ,
53
- String mediaId ) throws WxErrorException {
51
+ String mediaId ) throws WxErrorException {
54
52
// 发送群发消息
55
53
WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage ) this .wxService
56
- .getWxMpConfigStorage ();
54
+ .getWxMpConfigStorage ();
57
55
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage ();
58
56
massMessage .setMsgType (massMsgType );
59
57
massMessage .setMediaId (mediaId );
60
58
massMessage .getToUsers ().add (configProvider .getOpenid ());
61
59
62
60
WxMpMassSendResult massResult = this .wxService
63
- .massOpenIdsMessageSend (massMessage );
61
+ .massOpenIdsMessageSend (massMessage );
64
62
Assert .assertNotNull (massResult );
65
63
Assert .assertNotNull (massResult .getMsgId ());
66
64
}
67
65
68
66
@ Test
69
67
public void testTextMassGroupMessageSend () throws WxErrorException {
70
68
WxMpMassTagMessage massMessage = new WxMpMassTagMessage ();
71
- massMessage .setMsgtype (WxConsts .MASS_MSG_TEXT );
69
+ massMessage .setMsgType (WxConsts .MASS_MSG_TEXT );
72
70
massMessage .setContent ("测试群发消息\n 欢迎欢迎,热烈欢迎\n 换行测试\n 超链接:<a href=\" http://www.baidu.com\" >Hello World</a>" );
73
71
massMessage
74
- .setTagId (this .wxService .getUserTagService ().tagGet ().get (0 ).getId ());
72
+ .setTagId (this .wxService .getUserTagService ().tagGet ().get (0 ).getId ());
75
73
76
74
WxMpMassSendResult massResult = this .wxService
77
- .massGroupMessageSend (massMessage );
75
+ .massGroupMessageSend (massMessage );
78
76
Assert .assertNotNull (massResult );
79
77
Assert .assertNotNull (massResult .getMsgId ());
80
78
}
81
79
82
- @ Test (dataProvider = "massMessages" )
80
+ @ Test (dataProvider = "massMessages" )
83
81
public void testMediaMassGroupMessageSend (String massMsgType , String mediaId )
84
- throws WxErrorException {
82
+ throws WxErrorException {
85
83
WxMpMassTagMessage massMessage = new WxMpMassTagMessage ();
86
- massMessage .setMsgtype (massMsgType );
84
+ massMessage .setMsgType (massMsgType );
87
85
massMessage .setMediaId (mediaId );
88
86
massMessage
89
- .setTagId (this .wxService .getUserTagService ().tagGet ().get (0 ).getId ());
87
+ .setTagId (this .wxService .getUserTagService ().tagGet ().get (0 ).getId ());
90
88
91
89
WxMpMassSendResult massResult = this .wxService
92
- .massGroupMessageSend (massMessage );
90
+ .massGroupMessageSend (massMessage );
93
91
Assert .assertNotNull (massResult );
94
92
Assert .assertNotNull (massResult .getMsgId ());
95
93
}
@@ -102,10 +100,10 @@ public Object[][] massMessages() throws WxErrorException, IOException {
102
100
* 视频素材
103
101
*/
104
102
try (InputStream inputStream = ClassLoader
105
- .getSystemResourceAsStream ("mm.mp4" )) {
103
+ .getSystemResourceAsStream ("mm.mp4" )) {
106
104
// 上传视频到媒体库
107
105
WxMediaUploadResult uploadMediaRes = this .wxService .getMaterialService ()
108
- .mediaUpload (WxConsts .MEDIA_VIDEO , WxConsts .FILE_MP4 , inputStream );
106
+ .mediaUpload (WxConsts .MEDIA_VIDEO , WxConsts .FILE_MP4 , inputStream );
109
107
Assert .assertNotNull (uploadMediaRes );
110
108
Assert .assertNotNull (uploadMediaRes .getMediaId ());
111
109
@@ -117,41 +115,41 @@ public Object[][] massMessages() throws WxErrorException, IOException {
117
115
WxMpMassUploadResult uploadResult = this .wxService .massVideoUpload (video );
118
116
Assert .assertNotNull (uploadResult );
119
117
Assert .assertNotNull (uploadResult .getMediaId ());
120
- messages [0 ] = new Object [] { WxConsts .MASS_MSG_VIDEO , uploadResult .getMediaId () };
118
+ messages [0 ] = new Object []{ WxConsts .MASS_MSG_VIDEO , uploadResult .getMediaId ()};
121
119
}
122
120
123
121
/**
124
122
* 图片素材
125
123
*/
126
124
try (InputStream inputStream = ClassLoader
127
- .getSystemResourceAsStream ("mm.jpeg" )) {
125
+ .getSystemResourceAsStream ("mm.jpeg" )) {
128
126
WxMediaUploadResult uploadMediaRes = this .wxService .getMaterialService ()
129
- .mediaUpload (WxConsts .MEDIA_IMAGE , WxConsts .FILE_JPG , inputStream );
127
+ .mediaUpload (WxConsts .MEDIA_IMAGE , WxConsts .FILE_JPG , inputStream );
130
128
Assert .assertNotNull (uploadMediaRes );
131
129
Assert .assertNotNull (uploadMediaRes .getMediaId ());
132
- messages [1 ] = new Object [] { WxConsts .MASS_MSG_IMAGE , uploadMediaRes .getMediaId () };
130
+ messages [1 ] = new Object []{ WxConsts .MASS_MSG_IMAGE , uploadMediaRes .getMediaId ()};
133
131
}
134
132
135
133
/**
136
134
* 语音素材
137
135
*/
138
136
try (InputStream inputStream = ClassLoader
139
- .getSystemResourceAsStream ("mm.mp3" )) {
137
+ .getSystemResourceAsStream ("mm.mp3" )) {
140
138
WxMediaUploadResult uploadMediaRes = this .wxService .getMaterialService ()
141
- .mediaUpload (WxConsts .MEDIA_VOICE , WxConsts .FILE_MP3 , inputStream );
139
+ .mediaUpload (WxConsts .MEDIA_VOICE , WxConsts .FILE_MP3 , inputStream );
142
140
Assert .assertNotNull (uploadMediaRes );
143
141
Assert .assertNotNull (uploadMediaRes .getMediaId ());
144
- messages [2 ] = new Object [] { WxConsts .MASS_MSG_VOICE , uploadMediaRes .getMediaId () };
142
+ messages [2 ] = new Object []{ WxConsts .MASS_MSG_VOICE , uploadMediaRes .getMediaId ()};
145
143
}
146
144
147
145
/**
148
146
* 图文素材
149
147
*/
150
148
try (InputStream inputStream = ClassLoader
151
- .getSystemResourceAsStream ("mm.jpeg" )) {
149
+ .getSystemResourceAsStream ("mm.jpeg" )) {
152
150
// 上传照片到媒体库
153
151
WxMediaUploadResult uploadMediaRes = this .wxService .getMaterialService ()
154
- .mediaUpload (WxConsts .MEDIA_IMAGE , WxConsts .FILE_JPG , inputStream );
152
+ .mediaUpload (WxConsts .MEDIA_IMAGE , WxConsts .FILE_JPG , inputStream );
155
153
Assert .assertNotNull (uploadMediaRes );
156
154
Assert .assertNotNull (uploadMediaRes .getMediaId ());
157
155
@@ -174,10 +172,10 @@ public Object[][] massMessages() throws WxErrorException, IOException {
174
172
news .addArticle (article2 );
175
173
176
174
WxMpMassUploadResult massUploadResult = this .wxService
177
- .massNewsUpload (news );
175
+ .massNewsUpload (news );
178
176
Assert .assertNotNull (massUploadResult );
179
177
Assert .assertNotNull (uploadMediaRes .getMediaId ());
180
- messages [3 ] = new Object [] { WxConsts .MASS_MSG_NEWS , massUploadResult .getMediaId () };
178
+ messages [3 ] = new Object []{ WxConsts .MASS_MSG_NEWS , massUploadResult .getMediaId ()};
181
179
}
182
180
183
181
return messages ;
0 commit comments