1 package com.foxinmy.weixin4j.mp.test;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.util.Calendar;
7 import java.util.Date;
8 import java.util.List;
9
10 import org.junit.Assert;
11 import org.junit.Before;
12 import org.junit.Test;
13
14 import com.foxinmy.weixin4j.exception.WeixinException;
15 import com.foxinmy.weixin4j.http.weixin.ApiResult;
16 import com.foxinmy.weixin4j.mp.api.CustomApi;
17 import com.foxinmy.weixin4j.mp.model.KfAccount;
18 import com.foxinmy.weixin4j.mp.model.KfChatRecord;
19 import com.foxinmy.weixin4j.mp.model.KfOnlineAccount;
20 import com.foxinmy.weixin4j.mp.model.KfSession;
21 import com.foxinmy.weixin4j.mp.model.KfSession.KfSessionCounter;
22
23
24
25
26
27
28
29
30
31
32 public class CustomTest extends TokenTest {
33
34 private CustomApi customApi;
35
36 @Before
37 public void init() {
38 customApi = new CustomApi(tokenManager);
39 }
40
41 @Test
42 public void kfChatRecord() throws WeixinException {
43 Calendar calendar = Calendar.getInstance();
44 calendar.set(Calendar.HOUR_OF_DAY, 9);
45 calendar.add(Calendar.DAY_OF_MONTH, -2);
46 Date starttime = calendar.getTime();
47 calendar.set(Calendar.HOUR_OF_DAY, 21);
48 Date endtime = calendar.getTime();
49 List<KfChatRecord> recordList = customApi.getKfChatRecord(starttime,
50 endtime, 10);
51 Assert.assertFalse(recordList.isEmpty());
52 System.out.println(recordList);
53 }
54
55 @Test
56 public void kfList() throws WeixinException {
57 List<KfAccount> kfList = customApi.listKfAccount();
58 Assert.assertFalse(kfList.isEmpty());
59 System.out.println(kfList);
60 List<KfOnlineAccount> kfOnlineList = customApi.listOnlineKfAccount();
61 Assert.assertFalse(kfOnlineList.isEmpty());
62 System.out.println(kfOnlineList);
63 }
64
65 @Test
66 public void createKfAccount() throws WeixinException {
67 ApiResult result = customApi.createKfAccount("test@test", "test");
68 Assert.assertEquals("0", result.getReturnCode());
69 }
70
71 @Test
72 public void updateKfAccount() throws WeixinException {
73 ApiResult result = customApi.updateKfAccount("temp1@canyidianzhang",
74 "temp");
75 Assert.assertEquals("0", result.getReturnCode());
76 }
77
78 @Test
79 public void uploadKfAvatar() throws WeixinException, IOException {
80 ApiResult result = customApi.uploadKfAvatar("temp1@canyidianzhang",
81 new FileInputStream(new File("/Users/jy/Music/简谱/风动草.jpg")),
82 "风动草.jpg");
83 Assert.assertEquals("0", result.getReturnCode());
84 }
85
86 @Test
87 public void deleteKfAccount() throws WeixinException, IOException {
88 ApiResult result = customApi.deleteKfAccount("temp@canyidianzhang");
89 Assert.assertEquals("0", result.getReturnCode());
90 }
91
92 @Test
93 public void createSession() throws WeixinException {
94 ApiResult result = customApi.createKfSession(
95 "opKwyt6IhrqPmTTZshyqH5W9gIVo", "kfAccount", "text");
96 Assert.assertEquals("0", result.getReturnCode());
97 }
98
99 @Test
100 public void closeSession() throws WeixinException {
101 ApiResult result = customApi.closeKfSession(
102 "opKwyt6IhrqPmTTZshyqH5W9gIVo", "kfAccount", "text");
103 Assert.assertEquals("0", result.getReturnCode());
104 }
105
106 @Test
107 public void getSession() throws WeixinException {
108 KfSession session = customApi
109 .getKfSession("oz5axuNnJim8yTYs_jzE1bWFj9eA");
110 System.err.println(session);
111 }
112
113 @Test
114 public void getSessionList() throws WeixinException {
115 List<KfSession> sessionList = customApi.listKfSession("kfAccount");
116 Assert.assertFalse(sessionList.isEmpty());
117 System.err.println(sessionList);
118 }
119
120 @Test
121 public void getSessionWaitList() throws WeixinException {
122 KfSessionCounter sessionCounter = customApi.listKfWaitSession();
123 System.err.println(sessionCounter);
124 }
125 }