diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 2543c9a..f9e3969 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -15,7 +15,7 @@
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 4ce9b91..d26c6d5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
-
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.3.2.RELEASE
+
+
com.icomsys.message
message-module
0.0.1-SNAPSHOT
@@ -61,10 +66,37 @@
common-utils
0.0.8-SNAPSHOT
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.1.3
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+ org.codehaus.jackson
+ jackson-mapper-asl
+ 1.9.13
+
+
+ org.codehaus.jackson
+ jackson-core-asl
+ 1.9.13
+
\ No newline at end of file
diff --git a/src/main/java/com/icomsys/MessagingConnector.java b/src/main/java/com/icomsys/MessagingConnector.java
index ef76539..dfad7e5 100644
--- a/src/main/java/com/icomsys/MessagingConnector.java
+++ b/src/main/java/com/icomsys/MessagingConnector.java
@@ -1,203 +1,241 @@
package com.icomsys;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.icomsys.dsl.MessageSendServiceDsl;
import com.icomsys.util.CommonBeanUtils;
import com.icomsys.vo.*;
-import org.mybatis.spring.annotation.MapperScan;
+import lombok.extern.slf4j.Slf4j;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.http.HttpClient;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-import java.nio.charset.StandardCharsets;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.*;
+import org.springframework.stereotype.Service;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Type;
import java.time.LocalDate;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
-@MapperScan(basePackages = "com.icomsys.mapper")
+@Service
+@Slf4j
public class MessagingConnector {
- private final String sms;
- private final String lms;
- private final String mms;
- private final String kakao;
- private final String apiKey;
- private final MessageSendServiceDsl messageSendServiceDsl;
- private final HttpClient httpClient;
-
- public MessagingConnector(String sms, String lms, String mms, String kakao, String apiKey, MessageSendServiceDsl messageSendServiceDsl) {
- this.sms = sms;
- this.lms = lms;
- this.mms = mms;
- this.kakao = kakao;
- this.apiKey = apiKey;
- this.httpClient = HttpClient.newHttpClient();
- this.messageSendServiceDsl = messageSendServiceDsl;
- }
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @Autowired
+ private MessageSendServiceDsl messageSendServiceDsl;
+
+ @Value("${message.url.sms}")
+ private String sms;
+
+ @Value("${message.url.lms}")
+ private String lms;
+
+ @Value("${message.url.mms}")
+ private String mms;
- public MessageSendResponse messageDiv(MessageSendRequest messageSendRequest) throws IOException, InterruptedException {
+ @Value("${message.url.kakao}")
+ private String kakao;
+
+ @Value("${message.key.sejong}")
+ private String apiKey;
+
+ /**
+ * @Name messageDiv
+ * @Description 세종텔레콤 메신저 구분 API
+ * @Author EunGu. Lee
+ * @CreateDate 2024. 07. 22
+ *
+ * @param messageSendRequest
+ * @return messageSendResponse
+ *
+ * @ChangeDescription
+ */
+ public MessageSendResponse messageDiv(MessageSendRequest messageSendRequest) throws UnsupportedEncodingException {
String url = sms;
String key = UUID.randomUUID().toString().substring(0, 6);
LocalDate now = LocalDate.now();
- messageSendRequest.setUserKey(now.toString().substring(2).replace("-", "") + key);
+ messageSendRequest.setUserKey(now.toString().substring(2).replace("-", "")+key);
- if (messageSendRequest.getSendType() == null || messageSendRequest.getSendType().isEmpty()) {
- if (messageSendRequest.getContents().getBytes(StandardCharsets.UTF_8).length < 91) {
+ // sendType(발송 타입)이 없는 경우 contents(메시지 내용)의 Byte를 체크하여 SMS, LMS로 전송
+ if (messageSendRequest.getSendType() == null || messageSendRequest.getSendType() == ""){
+ if (messageSendRequest.getContents().getBytes("euc-kr").length < 91) {
messageSendRequest.setSendType("SMS");
return this.messageSend(messageSendRequest, url);
- } else {
+ }
+ else {
messageSendRequest.setSendType("LMS");
url = lms;
return this.messageSend(messageSendRequest, url);
}
- } else {
- switch (messageSendRequest.getSendType()) {
- case "SMS":
- return this.messageSend(messageSendRequest, url);
- case "LMS":
- url = lms;
- return this.messageSend(messageSendRequest, url);
- case "MMS":
- url = mms;
- return this.messageSend(messageSendRequest, url);
- case "KAKAO":
- url = kakao;
- return this.messageSend(messageSendRequest, url);
- default:
- return null;
- }
}
+ // 발송 타입이 있는 경우
+ // 발송 타입이 SMS 일 때
+ else if (messageSendRequest.getSendType().equals("SMS")) {
+ return this.messageSend(messageSendRequest, url);
+ }
+ // 발송 타입이 LMS 일 때
+ else if (messageSendRequest.getSendType().equals("LMS")) {
+ url = lms;
+ return this.messageSend(messageSendRequest, url);
+ }
+ // 발송 타입이 MMS 일 때
+ else if (messageSendRequest.getSendType().equals("MMS")) {
+ url = mms;
+ return this.messageSend(messageSendRequest, url);
+ }
+ // 발송 타입이 KAKAO(알림톡) 일 때
+ else if (messageSendRequest.getSendType().equals("KAKAO")) {
+ url = kakao;
+ return this.messageSend(messageSendRequest, url);
+ }
+ return null;
}
- public MessageSendResponse messageSend(MessageSendRequest messageSendRequest, String url) throws IOException, InterruptedException {
+ /**
+ * @Name messageSend
+ * @Description 세종텔레콤 메신저 전송 API
+ * @Author EunGu. Lee
+ * @CreateDate 2024. 07. 22
+ *
+ * @param messageSendRequest
+ * @return messageSendResponse
+ *
+ * @ChangeDescription
+ */
+
+ public MessageSendResponse messageSend(MessageSendRequest messageSendRequest, String url) throws UnsupportedEncodingException {
MessageSendResponse messageSendResponse = new MessageSendResponse();
SejongMessageSendResponse sejongMessageSendResponse = null;
- try {
- ObjectMapper objectMapper = new ObjectMapper();
- Map body = this.prepareRequestBody(messageSendRequest, objectMapper);
- String boundary = "----WebKitFormBoundary" + System.currentTimeMillis();
-
- // Multipart body 생성
- HttpRequest.BodyPublisher bodyPublisher = createMultipartBody(body, boundary);
-
- HttpRequest request = HttpRequest.newBuilder()
- .uri(URI.create(url))
- .header("Content-Type", "multipart/form-data; boundary=" + boundary)
- .header("sejongApiKey", this.apiKey)
- .POST(bodyPublisher)
- .build();
-
- HttpResponse 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);
-
- if (response.statusCode() == 200) {
- sejongMessageSendResponse = objectMapper.readValue(response.body(), SejongMessageSendResponse.class);
- } else {
- messageSendResponse.setCode("500");
- messageSendResponse.setMessage("서버 통신 오류");
- }
- } catch (Exception e) {
- e.printStackTrace();
- messageSendResponse.setCode("500");
- messageSendResponse.setMessage("서버 통신 오류");
- }
+ // Header 정보 입력
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+ headers.add("sejongApiKey", apiKey);
- if (this.messageSendServiceDsl == null) {
- System.out.println("messageSendServiceDsl is null");
- throw new IllegalStateException("messageSendServiceDsl is not initialized.");
- }
+ // Body MULTIPART_FORM_DATA로 변환
+ MultiValueMap body = new LinkedMultiValueMap<>();
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map map = null;
- if (sejongMessageSendResponse == null) {
- System.out.println("sejongMessageSendResponse is null");
+ // SMS
+ if (messageSendRequest.getSendType().equals("SMS")) {
+ SejongSmsSendRequest smsSendRequest = CommonBeanUtils.convertType(messageSendRequest, SejongSmsSendRequest.class);
+ map = objectMapper.convertValue(smsSendRequest, new TypeReference