View Javadoc
1   package com.foxinmy.weixin4j.qy.test;
2   
3   import org.junit.Before;
4   import org.junit.Test;
5   
6   import com.foxinmy.weixin4j.exception.WeixinException;
7   import com.foxinmy.weixin4j.qy.api.NotifyApi;
8   import com.foxinmy.weixin4j.qy.message.NotifyMessage;
9   import com.foxinmy.weixin4j.qy.model.IdParameter;
10  import com.foxinmy.weixin4j.tuple.File;
11  import com.foxinmy.weixin4j.tuple.Image;
12  import com.foxinmy.weixin4j.tuple.MpNews;
13  import com.foxinmy.weixin4j.tuple.News;
14  import com.foxinmy.weixin4j.tuple.Text;
15  import com.foxinmy.weixin4j.tuple.Video;
16  import com.foxinmy.weixin4j.tuple.Voice;
17  
18  /**
19   * 客服消息测试
20   * 
21   * @className NotifyTest
22   * @author jinyu(foxinmy@gmail.com)
23   * @date 2014年4月10日
24   * @since JDK 1.6
25   * @see
26   */
27  public class NotifyTest extends TokenTest {
28  
29  	private NotifyApi notifyApi;
30  
31  	@Before
32  	public void init() {
33  		notifyApi = new NotifyApi(tokenManager);
34  	}
35  
36  	@Test
37  	public void text() throws WeixinException {
38  		NotifyMessage notify = new NotifyMessage(40, new Text("content"));
39  		System.out.println(notifyApi.sendNotifyMessage(notify));
40  	}
41  
42  	@Test
43  	public void image() throws WeixinException {
44  		NotifyMessage notify = new NotifyMessage(0, new Image("123"));
45  		System.out.println(notifyApi.sendNotifyMessage(notify));
46  	}
47  
48  	@Test
49  	public void voice() throws WeixinException {
50  		NotifyMessage notify = new NotifyMessage(0, new Voice("123"));
51  		System.out.println(notifyApi.sendNotifyMessage(notify));
52  	}
53  
54  	@Test
55  	public void video() throws WeixinException {
56  		NotifyMessage notify = new NotifyMessage(0, new Video("mediaId",
57  				"title", "desc"));
58  		System.out.println(notifyApi.sendNotifyMessage(notify));
59  	}
60  
61  	@Test
62  	public void file() throws WeixinException {
63  		File file = new File("file");
64  		NotifyMessage notify = new NotifyMessage(0, file);
65  		System.out.println(notifyApi.sendNotifyMessage(notify));
66  	}
67  
68  	@Test
69  	public void news() throws WeixinException {
70  		News news = new News();
71  		NotifyMessage notify = new NotifyMessage(0, news);
72  		news.addArticle("title1", "desc1", "picUrl1", "url1");
73  		news.addArticle("title2", "desc2", "picUrl2", "url2");
74  		System.out.println(notifyApi.sendNotifyMessage(notify));
75  	}
76  
77  	@Test
78  	public void mpnews() throws WeixinException {
79  		MpNews news = new MpNews();
80  		NotifyMessage notify = new NotifyMessage(0, news);
81  		news.addArticle("thumbMediaId1", "title1", "content1");
82  		news.addArticle("thumbMediaId2", "title1", "content2");
83  		System.out.println(notifyApi.sendNotifyMessage(notify));
84  	}
85  
86  	@Test
87  	public void send1() throws WeixinException {
88  		Text text = new Text("this is a text");
89  		IdParameter result = notifyApi.sendNotifyMessage(new NotifyMessage(1,
90  				text));
91  		System.err.println(result);
92  	}
93  }