feat: 카카오톡 API 반영

main
Jonguk. Lim 3 months ago
parent 1f01212ba5
commit b5d538baa9

@ -18,7 +18,7 @@
<java.version>1.8</java.version>
<webapp.lib>${basedir}/libs</webapp.lib>
<webapp.lib.jdbc.oracle>ojdbc8</webapp.lib.jdbc.oracle>
<springdoc.swagger>1.6.3</springdoc.swagger>
<springdoc.swagger>1.6.14</springdoc.swagger>
<mapstruct.version>1.4.2.Final</mapstruct.version>
<lombok.version>1.18.20</lombok.version>
</properties>
@ -205,6 +205,11 @@
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc.swagger}</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
@ -231,6 +236,29 @@
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- JSONArray -->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<!-- JSONArray -->
</dependencies>

@ -0,0 +1,274 @@
package cokr.xit.ens.core.aop;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.google.gson.GsonBuilder;
import cokr.xit.ens.core.exception.BizRuntimeException;
import cokr.xit.ens.core.exception.code.ErrorCode;
import cokr.xit.ens.core.utils.Checks;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* <pre>
* description : Api
* TODO :: json @JsonIgnore
* packageName : kr.xit.core.model
* fileName : ApiResponseDTO
* author : julim
* date : 2023-04-28
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-04-28 julim
*
* </pre>
*/
@Schema(name = "ApiResponseDTO", description = "Restful API 결과")
@Data
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
@JsonRootName("result")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResponseDTO<T> implements IApiResponse {
private static final String FAIL_STATUS = "fail";
private static final String ERROR_STATUS = "error";
@Schema(example = "true", description = "에러인 경우 false", requiredMode = Schema.RequiredMode.REQUIRED)
private boolean success;
@Schema(example = " ", description = "HttpStatus.OK", requiredMode = Schema.RequiredMode.REQUIRED)
private String code;
@Schema(description = "결과 데이타, 오류시 null", example = " ")
private T data;
@Schema(description = "오류 발생시 오류 메세지", example = " ", requiredMode = Schema.RequiredMode.AUTO)
@Setter
private String message;
@JsonIgnore
@Schema(example = " ", description = "HttpStatus.OK", requiredMode = Schema.RequiredMode.AUTO)
private HttpStatus httpStatus;
@Schema(description = "API 실행 결과 데이타 수")
private int count;
/**
* ApiResponseDTO<T> return
*
* @param future CompletableFuture<T>
* @return ApiResponseDTO<T>
*/
//@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public static <T> ApiResponseDTO of(final CompletableFuture<T> future) {
try {
if(future.get() instanceof ApiResponseDTO<?>) return (ApiResponseDTO)future.get();
return new ApiResponseDTO<>(true, future.get(), String.valueOf(HttpStatus.OK.value()),
HttpStatus.OK.name(), HttpStatus.OK);
} catch (InterruptedException ie){
// thread pool에 에러 상태 전송
Thread.currentThread().interrupt();
throw BizRuntimeException.create(ie);
} catch (ExecutionException ee) {
throw BizRuntimeException.create(ee);
}
}
/**
* ApiResponseDTO<T> return
* @return ApiResponseDTO<T>
*/
public static <T> ApiResponseDTO<T> success() {
return new ApiResponseDTO<>(true, null, String.valueOf(HttpStatus.OK.value()), HttpStatus.OK.name(), HttpStatus.OK);
}
/**
* ApiResponseDTO<T> return
* @param data T
* @return ApiResponseDTO<T>
*/
public static <T> ApiResponseDTO<T> success(T data) {
return new ApiResponseDTO<>(true, data, String.valueOf(HttpStatus.OK.value()), HttpStatus.OK.name(), HttpStatus.OK);
}
/**
* ApiResponseDTO<T> return
* @param httpStatus HttpStatus
* @return ApiResponseDTO<T>
*/
public static <T> ApiResponseDTO<T> success(final HttpStatus httpStatus) {
return new ApiResponseDTO<>(true, null, String.valueOf(httpStatus.value()), httpStatus.name(), httpStatus);
}
/**
* ApiResponseDTO<T> return
* @param data T
* @param httpStatus HttpStatus
* @return ApiResponseDTO<T>
*/
public static <T> ApiResponseDTO<T> success(final T data, final HttpStatus httpStatus) {
return new ApiResponseDTO<>(true, data, String.valueOf(httpStatus.value()), httpStatus.name(), httpStatus);
}
/**
* ApiResponseDTO<T> return
* @param data T
* @param message String
* @return ApiResponseDTO<T>
*/
public static <T> ApiResponseDTO<T> success(final T data, final String message) {
return new ApiResponseDTO<>(true, data, String.valueOf(HttpStatus.OK.value()), message, HttpStatus.OK);
}
/**
* return - body empty
* @return ApiResponseDTO
*/
public static <T> ApiResponseDTO<T> empty() {
return new ApiResponseDTO<>(true, null, String.valueOf(HttpStatus.NO_CONTENT.value()), HttpStatus.NO_CONTENT.name(), HttpStatus.OK);
}
/**
* Error ApiResponseDTO return
* Hibernate Validator API
* @param bindingResult BindingResult
* @return ApiResponseDTO
*/
public static <T> ApiResponseDTO<T> error(final BindingResult bindingResult) {
Map<String, String> errors = new HashMap<>();
List<ObjectError> allErrors = bindingResult.getAllErrors();
for (ObjectError error : allErrors) {
if (error instanceof FieldError) {
errors.put(((FieldError) error).getField(), error.getDefaultMessage());
} else {
errors.put( error.getObjectName(), error.getDefaultMessage());
}
}
return new ApiResponseDTO<>(false, null, FAIL_STATUS, errors.toString(), null);
}
/**
* Error ApiResponseDTO return
* @param message
* @return ApiResponseDTO
*/
public static <T> ApiResponseDTO<T> error(final String message) {
return new ApiResponseDTO<>(false, null, ERROR_STATUS, message, null);
}
/**
* Error ApiResponseDTO return
* @param errorCode ErrorCode
* @return ApiResponseDTO
*/
public static <T> ApiResponseDTO<T> error(final ErrorCode errorCode) {
return new ApiResponseDTO<>(false, null, errorCode.name(), errorCode.getMessage(), errorCode.getHttpStatus());
}
/**
* Error ApiResponseDTO return
* @param e BizRuntimeException
* @return ApiResponseDTO
*/
public static <T> ApiResponseDTO<T> error(final BizRuntimeException e) {
if (Checks.isNotEmpty(e.getErrorCode())) {
return ApiResponseDTO.error(e.getErrorCode());
}
return new ApiResponseDTO<>(
false,
null,
org.apache.commons.lang3.StringUtils.defaultString(e.getCode(), org.apache.commons.lang3.StringUtils.EMPTY),
org.apache.commons.lang3.StringUtils.defaultString(e.getMessage(), org.apache.commons.lang3.StringUtils.EMPTY),
e.getHttpStatus());
}
/**
* Error ApiResponseDTO return
* @param code
* @param message
* @return ApiResponseDTO
*/
public static <T> ApiResponseDTO<T> error(final String code, final String message) {
return new ApiResponseDTO<>(false, null, code, message, null);
}
/**
* Error ApiResponseDTO return
* @param code
* @param message
* @param httpStatus HttpStatus
* @return ApiResponseDTO
*/
public static <T> ApiResponseDTO<T> error(final String code, final String message, HttpStatus httpStatus) {
return new ApiResponseDTO<>(false, null, code, message, httpStatus);
}
/**
*
* @param success true|false
* @param data data
* @param code
* @param message ( )
* @param httpStatus HttpStatus
*/
private ApiResponseDTO(final boolean success, final T data, final String code, final String message, final HttpStatus httpStatus) {
this.success = success;
this.data = data;
this.code = code;
this.message = message;
this.httpStatus = httpStatus;
if(data == null){
this.count = 0;
}else {
if (Collection.class.isAssignableFrom(data.getClass())) {
this.count = (((Collection<?>) data).size());
} else {
this.count = 1;
}
}
if(httpStatus == null){
if(!success) this.httpStatus = HttpStatus.BAD_REQUEST;
else this.httpStatus = HttpStatus.OK;
}
}
@Override
public String toString() {
// value가 null값인 경우도 생성
GsonBuilder builder = new GsonBuilder().serializeNulls();
builder.disableHtmlEscaping();
return builder.setPrettyPrinting().create().toJson(this);
}
}

@ -1,9 +1,10 @@
package cokr.xit.ens.core.aop;
import cokr.xit.ens.core.exception.code.EnsErrCd;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import cokr.xit.ens.core.exception.code.EnsErrCd;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
@ -14,7 +15,7 @@ import lombok.ToString;
@ToString
@Schema(name = "EnsResponseVO")
@NoArgsConstructor
public class EnsResponseVO<T> {
public class EnsResponseVO<T> implements IApiResponse {
@Schema(required = true, title = "에러 코드", example = " ")
@JsonProperty("errCode")

@ -0,0 +1,19 @@
package cokr.xit.ens.core.aop;
/**
* <pre>
* description :
*
* packageName : kr.xit.core.model
* fileName : IApiResponse
* author : limju
* date : 2023-05-31
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-05-31 limju
*
* </pre>
*/
public interface IApiResponse {
}

@ -0,0 +1,75 @@
package cokr.xit.ens.core.config.support;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import cokr.xit.ens.core.utils.CoreSpringUtils;
import cokr.xit.ens.core.utils.JsonUtils;
/**
* <pre>
* description : Jackson(ObjectMapper)
* ObjectMapper .
* - Cannot coerce empty String("") to ...
* value(but could if coercion was enabled using `CoercionConfig`)
* packageName : kr.xit.core.spring.config.support
* fileName : CustomJacksonConfig
* author : julim
* date : 2023-09-13
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-13 julim
*
* </pre>
* @see CoreSpringUtils#getObjectMapper()
* @see JsonUtils
* @see WebClientConfig
*/
@Configuration
public class CustomJacksonConfig {
/**
* <pre>
* override
* Cannot coerce empty String("") to ...
* value(but could if coercion was enabled using `CoercionConfig`)
* </pre>
*
* @return
*/
@Bean
@Primary
public ObjectMapper objectMapper() {
ObjectMapper om = new ObjectMapper()
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
//.setSerializationInclusion(Include.NON_NULL)
//.setSerializationInclusion(Include.NON_EMPTY)
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, false)
.registerModule(new JavaTimeModule());
om.coercionConfigDefaults()
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull);
// om.coercionConfigFor(LogicalType.Enum)
// .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull);
// om.coercionConfigFor(LogicalType.POJO)
// .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull);
return om;
}
}

@ -0,0 +1,245 @@
package cokr.xit.ens.core.config.support;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.web.reactive.function.client.ClientRequest;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.DefaultUriBuilderFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import cokr.xit.ens.core.exception.BizRuntimeException;
import cokr.xit.ens.core.exception.ClientErrorException;
import cokr.xit.ens.core.exception.ServerErrorException;
import io.netty.channel.ChannelOption;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.handler.timeout.WriteTimeoutHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;
import reactor.netty.resources.ConnectionProvider;
import reactor.netty.transport.logging.AdvancedByteBufFormat;
/**
* <pre>
* description : WebClient configuration
* Spring WebFlux HTTP Client Config
* logging : - ExchangeFilterFunction (requestFilter, responseFilter)
* - logging.level.reactor.netty.http.client: DEBUG|ERROR
*
* packageName : kr.xit.core.spring.config.support
* fileName : WebClientConfig
* author : julim
* date : 2023-09-06
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-06 julim
*
* </pre>
*/
@Slf4j
@RequiredArgsConstructor
@Configuration
public class WebClientConfig {
@Value("${app.contract.connection.timeout:5000}")
private int connectTimeout;
@Value("${app.contract.connection.readTimeout:5000}")
private int readTimeout;
private final ObjectMapper objectMapper;
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
/**
* setEncodingMode : GET URI 릿
* @return
*/
@Bean
public WebClient webClient() {
factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY);
return WebClient.builder()
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.uriBuilderFactory(factory)
.clientConnector(new ReactorClientHttpConnector(defaultHttpClient()))
.codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(2 * 1024 * 1024))
.exchangeStrategies(defaultExchangeStrategies())
.filters(exchangeFilterFunctions -> {
//exchangeFilterFunctions.add(requestFilter());
exchangeFilterFunctions.add(responseFilter());
})
.build();
}
/**
* <pre>
* Http client
* - / debugging wiretap - AdvancedByteBufFormat.TEXTUAL
* @return HttpClient
* </pre>
*/
@Bean
public HttpClient defaultHttpClient() {
try {
// SSL check bypass
SslContext sslContext = SslContextBuilder
.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();
return HttpClient.create(connectionProvider())
.secure(t -> t.sslContext(sslContext))
.wiretap(this.getClass().getCanonicalName(), LogLevel.DEBUG,
AdvancedByteBufFormat.TEXTUAL)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout)
.responseTimeout(Duration.ofMillis(this.connectTimeout))
.doOnConnected(conn ->
conn.addHandlerLast(new ReadTimeoutHandler(readTimeout, TimeUnit.MILLISECONDS))
.addHandlerLast(
new WriteTimeoutHandler(readTimeout, TimeUnit.MILLISECONDS)));
}catch(SSLException se){
throw BizRuntimeException.create(se.getMessage());
}
}
/**
* maxConnections : connection pool
* pendingAcquireTimeout :
* pendingAcquireMaxCount : (-1: no limit)
* maxIdleTime : idle
* @return ConnectionProvider
*/
@Bean
public ConnectionProvider connectionProvider() {
return ConnectionProvider.builder("http-pool")
.maxConnections(100)
.pendingAcquireTimeout(Duration.ofMillis(0))
.pendingAcquireMaxCount(-1)
.maxIdleTime(Duration.ofMillis(2000L))
.build();
}
/**
* <pre>
* 1. 256KB HTTP DataBufferLimitException
* 2. messageWriters logging(setEnableLoggingRequestDetails(true)
* -> org.springframework.web.reactive.function.client.ExchangeFunctions: DEBUG
* -> defaultHttpClient() wiretap
* </pre>
* @return ExchangeStrategies
*/
@Bean
public ExchangeStrategies defaultExchangeStrategies() {
// 256KB 보다 큰 HTTP 메시지를 처리 시도 → DataBufferLimitException 에러 발생 방어
return ExchangeStrategies.builder()
.codecs(config -> {
config.defaultCodecs().maxInMemorySize(2 * 1024 * 1024);
config.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON));
config.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON));
})
.build();
// es.messageWriters()
// .stream()
// .filter(LoggingCodecSupport.class::isInstance)
// .forEach(writer -> ((LoggingCodecSupport)writer).setEnableLoggingRequestDetails(true));
}
private ExchangeFilterFunction requestFilter() {
return ExchangeFilterFunction.ofRequestProcessor(cr -> {
if (log.isDebugEnabled()) {
StringBuilder sb = new StringBuilder("\n>>>>>>>>>> WebClient Http Request <<<<<<<<<<<<<\n");
sb.append(logMethodAndUrl(cr));
sb.append(logHeaders(cr));
sb.append("-------------------------------------------------------");
log.debug(sb.toString());
}
return Mono.just(cr);
});
}
/**
* reponse logging && error Handling
* @return ExchangeFilterFunction
*/
private ExchangeFilterFunction responseFilter() {
return ExchangeFilterFunction.ofResponseProcessor(cr -> {
HttpStatus status = cr.statusCode();
if(cr.statusCode().is4xxClientError()) {
return cr.bodyToMono(String.class)
.flatMap(errorBody -> Mono.error(new ClientErrorException(status, errorBody)));
} else if(cr.statusCode().is5xxServerError()) {
return cr.bodyToMono(String.class)
.flatMap(errorBody -> Mono.error(new ServerErrorException(status, errorBody)));
}
// if(log.isDebugEnabled()) {
// StringBuilder sb = new StringBuilder(
// "\n>>>>>>>>>> WebClient Http Response <<<<<<<<<<<<<\n");
// sb.append(logStatus(cr));
// sb.append(logHeaders(cr));
// sb.append("-------------------------------------------------------");
// log.debug(sb.toString());
// }
return Mono.just(cr);
});
}
private static String logStatus(ClientResponse response) {
HttpStatus status = response.statusCode();
return String.format("Returned staus code %s (%s)", status.value(), status.getReasonPhrase());
}
private static String logHeaders(ClientRequest request) {
StringBuilder sb = new StringBuilder();
request.headers()
.forEach((name, values) ->
values.forEach(value -> sb.append(name).append(": ").append(value).append("\n"))
);
return sb.toString();
}
private static String logHeaders(ClientResponse response) {
StringBuilder sb = new StringBuilder();
response.headers()
.asHttpHeaders()
.forEach((name, values) ->
values.forEach(value -> sb.append(name).append(": ").append(value).append("\n"))
);
return sb.toString();
}
private static String logMethodAndUrl(ClientRequest request) {
StringBuilder sb = new StringBuilder();
sb.append(request.method().name());
sb.append(" to ");
sb.append(request.url());
return sb.append("\n").toString();
}
}

