스윙챗 발송
This commit is contained in:
@@ -1,9 +1,17 @@
|
|||||||
package com.eactive.ext.djb.ums;
|
package com.eactive.ext.djb.ums;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.hc.client5.http.config.RequestConfig;
|
import org.apache.hc.client5.http.config.RequestConfig;
|
||||||
@@ -15,6 +23,7 @@ import com.eactive.apim.portal.template.entity.MessageCode;
|
|||||||
import com.eactive.apim.portal.template.entity.MessageRequest;
|
import com.eactive.apim.portal.template.entity.MessageRequest;
|
||||||
import com.eactive.ext.kjb.common.KjbProperty;
|
import com.eactive.ext.kjb.common.KjbProperty;
|
||||||
import com.eactive.ext.kjb.common.KjbPropertyHolder;
|
import com.eactive.ext.kjb.common.KjbPropertyHolder;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -22,6 +31,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
public class DjbMessengerService {
|
public class DjbMessengerService {
|
||||||
public final static int[] ALLOW_CHANNELS = { MessageCode.Channels.MESSENGER.getValue() };
|
public final static int[] ALLOW_CHANNELS = { MessageCode.Channels.MESSENGER.getValue() };
|
||||||
|
|
||||||
|
private static final Gson gson = new Gson();
|
||||||
|
|
||||||
private static volatile DjbMessengerService instance;
|
private static volatile DjbMessengerService instance;
|
||||||
|
|
||||||
@@ -90,42 +100,233 @@ public class DjbMessengerService {
|
|||||||
|
|
||||||
private void httpConnection(MessageRequest messageRequest) throws Exception {
|
private void httpConnection(MessageRequest messageRequest) throws Exception {
|
||||||
|
|
||||||
URL url = new URL(getProperty().getSwingUrl());
|
KjbProperty prop = getProperty();
|
||||||
int timeoutvalue = 5 * 1000; // 타임아웃 설정을 위한 값 (단위: ms)
|
|
||||||
|
URL url = new URL(prop.getSwingUrl());
|
||||||
|
int timeoutValue = 5 * 1000; // 타임아웃 설정을 위한 값 (단위: ms)
|
||||||
// Charset charset = Charset.forName("UTF-8");
|
// Charset charset = Charset.forName("UTF-8");
|
||||||
Charset charset = Charset.forName("MS949");
|
Charset charset = Charset.forName("MS949");
|
||||||
HttpURLConnection conn = null;
|
HttpURLConnection conn = null;
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
StringBuffer sb = null;
|
StringBuffer sb = null;
|
||||||
// String bodyData = this.makeBodyData(cnslDivCdval);
|
String bodyData = this.makeBodyData(messageRequest);
|
||||||
|
|
||||||
|
String responseData = "";
|
||||||
|
String method = bodyData != "" ? "POST" : "GET";
|
||||||
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod(method); // 전송방식
|
||||||
|
// conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||||
|
conn.setRequestProperty("Content-Type", "application/json; charset=MS949");
|
||||||
|
conn.setConnectTimeout(timeoutValue); // 연결 타임아웃 설정(5초)
|
||||||
|
conn.setReadTimeout(timeoutValue); // 읽기 타임아웃 설정(5초)
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
|
||||||
// String responseData = "";
|
// POst 방식인 경우에만
|
||||||
// String method = bodyData != "" ? "POST" : "GET";
|
if (method.equals("POST")) {
|
||||||
// conn " (HttpURL Connection) url.openConnection();
|
OutputStream os = conn.getOutputStream();
|
||||||
// conn.setRequestMethod(method); // w #4
|
byte requestData[] = bodyData.getBytes(charset);
|
||||||
// // conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
os.write(requestData);
|
||||||
// conn.setRequestProperty("Content-Type", "application/json; charset=MS949");
|
os.close();
|
||||||
// conn.setConnectTimeout(timeoutValue); // Cz EGoR 48(5=)
|
}
|
||||||
// conn.setReadTimeout(timeoutValue); // 8 #gOR N8(5s)
|
|
||||||
// conn.setDoOutput(true);
|
|
||||||
// // POst 40
|
|
||||||
// if (method.equals("POST")) (
|
|
||||||
// Outputstream os = conn.getOutputStream();
|
|
||||||
// byte requestData[] - bodyData.getBytes(charset);
|
|
||||||
// os.write(requestData);
|
|
||||||
// os.close();
|
|
||||||
// ph
|
|
||||||
// System.out.println("getContentType():"t conn.getContentType());
|
// System.out.println("getContentType():"t conn.getContentType());
|
||||||
// System,out.println("getResponseCode();" t conn.getResponseCode());
|
// System,out.println("getResponseCode();" t conn.getResponseCode());
|
||||||
// System.out.println("getResponseMessage();" + conn.getResponseMessage());
|
// System.out.println("getResponseMessage();" + conn.getResponseMessage());
|
||||||
// if (LOG_DEBUG, isDebugEnabled()) (
|
if (log.isDebugEnabled()) {
|
||||||
// LOG_DEBUG. debug("getContentType();" + conn.getContentType()); // 5 0= 5 #7
|
log.debug("getContentType();" + conn.getContentType()); // 응답 콘텐츠 유형 구하기
|
||||||
// LOG_DEBUG. debug("getResponsecode();" + conn.getResponseCode()); // ## #5 7#7|
|
log.debug("getResponsecode();" + conn.getResponseCode()); // 응답 코드 구하기
|
||||||
// LOG_DEBUG. debug("getResponseMessage():" + conn.getResponseMessage()); //
|
log.debug("getResponseMessage():" + conn.getResponseMessage()); // 응답 메세지 구하기
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// http 요청 후 응답 받은 데이타를 버퍼에 쌓는다
|
||||||
|
if (conn.getResponseCode() >= 200 && conn.getResponseCode() <= 300) {
|
||||||
|
br = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset));
|
||||||
|
} else {
|
||||||
|
br = new BufferedReader(new InputStreamReader(conn.getErrorStream(), charset));
|
||||||
|
}
|
||||||
|
|
||||||
|
String inputLine;
|
||||||
|
sb = new StringBuffer();
|
||||||
|
while ((inputLine = br.readLine()) != null) {
|
||||||
|
sb.append(inputLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = sb.toString();
|
||||||
|
|
||||||
|
// http 요청 및 응답 완료 후 BufferedReader를 닫는다
|
||||||
|
if (br != null) {
|
||||||
|
br.close();
|
||||||
|
conn.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String makeBodyData(MessageRequest messageRequest) {
|
||||||
|
|
||||||
|
KjbProperty prop = getProperty();
|
||||||
|
|
||||||
|
// 리턴값
|
||||||
|
String rtnVal = "";
|
||||||
|
|
||||||
|
// 스윙챗 알림 헤더
|
||||||
|
SwingHeadVO swiHeadVO = new SwingHeadVO();
|
||||||
|
|
||||||
|
// 스윙챗 알림 공용
|
||||||
|
SwingCommonVO swiComVO = new SwingCommonVO();
|
||||||
|
|
||||||
|
// 스윙챗 알림 데이터
|
||||||
|
SwingDataVO swiDataVO = new SwingDataVO();
|
||||||
|
|
||||||
|
// 스윙챗 알림 데이터
|
||||||
|
List<SwingReceiverDataVO> swiReDataVOList = new ArrayList<SwingReceiverDataVO>();
|
||||||
|
|
||||||
|
// guID 및 날짜 시간 정보
|
||||||
|
String jsonData[] = this.makeJsonDataInfo();
|
||||||
|
|
||||||
|
// 스윙챗 알림 헤더 설정
|
||||||
|
swiHeadVO.setNxgn_stnd_idfr("JERA");
|
||||||
|
swiHeadVO.setGuid(jsonData[2]);
|
||||||
|
swiHeadVO.setGuid_prgs_no("1");
|
||||||
|
swiHeadVO.setStnd_mesg_ver("R10");
|
||||||
|
swiHeadVO.setOrtr_guid(jsonData[2]);
|
||||||
|
swiHeadVO.setSect_ecrpt_yn("N");
|
||||||
|
swiHeadVO.setFrst_trnm_ipad(prop.getSwingWasIpAddress());
|
||||||
|
swiHeadVO.setFrst_trnm_ipv4_addr(prop.getSwingWasIpAddress());
|
||||||
|
swiHeadVO.setFrst_trnm_mac(prop.getSwingMacIpAddress());
|
||||||
|
swiHeadVO.setFrst_mesg_dman_dt(jsonData[0]);
|
||||||
|
swiHeadVO.setFrst_mesg_dman_time(jsonData[1]);
|
||||||
|
swiHeadVO.setFrst_trnm_sys_dvcd("EBG");
|
||||||
|
swiHeadVO.setTrnm_sys_dvcd("FEP");
|
||||||
|
swiHeadVO.setDman_rspn_dvcd("S");
|
||||||
|
swiHeadVO.setSys_env_dvcd("TODO: 설정값 확인 할것!!!"); //TODO: EgovPropertiesUtils.getOptionalProp("SYS_ENV_DVCD"));
|
||||||
|
swiHeadVO.setTx_tycd("0");
|
||||||
|
swiHeadVO.setSynz_dvcd("S");
|
||||||
|
swiHeadVO.setTx_id("MSGSENDMSG1S");
|
||||||
|
swiHeadVO.setXtis_cd(null);
|
||||||
|
swiHeadVO.setOsdch_dvcd(null);
|
||||||
|
swiHeadVO.setChnl_tycd("FEP");
|
||||||
|
swiHeadVO.setIf_id("F2HMPSHGMSGSENDMSG1S");
|
||||||
|
swiHeadVO.setHmab_dvcd("2");
|
||||||
|
swiHeadVO.setTx_brcd("157");
|
||||||
|
swiHeadVO.setTlrno("ET0001");
|
||||||
|
swiHeadVO.setInsl_brcd("157");
|
||||||
|
swiHeadVO.setBlng_brcd("157");
|
||||||
|
swiHeadVO.setMgmt_brcd("157");
|
||||||
|
swiComVO.setClientld(prop.getSwingClientId());
|
||||||
|
swiComVO.setClientSecret(prop.getSwingClientSecret());
|
||||||
|
swiComVO.setCompanyCode("CB");
|
||||||
|
|
||||||
|
// 랜던값(26)
|
||||||
|
String random26 = this.genrateRandomStringNumber26();
|
||||||
|
swiComVO.setRequestUniqueKey(random26);
|
||||||
|
swiDataVO.setNotiCode("CNO_FEP_HMP_0002");
|
||||||
|
swiDataVO.setNotiTitle("알림");
|
||||||
|
swiDataVO.setNotiContent(messageRequest.getMessage());
|
||||||
|
|
||||||
|
SwingReceiverDataVO receiver = new SwingReceiverDataVO();
|
||||||
|
receiver.setCode(messageRequest.getMessengerId());
|
||||||
|
swiReDataVOList.add(receiver);
|
||||||
|
|
||||||
|
swiDataVO.setReceiverInfo(swiReDataVOList);
|
||||||
|
|
||||||
|
String header = gson.toJson(swiHeadVO);
|
||||||
|
String common = gson.toJson(swiComVO);
|
||||||
|
String data = gson.toJson(swiDataVO);
|
||||||
|
|
||||||
|
// 헤더 + 데이터
|
||||||
|
rtnVal = "{\"HEAD\":" + header + " ,\r\n" + "\"DATA\":\r\n" + " [" + "{\r\n"
|
||||||
|
+ " \"data_dvcd\":\"IO\", \r\n" + " \"BIZ_DATA\":\r\n" + " {\r\n"
|
||||||
|
+ " \"common\":\r\n" + common + ",\r\n" + " \"data\":" + data
|
||||||
|
+ " }\r\n" + " }\r\n" + " ]\r\n" + "}";
|
||||||
|
|
||||||
|
log.debug(rtnVal);
|
||||||
|
|
||||||
|
return rtnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String makeBodyData() {
|
private String[] makeJsonDataInfo() {
|
||||||
return "";
|
// 리턴값
|
||||||
|
String rtnVal[] = new String[3];
|
||||||
|
|
||||||
|
// 현재시간
|
||||||
|
Date currentDate = new Date();
|
||||||
|
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||||||
|
String formattedDate = sdf.format(currentDate);
|
||||||
|
|
||||||
|
rtnVal[0] = formattedDate.substring(0,8);
|
||||||
|
rtnVal[1] = formattedDate.substring(8);
|
||||||
|
|
||||||
|
// 랜던값
|
||||||
|
String random20 = this.genrateRandomStringNumber20();
|
||||||
|
|
||||||
|
rtnVal[2] = formattedDate + "HMP" + random20;
|
||||||
|
|
||||||
|
return rtnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String genrateRandomStringNumber20() {
|
||||||
|
String rtnVal= "";
|
||||||
|
|
||||||
|
StringBuilder buffer= new StringBuilder(10);
|
||||||
|
|
||||||
|
// 랜덤값
|
||||||
|
String characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
|
||||||
|
// 랜덤객체 생성
|
||||||
|
SecureRandom random = new SecureRandom();
|
||||||
|
|
||||||
|
// 반복문
|
||||||
|
for (int i= 0;i< 10;i++) {
|
||||||
|
// 랜덤수
|
||||||
|
int randomIndex = random.nextInt(characters.length());
|
||||||
|
|
||||||
|
// 생성된 랜덤값
|
||||||
|
char randomChar = characters.charAt(randomIndex);
|
||||||
|
|
||||||
|
// 랜덤값 저장
|
||||||
|
buffer.append(randomChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 랜덤객체 재생성
|
||||||
|
random = new SecureRandom();
|
||||||
|
|
||||||
|
// 난수 10개 생성
|
||||||
|
int random10 = (int) (Math.pow(10, 9) + random.nextDouble() * Math.pow(10, 9));
|
||||||
|
|
||||||
|
// 문자 숫자 조합(10) + 숫자(10)
|
||||||
|
rtnVal = buffer.toString() + Integer.toString(random10);
|
||||||
|
|
||||||
|
//리턴
|
||||||
|
return rtnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String genrateRandomStringNumber26() {
|
||||||
|
String rtnVal = "";
|
||||||
|
|
||||||
|
// 리턴값
|
||||||
|
StringBuilder buffer = new StringBuilder(26);
|
||||||
|
|
||||||
|
String characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
|
||||||
|
// 랜덤객체 생성
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
//반복문
|
||||||
|
for (int i= 0; i < 26; i++) {
|
||||||
|
// 랜덤수
|
||||||
|
int randomIndex = random.nextInt(characters.length());
|
||||||
|
// 생성된 랜덤값
|
||||||
|
char randomChar = characters.charAt(randomIndex);
|
||||||
|
// 랜덤값 저장
|
||||||
|
buffer.append(randomChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 문자 숫자 조합(26)
|
||||||
|
rtnVal= buffer.toString();
|
||||||
|
|
||||||
|
// 리턴
|
||||||
|
return rtnVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.eactive.ext.djb.ums;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SwingCommonVO {
|
||||||
|
|
||||||
|
/** 클라이업트 D */
|
||||||
|
private String clientld;
|
||||||
|
|
||||||
|
/** 클라이언트 시크릿 */
|
||||||
|
private String clientSecret;
|
||||||
|
|
||||||
|
/** 회사코드 */
|
||||||
|
private String companyCode;
|
||||||
|
|
||||||
|
/** 요청고유키 */
|
||||||
|
private String requestUniqueKey;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.eactive.ext.djb.ums;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SwingDataVO {
|
||||||
|
|
||||||
|
/** 알림코드 */
|
||||||
|
private String notiCode;
|
||||||
|
|
||||||
|
/** 알림제목 */
|
||||||
|
private String notiTitle;
|
||||||
|
|
||||||
|
/** 알림내용 */
|
||||||
|
private String notiContent;
|
||||||
|
|
||||||
|
/** 수신자정보 */
|
||||||
|
private List<SwingReceiverDataVO> receiverInfo;
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.eactive.ext.djb.ums;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SwingHeadVO {
|
||||||
|
|
||||||
|
private String nxgn_stnd_idfr;
|
||||||
|
|
||||||
|
private String guid;
|
||||||
|
|
||||||
|
private String guid_prgs_no;
|
||||||
|
|
||||||
|
private String stnd_mesg_ver;
|
||||||
|
|
||||||
|
private String ortr_guid;
|
||||||
|
|
||||||
|
private String sect_ecrpt_yn;
|
||||||
|
|
||||||
|
private String frst_trnm_ipad;
|
||||||
|
|
||||||
|
private String frst_trnm_ipv4_addr;
|
||||||
|
|
||||||
|
private String frst_trnm_mac;
|
||||||
|
|
||||||
|
private String frst_mesg_dman_dt;
|
||||||
|
|
||||||
|
private String frst_mesg_dman_time;
|
||||||
|
|
||||||
|
private String frst_trnm_sys_dvcd;
|
||||||
|
|
||||||
|
private String trnm_sys_dvcd;
|
||||||
|
|
||||||
|
private String dman_rspn_dvcd;
|
||||||
|
|
||||||
|
private String sys_env_dvcd;
|
||||||
|
|
||||||
|
private String tx_tycd;
|
||||||
|
|
||||||
|
private String synz_dvcd;
|
||||||
|
|
||||||
|
private String tx_id;
|
||||||
|
|
||||||
|
private String xtis_cd;
|
||||||
|
|
||||||
|
private String osdch_dvcd;
|
||||||
|
|
||||||
|
private String chnl_tycd;
|
||||||
|
|
||||||
|
private String if_id;
|
||||||
|
|
||||||
|
private String hmab_dvcd;
|
||||||
|
|
||||||
|
private String tx_brcd;
|
||||||
|
|
||||||
|
private String tlrno;
|
||||||
|
|
||||||
|
private String insl_brcd;
|
||||||
|
|
||||||
|
private String blng_brcd;
|
||||||
|
|
||||||
|
private String mgmt_brcd;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.eactive.ext.djb.ums;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SwingReceiverDataVO {
|
||||||
|
|
||||||
|
/** 알림코드 */
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 알림제목 */
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/** 알림내용 */
|
||||||
|
private String companyCode;
|
||||||
|
|
||||||
|
/** 수신자정보 */
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/** 상품명 */
|
||||||
|
private String prdNm;
|
||||||
|
}
|
||||||
@@ -194,10 +194,22 @@ public class KjbProperty {
|
|||||||
|
|
||||||
|
|
||||||
// 제주은행 swing chat (messenger)
|
// 제주은행 swing chat (messenger)
|
||||||
@KjbPropertyValue(key = "djb.swing.url", defaultValue = "http://172.31.35.144:9021")
|
|
||||||
@NotEmpty
|
@KjbPropertyValue(key = "djb.swing.url", defaultValue = "http://127.0.0.1")
|
||||||
private String swingUrl = "";
|
private String swingUrl = "";
|
||||||
|
|
||||||
|
@KjbPropertyValue(key = "djb.swing.was_ip_address", defaultValue = "http://127.0.0.1")
|
||||||
|
private String swingWasIpAddress = "";
|
||||||
|
|
||||||
|
@KjbPropertyValue(key = "djb.swing.was_mac_address", defaultValue = "http://127.0.0.1")
|
||||||
|
private String swingMacIpAddress = "";
|
||||||
|
|
||||||
|
@KjbPropertyValue(key = "djb.swing.client_id", defaultValue = "12345")
|
||||||
|
private String swingClientId = "";
|
||||||
|
|
||||||
|
@KjbPropertyValue(key = "djb.swing.client_secret", defaultValue = "12345")
|
||||||
|
private String swingClientSecret = "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user