|
|
@@ -1,271 +0,0 @@
|
|
1
|
|
-package TestDate;
|
|
2
|
|
-
|
|
3
|
|
-import com.alibaba.fastjson2.JSON;
|
|
4
|
|
-import com.alibaba.fastjson2.JSONObject;
|
|
5
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
6
|
|
-import com.example.WebApiApplication;
|
|
7
|
|
-import com.example.entity.database.system.Menu;
|
|
8
|
|
-import com.example.entity.database.system.User;
|
|
9
|
|
-import com.example.entity.view.system.GroupLogins;
|
|
10
|
|
-import com.example.service.rabbitmqListener.Consumer;
|
|
11
|
|
-import com.example.service.rabbitmqListener.PicDownload;
|
|
12
|
|
-import com.example.service.system.IMenuService;
|
|
13
|
|
-import com.example.service.system.IUserService;
|
|
14
|
|
-import com.example.service.webScoket.WebSocket;
|
|
15
|
|
-import com.example.util.config.RabbitConfig;
|
|
16
|
|
-import com.example.util.config.WxMpConfig;
|
|
17
|
|
-import com.example.util.helper.RedisHelper;
|
|
18
|
|
-import com.rabbitmq.client.Channel;
|
|
19
|
|
-import com.rabbitmq.client.Connection;
|
|
20
|
|
-import com.rabbitmq.client.GetResponse;
|
|
21
|
|
-import me.chanjar.weixin.common.error.WxErrorException;
|
|
22
|
|
-import me.chanjar.weixin.mp.api.WxMpService;
|
|
23
|
|
-import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
|
24
|
|
-import org.junit.Test;
|
|
25
|
|
-import org.junit.runner.RunWith;
|
|
26
|
|
-import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
27
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
28
|
|
-import org.springframework.boot.test.context.SpringBootTest;
|
|
29
|
|
-import org.springframework.data.mongodb.core.MongoTemplate;
|
|
30
|
|
-import org.springframework.test.context.junit4.SpringRunner;
|
|
31
|
|
-import org.springframework.web.context.request.RequestContextHolder;
|
|
32
|
|
-import org.springframework.web.socket.WebSocketSession;
|
|
33
|
|
-
|
|
34
|
|
-import java.io.*;
|
|
35
|
|
-import java.net.URL;
|
|
36
|
|
-import java.net.URLConnection;
|
|
37
|
|
-import java.nio.charset.StandardCharsets;
|
|
38
|
|
-import java.text.SimpleDateFormat;
|
|
39
|
|
-import java.util.*;
|
|
40
|
|
-
|
|
41
|
|
-@SpringBootTest(classes = WebApiApplication.class)
|
|
42
|
|
-@RunWith(SpringRunner.class)
|
|
43
|
|
-public class TestDateInput {
|
|
44
|
|
- @Autowired
|
|
45
|
|
- public IMenuService menuService;
|
|
46
|
|
- @Autowired
|
|
47
|
|
- public WxMpService wxMpService;
|
|
48
|
|
- @Autowired
|
|
49
|
|
- public RedisHelper redisHelper;
|
|
50
|
|
- @Autowired
|
|
51
|
|
- public RabbitTemplate rabbitTemplate;
|
|
52
|
|
- @Autowired
|
|
53
|
|
- public Consumer consumer;
|
|
54
|
|
- @Autowired
|
|
55
|
|
- public MongoTemplate mongoTemplate;
|
|
56
|
|
- @Autowired
|
|
57
|
|
- private WebSocket webSocket;
|
|
58
|
|
- @Autowired
|
|
59
|
|
- private IUserService userService;
|
|
60
|
|
- @Test
|
|
61
|
|
- public void test1() {
|
|
62
|
|
- Calendar oldCal = Calendar.getInstance();
|
|
63
|
|
- oldCal.setTime(new Date());
|
|
64
|
|
- oldCal.add(2, -1);
|
|
65
|
|
-
|
|
66
|
|
- Calendar nowCal = Calendar.getInstance();
|
|
67
|
|
- nowCal.setTime(new Date());
|
|
68
|
|
- System.out.println(nowCal.after(oldCal));
|
|
69
|
|
- if (nowCal.after(oldCal)) {
|
|
70
|
|
- System.out.println(true);
|
|
71
|
|
- } else {
|
|
72
|
|
- System.out.println(false);
|
|
73
|
|
- }
|
|
74
|
|
-
|
|
75
|
|
-
|
|
76
|
|
- }
|
|
77
|
|
-
|
|
78
|
|
- @Test
|
|
79
|
|
- public void test2() {
|
|
80
|
|
- List<Menu> menus = menuService.selectMenuTreeByUserId(2l);
|
|
81
|
|
- System.out.println(menus);
|
|
82
|
|
- }
|
|
83
|
|
-
|
|
84
|
|
- @Test
|
|
85
|
|
- public void test3() {
|
|
86
|
|
- String cache = redisHelper.getCache("orR6E6l4wDixgeO8iaDetMoeb3hs");
|
|
87
|
|
- System.out.println(cache);
|
|
88
|
|
- }
|
|
89
|
|
-
|
|
90
|
|
- @Test
|
|
91
|
|
- public void test223() {
|
|
92
|
|
- LambdaQueryWrapper<User> qw = new LambdaQueryWrapper<>();
|
|
93
|
|
- qw.eq(User::getUserId,"1");
|
|
94
|
|
- User entity = userService.getEntity(qw);
|
|
95
|
|
- System.out.println(entity);
|
|
96
|
|
- }
|
|
97
|
|
-
|
|
98
|
|
-
|
|
99
|
|
- @Test
|
|
100
|
|
- public void test222() {
|
|
101
|
|
-
|
|
102
|
|
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
103
|
|
- //String format = simpleDateFormat.format(createTime);
|
|
104
|
|
- }
|
|
105
|
|
-
|
|
106
|
|
- @Test
|
|
107
|
|
- public void Test777() throws IOException {
|
|
108
|
|
- //创建连接
|
|
109
|
|
- Connection connection = RabbitConfig.getConnection();
|
|
110
|
|
- //创建消息信道
|
|
111
|
|
- Channel channel = connection.createChannel();
|
|
112
|
|
- GetResponse groupQueue = channel.basicGet("group_queue", true);
|
|
113
|
|
- String groupMessage = new String(groupQueue.getBody());
|
|
114
|
|
- GroupLogins groupLogins = JSON.parseObject(groupMessage, GroupLogins.class);
|
|
115
|
|
- Long workNumber = groupLogins.getWorkNumber();
|
|
116
|
|
-
|
|
117
|
|
- Map<String, Object> map = new HashMap<>();
|
|
118
|
|
- map.put("id", groupLogins.getId());
|
|
119
|
|
- map.put("userName", groupLogins.getUserName());
|
|
120
|
|
- map.put("workNumber", groupLogins.getWorkNumber());
|
|
121
|
|
- map.put("status", groupLogins.getStatus());
|
|
122
|
|
- rabbitTemplate.convertAndSend("group_queue", map);
|
|
123
|
|
- }
|
|
124
|
|
-
|
|
125
|
|
- @Test
|
|
126
|
|
- public void test66() {
|
|
127
|
|
- Map<String, Object> map = new HashMap<>();
|
|
128
|
|
- map.put("id", "1");
|
|
129
|
|
- map.put("type", "1");
|
|
130
|
|
- map.put("formUser", "1");
|
|
131
|
|
- map.put("appId", "1");
|
|
132
|
|
- map.put("openId", "1");
|
|
133
|
|
- map.put("sendTime", 1);
|
|
134
|
|
- map.put("content", "1");
|
|
135
|
|
- rabbitTemplate.convertAndSend("message_queue", map);
|
|
136
|
|
- }
|
|
137
|
|
-
|
|
138
|
|
- @Test
|
|
139
|
|
- public void Test() {
|
|
140
|
|
- WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser("orR6E6l4wDixgeO8iaDetMoeb3hs").content("content").build();
|
|
141
|
|
- try {
|
|
142
|
|
- wxMpService.getKefuService().sendKefuMessage(message);
|
|
143
|
|
- } catch (WxErrorException e) {
|
|
144
|
|
- e.printStackTrace();
|
|
145
|
|
- }
|
|
146
|
|
- }
|
|
147
|
|
- @Test
|
|
148
|
|
- public void Teswdadt() {
|
|
149
|
|
- Set<WebSocketSession> sessions = webSocket.getSessions();
|
|
150
|
|
- System.out.println(sessions);
|
|
151
|
|
- }
|
|
152
|
|
-
|
|
153
|
|
- @Test
|
|
154
|
|
- public void Test2() {
|
|
155
|
|
- //String cache = redisHelper.getCache("onLineKefu");
|
|
156
|
|
- //JSONObject jsonObject = JSON.parseObject(cache);
|
|
157
|
|
- //UserView userView = new UserView();
|
|
158
|
|
- List<GroupLogins> groupLoginsList = new ArrayList<>();
|
|
159
|
|
- GroupLogins groupLogins = new GroupLogins();
|
|
160
|
|
- groupLogins.setWorkNumber(1l);
|
|
161
|
|
- groupLogins.setUserName("admin");
|
|
162
|
|
- groupLogins.setStatus("0");
|
|
163
|
|
- groupLoginsList.add(groupLogins);
|
|
164
|
|
- //userView.setGroupLogins(groupLoginsList);
|
|
165
|
|
- redisHelper.setCache("onLineKefu", JSON.toJSONString(groupLoginsList));
|
|
166
|
|
- }
|
|
167
|
|
-
|
|
168
|
|
- @Test
|
|
169
|
|
- public void Test3() {
|
|
170
|
|
- String cache = redisHelper.getCache("onLineKefu");
|
|
171
|
|
- List<GroupLogins> groupLoginsList = JSON.parseArray(cache, GroupLogins.class);
|
|
172
|
|
- System.out.println(groupLoginsList);
|
|
173
|
|
- //UserView userView = new UserView();
|
|
174
|
|
- GroupLogins groupLogins = new GroupLogins();
|
|
175
|
|
- groupLogins.setWorkNumber(2l);
|
|
176
|
|
- groupLogins.setUserName("admindd");
|
|
177
|
|
- groupLogins.setStatus("0");
|
|
178
|
|
- groupLoginsList.add(groupLogins);
|
|
179
|
|
- //userView.setGroupLogins(groupLoginsList);
|
|
180
|
|
- redisHelper.setCache("onLineKefu", JSON.toJSONString(groupLoginsList));
|
|
181
|
|
- }
|
|
182
|
|
-
|
|
183
|
|
- @Test
|
|
184
|
|
- public void Tes222t() {
|
|
185
|
|
- File file = null;
|
|
186
|
|
- try {
|
|
187
|
|
- file = wxMpService.getMaterialService().mediaDownload("sFooQ4TojSWPTePnfYo3eQmsJbBU1mdfLAxucQkg5RPaFeQWwcvr19TpCZIHz3lq");
|
|
188
|
|
- System.out.println(file);
|
|
189
|
|
- } catch (WxErrorException e) {
|
|
190
|
|
- e.printStackTrace();
|
|
191
|
|
- }
|
|
192
|
|
- }
|
|
193
|
|
-
|
|
194
|
|
-
|
|
195
|
|
- @Test
|
|
196
|
|
- public void Tes22222t() {
|
|
197
|
|
- File file = null;
|
|
198
|
|
- try {
|
|
199
|
|
- file = wxMpService.getMaterialService().mediaDownload("sFooQ4TojSWPTePnfYo3eQmsJbBU1mdfLAxucQkg5RPaFeQWwcvr19TpCZIHz3lq");
|
|
200
|
|
- System.out.println(file);
|
|
201
|
|
- } catch (WxErrorException e) {
|
|
202
|
|
- e.printStackTrace();
|
|
203
|
|
- }
|
|
204
|
|
- }
|
|
205
|
|
-
|
|
206
|
|
- @Test
|
|
207
|
|
- public void Tes22222wwt() {
|
|
208
|
|
- WxMpConfig wxMpConfig = new WxMpConfig();
|
|
209
|
|
- String accessTokenMethod = getAccessTokenMethod(wxMpConfig.wxMpDefaultConfigImpl().getAppId(), wxMpConfig.wxMpDefaultConfigImpl().getSecret());
|
|
210
|
|
- System.out.println(accessTokenMethod);
|
|
211
|
|
- }
|
|
212
|
|
-
|
|
213
|
|
- @Test
|
|
214
|
|
- public void Tes22222222wwt() {
|
|
215
|
|
- Object currentUser = RequestContextHolder.getRequestAttributes().getAttribute("CurrentUser", 0);
|
|
216
|
|
- System.out.println(currentUser);
|
|
217
|
|
- }
|
|
218
|
|
-
|
|
219
|
|
- @Test
|
|
220
|
|
- public void Tes22www222wwt() throws IOException {
|
|
221
|
|
- WxMpConfig wxMpConfig = new WxMpConfig();
|
|
222
|
|
- String accessTokenMethod = getAccessTokenMethod(wxMpConfig.wxMpDefaultConfigImpl().getAppId(), wxMpConfig.wxMpDefaultConfigImpl().getSecret());
|
|
223
|
|
- InputStream inputStream = PicDownload.fetchTmpFile("E5Jzo_ybkPFXDHIrCMjubZU8I_47YaUpPoreV7DsBWZHFOmz1sWj9w9X3YO4lB26", "image", accessTokenMethod);
|
|
224
|
|
- byte[] flash = new byte[inputStream.available()];
|
|
225
|
|
- inputStream.read(flash);
|
|
226
|
|
- //二进制转化为图片
|
|
227
|
|
- try (FileOutputStream fileOutputStream = new FileOutputStream(new File("C:/Users/2.jpg"));) {
|
|
228
|
|
- fileOutputStream.write(flash);
|
|
229
|
|
- } catch (IOException e) {
|
|
230
|
|
- e.printStackTrace();
|
|
231
|
|
- }
|
|
232
|
|
- }
|
|
233
|
|
-
|
|
234
|
|
-
|
|
235
|
|
- /**
|
|
236
|
|
- * 获取AccessToken
|
|
237
|
|
- *
|
|
238
|
|
- * @param appId 填写公众号的appid
|
|
239
|
|
- * @param appSecret 填写公众号的开发者密码(AppSecret)
|
|
240
|
|
- * @return
|
|
241
|
|
- */
|
|
242
|
|
- public String getAccessTokenMethod(String appId, String appSecret) {
|
|
243
|
|
- try {
|
|
244
|
|
- String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" +
|
|
245
|
|
- appId + "&secret=" + appSecret;
|
|
246
|
|
-
|
|
247
|
|
- StringBuilder json = new StringBuilder();
|
|
248
|
|
- URL oracle = new URL(url);
|
|
249
|
|
- URLConnection yc = oracle.openConnection();
|
|
250
|
|
- BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream(), StandardCharsets.UTF_8));
|
|
251
|
|
- String inputLine = null;
|
|
252
|
|
- while ((inputLine = in.readLine()) != null) {
|
|
253
|
|
- json.append(inputLine);
|
|
254
|
|
- }
|
|
255
|
|
- in.close();
|
|
256
|
|
- JSONObject object = (JSONObject) JSONObject.parse(String.valueOf(json));
|
|
257
|
|
- //log.info(title + "==>" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "获取access_token:{}", object.getString("access_token"));
|
|
258
|
|
- if (object.getString("access_token") != null) {
|
|
259
|
|
-
|
|
260
|
|
- return object.getString("access_token");
|
|
261
|
|
- }
|
|
262
|
|
- return null;
|
|
263
|
|
-
|
|
264
|
|
- } catch (Exception e) {
|
|
265
|
|
- // log.error("获取accessToken异常" + e.getMessage());
|
|
266
|
|
- return null;
|
|
267
|
|
- }
|
|
268
|
|
- }
|
|
269
|
|
-
|
|
270
|
|
-
|
|
271
|
|
-}
|