@ -0,0 +1,224 @@
package cokr.xit.ens.core.exception;
import java.text.MessageFormat;
import java.util.Locale;
import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import cokr.xit.ens.core.exception.code.ErrorCode;
import cokr.xit.ens.core.utils.CoreSpringUtils;
import cokr.xit.ens.core.utils.MessageUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
/**
* <pre>
* description : egov BaseRuntimeException
* packageName : kr.xit.core.exception
* fileName : BizRuntimeException
* author : julim
* date : 2023-04-28
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-04-28 julim
*
* </pre>
*/
@Getter
@Setter
@Slf4j
@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "Invalid parameter")
public class BizRuntimeException extends RuntimeException{
private String code;
private String message;
private ErrorCode errorCode;
private static final MessageUtil messageUtil = CoreSpringUtils.getMessageUtil();
/**
* BizRuntimeException .
* @param errorCode ErrorCode
*/
public static BizRuntimeException create(ErrorCode errorCode) {
return new BizRuntimeException(errorCode);
}
/**
* BizRuntimeException .
* @param errorCode ErrorCode
*/
private BizRuntimeException(ErrorCode errorCode) {
super(errorCode.getMessage());
this.code = String.valueOf(errorCode.getHttpStatus().value());
this.errorCode = errorCode;
}
/**
* BizRuntimeException .
* @param errorCode
*/
public static BizRuntimeException of(String errorCode) {
BizRuntimeException e = new BizRuntimeException();
e.setCode(errorCode);
e.setMessage(messageUtil.getMessage(errorCode));
return e;
}
/**
* BizRuntimeException .
* @param defaultMessage
*/
public static BizRuntimeException create(String defaultMessage) {
return new BizRuntimeException(defaultMessage, null, null);
}
/**
* BizRuntimeException .
* @param code
* @param defaultMessage
*/
public static BizRuntimeException create(String code, String defaultMessage) {
BizRuntimeException e = new BizRuntimeException();
e.setCode(code);
e.setMessage(defaultMessage);
return e;
}
public static BizRuntimeException create(String code, Object[] messageParameters) {
BizRuntimeException e = new BizRuntimeException();
e.setCode(code);
e.setMessage(messageUtil.getMessage(code, messageParameters));
return e;
}
/**
* BizRuntimeException .
* @param wrappedException Exception
*/
public static BizRuntimeException create(Throwable wrappedException) {
return new BizRuntimeException("BizRuntimeException without message", null, wrappedException);
}
/**
* BizRuntimeException .
* @param defaultMessage
* @param wrappedException Exception
*/
public static BizRuntimeException create(String defaultMessage, Throwable wrappedException) {
return new BizRuntimeException(defaultMessage, null, wrappedException);
}
/**
* BizRuntimeException .
* @param defaultMessage ()
* @param messageParameters
* @param wrappedException Exception
*/
private static BizRuntimeException create(String defaultMessage, Object[] messageParameters, Throwable wrappedException) {
return new BizRuntimeException(defaultMessage, messageParameters, wrappedException);
}
/**
* BizRuntimeException .
*/
private BizRuntimeException() {
this("BizRuntimeException without message", null, null);
}
/**
* BizRuntimeException .
* @param defaultMessage ()
* @param messageParameters
* @param wrappedException Exception
*/
private BizRuntimeException(String defaultMessage, Object[] messageParameters, Throwable wrappedException) {
super(wrappedException);
if(messageParameters != null) {
message = MessageFormat.format(defaultMessage, messageParameters);
}else{
message = defaultMessage;
}
}
/**
* BizRuntimeException .
* @param messageSource
* @param messageKey
*/
public static BizRuntimeException create(MessageSource messageSource, String messageKey) {
return new BizRuntimeException(messageSource, messageKey, null, null, Locale.getDefault(), null);
}
/**
* BizRuntimeException .
* @param messageSource
* @param messageKey
*/
public static BizRuntimeException create(MessageSource messageSource, String messageKey, Throwable wrappedException) {
return new BizRuntimeException(messageSource, messageKey, null, null, Locale.getDefault(), wrappedException);
}
/**
* BizRuntimeException .
* @param messageSource
* @param messageKey
* @param locale /
* @param wrappedException Exception
*/
public static BizRuntimeException create(MessageSource messageSource, String messageKey, Locale locale, Throwable wrappedException) {
return new BizRuntimeException(messageSource, messageKey, null, null, locale, wrappedException);
}
/**
* BizRuntimeException .
* @param messageSource
* @param messageKey
* @param messageParameters
* @param locale /
* @param wrappedException Exception
*/
public static BizRuntimeException create(MessageSource messageSource, String messageKey, Object[] messageParameters, Locale locale, Throwable wrappedException) {
return new BizRuntimeException(messageSource, messageKey, messageParameters, null, locale, wrappedException);
}
/**
* BizRuntimeException .
* @param messageSource
* @param messageKey
* @param messageParameters
* @param wrappedException Exception
*/
public static BizRuntimeException create(MessageSource messageSource, String messageKey, Object[] messageParameters, Throwable wrappedException) {
return new BizRuntimeException(messageSource, messageKey, messageParameters, null, Locale.getDefault(), wrappedException);
}
/**
* BizRuntimeException .
* @param messageSource
* @param messageKey
* @param messageParameters
* @param defaultMessage ()
* @param wrappedException Exception
*/
public static BizRuntimeException create(MessageSource messageSource, String messageKey, Object[] messageParameters, String defaultMessage, Throwable wrappedException) {
return new BizRuntimeException(messageSource, messageKey, messageParameters, defaultMessage, Locale.getDefault(), wrappedException);
}
public BizRuntimeException(MessageSource messageSource, String messageKey, Object[] messageParameters, String defaultMessage, Locale locale, Throwable wrappedException) {
super(wrappedException);
code = messageKey;
message = messageSource.getMessage(messageKey, messageParameters, defaultMessage, locale);
}
public HttpStatus getHttpStatus(){
return HttpStatus.BAD_REQUEST;
}
public static void main(String[] args) {
}
}

@ -0,0 +1,33 @@
package cokr.xit.ens.core.exception;
import org.springframework.http.HttpStatus;
import cokr.xit.ens.core.utils.ApiWebClientUtil;
import lombok.Getter;
/**
* <pre>
* description : WebClient 4xx :
*
* packageName : kr.xit.core.exception
* fileName : ClientErrorException
* author : limju
* date : 2023-05-25
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-05-25 limju
*
* </pre>
* @see ApiWebClientUtil
*/
@Getter
public class ClientErrorException extends RuntimeException {
private final HttpStatus status;
private final String body;
public ClientErrorException(HttpStatus status, String body) {
this.status = status;
this.body = body;
}
}

@ -0,0 +1,99 @@
package cokr.xit.ens.core.exception;
import java.util.concurrent.ExecutionException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import cokr.xit.ens.core.aop.ApiResponseDTO;
import cokr.xit.ens.core.utils.Checks;
import io.netty.channel.ConnectTimeoutException;
import io.netty.handler.timeout.ReadTimeoutException;
/**
* <pre>
* description :
*
* packageName : kr.xit.core.exception
* fileName : ErrorParse
* author : limju
* date : 2023-06-01
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-06-01 limju
*
* </pre>
*/
public class ErrorParse {
@SuppressWarnings("rawtypes")
public static ApiResponseDTO extractError(final Throwable e){
String errCode = String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value());
String message = Checks.isNotNull(e) ? e.getLocalizedMessage() : StringUtils.EMPTY;
HttpStatus httpStatus = null;
if(e instanceof BizRuntimeException) {
BizRuntimeException be = (BizRuntimeException) e;
return ApiResponseDTO.error(be.getCode(), be.getMessage(), HttpStatus.BAD_REQUEST);
}
if(e instanceof ClientErrorException) {
ClientErrorException ce = (ClientErrorException) e;
return ApiResponseDTO.error(String.valueOf(ce.getStatus()), ce.getBody(), ce.getStatus());
}
if(e instanceof ServerErrorException) {
ServerErrorException ce = (ServerErrorException) e;
return ApiResponseDTO.error(String.valueOf(ce.getStatus()), ce.getBody(), ce.getStatus());
}
// Async(React) Exception 처리
if(e instanceof WebClientRequestException) {
if (e.getCause() instanceof ConnectTimeoutException || e.getCause() instanceof ReadTimeoutException) {
return getTimeoutException();
}
}
if(e instanceof ExecutionException) {
if (e.getCause() instanceof WebClientRequestException) {
message = e.getCause().getMessage();
// Timeout 에러
if (e.getCause().getCause() instanceof ReadTimeoutException || e.getCause().getCause() instanceof ConnectTimeoutException) {
return getTimeoutException();
}
}
}
if(e instanceof ReadTimeoutException){
return getTimeoutException();
}
// Async(React) Exception 처리
if(e.getCause() instanceof WebClientRequestException){
// Timeout 에러
if(e.getCause().getCause() instanceof ReadTimeoutException){
return getTimeoutException();
}
}
if(Checks.isNotEmpty(e.getCause())) {
message = e.getCause().getMessage();
}
return ApiResponseDTO.error(errCode, message, httpStatus);
}
@SuppressWarnings("rawtypes")
private static ApiResponseDTO getTimeoutException(){
return ApiResponseDTO.error(
String.valueOf(HttpStatus.REQUEST_TIMEOUT.value()),
HttpStatus.REQUEST_TIMEOUT.getReasonPhrase(),
HttpStatus.REQUEST_TIMEOUT);
}
}

@ -0,0 +1,33 @@
package cokr.xit.ens.core.exception;
import org.springframework.http.HttpStatus;
import cokr.xit.ens.core.utils.ApiWebClientUtil;
import lombok.Getter;
/**
* <pre>
* description : WebClient 5xx :
*
* packageName : kr.xit.core.exception
* fileName : ServerErrorException
* author : limju
* date : 2023-05-25
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-05-25 limju
*
* </pre>
* @see ApiWebClientUtil
*/
@Getter
public class ServerErrorException extends RuntimeException {
private final HttpStatus status;
private final String body;
public ServerErrorException(HttpStatus status, String body) {
this.status = status;
this.body = body;
}
}

