|
|
|
@ -38,7 +38,7 @@ public class MessagingConnector {
|
|
|
|
|
|
|
|
|
|
public MessageSendResponse messageDiv(MessageSendRequest messageSendRequest) throws IOException, InterruptedException {
|
|
|
|
|
String url = sms;
|
|
|
|
|
String key = UUID.randomUUID().toString().substring(0, 7);
|
|
|
|
|
String key = UUID.randomUUID().toString().substring(0, 6);
|
|
|
|
|
LocalDate now = LocalDate.now();
|
|
|
|
|
messageSendRequest.setUserKey(now.toString().substring(2).replace("-", "") + key);
|
|
|
|
|
|
|
|
|
@ -76,20 +76,20 @@ public class MessagingConnector {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
Map<String, String> body = prepareRequestBody(messageSendRequest, objectMapper);
|
|
|
|
|
System.out.println("body : " + body);
|
|
|
|
|
Map<String, String> body = this.prepareRequestBody(messageSendRequest, objectMapper);
|
|
|
|
|
String boundary = "----WebKitFormBoundary" + System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
String jsonBody = objectMapper.writeValueAsString(body);
|
|
|
|
|
System.out.println("jsonbody : " + jsonBody);
|
|
|
|
|
// Multipart body 생성
|
|
|
|
|
HttpRequest.BodyPublisher bodyPublisher = createMultipartBody(body, boundary);
|
|
|
|
|
|
|
|
|
|
HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
.uri(URI.create(url))
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.header("sejongApiKey", apiKey)
|
|
|
|
|
.POST(HttpRequest.BodyPublishers.ofString(jsonBody))
|
|
|
|
|
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
|
|
|
|
|
.header("sejongApiKey", this.apiKey)
|
|
|
|
|
.POST(bodyPublisher)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
HttpResponse<String> response = this.httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
System.out.println("responseCode : " + response.statusCode());
|
|
|
|
|
System.out.println("responseBody : " + response.body());
|
|
|
|
|
System.out.println("responseFull : " + response);
|
|
|
|
@ -101,18 +101,18 @@ public class MessagingConnector {
|
|
|
|
|
messageSendResponse.setMessage("서버 통신 오류");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
messageSendResponse.setCode("500");
|
|
|
|
|
messageSendResponse.setMessage("서버 통신 오류");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
messageSendResponse = this.responseChange(sejongMessageSendResponse, messageSendRequest);
|
|
|
|
|
messageSendServiceDsl.insertSendLog(sejongMessageSendResponse, messageSendRequest, messageSendResponse);
|
|
|
|
|
this.messageSendServiceDsl.insertSendLog(sejongMessageSendResponse, messageSendRequest, messageSendResponse);
|
|
|
|
|
|
|
|
|
|
if ("KAKAO".equals(messageSendRequest.getSendType()) && "Y".equals(messageSendRequest.getOptionYn())) {
|
|
|
|
|
if (!Objects.equals(sejongMessageSendResponse.getCode(), "200")) {
|
|
|
|
|
messageSendRequest.setSendType("");
|
|
|
|
|
messageSendResponse = this.messageDiv(messageSendRequest);
|
|
|
|
|
}
|
|
|
|
|
if ("KAKAO".equals(messageSendRequest.getSendType()) && "Y".equals(messageSendRequest.getOptionYn()) &&
|
|
|
|
|
!Objects.equals(sejongMessageSendResponse.getCode(), "200")) {
|
|
|
|
|
messageSendRequest.setSendType("");
|
|
|
|
|
messageSendResponse = this.messageDiv(messageSendRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return messageSendResponse;
|
|
|
|
@ -133,6 +133,21 @@ public class MessagingConnector {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private HttpRequest.BodyPublisher createMultipartBody(Map<String, String> body, String boundary) {
|
|
|
|
|
StringBuilder multipartBody = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, String> entry : body.entrySet()) {
|
|
|
|
|
multipartBody.append("--").append(boundary).append("\r\n");
|
|
|
|
|
multipartBody.append("Content-Disposition: form-data; name=\"").append(entry.getKey()).append("\"\r\n\r\n");
|
|
|
|
|
multipartBody.append(entry.getValue()).append("\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 마지막 바운더리 추가
|
|
|
|
|
multipartBody.append("--").append(boundary).append("--\r\n");
|
|
|
|
|
|
|
|
|
|
return HttpRequest.BodyPublishers.ofString(multipartBody.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MessageSendResponse responseChange(SejongMessageSendResponse response, MessageSendRequest request) {
|
|
|
|
|
MessageSendResponse messageSendResponse = new MessageSendResponse();
|
|
|
|
|
messageSendResponse.setSendType(request.getSendType());
|
|
|
|
|