WorkWechatOAManager.java
9.04 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package cn.com.glsx.wechatbuild.manager;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.scrm.wechat.dto.workwechat.media.response.GetWorkWechatMediaResponseDTO;
import cn.com.glsx.scrm.wechat.enums.WorkWechatMediaTypeEnum;
import cn.com.glsx.wechatbuild.Constants.oa.WorkWechatOAConstants;
import cn.com.glsx.wechatbuild.config.WechatApiUrlConfig;
import cn.com.glsx.wechatbuild.model.*;
import cn.com.glsx.wechatbuild.model.request.oa.*;
import cn.com.glsx.wechatbuild.model.request.oa.approval.GetWorkWechatApprovalInfoRequestDTO;
import cn.com.glsx.wechatbuild.model.response.oa.*;
import cn.com.glsx.wechatbuild.util.HttpUtils;
import com.alibaba.fastjson.JSON;
import java.text.MessageFormat;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.oreframework.util.http.HttpUtil;
import org.oreframework.util.json.JacksonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.io.*;
import java.nio.file.Files;
import java.util.UUID;
/**
* @author chizw
* @version ver.1.0.0
* @Description
* @create 2025/2/13 16:32
*/
@Component
@Slf4j
public class WorkWechatOAManager {
@Autowired
private TokenManager tokenManager;
/**
* @Description 获取审批模板详情
* @author chizw
* @create 2025/2/13 16:59
* @version ver.1.0.0
*/
public WorkWechatOAGetTemplateDetailResponseDTO getTemplateDetail(
WorkWechatOAGetTemplateDetailRequestDTO request) {
try {
String url = WechatApiUrlConfig.getApi(WorkWechatOAConstants.OA_GET_TEMPLATE_DETAIL_PATH,
tokenManager.getAccessToken(request));
String body = JacksonUtils.beanToJson(request);
log.info("work wechat oa get template detail request url:{},body:{}", url, body);
String response = HttpUtils.post(url, body,null);
log.info("work wechat oa get template detail response:{}", response);
return JacksonUtils.jsonCastBean(response, WorkWechatOAGetTemplateDetailResponseDTO.class);
} catch (RpcServiceException e) {
throw new RpcServiceException(e.getErrId(), e.getMessage());
} catch (Exception e) {
log.error("work wechat oa get template detail error:{}", e.getMessage(), e);
throw new RpcServiceException(WechatErrorEnum.SERVER_ERROR, e.getMessage());
}
}
/**
* @Description 提交审批申请
* @author chizw
* @create 2025/2/17 16:10
* @version ver.1.0.0
*/
public WorkWechatOAApplyEventResponseDTO applyEvent(
WorkWechatOAApplyEventRequestDTO request) {
try {
String url = WechatApiUrlConfig.getApi(WorkWechatOAConstants.OA_APPLY_EVENT_PATH,
tokenManager.getAccessToken(request));
String body = JacksonUtils.beanToJson(request);
log.info("work wechat oa apply event request url:{},body:{}", url, body);
String response = HttpUtils.post(url, body,null);
log.info("work wechat oa apply event response:{}", response);
return JacksonUtils.jsonCastBean(response, WorkWechatOAApplyEventResponseDTO.class);
} catch (RpcServiceException e) {
throw new RpcServiceException(e.getErrId(), e.getMessage());
} catch (Exception e) {
log.error("work wechat oa apply event error:{}", e.getMessage(), e);
throw new RpcServiceException(WechatErrorEnum.SERVER_ERROR, e.getMessage());
}
}
public static void main(String[] args) throws IOException {
String token = "zcOftjvhm-rPlsqrB6N2rmXYGrxXUYd3spCBThEfj22HpcbPNfgY_mtK87nvQUA9lHZ3iPme-9Wa_W1zIeCfrlxhzFhgjWgcVNx77_gf6INqdga3fabPt8Q-8LhAushhUJJMGukMnxMaA6ZlRNP-5AdHxc3A1MvFdEmKa5zgy7zXUY0Cg5L9lTTzSRKxLi5Rlci3GG_StdadFD2slxosmw";
String url = "https://qyapi.weixin.qq.com/cgi-bin/oa/getapprovaldetail?access_token=" + token;
String body = "{\"sp_no\":\"202504220009\"}";
String response = HttpUtil.post(url, body);
System.out.println(JSON.toJSONString(response));
WorkWechatOAGetApprovalDetailResponseDTO dto = JacksonUtils.jsonCastBean(response, WorkWechatOAGetApprovalDetailResponseDTO.class);
System.out.println(JSON.toJSONString(dto));
}
/**
* @Description 获取审批申请详情
* @author chizw
* @create 2025/2/17 16:10
* @version ver.1.0.0
*/
public WorkWechatOAGetApprovalDetailResponseDTO getApprovalDetail(
WorkWechatOAGetApprovalDetailRequestDTO request) {
try {
String url = WechatApiUrlConfig.getApi(WorkWechatOAConstants.OA_GET_APPROVAL_DETAIL_PATH,
tokenManager.getAccessToken(request));
String body = JacksonUtils.beanToJson(request);
log.info("work wechat oa get approval detail request url:{},body:{}", url, body);
String response = HttpUtils.post(url, body,null);
log.info("work wechat oa get approval detail response:{}", response);
return JacksonUtils.jsonCastBean(response, WorkWechatOAGetApprovalDetailResponseDTO.class);
} catch (RpcServiceException e) {
throw new RpcServiceException(e.getErrId(), e.getMessage());
} catch (Exception e) {
log.error("work wechat oa get approval detail error:{}", e.getMessage(), e);
throw new RpcServiceException(WechatErrorEnum.SERVER_ERROR, e.getMessage());
}
}
/**
* @Description 获取审批申请详情
* @author chizw
* @create 2025/2/17 16:10
* @version ver.1.0.0
*/
public UploadWorkUserGetuseridResponseDTO getuserid(WorkWechatUserGetuseridRequestDTO request) {
try {
String url = WechatApiUrlConfig.getApi(WorkWechatOAConstants.GET_USERID_PATH,
tokenManager.getAccessToken(request));
String body = JacksonUtils.beanToJson(request);
log.info("work wechat user getuserid request url:{},body:{}", url, body);
String response = HttpUtils.post(url, body, null);
log.info("work wechat user getuserid detail response:{}", response);
return JacksonUtils.jsonCastBean(response, UploadWorkUserGetuseridResponseDTO.class);
} catch (RpcServiceException e) {
throw new RpcServiceException(e.getErrId(), e.getMessage());
} catch (Exception e) {
log.error("work wechat user getuserid detail error:{}", e.getMessage(), e);
throw new RpcServiceException(WechatErrorEnum.SERVER_ERROR, e.getMessage());
}
}
public WorkWechatOAApprovalInfoResponseDTO getapprovalinfo(
GetWorkWechatApprovalInfoRequestDTO getWorkWechatApprovalInfoRequestDTO) {
try{
String url = MessageFormat.format(WorkWechatOAConstants.WW_GETAPPROVALINFO_PATH, tokenManager.getAccessToken(new WorkWechatBaseRequestDTO(getWorkWechatApprovalInfoRequestDTO.getMerchantId())));
String body = JacksonUtils.beanToJson(getWorkWechatApprovalInfoRequestDTO);
log.info("send work wechat message request url:{}, body:{}", url, body);
String response = HttpUtils.post(url, body,null);
log.info("send work wechat message response:{}", response);
return JacksonUtils.jsonCastBean(response, WorkWechatOAApprovalInfoResponseDTO.class);
}catch(Exception e){
log.error("send work wechat message error:{}", e.getMessage(), e);
throw new RpcServiceException(cn.com.glsx.scrm.wechat.enums.WechatErrorEnum.SEND_WORK_WECHAT_MESSAGE_FAILED, e);
}
}
/**
* @Description 获取审批申请详情独立
* @author chizw
* @create 2025/2/17 16:10
* @version ver.1.0.0
*/
public WorkWechatOAGetApprovalDetailSingleResponseDTO getApprovalDetailSingle(
WorkWechatOAGetApprovalDetailRequestDTO request) {
try {
String url = WechatApiUrlConfig.getApi(WorkWechatOAConstants.OA_GET_APPROVAL_DETAIL_PATH,
tokenManager.getAccessToken(request));
String body = JacksonUtils.beanToJson(request);
log.info("work wechat oa get approval detail request url:{},body:{}", url, body);
String response = HttpUtil.post(url, body);
log.info("work wechat oa get approval detail response:{}", response);
return JacksonUtils.jsonCastBean(response, WorkWechatOAGetApprovalDetailSingleResponseDTO.class);
} catch (RpcServiceException e) {
throw new RpcServiceException(e.getErrId(), e.getMessage());
} catch (Exception e) {
log.error("work wechat oa get approval detail error:{}", e.getMessage(), e);
throw new RpcServiceException(WechatErrorEnum.SERVER_ERROR, e.getMessage());
}
}
}