@ -0,0 +1,114 @@
package cokr.xit.ens.core.exception.code;
import org.springframework.http.HttpStatus;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* <pre>
* description : HttpStatus
* packageName : kr.xit.core.const
* fileName : ErrorCode
* author : julim
* date : 2023-04-28
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-04-28 julim
*
* </pre>
* @see HttpStatus
*/
@Getter
@RequiredArgsConstructor
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum
ErrorCode {
/*
200 : OK,
201 : Created,
202 : Accepted,
204 : No Content, , .
400 : Bad Request, , , .
401 : Unauthorized, ,
402 : Payment Required
403 : Forbidden, . , .
404 : Not Found, URI .
405 : Method Not Allowed, Method .
406 : Not Acceptable, .
408 : Request Timeout
409 : Conflict, .
413 : Payload Too Large
423 : Locked
428 : Precondition Required
429 : Too Many Requests
500 :
*/
BAD_REQUEST(HttpStatus.BAD_REQUEST, "요청 매개변수 오류 입니다."),
NOT_FOUND(HttpStatus.NOT_FOUND, "잘못된 요청 입니다"),
FILE_NOT_FOUND(HttpStatus.NOT_FOUND, "파일이 존재하지 않습니다"),
DATA_NOT_FOUND(HttpStatus.NOT_FOUND, "처리 데이타 오류(처리 요청 데이타 미존재)"),
/* 400 BAD_REQUEST : 잘못된 요청 */
CANNOT_FOLLOW_MYSELF(HttpStatus.BAD_REQUEST, "자기 자신은 팔로우 할 수 없습니다"),
/* 401 UNAUTHORIZED : 인증되지 않은 사용자 */
INVALID_AUTH_TOKEN(HttpStatus.FORBIDDEN, "인가된 사용자가 아닙니다"),
UN_AUTHORIZED_USER(HttpStatus.UNAUTHORIZED, "계정 정보가 존재하지 않습니다"),
AUTH_HEADER_NOT_EXISTS(HttpStatus.UNAUTHORIZED, "헤더에 인증 정보를 찾을 수 없습니다"),
LOGOUT_USER(HttpStatus.UNAUTHORIZED, "로그아웃된 사용자 입니다"),
NOT_EXISTS_SECURITY_AUTH(HttpStatus.UNAUTHORIZED, "Security Context 에 인증 정보가 없습니다"),
NOT_EXISTS_TOKEN(HttpStatus.UNAUTHORIZED, "인증된 토큰이 없습니다"),
NOT_EXISTS_SAVED_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "저장된 인증 토큰이 없습니다"),
INVALID_TOKEN(HttpStatus.UNAUTHORIZED, "유효한 토큰이 아닙니다"),
INVALID_ROLE_TOKEN(HttpStatus.UNAUTHORIZED, "사용 권한이 없는 토큰 입니다"),
EXPIRED_TOKEN(HttpStatus.UNAUTHORIZED, "유효기간이 경과된 토큰 입니다"),
INVALID_SIGN_TOKEN(HttpStatus.UNAUTHORIZED, "잘못된 서명의 토큰 입니다"),
INVALID_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "리프레시 토큰이 유효하지 않습니다"),
MISMATCH_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "리프레시 토큰의 유저 정보가 일치하지 않습니다"),
MISMATCH_REFRESH_ACCESS_TOKEN(HttpStatus.UNAUTHORIZED, "발급된 refresh token의 정보가 일치하지 않습니다"),
NOT_EXPIRED_TOKEN_YET(HttpStatus.UNAUTHORIZED, "토큰 유효기간이 경과되지 않았습니다"),
/* 404 NOT_FOUND : Resource 를 찾을 수 없음 */
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "사용자 정보를 찾을 수 없습니다"),
REFRESH_TOKEN_NOT_FOUND(HttpStatus.NOT_FOUND, "로그아웃 된 사용자입니다"),
/* 409 CONFLICT : Resource 의 현재 상태와 충돌. 보통 중복된 데이터 존재 */
DUPLICATE_RESOURCE(HttpStatus.CONFLICT, "데이터가 이미 존재합니다"),
MEMBER_EXISTS(HttpStatus.CONFLICT, "가입되어 있는 회원 입니다"),
// JPA query error
SQL_DATA_RESOURCE_INVALID(HttpStatus.CONFLICT, "SQL 오류(데이터가 이미 존재합니다)"),
MPOWER_CONNECT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "MPower DB 접속 에러 입니다"),
MPOWER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "MPower DB 에러 입니다"),
FORBIDDEN(HttpStatus.FORBIDDEN, "FORBIDDEN"),
INVALID_CODE(HttpStatus.BAD_REQUEST, "유효하지 않은 HttpStatus 상태 코드 입니다"),
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "INTERNAL_SERVER_ERROR"),
MISMATCH_PASSWORD(HttpStatus.BAD_REQUEST, "비밀 번호가 일치하지 않습니다."),
CONNECT_TIMEOUT(HttpStatus.REQUEST_TIMEOUT, "서버 접속 에러입니다(Connect timeout)")
;
private HttpStatus httpStatus;
private String message;
ErrorCode(HttpStatus httpStatus, String message){
this.httpStatus = httpStatus;
this.message = message;
}
}

@ -0,0 +1,253 @@
package cokr.xit.ens.core.utils;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.util.UriComponentsBuilder;
import cokr.xit.ens.core.aop.ApiResponseDTO;
import cokr.xit.ens.core.config.support.WebClientConfig;
import cokr.xit.ens.core.exception.ClientErrorException;
import cokr.xit.ens.core.exception.ErrorParse;
import cokr.xit.ens.modules.kkotalk.model.CmmEnsRlaybsnmDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* <pre>
* description : react Restfull Util
* error(.onStatus) ExchangeFilterFunction {@link WebClientConfig responseFilter}
* packageName : kr.xit.core.spring.util
* fileName : ApiWebClientUtil
* author : julim
* date : 2023-09-06
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-06 julim
*
* </pre>
* @see WebClientConfig
* @see kr.xit.core.spring.config.AsyncExecutorConfig
* @see ClientErrorException
* @see ServerErrorException
* @see ErrorParse
* @see kr.xit.core.spring.config.support.CustomJacksonConfig
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class ApiWebClientUtil {
private static final String AUTH_TYPE_BEARER = "bearer";
private final WebClientConfig webClientConfig;
/**
* WebClient GET
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig responseFilter}
* @param url String
* @param responseDtoClass Class<T>
* @param headerMap Map<String, String>
* @return responseDtoClass
*/
public <T> T get(final String url, final Class<T> responseDtoClass, Map<String, String> headerMap) {
return webClientConfig.webClient()
.method(HttpMethod.GET)
.uri(url)
.headers(httpHeaders -> getHeaders(httpHeaders, headerMap))
.retrieve()
.bodyToMono(responseDtoClass)
.block();
}
/**
* WebClient POST
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig responseFilter}
* @param url String
* @param requestDto V
* @param responseDtoClass Class<T>
* @param headerMap Map<String, String>
* @return responseDtoClass
*/
public <T, V> T post(final String url, final V requestDto, final Class<T> responseDtoClass, Map<String, String> headerMap) {
return webClientConfig.webClient()
.method(HttpMethod.POST)
.uri(url)
.headers(httpHeaders -> getHeaders(httpHeaders, headerMap))
.bodyValue(requestDto != null ? requestDto : "")
.retrieve()
.bodyToMono(responseDtoClass)
.block();
}
/**
* kakaotalk WebClient
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig responseFilter}
* @param url String
* @param method HttpMethod
* @param body Object
* @param rtnClzz Class<T>
* @param ensDTO CmmEnsRlaybsnmDTO
* @return rtnClzz<T>
*/
public <T> T exchangeKkotalk(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final CmmEnsRlaybsnmDTO ensDTO) {
Map<String, String> map = new HashMap<>();
map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
map.put(HttpHeaders.AUTHORIZATION, String.format("KakaoAK %s", ensDTO.getKakaoDealerRestApiKey()));
map.put("Target-Authorization", String.format("KakaoAK %s", ensDTO.getKakaoPartnerRestApiKey()));
map.put("settle-Id", ensDTO.getKakaoSettleId());
return exchange(url, method, body, rtnClzz, map);
}
/**
* KT-BC WebClient
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig responseFilter}
* @param url String
* @param method HttpMethod
* @param body Object
* @param rtnClzz Class<T>
* @param ensDTO CmmEnsRlaybsnmDTO
* @return rtnClzz<T>
*/
public <T> T exchangeKt(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final CmmEnsRlaybsnmDTO ensDTO) {
final Map<String,String> headerMap = new HashMap<>();
headerMap.put(HttpHeaders.AUTHORIZATION, String.format("%s %s", AUTH_TYPE_BEARER, ensDTO.getKtAccessToken()));
headerMap.put("client-id", ensDTO.getKtClientId());
headerMap.put("client-tp", ensDTO.getKtClientTp());
return exchange(url, method, body, rtnClzz, headerMap);
}
/**
* KT-GIBIS WebClient
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig responseFilter}
* @param url String
* @param method HttpMethod
* @param body Object
* @param rtnClzz Class<T>
* @param ensDTO CmmEnsRlaybsnmDTO
* @return rtnClzz<T>
*/
public <T> T exchangeKtGbs(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final CmmEnsRlaybsnmDTO ensDTO) {
final Map<String,String> headerMap = new HashMap<>();
headerMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
headerMap.put(HttpHeaders.AUTHORIZATION, String.format("Bearer %s", ensDTO.getKtAccessToken()));
return exchange(url, method, body, rtnClzz, headerMap);
}
/**
* <pre>
* WebClient
* GET url (?key=value&key2=value2)
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig responseFilter}
* @param url call url
* @param method POST|GET
* @param body JSON String type
* @param rtnClzz rtnClzz return type class
* (ex: new KkopayDocDTO.DocStatusResponse().getClass())
* @return T rtnClzz return DTO
* </pre>
*/
public <T> T exchange(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final Map<String,String> headerMap) {
return webClientConfig.webClient()
.method(method)
.uri(url)
.headers(httpHeaders -> getHeaders(httpHeaders, headerMap))
.bodyValue(body != null ? body : "")
.exchangeToMono(res -> res.bodyToMono(rtnClzz))
.block();
}
/**
* <pre>
* WebClient form data
* -> application/x-www-form-urlencoded
* GET url (?key=value&key2=value2)
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig responseFilter}
* @param url call url
* @param method POST|GET
* @param body JSON String type
* @param rtnClzz rtnClzz return type class
* (ex: new KkopayDocDTO.DocStatusResponse().getClass())
* @return T rtnClzz return DTO
* </pre>
*/
public <T> T exchangeFormData(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final Map<String,String> headerMap) {
return webClientConfig.webClient()
.method(method)
.uri(url)
.headers(httpHeaders -> getHeaders(httpHeaders, headerMap))
.body(ObjectUtils.isNotEmpty(body)? BodyInserters.fromFormData(JsonUtils.toMultiValue(body)): BodyInserters.empty())
.exchangeToMono(res -> res.bodyToMono(rtnClzz))
.block();
}
/**
* webclient file data
* -> multipart/form-data
* url (?key=value&key2=value2)
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> WebClientConfig.responseFilter()
* @param url
* @param method
* @param files
* @param rtnClzz
* @return rtnClzz
*/
public <T> T exchangeFileData(final String url, final HttpMethod method, final List<MultipartFile> files, final String pFileName, final Class<T> rtnClzz) {
MultipartBodyBuilder builder = new MultipartBodyBuilder();
for(MultipartFile mf : files) {
//builder.part(mf.getOriginalFilename().split("\\.")[0], mf.getResource());
builder.part(pFileName, mf.getResource());
}
return webClientConfig.webClient()
.method(method)
.uri(url)
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromMultipartData(builder.build()))
.exchangeToMono(res -> res.bodyToMono(rtnClzz))
.block();
// .blockOptional()
// .orElse("");
}
public <T> ApiResponseDTO<T> sendError(final Throwable e) {
return ErrorParse.extractError(e.getCause());
}
private URI createUrl(final String endPoint, final String... value) {
return UriComponentsBuilder.fromUriString(endPoint)
.build(value);
}
private HttpHeaders getHeaders(final HttpHeaders headers, final Map<String, String> map) {
if(ObjectUtils.isEmpty(map)) return headers;
for(Map.Entry<String, String> e : map.entrySet()){
headers.add(e.getKey(), e.getValue());
}
return headers;
}
}

@ -0,0 +1,70 @@
package cokr.xit.ens.core.utils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource;
import org.springframework.core.env.Environment;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
* <pre>
* description : Get Bean Object
* Filter / Interceptor Bean
* (Bean @Autowired / @Resource )
* packageName : kr.xit.core.spring.util
* fileName : CoreSpringUtils
* author : julim
* date : 2023-04-28
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-04-28 julim
*
* </pre>
* @see ApplicationContextProvider
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CoreSpringUtils {
public static ApplicationContext getApplicationContext() {
return ApplicationContextProvider.getApplicationContext();
}
public static boolean containsBean(String beanName) {
return getApplicationContext().containsBean(beanName);
}
public static Object getBean(String beanName) {
return getApplicationContext().getBean(beanName);
}
public static Object getBean(Class<?> clazz) {
return getApplicationContext().getBean(clazz);
}
/**
*
* @return MessageSourceAccessor
*/
public static MessageUtil getMessageUtil(){
return (MessageUtil)getBean(MessageUtil.class);
}
/**
*
* @return MessageSourceAccessor
*/
public static MessageSource getMessageSource(){
return (MessageSource)getBean(MessageSource.class);
}
public static Environment getEnvironment(){
return (Environment)getBean(Environment.class);
}
public static ObjectMapper getObjectMapper(){
return (ObjectMapper)getBean(ObjectMapper.class);
}
}

