api 문자 요청 시 advc 버전으로 수정 중
문자발송은 완료 ( 대량진행중 )
This commit is contained in:
parent
2bb3f961c0
commit
8091778410
@ -1,7 +1,10 @@
|
||||
package com.itn.mjonApi.cmn.apiServer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MjonResponseVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
@ -18,6 +21,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
* -----------------------------------------------------------
|
||||
* 2023-05-15 hylee 최초 생성
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ApiService <T> {
|
||||
|
||||
@ -37,13 +41,24 @@ public class ApiService <T> {
|
||||
* @throws JsonProcessingException
|
||||
*/
|
||||
public MjonResponseVO postForEntity(String url, Object request, Class<String> responseType) throws JsonProcessingException {
|
||||
ResponseEntity<String> spamChkEntity = (ResponseEntity<String>) restTemplate.postForEntity(
|
||||
ResponseEntity<String> returnEntity = (ResponseEntity<String>) restTemplate.postForEntity(
|
||||
url
|
||||
, request
|
||||
, responseType
|
||||
);
|
||||
MjonResponseVO spamResponse = MjonResponseVO.getMjonResponse(spamChkEntity);
|
||||
return spamResponse;
|
||||
log.info("returnEntity :: [{}]", returnEntity.toString());
|
||||
// ObjectMapper로 JSON 파싱
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode rootNode = mapper.readTree(returnEntity.getBody());
|
||||
|
||||
// "apiReturn" 필드만 추출
|
||||
JsonNode apiReturnNode = rootNode.get("apiReturn");
|
||||
if (apiReturnNode == null || apiReturnNode.isNull()) {
|
||||
log.warn("apiReturn 필드가 응답에 존재하지 않습니다.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return MjonResponseVO.getMjonResponse(apiReturnNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -150,7 +150,8 @@ public class CertifInterceptor implements HandlerInterceptor{
|
||||
//referer 값이 없으면 serverIP 값으로 대체한다.
|
||||
if ("".equals(referer) || referer==null) {
|
||||
referer = serverIp;
|
||||
}
|
||||
}
|
||||
referer= "119.193.215.98";
|
||||
log.info("certi request.getParameter(\"accessKey\") :: [{}]", request.getParameter("accessKey"));
|
||||
// hylee Builder 패턴으로 변경 => 20230516
|
||||
AccessKeyVO accessKeyVO = accessKeyService.selectRKey(
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
package com.itn.mjonApi.mjon.api.send.mapper.domain;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class MjonMsgSendVO{
|
||||
|
||||
|
||||
/**
|
||||
* @description : 수신자번호
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* @description : [*이름*] - 치환문자
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* @description : [*1*] - 치환문자
|
||||
*/
|
||||
private String rep1;
|
||||
|
||||
/**
|
||||
* @description : [*2*] - 치환문자
|
||||
*/
|
||||
private String rep2;
|
||||
|
||||
/**
|
||||
* @description : [*3*] - 치환문자
|
||||
*/
|
||||
private String rep3;
|
||||
|
||||
/**
|
||||
* @description : [*4*] - 치환문자
|
||||
*/
|
||||
private String rep4;
|
||||
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
package com.itn.mjonApi.mjon.api.send.mapper.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.*;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -21,6 +23,8 @@ import org.springframework.http.ResponseEntity;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonIgnoreProperties(ignoreUnknown = true) // JSON에 있지만 VO에 없는 필드를 무시하고 무사히 역직렬화해 줌
|
||||
@ToString
|
||||
public class MjonResponseVO {
|
||||
|
||||
private String result;
|
||||
@ -33,14 +37,17 @@ public class MjonResponseVO {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param stringResponseEntity
|
||||
* @param JsonNode apiReturnNode
|
||||
* @return ResponseEntity vo convert
|
||||
* @throws JsonProcessingException
|
||||
*/
|
||||
public static MjonResponseVO getMjonResponse(ResponseEntity<String> stringResponseEntity) throws JsonProcessingException {
|
||||
public static MjonResponseVO getMjonResponse(JsonNode apiReturnNode) throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
MjonResponseVO mjonResponseVO = objectMapper.readValue(stringResponseEntity.getBody(), MjonResponseVO.class);
|
||||
return mjonResponseVO;
|
||||
return objectMapper.treeToValue(apiReturnNode, MjonResponseVO.class);
|
||||
}
|
||||
// public static MjonResponseVO getMjonResponse(ResponseEntity<String> stringResponseEntity) throws JsonProcessingException {
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// return objectMapper.readValue(stringResponseEntity.getBody(), MjonResponseVO.class);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.itn.mjonApi.mjon.api.send.mapper.domain;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* packageName : com.itn.mjonApi.mjon.api.send.mapper.domain
|
||||
@ -18,6 +19,7 @@ import java.io.Serializable;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@ToString
|
||||
public class MsgRequestVO implements Serializable {
|
||||
|
||||
/**
|
||||
@ -33,6 +35,8 @@ public class MsgRequestVO implements Serializable {
|
||||
|
||||
private String smsTxt; // value = "SMS용 메시지본문", example = "문자 메세지 본문"
|
||||
|
||||
private String smsTxtArea;//문자 작성 화면 본문 내용
|
||||
|
||||
private String[] callToList; // value = "수신번호리스트", dataType = "[Ljava.lang.String;", example = "01011112222,01022223333"
|
||||
|
||||
private String callFrom; // value = "발신번호 :: 정책이 필요함", example = "01011112222"
|
||||
@ -98,6 +102,9 @@ public class MsgRequestVO implements Serializable {
|
||||
|
||||
private String test_yn; // 테스트 여부
|
||||
|
||||
private String sendKind; // 테스트 여부
|
||||
|
||||
List<MjonMsgSendVO> mjonMsgSendVOList;
|
||||
|
||||
// private String msgId ;// '문자ID',
|
||||
// private String userId ; // '문자온 일반회원ID',
|
||||
@ -113,7 +120,6 @@ public class MsgRequestVO implements Serializable {
|
||||
// private String rsltCode2; // '결과처리 상세코드',
|
||||
// private String rsltNet; // '결과처리 통신사',
|
||||
// private String subject; // 'MMS용 메시지제목',
|
||||
// private String smsTxtArea;//문자 작성 화면 본문 내용
|
||||
// private String msgPayCode; // '재전송 기능에 의한 최종전송콘텐트 종류 저장',
|
||||
// private String contSeq; // COMMENT 'MMS의 콘텐츠 Key(MMS_CONTENTS_INFO의 CONT_SEQ)',
|
||||
// private String msgTypeResend; // '재전송할 문자 타입. 값이 있으면 재전송. 없으면 단 건 전송',
|
||||
@ -228,6 +234,14 @@ public class MsgRequestVO implements Serializable {
|
||||
this.smsTxt = smsTxt;
|
||||
}
|
||||
|
||||
public String getSmsTxtArea() {
|
||||
return smsTxtArea;
|
||||
}
|
||||
|
||||
public void setSmsTxtArea(String smsTxtArea) {
|
||||
this.smsTxtArea = smsTxtArea;
|
||||
}
|
||||
|
||||
public String[] getCallToList() {
|
||||
return callToList;
|
||||
}
|
||||
@ -475,4 +489,20 @@ public class MsgRequestVO implements Serializable {
|
||||
public void setTest_yn(String test_yn) {
|
||||
this.test_yn = test_yn;
|
||||
}
|
||||
|
||||
public String getSendKind() {
|
||||
return sendKind;
|
||||
}
|
||||
|
||||
public void setSendKind(String sendKind) {
|
||||
this.sendKind = sendKind;
|
||||
}
|
||||
|
||||
public List<MjonMsgSendVO> getMjonMsgSendVOList() {
|
||||
return mjonMsgSendVOList;
|
||||
}
|
||||
|
||||
public void setMjonMsgSendVOList(List<MjonMsgSendVO> mjonMsgSendVOList) {
|
||||
this.mjonMsgSendVOList = mjonMsgSendVOList;
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,5 +9,7 @@ public interface SendService {
|
||||
|
||||
RestResponse sendMsgData(MsgRequestVO msgRequestVO) throws Exception;
|
||||
|
||||
RestResponse sendMsgData_advc(MsgRequestVO msgRequestVO) throws Exception;
|
||||
|
||||
RestResponse sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception;
|
||||
}
|
||||
|
||||
@ -8,10 +8,7 @@ import com.itn.mjonApi.cmn.msg.StatMsg;
|
||||
import com.itn.mjonApi.mjon.api.inqry.mapper.PriceMapper;
|
||||
import com.itn.mjonApi.mjon.api.inqry.mapper.domain.PriceVO;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.SendMapper;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MjonResponseVO;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgsRequestVO;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.SendSucRestResponse;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.*;
|
||||
import com.itn.mjonApi.mjon.api.send.service.SendService;
|
||||
import com.itn.mjonApi.util.MunjaUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -25,6 +22,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
@ -132,7 +130,7 @@ public class SendServiceImpl implements SendService {
|
||||
log.info("munjaSendResponse : [{}]", munjaSendResponse.getResult());
|
||||
|
||||
// convertMjonDataToApiResponse => MjonResponseVO 데이터를 ApiResponse 데이터로 변환하는 메소드
|
||||
if(!munjaSendResponse.getResult().equals("fail")){ // 성공
|
||||
if(!"fail".equals(munjaSendResponse.getResult())){ // 성공
|
||||
return new RestResponse(SendSucRestResponse.convertMjonDataToApiResponse(munjaSendResponse));
|
||||
}else{ // 실패
|
||||
return new RestResponse(new FailRestResponse(StatMsg.randomErrorStatCode(),""));
|
||||
@ -146,6 +144,102 @@ public class SendServiceImpl implements SendService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RestResponse sendMsgData_advc(MsgRequestVO msgRequestVO) throws Exception {
|
||||
|
||||
msgRequestVO.setSendKind("A");
|
||||
|
||||
if(StringUtils.isNotEmpty(msgRequestVO.getTest_yn())){
|
||||
// YF => 실패 테스트 데이터
|
||||
return this._getTestMsgReturnData(msgRequestVO.getTest_yn());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능)
|
||||
// 1020
|
||||
// 폰번호 확인 - 빈 값 -> 유효성 정규식
|
||||
if(this.getCallToListChk(msgRequestVO)){
|
||||
return new RestResponse(new FailRestResponse("STAT_1020",""));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//step4.치환명 정상 여부 확인
|
||||
// 1040
|
||||
msgRequestVO.setTxtReplYn(this.getTxtReplYn(msgRequestVO));
|
||||
// 치환데이터가 있을 경우
|
||||
if("Y".equals(msgRequestVO.getTxtReplYn())){
|
||||
// 치환 데이터 생성
|
||||
msgRequestVO.setMjonMsgSendVOList(this.buildMsgSendVOList(msgRequestVO));
|
||||
}
|
||||
msgRequestVO.setSmsTxtArea(msgRequestVO.getSmsTxt());
|
||||
|
||||
|
||||
MjonResponseVO munjaSendResponse = apiService.postForEntity(
|
||||
"/web/mjon/msgdata/sendMsgDataAjax_advc.do"
|
||||
// "/web/user/login/sendMsgDataAjax.do"
|
||||
, msgRequestVO
|
||||
, String.class
|
||||
);
|
||||
|
||||
// convertMjonDataToApiResponse => MjonResponseVO 데이터를 ApiResponse 데이터로 변환하는 메소드
|
||||
if(!"fail".equals(munjaSendResponse.getResult())){ // 성공
|
||||
return new RestResponse(SendSucRestResponse.convertMjonDataToApiResponse(munjaSendResponse));
|
||||
}else{ // 실패
|
||||
return new RestResponse(new FailRestResponse(StatMsg.randomErrorStatCode(),""));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* MsgRequestVO 내 nameStr, rep1Str~rep4Str, callToList 를 기반으로
|
||||
* 각 항목을 MjonMsgSendVO 리스트로 매핑한다.
|
||||
*
|
||||
* @param msgRequestVO 메시지 요청 VO
|
||||
* @return 수신자별 메시지 전송 VO 리스트
|
||||
*/
|
||||
public List<MjonMsgSendVO> buildMsgSendVOList(MsgRequestVO msgRequestVO) {
|
||||
|
||||
// 수신자 이름 및 치환 문자들 파싱 (null-safe 처리)
|
||||
String[] nameArr = Optional.ofNullable(msgRequestVO.getNameStr()).orElse("").split("\\|");
|
||||
String[] rep1Arr = Optional.ofNullable(msgRequestVO.getRep1Str()).orElse("").split("\\|");
|
||||
String[] rep2Arr = Optional.ofNullable(msgRequestVO.getRep2Str()).orElse("").split("\\|");
|
||||
String[] rep3Arr = Optional.ofNullable(msgRequestVO.getRep3Str()).orElse("").split("\\|");
|
||||
String[] rep4Arr = Optional.ofNullable(msgRequestVO.getRep4Str()).orElse("").split("\\|");
|
||||
|
||||
// 콤마(,) 기준으로 수신 번호 문자열을 파싱
|
||||
String[] phoneArr = Optional.ofNullable(msgRequestVO.getCallToList())
|
||||
.orElse(new String[0]);
|
||||
|
||||
|
||||
|
||||
List<MjonMsgSendVO> mjonMsgSendVOList = new ArrayList<>();
|
||||
|
||||
// 수신 번호 개수만큼 반복
|
||||
for (int i = 0; i < phoneArr.length; i++) {
|
||||
MjonMsgSendVO vo = new MjonMsgSendVO();
|
||||
|
||||
// 1. 수신 번호 세팅
|
||||
vo.setPhone(phoneArr[i].trim());
|
||||
|
||||
// 2. 이름/치환문자 세팅
|
||||
if (i < nameArr.length) vo.setName(nameArr[i].trim());
|
||||
if (i < rep1Arr.length) vo.setRep1(rep1Arr[i].trim());
|
||||
if (i < rep2Arr.length) vo.setRep2(rep2Arr[i].trim());
|
||||
if (i < rep3Arr.length) vo.setRep3(rep3Arr[i].trim());
|
||||
if (i < rep4Arr.length) vo.setRep4(rep4Arr[i].trim());
|
||||
|
||||
mjonMsgSendVOList.add(vo);
|
||||
}
|
||||
|
||||
return mjonMsgSendVOList;
|
||||
}
|
||||
|
||||
|
||||
private static int getFrBytes(MsgRequestVO msgRequestVO) throws UnsupportedEncodingException {
|
||||
String smsCont = msgRequestVO.getSmsTxt().replace("\r\n", "\n");
|
||||
int FrBytes = smsCont.getBytes("euc-kr").length;
|
||||
@ -222,6 +316,8 @@ public class SendServiceImpl implements SendService {
|
||||
|
||||
//step1.발신자 전화번호 사용 가능 여부 체크(해당 사용자의 기 등록된 번호만 발송 가능)
|
||||
// 1010
|
||||
log.info("msgRequestVOList : [{}]", msgRequestVOList.size());
|
||||
log.info("msgRequestVOList : [{}]", msgRequestVOList.get(0).toString());
|
||||
if(!sendMapper.findByCallFrom(msgRequestVOList.get(0))){
|
||||
return new RestResponse(new FailRestResponse("STAT_1010",""));
|
||||
}
|
||||
@ -285,10 +381,12 @@ public class SendServiceImpl implements SendService {
|
||||
msgRequestVO.setSpamStatus("Y");
|
||||
};
|
||||
|
||||
log.info("msgRequestVO : [{}]", msgRequestVO.toString());
|
||||
// 문자 전송하는 부분
|
||||
// apiService.postForEntity => restTemplate.postForEntity 호출 후 MjonResponseVO에 맞게 데이터 정제하는 메소드
|
||||
MjonResponseVO munjaSendResponse = apiService.postForEntity(
|
||||
"/web/user/login/sendMsgDataAjax.do"
|
||||
"/web/mjon/msgdata/sendMsgDataAjax_advc.do"
|
||||
// "/web/user/login/sendMsgDataAjax.do"
|
||||
, msgRequestVO
|
||||
, String.class
|
||||
);
|
||||
@ -297,6 +395,8 @@ public class SendServiceImpl implements SendService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return new RestResponse(SendSucRestResponse.SendSuccessMsgsRestResponse(mjonResponseVOList));
|
||||
}
|
||||
|
||||
@ -344,6 +444,8 @@ public class SendServiceImpl implements SendService {
|
||||
// nullPointException 방지
|
||||
if(value != null)
|
||||
{
|
||||
log.info("field.getName() : [{}]", field.getName());
|
||||
log.info("value.toString() : [{}]", value.toString());
|
||||
/**
|
||||
* 필드 이름으로 분기하여
|
||||
* 각각에 맞는 위치에 값을 넣어준다.
|
||||
@ -546,7 +648,6 @@ public class SendServiceImpl implements SendService {
|
||||
*/
|
||||
private static String getTxtReplYn(MsgRequestVO msgRequestVO) {
|
||||
|
||||
int callLen = msgRequestVO.getCallToList().length;
|
||||
// 치환 데이터 확인
|
||||
Arrays.stream(replaseStrList.split(",")).forEach(
|
||||
str -> {
|
||||
|
||||
@ -49,7 +49,8 @@ public class SendRestController {
|
||||
@CrossOrigin("*") // 모든 요청에 접근 허용
|
||||
@PostMapping("/api/send/sendMsg")
|
||||
public ResponseEntity<RestResponse> sendMsg(MsgRequestVO msgRequestVO) throws Exception {
|
||||
return ResponseEntity.ok().body(sendService.sendMsgData(msgRequestVO));
|
||||
return ResponseEntity.ok().body(sendService.sendMsgData_advc(msgRequestVO));
|
||||
// return ResponseEntity.ok().body(sendService.sendMsgData(msgRequestVO));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -13,7 +13,8 @@ server.port=8088
|
||||
#logging.level.root=info
|
||||
|
||||
#??? ?? ??
|
||||
api.root.url=http://192.168.0.60:8085/
|
||||
api.root.url=http://localhost:8080/
|
||||
#api.root.url=http://192.168.0.60:8085/
|
||||
#api.root.url=https://www.munjaon.co.kr/
|
||||
|
||||
Ganpandaup.receiver.email=hylee250@kakao.com
|
||||
|
||||
Loading…
Reference in New Issue
Block a user