FeiShuEventController.java
4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.pipihelper.project.feishu.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.FeiShuEventDTO;
import com.pipihelper.project.feishu.dto.FeiShuMsgCardEventDTO;
import com.pipihelper.project.feishu.dto.chat.FeiShuChatDTO;
import com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO;
import com.pipihelper.project.feishu.service.EmployeeService;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.feishu.service.FeiShuEventService;
import com.pipihelper.project.feishu.utils.FeiShuEventDataDecrypter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* @Description: TODO
* @author: charles
* @date: 2022年03月30日 17:39
*/
@RestController
@RequestMapping("/pipitest/feishu")
public class FeiShuEventController {
@Resource
private FeiShuConfig feiShuConfig;
@Resource
private FeiShuEventService feiShuEventService;
@Autowired
private FeiShuApiService feiShuApiService;
@Autowired
private EmployeeService employeeService;
@PostMapping("/event")
public JSONObject event(@RequestBody String s) throws Exception {
JSONObject reqJsonObject = JSON.parseObject(s);
System.out.println(s);
FeiShuEventDataDecrypter d = new FeiShuEventDataDecrypter(feiShuConfig.getEncryptKey());
JSONObject encryptJsonObject = JSON.parseObject(d.decrypt(reqJsonObject.getString("encrypt")));
System.out.println(encryptJsonObject);
if (encryptJsonObject.containsKey("challenge")) {
return encryptJsonObject;
}
FeiShuEventDTO feiShuEventDTO = encryptJsonObject.toJavaObject(FeiShuEventDTO.class);
if (!feiShuEventDTO.getHeader().getToken().equalsIgnoreCase(feiShuConfig.getVerificationToken())) {
return null;
}
if ("im.message.receive_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) {
// feiShuEventService.imMessageReceiveV1(feiShuEventDTO);
} else if ("im.message.message_read_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) {
// feiShuEventService.imMessageMessageReadV1(feiShuEventDTO);
}
return null;
}
@PostMapping("/msg_card")
public JSONObject msgCardEvent(@RequestBody String s) throws Exception {
JSONObject reqJsonObject = JSON.parseObject(s);
System.out.println(s);
if (reqJsonObject.containsKey("challenge")) {
return reqJsonObject;
}
FeiShuMsgCardEventDTO feiShuMsgCardEventDTO = reqJsonObject.toJavaObject(FeiShuMsgCardEventDTO.class);
String actionType = feiShuMsgCardEventDTO.getAction().getValue().getKey().split("\\.")[0];
/* switch (actionType) {
case "massage-singel":*/
//
//// default:
//// }
// }
return null;
}
@PostMapping("/employee-list")
public Object event() {
//employeeService.uprsetAllEmployee();
List<FeiShuEmployeeDTO> dtos = feiShuApiService.getEmployeeList();
return dtos;
}
@PostMapping("/department")
public Object department(String department) {
return feiShuApiService.getDepartment(department);
}
@PostMapping("/create-chart")
public Object createChatList(String department) {
FeiShuChatDTO feiShuChatDTO = new FeiShuChatDTO();
feiShuChatDTO.setName("按摩群");
feiShuChatDTO.setOwnerId("ou_5d72916b0a0b800b0fff6861eb52cf13");
ArrayList<String> strings = Lists.newArrayList("ou_5d72916b0a0b800b0fff6861eb52cf13", "ou_59498f75298812fbbed4de46fc5462e3"
, "ou_aa066da071443aefb2351ee248190583", "ou_5f30c2076fc2c5a5225bfdbb2da1ea6f", "ou_c902848a93e19928043a7fa38bef295b");
String[] userIds = new String[strings.size()];
for (int i = 0; i < strings.size(); i++) {
userIds[i] = strings.get(i);
}
feiShuChatDTO.setUserIdList(userIds);
return feiShuApiService.createChatList(feiShuChatDTO);
}
@PostMapping("/join-chart")
public Object joinChatList(String openId) {
FeiShuChatDTO feiShuChatDTO = new FeiShuChatDTO();
feiShuChatDTO.setChatId("oc_398c8c0b88421980d840db157c14ec20");
feiShuChatDTO.setIdList(new String[]{openId});
return feiShuApiService.joinChatList(feiShuChatDTO);
}
}