@ -0,0 +1,339 @@
package cokr.xit.ens.core.utils;
import java.io.IOException;
import java.io.StringReader;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import cokr.xit.ens.core.config.support.CustomJacksonConfig;
import cokr.xit.ens.core.exception.BizRuntimeException;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
* <pre>
* description : JSON Utility
*
* packageName : kr.xit.core.support.utils
* fileName : JsonUtils
* author : limju
* date : 2023-09-04
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-04 limju
*
* </pre>
* @see CustomJacksonConfig
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class JsonUtils {
private static final ObjectMapper OM = CoreSpringUtils.getObjectMapper();
/**
* json string
* @param str String
* @return boolean
*/
public static boolean isJson(final String str) {
try {
OM.readTree(str);
return true;
} catch (JsonProcessingException e) {
return false;
}
}
/**
* Object -> json string
* @return String
* @param obj Object
*/
public static String toJson(final Object obj) {
try {
return ObjectUtils.isNotEmpty(obj)? OM.writeValueAsString(obj) : null;
} catch (JsonProcessingException e) {
throw BizRuntimeException.create(e.getLocalizedMessage());
}
}
/**
* Json string -> class
* @return T
* @param str String
* @param cls Class
*/
public static <T> T toObject(final String str, final Class<T> cls) {
try {
return ObjectUtils.isNotEmpty(str)? OM.readValue(str, cls) : null;
} catch (JsonProcessingException e) {
throw BizRuntimeException.create(e.getLocalizedMessage());
}
}
/**
* Object -> class
* @param obj Object
* @param cls Class
* @return T
*/
public static <T> T toObjByObj(final Object obj, final Class<T> cls) {
try {
return ObjectUtils.isNotEmpty(obj)? OM.convertValue(obj, cls) : null;
} catch (IllegalArgumentException e) {
throw BizRuntimeException.create(e.getLocalizedMessage());
}
}
/**
* xml String -> cls
* @param xml String
* @param cls Class
* @return cls Class
*/
public static <T> T toObjByXml(String xml, final Class<T> cls){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(xml)));
return toObject(OM.writeValueAsString(document), cls);
} catch (ParserConfigurationException | SAXException | IOException e) {
throw BizRuntimeException.create(e.getMessage());
}
}
/**
* Json string -> class list
* @return T
* @param str
* @param cls
* @throws IOException
*/
public static <T> List<T> toObjectList(final String str, final Class<T> cls) {
if(ObjectUtils.isNotEmpty(str)){
try {
return OM.readValue(str, OM.getTypeFactory().constructCollectionType(List.class, cls));
} catch (JsonProcessingException e) {
throw BizRuntimeException.create(e.getLocalizedMessage());
}
}else {
return null;
}
}
/**
* JSON -> Map
* @param str String str
* @return Map
*/
public static Map<String, Object> toMap(final String str) {
try {
return ObjectUtils.isNotEmpty(str)? OM.readValue(str, new TypeReference<Map<String, Object>>(){}) : null;
} catch (JsonProcessingException e) {
throw BizRuntimeException.create(e.getLocalizedMessage());
}
}
/**
* Object
* -> MultiValueMap<String, String> return
* @param obj Object
* @return MultiValueMap<String, String>
*/
public static MultiValueMap<String, String> toMultiValue(final Object obj){
if(ObjectUtils.isEmpty(obj)) return null;
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
JSONObject jsonObj = toObjByObj(obj, JSONObject.class);
for (Object key : jsonObj.keySet()) {
formData.add((String) key, (String) jsonObj.get(key));
}
return formData;
}
/**
* Object key value
* -> key, value JSONObject return
* @param obj key, value Object
* @param keyName key JSON key name
* @param valueName value JSON key name
* @return JSONObject key, value JSONObject
*/
public static JSONObject extractObjKeyValue(final Object obj, final String keyName, final String valueName){
return extractJsonKeyValue(toObjByObj(obj, JSONObject.class), keyName, valueName);
}
/**
* JSONObject key value
* -> key, value JSONObject return
* @param json
* @param keyName key JSON key name
* @param valueName value JSON key name
* @return JSONObject key, value JSONObject
*/
public static JSONObject extractJsonKeyValue(final JSONObject json, final String keyName, final String valueName){
final JSONObject rtnJson = new JSONObject();
final JSONArray keys = new JSONArray();
final JSONArray values = new JSONArray();
for (Object key : json.keySet()) {
Object value = json.get(key);
if (value instanceof JSONObject) {
JSONObject jo = (JSONObject) value;
extractJsonKeyValue(jo, keyName, valueName);
} else if (value instanceof JSONArray) {
JSONArray ja = (JSONArray) value;
ja.forEach(obj -> extractJsonKeyValue((JSONObject)obj, keyName, valueName));
} else{
//System.out.println(key + ", " + value);
keys.add(String.valueOf(key));
values.add(value);
}
}
rtnJson.put(keyName, keys);
rtnJson.put(valueName, values);
return rtnJson;
}
/**
* JSONArray key value
* -> key, value JSONObject return
* @param jsons JSONArray
* @param keyName key JSON key name
* @param valueName value JSON key name
* @return JSONObject key, value JSONObject
*/
public static JSONObject extractJsonArrayKeyValue(final net.sf.json.JSONArray jsons, final String keyName, final String valueName){
final JSONObject rtnJson = new JSONObject();
final JSONArray keys = new JSONArray();
final JSONArray values = new JSONArray();
for(int i = 0; i<jsons.size(); i++){
JSONObject json = extract(jsons.getJSONObject(i), keyName, valueName);
if(i == 0) rtnJson.put(keyName, json.get(keyName));
values.add(json.get(valueName));
}
rtnJson.put(valueName, values);
return rtnJson;
}
private static JSONObject extract(net.sf.json.JSONObject json, String keyName, String valueName) {
final JSONObject rtnJson = new JSONObject();
final JSONArray keys = new JSONArray();
final JSONArray values = new JSONArray();
for (Object key : json.keySet()) {
Object value = json.get(key);
if (value instanceof JSONObject) {
JSONObject jo = (JSONObject) value;
extractJsonKeyValue(jo, keyName, valueName);
} else if (value instanceof JSONArray) {
JSONArray ja = (JSONArray) value;
ja.forEach(obj -> extractJsonKeyValue((JSONObject)obj, keyName, valueName));
} else {
//System.out.println(key + ", " + value);
keys.add(String.valueOf(key));
values.add(value);
}
}
rtnJson.put(keyName, keys);
rtnJson.put(valueName, values);
return rtnJson;
}
/**
* Json .
* @param obj Object json
* @return String
*/
public static String jsonEnterConvert(final Object obj) {
try {
return jsonEnterConvert((JsonUtils.toJson(obj)));
} catch(Exception e) {
return StringUtils.EMPTY;
}
}
/**
* Json .
* @param json String json
* @return String
*/
private static String jsonEnterConvert(String json) {
if( json == null || json.length() < 2 )
return json;
final int len = json.length();
final StringBuilder sb = new StringBuilder();
char c;
String tab = "";
boolean beginEnd = true;
for( int i=0 ; i<len ; i++ ) {
c = json.charAt(i);
switch( c ) {
case '{': case '[':{
sb.append( c );
if( beginEnd ){
tab += "\t";
sb.append("\n");
sb.append( tab );
}
break;
}
case '}': case ']':{
if( beginEnd ){
tab = tab.substring(0, tab.length()-1);
sb.append("\n");
sb.append( tab );
}
sb.append( c );
break;
}
case '"':{
if( json.charAt(i-1)!='\\' )
beginEnd = ! beginEnd;
sb.append( c );
break;
}
case ',':{
sb.append( c );
if( beginEnd ){
sb.append("\n");
sb.append( tab );
}
break;
}
default :{
sb.append( c );
}
} // switch end
}
if( sb.length() > 0 )
sb.insert(0, '\n');
return sb.toString();
}
}

@ -0,0 +1,64 @@
package cokr.xit.ens.core.utils;
import java.util.Locale;
import javax.annotation.Resource;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
/**
* <pre>
* description : Spring MessageSource read
*
* packageName : kr.xit.core.spring.util
* fileName : MessageUtil
* author : julim
* date : 2023-04-28
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-04-28 julim
*
* </pre>
*/
@Component
public class MessageUtil {
@Resource(name = "messageSource")
private MessageSource messageSource;
/**
* messageSource .
*
* @param code
* @return
*/
public String getMessage(String code) {
return this.getMessage(code, new Object[]{});
}
/**
* messageSource .
*
* @param code
* @param args
* @return
*/
public String getMessage(String code, Object[] args) {
return this.getMessage(code, args, LocaleContextHolder.getLocale());
}
/**
* messageSource , , .
*
* @param code
* @param args
* @param locale
* @return
*/
public String getMessage(String code, Object[] args, Locale locale) {
return messageSource.getMessage(code, args, locale);
}
}

@ -0,0 +1,393 @@
package cokr.xit.ens.modules.kkotalk;
import java.util.Arrays;
import cokr.xit.ens.core.exception.BizRuntimeException;
import lombok.Getter;
/**
* <pre>
* description :
*
* packageName : kr.xit.ens.support.common
* fileName : KakaoConstants
* author : limju
* date : 2023-05-04
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-05-04 limju
*
* </pre>
*/
public class ApiConstants {
/**
* profile
*/
public static final String PROFILE = System.getProperty("spring.profiles.active");
/**
* profile : local
*/
public static final boolean IS_PROFILE_LOCAL = PROFILE.matches("local-.*");
/**
* profile :
*/
public static final boolean IS_CCN = PROFILE.matches(".*-ccn");
public static final String FFNLN_CODE = "11";
/**
* date-time
*/
public static final String FMT_DT_EMPTY_DLT = "yyyyMMddHHmmss";
/**
* date-time
*/
public static final String FMT_DT_STD = "yyyy-MM-dd HH:mm:ss";
/**
* <pre>
*
* code( ) : button_name( )- name( )
* Default : - Default
* BILL : -
* BILL_PAY : -
* NOTICE : -
* CONTRACT : -
* REPORT : -
* </pre>
*/
@Getter
public enum Categories {
DEFAULT("Default")
, BILL("BILL")
, BILL_PAY("BILL_PAY")
, NOTICE("NOTICE")
, CONTRACT("CONTRACT")
, REPORT("REPORT")
;
private final String code;
Categories(String code) {
this.code = code;
}
}
/**
* <pre>
* INVALID_VALUE : http status code : 400
*
* {"error_code": "INVALID_VALUE", "error_message": "유효하지 않은 값입니다."
* UNIDENTIFIED_USER : http status code : 400
*
* {"error_code": "INVALID_VALUE", "error_message": "유효하지 않은 값입니다."
* UNAUTHORIZED : http status code : 401
* access token
* {"error_code": "UNAUTHORIZED","error_message": "접근 권한이 없습니다."
* FORBIDDEN : http status code : 403
*
* {"error_code": "FORBIDDEN","error_message": "허용되지 않는 요청입니다. 수신거부된 사용자 입니다."}
* NOT_FOUND : http status code : 404
* "Contract-Uuid" or "document_binder_uuid"
* {"error_code": "NOT_FOUND","error_message": "요청 정보를 찾을 수 없습니다."
* INTERNAL_ERROR : http status code : 500
*
* {"error_code": "INTERNAL_SERVER_ERROR","error_message": "서버 에러입니다. 다시 시도해 주세요."}
* </pre>
*
*/
@Getter
public enum Error {
INVALID_VALUE("INVALID_VALUE")
, UNIDENTIFIED_USER("UNIDENTIFIED_USER")
, UNAUTHORIZED("UNAUTHORIZED")
, FORBIDDEN("FORBIDDEN")
, NOT_FOUND("NOT_FOUND")
, INTERNAL_ERROR("INTERNAL_ERROR")
;
private final String code;
Error(String code) {
this.code = code;
}
}
/**
* <pre>
*
* SENT() > RECEIVED() > READ()/EXPIRED( )
* </pre>
*/
@Getter
public enum KkopayDocStatus {
SENT("SENT")
, RECEIVED("RECEIVED")
, READ("READ")
, EXPIRED("EXPIRED")
;
private final String code;
KkopayDocStatus(String code) {
this.code = code;
}
}
/**
* <pre>
*
* RECEIVE(, ) > READ()/EXPIRED( )
* </pre>
*/
@Getter
public enum KkotalkDocStatus {
RECEIVED("RECEIVE")
, READ("READ")
, EXPIRED("EXPIRED")
;
private final String code;
KkotalkDocStatus(String code) {
this.code = code;
}
}
/**
* : ENS003
*/
@Getter
public enum SndngProcessStatus {
ACCEPT("accept"),
ACCEPT_OK("accept-ok"),
ACCEPT_FAIL("accept-fail"),
MAKE_OK("make-ok"),
MAKE_FAIL1("make-fail1"),
MAKE_FAIL2("make-fail2"),
MAKE_FAIL3("make-fail3"),
SENDING1("sending1"),
SENDING2("sending2"),
SEND_OK("send-ok"),
SEND_FAIL1("send-fail1"),
SEND_FAIL2("send-fail2"),
SEND_FAIL3("send-fail3"),
CLOSE("close")
;
private final String code;
SndngProcessStatus(String code) {
this.code = code;
}
}
/**
*
*/
@Getter
public enum SndngSeCode {
KAKAO("KKO-MY-DOC", "카카오"),
KAKAO_NEW("KKO-NEW", "카카오NEW"),
KT_BC("KT-BC", "공공알림문자"),
KT_GIBIS("KT-GIBIS", "GIBIS알림문자"),
;
private final String code;
private final String desc;
SndngSeCode(final String code, final String desc) {
this.code = code;
this.desc = desc;
}
public static SndngSeCode getSndngSeCode(final String code){
return Arrays.stream(SndngSeCode.values())
.filter(ssc -> ssc.getCode().equals(code))
.findFirst()
.orElseThrow(() -> BizRuntimeException.create(String.format("미정의된 문서 중계자가[%s]", code)));
}
}
/**
* SignguCode
*/
@Getter
public enum SignguCode {
/**
*
*/
CHUNCHEON("51110"),
/**
*
*/
CHEONAN_ES("44131"),
/**
*
*/
CHEONAN_WN("44133"),
;
private final String code;
SignguCode(String code) {
this.code = code;
}
}
public enum NiceCiWrkDiv {
TOKEN,
PUBLIC_KEY,
SYM_KEY,
CI
}
public enum KtServiceCode {
SISUL,
CHUMO;
public static KtServiceCode compare(final String en){
return valueOf(en);
}
}
/**
* <pre>
* : ENS003
* 01: , 11: , 19:
* 22: , 29: , 08: , 09: , 99:
* </pre>
*/
@Getter
public enum MappingCcnSndngProcessStatus {
ACCEPT("accept", "01"),
ACCEPT_OK("accept-ok", "11"),
ACCEPT_FAIL("accept-fail", "19"),
MAKE_OK("make-ok", "22"),
MAKE_FAIL1("make-fail1", "29"),
MAKE_FAIL2("make-fail2", "29"),
MAKE_FAIL3("make-fail3", "29"),
SENDING1("sending1", "08"),
SENDING2("sending2", "08"),
SEND_OK("send-ok", "08"),
SEND_FAIL1("send-fail1", "99"),
SEND_FAIL2("send-fail2", "99"),
SEND_FAIL3("send-fail3", "99"),
CLOSE("close", "09")
;
private final String ensCode;
private final String trfCode;
MappingCcnSndngProcessStatus(String ensCode, String trfCode) {
this.ensCode = ensCode;
this.trfCode = trfCode;
}
/**
* <pre>
* traffic ens
* @param trfCode
* @return traffic ens
* </pre>
*/
public static String fromTraffic(final String trfCode){
return Arrays.stream(MappingCcnSndngProcessStatus.values())
.filter(en -> en.getTrfCode().equals(trfCode))
.findFirst()
.map(MappingCcnSndngProcessStatus::getEnsCode)
.orElseThrow(() -> BizRuntimeException.create(String.format("미정의된 상태코드가[%s]", trfCode)));
}
/**
* <pre>
* ens traffic
* @param ensCode
* @return ens traffic
* </pre>
*/
public static String fromEns(final String ensCode){
return Arrays.stream(MappingCcnSndngProcessStatus.values())
.filter(en -> en.getEnsCode().equals(ensCode))
.findFirst()
.map(MappingCcnSndngProcessStatus::getTrfCode)
.orElseThrow(() -> BizRuntimeException.create(String.format("미정의된 상태코드가[%s]", ensCode)));
}
}
/**
* <pre>
* : ENS003
* 01: , 11: , 19:
* 22: , 29: , 08: , 09: , 99:
* </pre>
*/
@Getter
public enum MappingCanSndngProcessStatus {
ACCEPT("accept", "accept"),
ACCEPT_OK("accept-ok", "acptok"),
ACCEPT_FAIL("accept-fail", "acptfail"),
MAKE_OK("make-ok", "ensmake"),
MAKE_FAIL1("make-fail1", "makefail"),
MAKE_FAIL2("make-fail2", "makefail"),
MAKE_FAIL3("make-fail3", "makefail"),
SENDING1("sending1", "ensok"),
SENDING2("sending2", "ensok"),
SEND_OK("send-ok", "ensopen"),
SEND_FAIL1("send-fail1", "ensfail"),
SEND_FAIL2("send-fail2", "ensfail"),
SEND_FAIL3("send-fail3", "ensfail"),
CLOSE("close", "ensclose")
;
private final String ensCode;
private final String trfCode;
MappingCanSndngProcessStatus(String ensCode, String trfCode) {
this.ensCode = ensCode;
this.trfCode = trfCode;
}
/**
* <pre>
* traffic ens
* @param trfCode
* @return traffic ens
* </pre>
*/
public static String fromTraffic(final String trfCode){
return Arrays.stream(MappingCanSndngProcessStatus.values())
.filter(en -> en.getTrfCode().equals(trfCode))
.findFirst()
.map(MappingCanSndngProcessStatus::getEnsCode)
.orElseThrow(() -> BizRuntimeException.create(String.format("미정의된 상태코드가[%s]", trfCode)));
}
/**
* <pre>
* ens traffic
* @param ensCode
* @return ens traffic
* </pre>
*/
public static String fromEns(final String ensCode){
return Arrays.stream(MappingCanSndngProcessStatus.values())
.filter(en -> en.getEnsCode().equals(ensCode))
.findFirst()
.map(MappingCanSndngProcessStatus::getTrfCode)
.orElseThrow(() -> BizRuntimeException.create(String.format("미정의된 상태코드가[%s]", ensCode)));
}
}
}

