347 lines
11 KiB
Java
347 lines
11 KiB
Java
package itn.let.mjo.mjocommon;
|
|
|
|
import java.io.IOException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
|
|
import org.apache.commons.httpclient.HttpClient;
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
import org.apache.commons.httpclient.methods.PostMethod;
|
|
import org.json.simple.JSONObject;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import com.mysql.jdbc.StringUtils;
|
|
|
|
import itn.let.kakao.kakaoComm.KakaoVO;
|
|
import itn.let.mjo.msg.service.MjonMsgVO;
|
|
|
|
@Service("MjonCommon")
|
|
public class MjonCommon {
|
|
|
|
//Slack Web Hook URL
|
|
private String url = "https://hooks.slack.com/services/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";
|
|
|
|
/**
|
|
* @throws Exception
|
|
* @Method Name : getAdminSlackSand
|
|
* @작성일 : 2022. 12. 6.
|
|
* @작성자 : WYH
|
|
* @Method 설명 : slack 메시지 전송
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
public void getAdminSandSlack(MjonMsgVO mjonMsgVO) {
|
|
|
|
HttpClient client = new HttpClient();
|
|
PostMethod post = new PostMethod(url);
|
|
JSONObject json = new JSONObject();
|
|
try {
|
|
|
|
String reserveYn = mjonMsgVO.getReserveYn();
|
|
String delayYn = mjonMsgVO.getDelayYn();
|
|
String smsTxt = mjonMsgVO.getSmsTxt();
|
|
String smishingYn = mjonMsgVO.getSmishingYn();
|
|
String reservSmsTxt = "";
|
|
String smisingSmsTxt = "";
|
|
//예약문자를 발송하는 경우 문자 내용 앞에 "[예약]" 표시되도록 처리
|
|
if(reserveYn.equals("Y")) {
|
|
|
|
if(smishingYn.equals("Y") || delayYn.equals("Y")) {
|
|
reservSmsTxt = "[스미싱의심][예약]" + smsTxt;
|
|
}else {
|
|
reservSmsTxt = "[예약]" + smsTxt;
|
|
}
|
|
|
|
smsTxt = reservSmsTxt;
|
|
}else if(smishingYn.equals("Y") || delayYn.equals("Y")) {
|
|
|
|
smisingSmsTxt = "[스미싱의심]" + smsTxt;
|
|
smsTxt = smisingSmsTxt;
|
|
}
|
|
|
|
String sandName = mjonMsgVO.getCallFrom();
|
|
String userId = mjonMsgVO.getUserId();
|
|
String msgType = "";
|
|
int fileCount = Integer.parseInt(mjonMsgVO.getFileCnt());//그림 이미지 갯수
|
|
if(mjonMsgVO.getMsgType().equals("4")) { //단문 금액
|
|
msgType = "[단문]";
|
|
}else if(mjonMsgVO.getMsgType().equals("6")){
|
|
if(fileCount == 0) {
|
|
msgType = "[장문]";
|
|
}else {
|
|
msgType = "[그림]";
|
|
// 2022.12.21 JSP => 텍스트없는 그림문자만 발송시 슬랙알림 안됨
|
|
if (StringUtils.isNullOrEmpty(smsTxt)) {
|
|
smsTxt = "그림문자 " + smsTxt;
|
|
}
|
|
}
|
|
}
|
|
sandName = "[" + userId + "]" + "[" + sandName + "]" + msgType;
|
|
|
|
json.put("channel", "mjon메시지");
|
|
json.put("text", smsTxt);
|
|
json.put("username", sandName);
|
|
|
|
|
|
post.addParameter("payload", json.toString());
|
|
// 처음에 utf-8로 content-type안넣어주니까 한글은 깨져서 content-type넣어줌
|
|
post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
int responseCode = client.executeMethod(post);
|
|
String response = post.getResponseBodyAsString();
|
|
if (responseCode != HttpStatus.SC_OK) {
|
|
System.out.println("Response: " + response);
|
|
}
|
|
} catch (IllegalArgumentException e) {
|
|
System.out.println("IllegalArgumentException posting to Slack " + e);
|
|
} catch (IOException e) {
|
|
System.out.println("IOException posting to Slack " + e);
|
|
} catch (Exception e) {
|
|
System.out.println("Exception posting to Slack " + e);
|
|
} finally {
|
|
post.releaseConnection();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @Method Name : sendSimpleSlackMsg
|
|
* @작성일 : 2022. 12. 9
|
|
* @작성자 : AnJooYoung
|
|
* @Method 설명 : slack 단순 메시지 전송
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
public void sendSimpleSlackMsg(String msg) {
|
|
|
|
HttpClient client = new HttpClient();
|
|
PostMethod post = new PostMethod(url);
|
|
JSONObject json = new JSONObject();
|
|
try {
|
|
|
|
json.put("channel", "mjon메시지");
|
|
//json.put("channel", "C04DNV4FYP6"); //개발 서버용
|
|
|
|
json.put("text", msg);
|
|
|
|
post.addParameter("payload", json.toString());
|
|
// 처음에 utf-8로 content-type안넣어주니까 한글은 깨져서 content-type넣어줌
|
|
post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
int responseCode = client.executeMethod(post);
|
|
String response = post.getResponseBodyAsString();
|
|
if (responseCode != HttpStatus.SC_OK) {
|
|
System.out.println("Response: " + response);
|
|
}
|
|
} catch (IllegalArgumentException e) {
|
|
System.out.println("IllegalArgumentException posting to Slack " + e);
|
|
} catch (IOException e) {
|
|
System.out.println("IOException posting to Slack " + e);
|
|
} catch (Exception e) {
|
|
System.out.println("Exception posting to Slack " + e);
|
|
} finally {
|
|
post.releaseConnection();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 관리자로 문자 발송해주기
|
|
* 사용자가 보낸 문자를 문자온 법인폰으로 발송해주는 기능 함수.
|
|
* 일반문자 와 대량 문자 모두 적용하고 있음
|
|
* 2022.09.19 우영두 추가
|
|
* 2023.01.26 우영두 수정 => 대표전송사로 발송되도록 수정
|
|
* */
|
|
public MjonMsgVO getAdminPhoneSendMsgDataComm(MjonMsgVO mjonMsgVO) throws Exception{
|
|
|
|
try {
|
|
mjonMsgVO.setUserId("system");//시스템 발송 문자로 처리
|
|
|
|
//전송사 선택
|
|
String msgType = mjonMsgVO.getMsgType();
|
|
int fileCount = Integer.parseInt(mjonMsgVO.getFileCnt());//그림 이미지 갯수
|
|
|
|
if(msgType.equals("6")) {//장문 혹은 그림문자인 경우
|
|
if(fileCount > 0) {//그림문자인 경우
|
|
mjonMsgVO.setNeoType("4");
|
|
}
|
|
}
|
|
|
|
//수신번호가 배열로 되어있어서 배열에 담아준다.
|
|
String[] phone = new String[1];
|
|
String callTo = "01084329333";
|
|
phone[0] = callTo;
|
|
mjonMsgVO.setCallToList(phone);//수신번호 리스트
|
|
|
|
//시스템 로그용 수신 정보
|
|
mjonMsgVO.setCallTo("help@iten.co.kr");
|
|
|
|
//현재 고객의 보유 캐시가 문자 발송이 가능한 금액인지 체크
|
|
//String userMoney = "0.0";
|
|
String userPoint = "0.0";
|
|
mjonMsgVO.setBefPoint(userPoint); //현재 보유 포인트 정보 저장
|
|
mjonMsgVO.setBefCash("0.0"); //관리자가 발송하는 것이라서 0원으로 입력
|
|
mjonMsgVO.setMsgGroupCnt("1");
|
|
|
|
//문자종류 관리자가 발송하는 것은 msgKind : S 로 셋팅
|
|
mjonMsgVO.setMsgKind("S");
|
|
|
|
Date now = new Date();
|
|
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
|
mjonMsgVO.setReqDate(sdFormat.format(now));
|
|
|
|
//예약 문자 발송 없이 즉시 발송으로 처리
|
|
mjonMsgVO.setReserveYn("N");
|
|
|
|
} catch (Exception e) {
|
|
System.out.println("+++++++++++++++++++++++++++++ MjonCommon Class getAdminPhoneSendMsgData Function Error !!!" + e);
|
|
}
|
|
|
|
return mjonMsgVO;
|
|
}
|
|
|
|
|
|
/**
|
|
* 관리자가 사용자에게 문자 발송해주기
|
|
* 발신번호 승인 / 반려시 사용자에게 문자 발송해 주기.
|
|
* 일반문자 와 대량 문자 모두 적용하고 있음
|
|
* 2022.09.26 우영두 추가
|
|
*
|
|
* */
|
|
public MjonMsgVO getAdminToMberPhoneSendMsgDataComm(MjonMsgVO mjonMsgVO) throws Exception{
|
|
|
|
try {
|
|
mjonMsgVO.setUserId("system");//시스템 발송 문자로 처리
|
|
|
|
//전송사 선택
|
|
String msgType = mjonMsgVO.getMsgType();
|
|
int fileCount = Integer.parseInt(mjonMsgVO.getFileCnt());//그림 이미지 갯수
|
|
|
|
if(msgType.equals("6")) {//장문 혹은 그림문자인 경우
|
|
if(fileCount > 0) {//그림문자인 경우
|
|
mjonMsgVO.setNeoType("4");
|
|
}
|
|
}
|
|
|
|
//수신번호가 배열로 되어있어서 배열에 담아준다.
|
|
String[] phone = new String[1];
|
|
String callTo = mjonMsgVO.getCallTo();
|
|
phone[0] = callTo;
|
|
mjonMsgVO.setCallToList(phone);//수신번호 리스트
|
|
|
|
//시스템 로그용 수신 정보
|
|
mjonMsgVO.setCallTo(callTo);
|
|
|
|
//현재 고객의 보유 캐시가 문자 발송이 가능한 금액인지 체크
|
|
//String userMoney = "0.0";
|
|
String userPoint = "0.0";
|
|
mjonMsgVO.setBefPoint(userPoint); //현재 보유 포인트 정보 저장
|
|
mjonMsgVO.setBefCash("0.0"); //관리자가 발송하는 것이라서 0원으로 입력
|
|
mjonMsgVO.setMsgGroupCnt("1");
|
|
|
|
//문자종류 관리자가 발송하는 것은 msgKind : S 로 셋팅
|
|
mjonMsgVO.setMsgKind("S");
|
|
|
|
//예약 문자 발송 없이 즉시 발송으로 처리
|
|
mjonMsgVO.setReserveYn("N");
|
|
|
|
} catch (Exception e) {
|
|
System.out.println("+++++++++++++++++++++++++++++ MjonCommon Class getAdminToMberPhoneSendMsgData Function Error !!!" + e);
|
|
}
|
|
|
|
return mjonMsgVO;
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public void getAdminKakaoAtSandSlack(KakaoVO kakaoVO) {
|
|
|
|
HttpClient client = new HttpClient();
|
|
PostMethod post = new PostMethod(url);
|
|
JSONObject json = new JSONObject();
|
|
try {
|
|
|
|
String reserveYn = kakaoVO.getReserveYn();
|
|
String atDelayYn = kakaoVO.getAtDelayYn();
|
|
String smsTxt = kakaoVO.getTemplateContent();
|
|
String reservSmsTxt = "";
|
|
String smisingSmsTxt = "";
|
|
//예약문자를 발송하는 경우 문자 내용 앞에 "[예약]" 표시되도록 처리
|
|
if(reserveYn.equals("Y")) {
|
|
reservSmsTxt = "[예약]" + smsTxt;
|
|
smsTxt = reservSmsTxt;
|
|
}else if(atDelayYn.equals("Y")) {
|
|
|
|
smisingSmsTxt = "[스미싱의심]" + smsTxt;
|
|
smsTxt = smisingSmsTxt;
|
|
}
|
|
|
|
String sandName = kakaoVO.getCallFrom();
|
|
String userId = kakaoVO.getUserId();
|
|
String msgType = "";
|
|
|
|
if(kakaoVO.getMsgType().equals("8")) {
|
|
msgType = "[알림톡]";
|
|
}else if(kakaoVO.getMsgType().equals("9")){
|
|
|
|
}
|
|
sandName = "[" + userId + "]" + "[" + sandName + "]" + msgType;
|
|
|
|
json.put("channel", "mjon메시지");
|
|
json.put("text", smsTxt);
|
|
json.put("username", sandName);
|
|
|
|
|
|
post.addParameter("payload", json.toString());
|
|
// 처음에 utf-8로 content-type안넣어주니까 한글은 깨져서 content-type넣어줌
|
|
post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
int responseCode = client.executeMethod(post);
|
|
String response = post.getResponseBodyAsString();
|
|
if (responseCode != HttpStatus.SC_OK) {
|
|
System.out.println("Response: " + response);
|
|
}
|
|
} catch (IllegalArgumentException e) {
|
|
System.out.println("IllegalArgumentException posting to Slack " + e);
|
|
} catch (IOException e) {
|
|
System.out.println("IOException posting to Slack " + e);
|
|
} catch (Exception e) {
|
|
System.out.println("Exception posting to Slack " + e);
|
|
} finally {
|
|
post.releaseConnection();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public String getCreateMsgUserIdgen(String subUserId, String lastId) throws Exception{
|
|
|
|
String returnId = "";
|
|
String[] splitId = lastId.split("_");
|
|
|
|
if(splitId.length > 0) {
|
|
|
|
int lastNum = Integer.parseInt(splitId[1]);
|
|
|
|
lastNum = lastNum + 1;
|
|
|
|
String tmpLastNum = Integer.toString(lastNum);
|
|
|
|
int zeroPlusCnt = 14 - tmpLastNum.length();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(subUserId + "_");
|
|
|
|
for(int i=0; i< zeroPlusCnt; i++) {
|
|
|
|
sb.append('0');
|
|
|
|
}
|
|
|
|
sb.append(tmpLastNum);
|
|
|
|
returnId = sb.toString();
|
|
|
|
}
|
|
|
|
return returnId;
|
|
}
|
|
|
|
}
|