@ -0,0 +1,285 @@
// package cokr.xit.ens.modules.kkotalk;
//
// import java.nio.charset.StandardCharsets;
// import java.security.InvalidAlgorithmParameterException;
// import java.security.InvalidKeyException;
// import java.security.KeyFactory;
// import java.security.MessageDigest;
// import java.security.NoSuchAlgorithmException;
// import java.security.spec.InvalidKeySpecException;
// import java.security.spec.X509EncodedKeySpec;
// import java.util.ArrayList;
// import java.util.Base64;
// import java.util.List;
// import java.util.Locale;
// import java.util.Random;
// import java.util.Set;
// import java.util.UUID;
//
// import javax.crypto.BadPaddingException;
// import javax.crypto.Cipher;
// import javax.crypto.IllegalBlockSizeException;
// import javax.crypto.Mac;
// import javax.crypto.NoSuchPaddingException;
// import javax.crypto.SecretKey;
// import javax.crypto.spec.IvParameterSpec;
// import javax.crypto.spec.SecretKeySpec;
// import javax.validation.ConstraintViolation;
// import javax.validation.Validation;
// import javax.validation.Validator;
//
// import org.apache.commons.lang3.ObjectUtils;
// import org.apache.commons.lang3.StringUtils;
// import org.springframework.util.Base64Utils;
//
// import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
//
// import cokr.xit.ens.core.exception.BizRuntimeException;
// import cokr.xit.ens.core.utils.CoreSpringUtils;
// import cokr.xit.ens.core.utils.MessageUtil;
// import cokr.xit.ens.modules.kkotalk.model.CmmEnsRequestDTO;
// import cokr.xit.ens.modules.kkotalk.model.CmmEnsRlaybsnmDTO;
// import lombok.AccessLevel;
// import lombok.NoArgsConstructor;
//
// /**
// * <pre>
// * description : ENS 공통 method
// *
// * packageName : kr.xit.ens.cmm
// * fileName : CmmNiceCiUtils
// * author : limju
// * date : 2023-09-19
// * ======================================================================
// * 변경일 변경자 변경 내용
// * ----------------------------------------------------------------------
// * 2023-09-19 limju 최초 생성
// *
// * </pre>
// */
//
// @NoArgsConstructor(access = AccessLevel.PRIVATE)
// public class CmmEnsUtils {
// private static final MessageUtil messageUtil = CoreSpringUtils.getMessageUtil();
// private static final ICmmEnsCacheService cacheService = ApiSpringUtils.getCmmEnsCacheService();
// private static final IBizKtBcService bizKtService = ApiSpringUtils.getBizKtMmsService();
//
// /**
// * 문서 중개자 인증 정보 조회
// * @param signguCode string
// * @param ffnlgCode String
// * @param seCode SndngSeCode 문서중개자 구분 코드
// * @return CmmEnsRlaybsnmDTO 문서중개자 정보
// */
// public static CmmEnsRlaybsnmDTO getRlaybsnmInfo(final String signguCode, final String ffnlgCode, final
// SndngSeCode seCode) {
// CmmEnsRequestDTO ensDTO = CmmEnsRequestDTO.builder()
// .signguCode(signguCode)
// .ffnlgCode(ffnlgCode)
// .profile(ApiConstants.IS_PROFILE_LOCAL? "local" : "prod")
// .build();
//
// final CmmEnsRlaybsnmDTO dto = cacheService.getRlaybsnmInfoCache(ensDTO);
// if(ObjectUtils.isEmpty(dto)) throw BizRuntimeException.create(messageUtil.getMessage("fail.api.rlaybsnm.info"));
//
// // KT인 경우 토큰유효기간 check
// if(SndngSeCode.KT_BC.equals(seCode)){
//
// if(StringUtils.isNotEmpty(dto.getKtTokenExpiresIn())
// && DateUtils.getTodayAndNowTime(ApiConstants.FMT_DT_STD).compareTo(dto.getKtTokenExpiresIn()) < 0
// && ObjectUtils.isNotEmpty(dto.getKtAccessToken())
// ) return dto;
//
// // 유효기간이 경과된 경우 재발급
// bizKtService.requestToken(
// KtMnsRequest.builder()
// .signguCode(signguCode)
// .ffnlgCode(ffnlgCode)
// .profile(ApiConstants.IS_PROFILE_LOCAL? "local" : "prod")
// .build()
// );
// return cacheService.getRlaybsnmInfoCache(ensDTO);
// }
// return dto;
// }
//
// /**
// * <pre>
// * parameter validation check
// * invalid parameter message -> String으로 BizRuntimeException throw
// * @param t T
// * </pre>
// */
// public static <T> void validate(T t) {
// Locale.setDefault(Locale.KOREA);
// final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
// final Set<ConstraintViolation<T>> list = validator.validate(t);
//
// if (!list.isEmpty()) {
// throw BizRuntimeException.create(
// list.stream()
// .map(row -> String.format("%s=%s", row.getPropertyPath(), row.getMessageTemplate()))
// //.map(row -> String.format("%s=%s", row.getPropertyPath(), row.get()) ? row.getMessage(): row.getMessageTemplate()))
// .toList().toString());
// }
// }
//
// /**
// * parameter validation check
// * @param t T
// * @return List<ErrorMsg>
// */
// public static <T> List<ErrorMsg> getValidateErrors(T t) {
// Locale.setDefault(Locale.KOREA);
// final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
// final Set<ConstraintViolation<T>> list = validator.validate(t);
//
// if (!list.isEmpty()) {
// return list.stream()
// .map(row -> new ErrorMsg(String.format("%s=%s", row.getPropertyPath(), row.getMessageTemplate())))
// .toList();
// }
// return new ArrayList<>();
// }
//
// /**
// * length 길이의 UUID String return -> '-' remove
// * @param length
// * @return
// */
// public static String generateLengthUuid(int length) {
// final String allChars = UUID.randomUUID().toString().replace("-", "");
// final Random random = new Random();
// final char[] otp = new char[length];
// for (int i = 0; i < length; i++) {
// otp[i] = allChars.charAt(random.nextInt(allChars.length()));
// }
// return String.valueOf(otp);
// }
//
// /**
// * 공개키로 암호화를 수행
// *
// * @param publicKeyString String
// * @param symkeyRegInfo String
// * @return String
// */
// public static String encSymkeyRegInfo(String publicKeyString, String symkeyRegInfo) {
// try {
// KeyFactory keyFactory = KeyFactory.getInstance("RSA");
// byte[] cipherEnc = Base64.getDecoder().decode(publicKeyString);
// X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(cipherEnc);
// java.security.PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
//
// Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
// cipher.init(Cipher.ENCRYPT_MODE, publicKey);
// byte[] bytePlain = cipher.doFinal(symkeyRegInfo.getBytes());
//
// return Base64Utils.encodeToString(bytePlain);
// } catch (NoSuchAlgorithmException | InvalidKeySpecException | NoSuchPaddingException |
// IllegalBlockSizeException | BadPaddingException | InvalidKeyException e){
// throw BizRuntimeException.create(e.getMessage());
// }
// }
//
// /**
// * sha256 암호화
// *
// * @param text String
// * @return String
// */
// public static String hexSha256(final String text) {
// final StringBuilder sbuf = new StringBuilder();
//
// try {
// final MessageDigest mDigest = MessageDigest.getInstance("SHA-256");
// mDigest.update(text.getBytes());
//
// final byte[] msgStr = mDigest.digest();
//
// for(final byte tmpStrByte : msgStr) {
// final String tmpEncTxt = Integer.toString((tmpStrByte & 0xff) + 0x100, 16)
// .substring(1);
//
// sbuf.append(tmpEncTxt);
// }
// } catch (NoSuchAlgorithmException nae){
// throw BizRuntimeException.create(nae.getMessage());
// }
// return sbuf.toString();
// }
//
//
// /**
// * <pre>
// * AES 암호화 -> Base64 encoding return
// * -> Nice ci 데이타 암호화
// *
// * @param key String
// * @param iv String
// * @param planText String
// * @return String Base64 encoding data
// * </pre>
// */
// public static String encodeAesData(final String key, final String iv, final String planText) {
// final SecretKey secureKey = new SecretKeySpec(key.getBytes(), "AES");
// try {
// final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
// cipher.init(Cipher.ENCRYPT_MODE, secureKey, new IvParameterSpec(iv.getBytes()));
//
// final byte[] encData = cipher.doFinal(planText.trim().getBytes(StandardCharsets.UTF_8));
// return Base64.getEncoder().encodeToString(encData);
//
// }catch (NoSuchPaddingException | NoSuchAlgorithmException |
// InvalidAlgorithmParameterException | InvalidKeyException |
// IllegalBlockSizeException | BadPaddingException e){
// throw BizRuntimeException.create(e.getMessage());
// }
// }
//
// /**
// * <pre>
// * Hmac 무결성체크값(integrity_value) 생성
// * @param hmacKey String
// * @param message String
// * @return String
// * </pre>
// */
// public static String encodeHmacSha256(final String hmacKey, final String message) {
// try {
// final Mac mac = Mac.getInstance("HmacSHA256");
// final SecretKeySpec sks = new SecretKeySpec(hmacKey.getBytes(), "HmacSHA256");
// mac.init(sks);
// final byte[] hmac256 = mac.doFinal(message.getBytes());
// return Base64.getEncoder().encodeToString(hmac256);
//
// }catch (NoSuchAlgorithmException|InvalidKeyException e){
// throw BizRuntimeException.create(e.getMessage());
// }
// }
//
// /**
// * AES 복호화
// * @param encData String
// * @param key String
// * @param iv String
// * @return String
// */
// public static String decodeAesData(String encData, String key, String iv) {
//
// final byte[] respDataEnc = Base64.getDecoder().decode(encData.getBytes());
// final SecretKey secureKey = new SecretKeySpec(key.getBytes(), "AES");
//
// try {
// final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
// cipher.init(Cipher.DECRYPT_MODE, secureKey, new IvParameterSpec(iv.getBytes()));
// final byte[] decrypted = cipher.doFinal(respDataEnc);
// return new String(decrypted);
//
// }catch (NoSuchPaddingException | NoSuchAlgorithmException |
// InvalidAlgorithmParameterException | InvalidKeyException |
// IllegalBlockSizeException | BadPaddingException e){
// throw BizRuntimeException.create(e.getMessage());
// }
// }
// }

@ -0,0 +1,67 @@
package cokr.xit.ens.modules.kkotalk.model;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* <pre>
* description : Request DTO
*
* packageName : kr.xit.biz.ens.model.kt
* fileName : CmmEnsRequestDTO
* author : limju
* date : 2023-09-22
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-22 limju
*
* </pre>
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(Include.NON_NULL)
public class CmmEnsRequestDTO {
/**
*
*/
@Schema(requiredMode = RequiredMode.REQUIRED, title = "시군구코드", example = "51110")
@Size(min = 1, max = 10, message = "시군구 코드는 필수 입니다")
@JsonProperty("signguCode")
private String signguCode;
/**
*
*/
@Schema(requiredMode = RequiredMode.REQUIRED, title = "과태료코드", example = "11")
@Size(min = 1, max = 2, message = "과태료 코드는 필수 입니다")
@JsonProperty("ffnlgCode")
private String ffnlgCode = "11";
/**
* active profile
*/
@Schema(requiredMode = RequiredMode.AUTO, title = "profile", example = "local")
@JsonProperty("profile")
private String profile;
/**
* 1
*/
@Schema(hidden = true, requiredMode = RequiredMode.AUTO, title = "1차 발송", example = "KKO-MY-DOC")
@JsonProperty("try1")
private String try1;
}

@ -0,0 +1,174 @@
package cokr.xit.ens.modules.kkotalk.model;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* <pre>
* description : DTO
*
* packageName : kr.xit.biz.ens.model.kt
* fileName : KtMmsDTO
* author : limju
* date : 2023-09-22
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-22 limju
*
* </pre>
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CmmEnsRlaybsnmDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
private String signguCode;
/**
*
*/
private String ffnlgCode;
/**
* profile
*/
private String profile;
/**
*
*/
private String signguNm;
/**
*
*/
private String ffnlgNm;
/**
* KAKAO CLIENT ID
*/
private String kakaoClientId;
/**
* KAKAO
*/
private String kakaoProductCd;
/**
* KAKAO ACCESS TOKEN
*/
private String kakaoAccessToken;
/**
* KAKAO CONTRACT UUID
*/
private String kakaoContractUuid;
/**
* KAKAO_NEW PARTNER KEY
*/
private String kakaoPartnerRestApiKey;
/**
* KAKAO_NEW DEALER KEY
*/
private String kakaoDealerRestApiKey;
/**
* KAKAO_NEW SETTLE ID
*/
private String kakaoSettleId;
/**
* KT client id
*/
private String ktClientId;
/**
* KT client tp
*/
private String ktClientTp;
/**
* KT Scope
*/
private String ktScope;
/**
* KT Service code
*/
private String ktServiceCode;
/**
* KT service client ID
*/
private String ktSvcClientId;
/**
* KT service client secret
*/
private String ktSvcClientSecret;
/**
* KT service cerf key
*/
private String ktSvcCerfKey;
/**
* KT_ACCESS_TOKEN
*/
private String ktAccessToken;
/**
* KT
*/
private String ktTokenExpiresIn;
/**
* KT
*/
private String ktTokenJti;
/**
* postplus apiKey
*/
private String pplusApiKey;
/**
* EPost service key
*/
private String epostServiceKey;
/**
*
*/
private String senderNm;
/**
*
*/
private String senderZipNo;
/**
*
*/
private String senderAddr;
/**
*
*/
private String senderDetailAddr;
/**
*
*/
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd kk:mm:ss")
private LocalDateTime registDt;
/**
*
*/
private String register;
/**
*
*/
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd kk:mm:ss")
private LocalDateTime updtDt;
/**
*
*/
private String updusr;
}

@ -0,0 +1,416 @@
package cokr.xit.ens.modules.kkotalk.model;
import javax.validation.Valid;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotEmpty;
import com.fasterxml.jackson.annotation.JsonInclude;
import cokr.xit.ens.core.aop.IApiResponse;
import cokr.xit.ens.modules.kkotalk.ApiConstants;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* <pre>
* description : DTO
* API json .
* => @JsonInclude(JsonInclude.Include.NON_EMPTY)
* packageName : kr.xit.biz.ens.model.kakao.talk
* fileName : KkotalkApiDTO
* author : limju
* date : 2024-08-12
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024-08-12 limju
*
* </pre>
*/
public class KkotalkApiDTO {
//------------------- Envelope ------------------------------------------------------------------------------------------------
@Schema(name = "Envelope", description = "문서발송(단건) 요청 파라메터 DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class Envelope {
/**
* : - max 40
*/
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "발송할 문서의 제목", example = "문서 제목")
@Size(max = 40, message = "발송할 문서의 제목은 필수 입니다(max:40)")
private String title;
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@Valid
private Content content;
/**
* <pre>
* () hash
* D10_2
* </pre>
*/
@Schema(title = "문서 원문(열람정보)에 대한 hash 값", example = "6EFE827AC88914DE471C621AE")
@Pattern(regexp = "^$|^[a-fA-F0-9]{44}$|^[a-fA-F0-9]{64}$", message = "문서 해시값은 44자 또는 64자의 16진수여야 합니다")
private String hash;
/**
* (: 500) -
*/
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "문서 정보 안내 화면에 노출할 문구(최대: 500자)", example = "문서 정보 안내 화면에 노출할 문구")
@Size(min=1, max = 500, message = "문서 정보 안내 화면에 노출할 문구(max=500)")
private String guide;
/**
* payload
*/
@Schema(title = "payload", example = "payload 파라미터 입니다.")
@Size(max = 200, message = "payload(max=200)")
private String payload;
/**
* <pre>
* (: 6 ) -
* yyyy-MM-dd'T'HH:mm:ss > DateUtils.getTimeTOfNow()
* </pre>
*/
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "최초열람마감시간(yyyy-MM-dd'T'HH:mm:ss)", example = "2023-12-31T10:00:00")
@Size(min = 19, max = 19, message = "최초열람마감시간(yyyy-MM-dd'T'HH:mm:ss)")
private String readExpiresAt;
/**
* <pre>
*
* : readExpiredAt
* : 9999-12-31'T'23:59:59, null
* : DX0 6
* </pre>
*/
@Schema(title = "재열람 만료 일시(yyyy-MM-dd'T'HH:mm:ss)", example = "2023-12-31T13:00:00")
@Size(max = 19, message = "재열람 만료 일시(yyyy-MM-dd'T'HH:mm:ss)")
private String reviewExpiresAt;
/**
* <pre>
*
* default: false
* </pre>
*/
@Schema(title = "알림톡 내용에 개인정보 제거 여부", example = " ", defaultValue = "false", allowableValues = {"true", "false"})
@Builder.Default
private Boolean useNonPersonalizedNotification = false;
/**
* CI
*/
@Schema(title = "받는이 CI", example = " ")
@Size(max=88, message = "수신자 CI(max=88)")
private String ci;
/**
* <pre>
*
* ci
* </pre>
*/
@Schema(title = "수신자 전화번호", example = "01012345678")
@Pattern(regexp = "^$|^\\d{11}$", message = "수신자 전화번호(max=11)")
private String phoneNumber;
/**
* <pre>
*
* ci
* </pre>
*/
@Schema(title = "수신자 이름", example = "김페이")
@Size(max = 26, message = "수신자 이름(max=26)")
private String name;
/**
* <pre>
* (YYYY-MM-DD )
* ci
* </pre>
*/
@Schema(requiredMode = Schema.RequiredMode.AUTO, title = "수신자 생년월일 (YYYYMMDD 형식)", example = "19801101")
@Pattern(regexp = "^$|^(19\\d{2}|20\\d{2})(0[1-9]|1[0-2])(0[1-9]|[1-2]\\d|3[0-1])$", message = "수신자 생년월일(YYYYMMDD)")
private String birthday;
/**
* <pre>
* - 40
* </pre>
*/
@Schema(requiredMode = Schema.RequiredMode.AUTO, title = "문서매핑용 식별자", example = " ")
@Size(max=40, message = "문서매핑용 식별자(max=40)")
private String externalId;
}
@Schema(name = "Content", description = "문서 원문 웹링크 또는 HTML")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class Content {
/**
* <pre>
*
* D10
* 1000 URL
* </pre>
*/
@Schema(title = "본인인증 후 사용자에게 보여줄 웹페이지 주소", example = "http://ipAddress/api/kakaopay/v1/ott")
@Size(max = 1000, message = "본인인증후 사용자에게 보여줄 페이지 주소는 필수입니다(max=1000)")
private String link;
/**
* <pre>
* HTML
* D11 ( 64KB)
*/
@Schema(title = "HTML 전문", example = " ")
@Size(max = 65536, message = "HTML 전문(max=64KB)")
private String html;
}
//------------------- ValidToken ------------------------------------------------------------------------------------------------
@Schema(name = "ValidTokenRequest DTO", description = "카카오톡 전자문서 토큰 유효성 검증 파라메터 DTO")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public static class ValidTokenRequest extends CmmEnsRequestDTO {
/**
* ID, 34
*/
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "문서 고유 ID, 34자로 고정", example = " ")
@Size(min = 34, max = 34, message = "문서 고유 ID는 필수입니다(34자)")
private String envelopeId;
/**
* :
*/
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "카카오톡 전자문서 서버에서 생성한 일회용 토큰", example = "CON-cc375944ae3d11ecb91e42193199ee3c")
@NotEmpty(message = "카카오톡 전자문서 서버 토큰은 필수입니다")
private String token;
}
@Schema(name = "ValidTokenResponse DTO", description = "카카오톡 토큰 검증 response DTO")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public static class ValidTokenResponse extends KkotalkErrorDTO implements IApiResponse {
/**
* ID, 34
*/
private String envelopeId;
/**
* <pre>
* - 40
* </pre>
*/
private String externalId;
/**
* <pre>
* :
* ,||
* RECEIVE|READ|EXPIRED
* </pre>
* @see ApiConstants.KkotalkDocStatus
*/
private ApiConstants.KkotalkDocStatus status;
/**
* <pre>
* -
* yyyy-MM-dd'T'HH:mm:ss > DateUtils.getTimeTOfNow()
* </
*/
private String sentAt;
/**
* <pre>
* -
* yyyy-MM-dd'T'HH:mm:ss > DateUtils.getTimeTOfNow()
* </pre>
*/
private String receivedAt;
/**
* <pre>
*
* yyyy-MM-dd'T'HH:mm:ss > DateUtils.getTimeTOfNow()
* </pre>
*/
private String readAt;
/**
* <pre>
*
* yyyy-MM-dd'T'HH:mm:ss > DateUtils.getTimeTOfNow()
* </pre>
*/
private String authenticatedAt;
/**
* <pre>
*
* yyyy-MM-dd'T'HH:mm:ss > DateUtils.getTimeTOfNow()
* </pre>
*/
private String ottVerifiedAt;
/**
* <pre>
*
* </pre>
*/
private Boolean isNotificationUnavailable;
/**
* <pre>
*
* yyyy-MM-dd'T'HH:mm:ss > DateUtils.getTimeTOfNow()
* </pre>
*/
private String userNotifiedAt;
/**
* API
*/
private String payload;
}
//------------------ ValidToken ----------------------------------------------------------------------
//------------------ DocStatus ----------------------------------------------------------------------
@Schema(name = "EnvelopeStatusResponse DTO", description = "카카오톡 상태조회 response DTO")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@EqualsAndHashCode(callSuper = true)
public static class EnvelopeStatusResponse extends ValidTokenResponse implements IApiResponse {
/** /**
* <pre>
*
* yyyy-MM-dd'T'HH:mm:ss > DateUtils.getTimeTOfNow()
* </pre>
*/
private String readExpiredAt;
/** /**
* <pre>
*
*
* yyyy-MM-dd'T'HH:mm:ss > DateUtils.getTimeTOfNow()
* </pre>
*/
private String distributionReceivedAt;
}
//------------------ DocStatus ----------------------------------------------------------------------
//------------------ SendResponse ----------------------------------------------------------------------
@Schema(name = "EnvelopeRes DTO", description = "문서발송 응답 DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
//@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class EnvelopeRes extends KkotalkErrorDTO{
/**
* ID, 34
*/
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "문서 고유 ID, 34자로 고정", example = " ")
@Size(min = 34, max = 34, message = "문서 고유 ID는 필수입니다(34자)")
private String envelopeId;
/**
* <pre>
* - 40
* </pre>
*/
private String externalId;
}
@Schema(name = "KkotalkErrorResponse DTO", description = "카카오톡 에러 응답 DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public static class KkotalkErrorDTO {
/**
*
*/
private String errorCode;
/**
*
*/
private String errorMessage;
/**
* (Tracking) ID
*/
private String edocGtid;
}
@Schema(name = "SendResponse DTO", description = "문서발송 응답 DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public static class SendResponse extends KkotalkErrorDTO {
/**
* ID, 34 -
*/
private String envelopeId;
/**
* <pre>
* - 40
* </pre>
*/
private String externalId;
}
//-------------------------------------------------------------------------------------
@Schema(name = "EnvelopeId DTO", description = "EnvelopeId DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public static class EnvelopeId extends CmmEnsRequestDTO{
/**
* ID, 34
*/
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "문서 고유 ID, 34자로 고정", example = " ")
@Size(min = 34, max = 34, message = "문서 고유 ID는 필수입니다(34자)")
private String envelopeId;
}
}

@ -0,0 +1,111 @@
package cokr.xit.ens.modules.kkotalk.model;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* <pre>
* description : DTO
*
* packageName : kr.xit.ens.model.kakao.talk
* fileName : KkotalkDTO
* author : limju
* date : 2024-08-12
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024-08-12 limju
*
* </pre>
*/
public class KkotalkDTO extends KkotalkApiDTO {
//------------------ envelop ----------------------------------------------------------------------
@Schema(name = "SendRequest DTO", description = "문서발송 request DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public static class SendRequest extends CmmEnsRequestDTO {
/**
* <pre>
* -
* D10_1|D10_2|D11_1|D11_2
* </pre>
*/
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "상품코드", example = "D10_2", allowableValues = {"D10_1","D10_2","D11_1","D11_2"})
@Size(min = 3, max = 5, message = "상품 코드는 필수 입니다(\"D10_1\",\"D10_2\",\"D11_1\",\"D11_2\"")
private String productCode = "D10_2";
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@Valid
private Envelope envelope;
}
//------------------ envelop ----------------------------------------------------------------------
//------------------ bulk ----------------------------------------------------------------------
@Schema(name = "BulkSendRequest DTO", description = "문서발송[bulk] request DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public static class BulkSendRequest extends CmmEnsRequestDTO {
/**
* <pre>
* -
* D10_1|D10_2|D11_1|D11_2
* </pre>
*/
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "상품코드", example = "D10_1", allowableValues = {"D10_1","D10_2","D11_1","D11_2"})
@Size(min = 3, max = 5, message = "상품 코드는 필수 입니다(\"D10_1\",\"D10_2\",\"D11_1\",\"D11_2\"")
private String productCode = "D10_2";
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@Valid
private List<Envelope> envelopes;
}
@Schema(name = "BulkSendResponse DTO", description = "문서발송(bulk) response DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public static class BulkSendResponse {
private List<EnvelopeRes> envelopes;
}
@Schema(name = "BulkStatusRequest DTO", description = "문서상태조회[bulk] request DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public static class BulkStatusRequest extends CmmEnsRequestDTO {
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@Valid
private List<String> envelopes;
}
@Schema(name = "BulkStatusResponse DTO", description = "문서상태조회(bulk) response DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public static class BulkStatusResponse {
private List<KkotalkApiDTO.EnvelopeStatusResponse> envelopeStatus;
}
//------------------ bulk ----------------------------------------------------------------------
}

@ -0,0 +1,94 @@
package cokr.xit.ens.modules.kkotalk.service;
import cokr.xit.ens.modules.kkotalk.model.KkotalkApiDTO;
import cokr.xit.ens.modules.kkotalk.model.KkotalkDTO;
/**
* <pre>
* description :
* packageName : kr.xit.ens.kakao.talk.service
* fileName : IKkopayEltrcDocService
* author : julim
* date : 2023-04-28
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-04-28 julim
*
* </pre>
*/
public interface IKkotalkEltrcDocService {
/**
* <pre>
*
* -. .
* </pre>
* @param reqDTO KkotalkApiDTO.SendRequest
* @return KkotalkApiDTO.SendResponse
*/
KkotalkDTO.SendResponse requestSend(final KkotalkDTO.SendRequest reqDTO);
/**
* <pre>
* (Redirect URL /)
* </pre>
* @param reqDTO KkotalkApiDTO.ValidTokenRequest
* @return KkotalkApiDTO.ValidTokenResponse>
*/
KkotalkApiDTO.ValidTokenResponse validToken(final KkotalkApiDTO.ValidTokenRequest reqDTO);
/**
* <pre>
* API
* -. . (OTT ) API .
* -.
* 1) API .
* 2) API(/v1/envelopes/${ENVELOPE_ID}/read) read_at ) .
* </pre>
* @param reqDTO KkotalkDTO.EnvelopeId
*/
void modifyStatus(final KkotalkDTO.EnvelopeId reqDTO);
/**
* <pre>
* API
* -. .
* : , flow
* : polling , 5 .
* -.doc_box_status
* : RECEIVE(, ) > READ()/EXPIRED
* </pre>
* @param reqDTO KkotalkDTO.EnvelopeId
* @return KkotalkApiDTO.EnvelopeStatusResponse
*/
KkotalkApiDTO.EnvelopeStatusResponse findStatus(final KkotalkApiDTO.EnvelopeId reqDTO);
/**
* <pre>
* (bulk)
* -. (bulk) .
* </pre>
* @param reqDTO KkopayDocBulkDTO.BulkSendRequests
* @return KkopayDocBulkDTO.BulkSendResponses
*/
KkotalkDTO.BulkSendResponse requestSendBulk(final KkotalkDTO.BulkSendRequest reqDTO);
/**
* <pre>
* (bulk) API
* -. .
* : , flow
* : polling , 5 .
* : RECEIVED(,) > READ()/EXPIRED
* </pre>
* @param reqDTO KkotalkDTO.BulkStatusRequest
* @return KkotalkDTO.BulkStatusResponse
*/
KkotalkDTO.BulkStatusResponse findBulkStatus(final KkotalkDTO.BulkStatusRequest reqDTO);
//KkotalkApiDTO.ValidTokenResponse findKkotalkReadyAndMblPage(KkotalkApiDTO.ValidTokenRequest reqDTO);
}

@ -0,0 +1,317 @@
package cokr.xit.ens.modules.kkotalk.service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import cokr.xit.ens.core.exception.BizRuntimeException;
import cokr.xit.ens.core.utils.ApiWebClientUtil;
import cokr.xit.ens.core.utils.Checks;
import cokr.xit.ens.core.utils.JsonUtils;
import cokr.xit.ens.modules.kkotalk.model.CmmEnsRequestDTO;
import cokr.xit.ens.modules.kkotalk.model.CmmEnsRlaybsnmDTO;
import cokr.xit.ens.modules.kkotalk.model.KkotalkApiDTO;
import cokr.xit.ens.modules.kkotalk.model.KkotalkDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* <pre>
* description :
* packageName : kr.xit.ens.kakao.talk.service
* fileName : KkopayEltrcDocService
* author : julim
* date : 2023-04-28
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-04-28 julim
*
* </pre>
*/
@Slf4j
@RequiredArgsConstructor
@Component
public class KkotalkEltrcDocService implements
IKkotalkEltrcDocService {
@Value("${contract.kakao.talk.host}")
private String HOST;
@Value("#{'${contract.kakao.talk.send}'.split(';')}")
private String[] API_SEND;
@Value("#{'${contract.kakao.talk.bulksend}'.split(';')}")
private String[] API_BULKSEND;
@Value("#{'${contract.kakao.talk.validToken}'.split(';')}")
private String[] API_VALID_TOKEN;
@Value("#{'${contract.kakao.talk.modifyStatus}'.split(';')}")
private String[] API_MODIFY_STATUS;
@Value("#{'${contract.kakao.talk.bulkstatus}'.split(';')}")
private String[] API_BULKSTATUS;
private final ApiWebClientUtil webClient;
private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
private static final CharSequence ENVELOPE_ID = "{ENVELOPE_ID}";
/**
* <pre>
* : POST
* -.
* </pre>
* @param reqDTO KkoPayEltrDocDTO.RequestSendReq
* @return ApiResponseDTO<KkopayDocDTO.SendResponse>
*/
@Override
public KkotalkDTO.SendResponse requestSend(final KkotalkDTO.SendRequest reqDTO) {
if(Checks.isEmpty(reqDTO.getProductCode())){
throw BizRuntimeException.create("상품 코드는 필수 입니다.");
}
List<String> errors = new ArrayList<>();
errors = validate(reqDTO.getEnvelope(), errors);
final KkotalkApiDTO.Envelope envelope = reqDTO.getEnvelope();
if(envelope.getReviewExpiresAt() != null){
if(envelope.getReviewExpiresAt().compareTo(envelope.getReadExpiresAt()) < 0){
errors.add("reviewExpiresAt=재열람 만료일시를 최조 열람 만료일시 보다 큰 날짜로 입력해주세요.");
}
}
if(Checks.isEmpty(envelope.getCi())){
if(Checks.isEmpty(envelope.getName())) Objects.requireNonNull(errors).add("name=받는이 이름은 필수입니다.");
if(Checks.isEmpty(envelope.getPhoneNumber())) Objects.requireNonNull(errors).add("phoneNumber=받는이 전화번호는 필수입니다.");
if(Checks.isEmpty(envelope.getBirthday())) Objects.requireNonNull(errors).add("birthday=받는이 생년월일은 필수입니다.");
}
if(!Objects.requireNonNull(errors).isEmpty()) throw BizRuntimeException.create(errors.toString());
return webClient.exchangeKkotalk(
HOST + API_SEND[0].replace("{PRODUCT_CODE}", reqDTO.getProductCode()),
HttpMethod.valueOf(API_SEND[1]),
JsonUtils.toJson(envelope),
KkotalkDTO.SendResponse.class,
getRlaybsnmInfo(reqDTO));
}
/**
* <pre>
* (Redirect URL /) : GET
* </pre>
* @param reqDTO KkopayDocDTO.ValidTokenRequest
* @return ApiResponseDTO<KkopayDocDTO.ValidTokenResponse>
*/
@Override
public KkotalkApiDTO.ValidTokenResponse validToken(final KkotalkApiDTO.ValidTokenRequest reqDTO) {
validate(reqDTO, null);
return webClient.exchangeKkotalk(
HOST
+ API_VALID_TOKEN[0].replace(ENVELOPE_ID, reqDTO.getEnvelopeId())
.replace("{TOKEN}", reqDTO.getToken()),
HttpMethod.valueOf(API_VALID_TOKEN[1]),
null,
KkotalkApiDTO.ValidTokenResponse.class,
getRlaybsnmInfo(reqDTO));
}
/**
* <pre>
* API : POST
* -. . (OTT ) API .
* -.
* 1) API .
* 2) API(/v1/envelopes/${ENVELOPE_ID}/read) read_at ) .
* </pre>
* @param reqDTO KkopayDocAttrDTO.EnvelopeId
*/
@Override
public void modifyStatus(final KkotalkDTO.EnvelopeId reqDTO){
validate(reqDTO.getEnvelopeId(), null);
final String url = HOST + API_MODIFY_STATUS[0].replace(ENVELOPE_ID, reqDTO.getEnvelopeId());
webClient.exchangeKkotalk(url, HttpMethod.valueOf(API_MODIFY_STATUS[1]), null, Void.class, getRlaybsnmInfo(reqDTO));
}
/**
* <pre>
* API : GET
* -. .
* : , flow
* : polling , 5 .
* : RECEIVE(,) > READ()/EXPIRED
* </pre>
* @param reqDTO KkotalkDTO.EnvelopeId
* @return KkotalkApiDTO.EnvelopeStatusResponse
*/
@Override
public KkotalkApiDTO.EnvelopeStatusResponse findStatus(final KkotalkApiDTO.EnvelopeId reqDTO){
validate(reqDTO, null);
String param = "{\"envelopeIds\":" + JsonUtils.toJson(Collections.singletonList(reqDTO.getEnvelopeId())) + "}";
KkotalkDTO.BulkStatusResponse res = webClient.exchangeKkotalk(
HOST + API_BULKSTATUS[0],
HttpMethod.valueOf(API_BULKSTATUS[1]),
param,
KkotalkDTO.BulkStatusResponse.class,
getRlaybsnmInfo(reqDTO));
return res.getEnvelopeStatus().get(0);
}
/**
* <pre>
* : POST
* -. .
* </pre>
* @param reqDTO KkotalkDTO.BulkSendRequest
* @return KkotalkDTO.BulkSendResponse
*/
@Override
public KkotalkDTO.BulkSendResponse requestSendBulk(final KkotalkDTO.BulkSendRequest reqDTO) {
if(Checks.isEmpty(reqDTO.getProductCode())){
throw BizRuntimeException.create("상품 코드는 필수 입니다.");
}
List<String> errors = new ArrayList<>();
List<KkotalkApiDTO.Envelope> envelopes = reqDTO.getEnvelopes();
for(int idx = 0; idx < envelopes.size(); idx++) {
final Set<ConstraintViolation<KkotalkApiDTO.Envelope>> list = validator.validate(envelopes.get(idx));
if (!list.isEmpty()) {
int finalIdx = idx;
errors.addAll(list.stream()
.map(row -> String.format("%s[%d]=%s", row.getPropertyPath(), finalIdx +1, row.getMessageTemplate()))
.collect(Collectors.toList())
);
}
}
for(int idx = 0; idx < envelopes.size(); idx++) {
final KkotalkApiDTO.Envelope envelope = envelopes.get(idx);
if(envelope.getReviewExpiresAt() != null){
if(envelope.getReviewExpiresAt().compareTo(envelope.getReadExpiresAt()) < 0){
errors.add("reviewExpiresAt=재열람 만료일시를 최조 열람 만료일시 보다 큰 날짜로 입력해주세요.");
}
}
if (Checks.isEmpty(envelope.getCi())) {
if (Checks.isEmpty(envelope.getName())) errors.add(String.format("받는이 이름은 필수입니다(name[%d] 번째 오류)", idx+1));
if (Checks.isEmpty(envelope.getPhoneNumber())) errors.add(String.format("받는이 전화번호는 필수입니다(phoneNumber[%d] 번째 오류)", idx+1));
if (Checks.isEmpty(envelope.getBirthday())) errors.add(String.format("받는이 생년월일은 필수입니다(birthday[%d] 번째 오류)", idx+1));
} else {
final StringBuilder sb = new StringBuilder()
.append(StringUtils.defaultString(envelope.getName(), StringUtils.EMPTY))
.append(StringUtils.defaultString(envelope.getPhoneNumber(), StringUtils.EMPTY))
.append(StringUtils.defaultString(envelope.getBirthday(), StringUtils.EMPTY));
if(Checks.isNotEmpty(sb.toString())){
errors.add(String.format("CI가 지정 되었습니다(받는이 정보 불필요:[%d] 번째 오류) .", idx+1));
}
}
}
if(!errors.isEmpty()){
throw BizRuntimeException.create(errors.toString());
}
String param = "{\"envelopes\":" + JsonUtils.toJson(envelopes) + "}";
return webClient.exchangeKkotalk(
HOST + API_BULKSEND[0].replace("{PRODUCT_CODE}", reqDTO.getProductCode()),
HttpMethod.valueOf(API_BULKSEND[1]),
param,
KkotalkDTO.BulkSendResponse.class,
getRlaybsnmInfo(reqDTO));
}
/**
* <pre>
* (bulk) API : POST
* -. .
* : , flow
* : polling , 5 .
* : RECEIVE(,) > READ()/EXPIRED
* </pre>
* @param reqDTO KkotalkDTO.BulkStatusRequest
* @return KkotalkDTO.BulkStatusResponse
*/
@Override
public KkotalkDTO.BulkStatusResponse findBulkStatus(final KkotalkDTO.BulkStatusRequest reqDTO) {
List<String> errors = new ArrayList<>();
List<String> envelopes = reqDTO.getEnvelopes();
for(int idx = 0; idx < envelopes.size(); idx++) {
final String binderUuid = envelopes.get(idx);
if (Checks.isEmpty(binderUuid) || binderUuid.length() > 40) {
errors.add(String.format("문서 식별 번호는 40자를 넘을 수 없습니다[%d번째]", idx+1));
}
}
if(!errors.isEmpty()) {
throw BizRuntimeException.create(errors.toString());
}
String param = "{\"envelopeIds\":" + JsonUtils.toJson(envelopes) + "}";
return webClient.exchangeKkotalk(
HOST + API_BULKSTATUS[0],
HttpMethod.valueOf(API_BULKSTATUS[1]),
param,
KkotalkDTO.BulkStatusResponse.class,
getRlaybsnmInfo(reqDTO));
}
// @Override
// public KkotalkApiDTO.ValidTokenResponse findKkotalkReadyAndMblPage(final KkotalkApiDTO.ValidTokenRequest reqDTO) {
// final String url = HOST + API_VALID_TOKEN[0].replace(ENVELOPE_ID, reqDTO.getEnvelopeId())
// .replace("{TOKEN}", reqDTO.getToken());
//
// // 유효성 검증
// final KkotalkApiDTO.ValidTokenResponse validTokenRes = webClient.exchangeKkotalk(url, HttpMethod.valueOf(API_VALID_TOKEN[1]), null,
// KkotalkApiDTO.ValidTokenResponse.class, getRlaybsnmInfo(reqDTO));
//
// // 문서상태 변경
// final String url2 = HOST + API_MODIFY_STATUS[0].replace(ENVELOPE_ID, reqDTO.getEnvelopeId());
//
// // 정상 : HttpStatus.NO_CONTENT(204) return
// // error : body에 error_code, error_message return
// final KkotalkApiDTO.KkotalkErrorDTO errorDTO = webClient.exchangeKkotalk(url2, HttpMethod.valueOf(API_MODIFY_STATUS[1]), null, KkotalkApiDTO.KkotalkErrorDTO.class, getRlaybsnmInfo(reqDTO));
// if(errorDTO != null){
// return ApiResponseDTO.error(errorDTO.getErrorCode(), errorDTO.getErrorMessage());
// }
// return ApiResponseDTO.success();
// }
//-------------------------------------------------------------------------------------------------------------------
private static <T> List<String> validate(T t, List<String> errList) {
final Set<ConstraintViolation<T>> list = validator.validate(t);
if(!list.isEmpty()) {
final List<String> errors = list.stream()
.map(row -> String.format("%s=%s", row.getPropertyPath(), row.getMessageTemplate()))
.collect(Collectors.toList());
// 추가적인 유효성 검증이 필요 없는 경우
if(errList == null){
if(!errors.isEmpty()) throw BizRuntimeException.create(errors.toString());
return null;
}
errList.addAll(errors);
}
return errList;
}
private CmmEnsRlaybsnmDTO getRlaybsnmInfo(final CmmEnsRequestDTO request){
return null;//CmmEnsUtils.getRlaybsnmInfo(request.getSignguCode(), request.getFfnlgCode(), SndngSeCode.KAKAO);
}
}

@ -0,0 +1,256 @@
package cokr.xit.ens.modules.kkotalk.web;
import org.springframework.http.MediaType;
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 cokr.xit.ens.core.aop.ApiResponseDTO;
import cokr.xit.ens.core.aop.IApiResponse;
import cokr.xit.ens.modules.kkotalk.model.KkotalkApiDTO;
import cokr.xit.ens.modules.kkotalk.model.KkotalkDTO;
import cokr.xit.ens.modules.kkotalk.service.IKkotalkEltrcDocService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* <pre>
* description : controller
* packageName : kr.xit.ens.kakao.talk.web
* fileName : KkotalkEltrcDocController
* author : julim
* date : 2024-08-12
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024-08-12 julim
*
* </pre>
*/
@Tag(name = "KkotalkEltrcDocController", description = "카카오톡 전자문서 API")
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/api/ens/kakao/v2")
public class KkotalkEltrcDocController {
private final IKkotalkEltrcDocService service;
/**
* <pre>
*
* -. .
* </pre>
* @param reqDTO KkopayDocDTO.SendRequest
* @return ApiResponseDTO<KkopayDocDTO.SendResponse>
*/
@Operation(summary = "문서발송 요청", description = "카카오톡 전자문서 서버로 문서발송 처리를 요청")
@io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
@Content(mediaType = "application/json", examples = {
@ExampleObject(
name = "D10",
value = "{\n" +
" \"productCode\": \"D10_1\",\n" +
" \"envelope\": {\n" +
" \"title\": \"전자문서\",\n" +
" \"content\": {\n" +
" \"link\": \"https://nps.or.kr\"\n" +
" },\n" +
" \"guide\": \"국민연금 공단에서 보내는 문서입니다.\",\n" +
" \"payload\": \"이용기관 페이로드\",\n" +
" \"readExpiresAt\": \"2023-12-31T10:00:00\",\n" +
" \"reviewExpiresAt\": \"2023-12-31T13:00:00\",\n" +
" \"useNonPersonalizedNotification\": true,\n" +
" \"phoneNumber\": \"01099999999\",\n" +
" \"name\": \"홍길동\",\n" +
" \"birthday\": \"20000303\",\n" +
" \"externalId\": \"external_id1\"\n" +
" },\n" +
" \"signguCode\": \"51110\",\n" +
" \"ffnlgCode\": \"11\"\n" +
"}"
),
@ExampleObject(
name = "D11",
value = "{\n" +
" \"productCode\": \"D11_1\",\n" +
" \"envelope\": {\n" +
" \"title\": \"전자문서\",\n" +
" \"content\": {\n" +
" \"html\": \"<!DOCTYPEhtml><html><body><h1>MyFirstHeading</h1><p>Myfirstparagraph.</p></body></html>\"\n" +
" },\n" +
" \"guide\": \"국민연금 공단에서 보내는 문서입니다.\",\n" +
" \"readExpiresAt\": \"2023-12-31T10:00:00\",\n" +
" \"reviewExpiresAt\": \"2023-12-31T13:00:00\",\n" +
" \"ci\": \"${CI}\"\n" +
" },\n" +
" \"signguCode\": \"51110\",\n" +
" \"ffnlgCode\": \"11\"\n" +
"}"
)
})
}) @PostMapping(value = "/envelopes", produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse requestSend(
@RequestBody final KkotalkDTO.SendRequest reqDTO
) {
return ApiResponseDTO.success(service.requestSend(reqDTO));
}
/**
* <pre>
* (Redirect URL /)
* </pre>
* @param reqDTO KkopayDocDTO.ValidTokenRequest
* @return ApiResponseDTO<KkopayDocDTO.ValidTokenResponse>
*/
@Operation(summary = "토큰 유효성 검증", description = "Redirect URL 접속 허용/불허")
@PostMapping(value = "/validToken", produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse validToken(
@RequestBody final KkotalkDTO.ValidTokenRequest reqDTO
) {
return ApiResponseDTO.success(service.validToken(reqDTO));
}
/**
* <pre>
* API
* -. . (OTT ) API .
* -.
* 1) API .
* 2) API(/v1/envelopes/${ENVELOPE_ID}/read) read_at ) .
* </pre>
* @param reqDTO KkotalkApiDTO.EnvelopeStatusResponse
* @return ApiResponseDTO<Void>
*/
@Operation(summary = "문서열람처리(문서 상태 변경)", description = "문서열람처리(문서 상태 변경)")
@PostMapping(value = "/modifyStatus", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse modifyStatus(
@RequestBody final KkotalkApiDTO.EnvelopeId reqDTO
) {
service.modifyStatus(reqDTO);
return ApiResponseDTO.empty();
}
/**
* <pre>
* API
* -. .
* : , flow
* : polling , 5 .
* -.doc_box_status
* : SENT() > RECEIVED() > READ()/EXPIRED( )
* </pre>
* @param reqDTO KkotalkDTO.EnvelopeId
* @return ApiResponseDTO<KkotalkApiDTO.EnvelopeStatusResponse>
*/
@Operation(summary = "문서 상태 조회", description = "문서 상태 조회")
@PostMapping(value = "/findStatus", produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse findStatus(
@RequestBody final KkotalkApiDTO.EnvelopeId reqDTO
) {
return ApiResponseDTO.success(service.findStatus(reqDTO));
}
@Operation(summary = "대량 문서발송 요청 -> batch sendBulks 에서 호출", description = "카카오페이 전자문서 서버로 대량 문서발송 처리를 요청 -> batch sendBulks 에서 호출")
@io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
@Content(mediaType = "application/json", examples = {
@ExampleObject(
name = "D10",
value = "{\n" +
" \"productCode\": \"D10_1\",\n" +
" \"signguCode\": \"51110\",\n" +
" \"ffnlgCode\": \"11\",\n" +
" \"envelopes\": [\n" +
" {\n" +
" \"title\": \"전자문서\",\n" +
" \"content\": {\n" +
" \"html\": \"<!DOCTYPEhtml><html><body><h1>MyFirstHeading</h1><p>Myfirstparagraph.</p></body></html>\"\n" +
" },\n" +
" \"guide\": \"국민연금 공단에서 보내는 문서입니다.\",\n" +
" \"readExpiresAt\": \"2024-12-31T10:00:00\",\n" +
" \"reviewExpiresAt\": \"2025-03-31T13:00:00\",\n" +
" \"phoneNumber\": \"01099999999\",\n" +
" \"name\": \"홍길동\",\n" +
" \"birthday\": \"20000303\",\n" +
" \"externalId\": \"external_id1\"\n" +
" },\n" +
" {\n" +
" \"title\": \"전자문서\",\n" +
" \"content\": {\n" +
" \"html\": \"<!DOCTYPEhtml><html><body><h1>MyFirstHeading</h1><p>Myfirstparagraph.</p></body></html>\"\n" +
" },\n" +
" \"guide\": \"국민연금 공단에서 보내는 문서입니다.\",\n" +
" \"readExpiresAt\": \"2024-12-31T10:00:00\",\n" +
" \"reviewExpiresAt\": \"2025-03-31T13:00:00\",\n" +
" \"hash\": \"b0c34fdc5e2ecb0335919fdad3b2ada28fa3ab90ec16e9055c3e9e05c431c6e8\",\n" +
" \"ci\": \"vMtqVxJX56lBgbf9heK3QTc+jVndTfK77i/UJKAzPmBG4n9CazCdd/8YytlFZnN4qofIqgxHpSoiG0yYzgEpJg==\",\n" +
" \"externalId\": \"external_id2\"\n" +
" }\n" +
" ]\n" +
"}"
),
@ExampleObject(
name = "D11",
value = "{\n" +
" \"productCode\": \"D11_1\",\n" +
" \"signguCode\": \"51110\",\n" +
" \"ffnlgCode\": \"11\",\n" +
" \"envelopes\": [\n" +
" {\n" +
" \"title\": \"전자문서\",\n" +
" \"content\": {\n" +
" \"link\": \"https://nps.or.kr\"\n" +
" },\n" +
" \"guide\": \"국민연금 공단에서 보내는 문서입니다.\",\n" +
" \"payload\": \"이용기관 페이로드\",\n" +
" \"readExpiresAt\": \"2024-12-31T10:00:00\",\n" +
" \"reviewExpiresAt\": \"2025-03-31T13:00:00\",\n" +
" \"phoneNumber\": \"01099999999\",\n" +
" \"name\": \"홍길동\",\n" +
" \"birthday\": \"20000303\",\n" +
" \"externalId\": \"external_id1\"\n" +
" },\n" +
" {\n" +
" \"title\": \"전자문서\",\n" +
" \"content\": {\n" +
" \"link\": \"https://nps.or.kr\"\n" +
" },\n" +
" \"guide\": \"국민연금 공단에서 보내는 문서입니다.\",\n" +
" \"payload\": \"이용기관 페이로드\",\n" +
" \"readExpiresAt\": \"2024-12-31T10:00:00\",\n" +
" \"reviewExpiresAt\": \"2025-03-31T13:00:00\",\n" +
" \"ci\": \"${CI}\",\n" +
" \"externalId\": \"external_id2\"\n" +
" }\n" +
" ]\n" +
"}"
)
})
})
@PostMapping(value = "/envelopes/bulk", produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse requestSendBulk(
@RequestBody final KkotalkDTO.BulkSendRequest reqDTO
) {
return ApiResponseDTO.success(service.requestSendBulk(reqDTO));
}
/**
* <pre>
*
* -. .
* </pre>
* @param reqDTO KkotalkApiDTO.BulkStatusRequest
* @return KkotalkApiDTO.BulkStatusResponse
*/
@Operation(summary = "대량 문서 상태 조회 요청 -> batch statusBulks 에서 호출", description = "카카오페이 전자문서 서버로 대량 문서 상태 조회 요청 -> batch statusBulks 에서 호출")
@PostMapping(value = "/envelopes/bulk/status", produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse findBulkStatus(
@RequestBody final KkotalkDTO.BulkStatusRequest reqDTO
) {
return ApiResponseDTO.success(service.findBulkStatus(reqDTO));
}
}

@ -58,3 +58,9 @@ spring:
# enable-auto-commit: true
# auto-commit-interval: 1000
contract:
kakao:
talk:
host: https://test-edoc-gw.kakao.com
send: /v1/envelopes/{PRODUCT_CODE}T;POST
bulksend: /v1/bulk/envelopes/{PRODUCT_CODE}T;POST

@ -27,6 +27,13 @@ contract:
notice: /iup/kakao/notice
prepay: /iup/kakao/prepay
payresult: /iup/kakao/pay-result
talk:
host: https://edoc-gw.kakao.com
send: /v1/envelopes/{PRODUCT_CODE};POST
bulksend: /v1/bulk/envelopes/{PRODUCT_CODE};POST
validToken: /v1/envelopes/{ENVELOPE_ID}/tokens/{TOKEN}/verify;GET
modifyStatus: /v1/envelopes/{ENVELOPE_ID}/read;POST
bulkstatus: /v1/envelopes/status;POST
alimtalk:
biztalk:

Loading…
Cancel
Save