750 lines
27 KiB
Java
750 lines
27 KiB
Java
package seed.utils;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.io.OutputStream;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.security.KeyManagementException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.cert.X509Certificate;
|
|
import java.util.ArrayList;
|
|
import java.util.Base64;
|
|
import java.util.Calendar;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Properties;
|
|
import java.util.Random;
|
|
|
|
import javax.mail.Message;
|
|
import javax.mail.MessagingException;
|
|
import javax.mail.PasswordAuthentication;
|
|
import javax.mail.Session;
|
|
import javax.mail.Transport;
|
|
import javax.mail.internet.InternetAddress;
|
|
import javax.mail.internet.MimeMessage;
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
import javax.net.ssl.SSLContext;
|
|
import javax.net.ssl.TrustManager;
|
|
import javax.net.ssl.X509TrustManager;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import org.json.JSONObject;
|
|
import org.springframework.ui.ModelMap;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.node.TextNode;
|
|
import com.ibm.icu.text.SimpleDateFormat;
|
|
|
|
import kcc.com.snd.service.SendAtVO;
|
|
import kcc.com.snd.service.SendAtVO.Content;
|
|
import kcc.com.snd.service.SendAtVO.Content.At;
|
|
import kcc.com.snd.service.SendSmsVO;
|
|
import kcc.com.srch.service.SearchVO;
|
|
import kcc.let.uat.uia.service.CertVO;
|
|
|
|
public class FairnetUtils {
|
|
|
|
public static boolean hasAuth(
|
|
int p_memberIdx
|
|
, String p_memberGrant
|
|
, boolean p_memberAuth
|
|
, HttpSession p_session
|
|
, Map<String, Object> p_map
|
|
) {
|
|
boolean b_ret = true;
|
|
|
|
//기존 권한 관리 부분을 주석 처리함 - 필요시 사용할것
|
|
//egov 권한으로 대체 예정
|
|
/*
|
|
try {
|
|
if(p_memberIdx == 0 || (!p_memberGrant.equals("S") && !p_memberAuth)){
|
|
setSessionRemove(p_session);
|
|
p_map.put("url", "/gtm/login.do");
|
|
p_map.put("url", "/uat/uia/EgovLoginUsr.do");
|
|
p_map.put("message", "common.message.no.grant");
|
|
//return new ModelAndView("/_common/jsp/message");
|
|
b_ret = false;
|
|
}
|
|
}catch(Exception ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
*/
|
|
|
|
return b_ret;
|
|
}
|
|
|
|
public static boolean hasUserAuth(
|
|
int p_memberIdx
|
|
, String p_memberGrant
|
|
, boolean p_memberAuth
|
|
, HttpSession p_session
|
|
, Map<String, Object> p_map
|
|
) {
|
|
boolean b_ret = true;
|
|
|
|
//기존 권한 관리 부분을 주석 처리함 - 필요시 사용할것
|
|
//egov 권한으로 대체 예정
|
|
/*
|
|
try {
|
|
if(!memberGrant.equals("S") && !memberAuthM && !memberAuth && !managerSiteMenuAuthService.getSiteMenuAuthChk(siteMenuIdx, memberIdx)){
|
|
|
|
map.put("message", "common.message.no.grant");
|
|
|
|
if(memberIdx.equals(0)){
|
|
map.put("url", "/"+siteIdx+"/index.do");
|
|
}else{
|
|
map.put("self", "history");
|
|
}
|
|
|
|
//return new ModelAndView("/_common/jsp/umessage");
|
|
b_ret = false;
|
|
}
|
|
}catch(Exception ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
*/
|
|
|
|
return b_ret;
|
|
}
|
|
|
|
public static ModelMap myCheck(
|
|
ModelMap p_map
|
|
, HttpSession p_session
|
|
) {
|
|
boolean b_ret = true;
|
|
|
|
//인증여부 체크용
|
|
/*
|
|
try {
|
|
if(SeedUtils.setReplaceNull(p_session.getAttribute("hpName")).equals("")){
|
|
p_map.put("siteIdx", "case");
|
|
p_map.put("url", "/web/user/mypage/case/01/168/myCheck.do");
|
|
p_map.put("message", "common.message.my.check");
|
|
p_map.put("opener", "");
|
|
p_map.put("append", "");
|
|
p_map.put("self", "");
|
|
|
|
b_ret = false;
|
|
}
|
|
|
|
}catch(Exception ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
*/
|
|
|
|
p_map.put("b_ret", b_ret);
|
|
|
|
return p_map;
|
|
}
|
|
|
|
|
|
public static void certSet(ModelMap map, HttpServletRequest req, HttpSession session,String commandCode ) {
|
|
|
|
//실서버
|
|
String hpSrvNo = CertGlobalSet.getHpSrvNo();
|
|
String hpRetUrl = CertGlobalSet.getHpRetUrl() + "/web/user/siren/case/04/154/check.do";//모바일 인증후 리턴 페이지
|
|
|
|
//날짜 생성
|
|
Calendar today = Calendar.getInstance();
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
String day = sdf.format(today.getTime());
|
|
|
|
java.util.Random ran = new Random();
|
|
//랜덤 문자 길이
|
|
int numLength = 6;
|
|
String randomStr = "";
|
|
|
|
for (int i = 0; i < numLength; i++) {
|
|
//0 ~ 9 랜덤 숫자 생성
|
|
randomStr += ran.nextInt(10);
|
|
}
|
|
|
|
String hpId = "SKFA001"; // 본인실명확인 회원사 아이디
|
|
String hpReqNum = day + randomStr; // 본인실명확인 요청번호
|
|
String hpExVar = "0000000000000000"; // 복호화용 임시필드
|
|
String hpCertDate = day; // 본인실명확인 요청시간
|
|
String hpCertGb = "H"; // 본인실명확인 본인확인 인증수단
|
|
String hpAddVar = ""; // 본인실명확인 추가 파라메터
|
|
|
|
req.getSession().setAttribute("hpReqNumKey", hpReqNum); // 결과값 복호화시 필요
|
|
|
|
//01. 암호화 모듈 선언
|
|
com.sci.v2.pcc.secu.SciSecuManager hpSeed = new com.sci.v2.pcc.secu.SciSecuManager();
|
|
|
|
//02. 1차 암호화
|
|
String hpEncStr = "";
|
|
String hpReqInfo = hpId+"^"+hpSrvNo+"^"+hpReqNum+"^"+hpCertDate+"^"+hpCertGb+"^"+hpAddVar+"^"+hpExVar; // 데이터 암호화
|
|
hpEncStr = hpSeed.getEncPublic(hpReqInfo);
|
|
|
|
//03. 위변조 검증 값 생성
|
|
com.sci.v2.pcc.secu.hmac.SciHmac hpHmac = new com.sci.v2.pcc.secu.hmac.SciHmac();
|
|
String hpHmacMsg = hpHmac.HMacEncriptPublic(hpEncStr);
|
|
|
|
//03. 2차 암호화
|
|
hpReqInfo = hpSeed.getEncPublic(hpEncStr + "^" + hpHmacMsg + "^" + "0000000000000000"); //2차암호화
|
|
|
|
req.getSession().setAttribute("hpRetUrl", hpRetUrl);
|
|
req.getSession().setAttribute("hpReqInfo", hpReqInfo);
|
|
|
|
/**
|
|
* 핸드폰 인증 끝 */
|
|
|
|
}
|
|
|
|
/*첨부파일 목록의 정보를 이노릭스 화면에서 사용하기 위한 정보로 리턴 - T-EXTRA_FILE*/
|
|
public static String innorixFileListInfo(List<Map<String, Object>> fileList) throws Exception {
|
|
|
|
List<Map<String, Object>> innorixFileListInfo = new ArrayList<>();
|
|
for (Map<String, Object> file : fileList) {
|
|
Map<String, Object> innorixFileInfo = new HashMap<>();
|
|
innorixFileInfo.put("printFileName", file.get("EXTRA_FILE_NAME"));
|
|
innorixFileInfo.put("fileSize", file.get("EXTRA_FILE_SIZE"));
|
|
innorixFileInfo.put("dataIdx", file.get("EXTRA_FILE_IDX"));
|
|
innorixFileInfo.put("downloadUrl", "notUse"); //해당 값 없으면 목록이 안나와 임시로 사용
|
|
innorixFileListInfo.add(innorixFileInfo);
|
|
}
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
String innorixFileListInfoStr = objectMapper.writeValueAsString(innorixFileListInfo);
|
|
|
|
return innorixFileListInfoStr;
|
|
|
|
|
|
}
|
|
/*첨부파일 목록의 정보를 이노릭스 화면에서 사용하기 위한 정보로 리턴 - C_CASEFILE*/
|
|
public static String innorixCaseFileListInfo(List<Map<String, Object>> fileList) throws Exception {
|
|
|
|
List<Map<String, Object>> innorixFileListInfo = new ArrayList<>();
|
|
for (Map<String, Object> file : fileList) {
|
|
Map<String, Object> innorixFileInfo = new HashMap<>();
|
|
innorixFileInfo.put("printFileName", file.get("FILE_NAME"));
|
|
innorixFileInfo.put("fileSize", file.get("FILE_SIZE"));
|
|
innorixFileInfo.put("dataIdx", file.get("SEQ_NO"));
|
|
innorixFileInfo.put("downloadUrl", "notUse"); //해당 값 없으면 목록이 안나와 임시로 사용
|
|
innorixFileListInfo.add(innorixFileInfo);
|
|
}
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
String innorixFileListInfoStr = objectMapper.writeValueAsString(innorixFileListInfo);
|
|
|
|
return innorixFileListInfoStr;
|
|
|
|
}
|
|
|
|
/**
|
|
* @methodName : setCertSession
|
|
* @author : JunHo Lee
|
|
* @date : 2024.11.27
|
|
* @description :
|
|
* @param reqeust
|
|
* @param certNm - 이름
|
|
* @param certNo - 휴대폰 번호
|
|
*/
|
|
public static void setCertSession(
|
|
HttpServletRequest reqeust
|
|
, String certNm
|
|
, String certHpNo
|
|
) {
|
|
HttpSession session = reqeust.getSession();
|
|
session.setAttribute("certNm", certNm);
|
|
session.setAttribute("certHpNo", certHpNo);
|
|
|
|
session.setMaxInactiveInterval(60*60*2);
|
|
}
|
|
|
|
public static CertVO getCertSession(
|
|
HttpServletRequest reqeust
|
|
) {
|
|
HttpSession session = reqeust.getSession();
|
|
session.getAttribute("certNm");
|
|
session.getAttribute("certHpNo");
|
|
|
|
CertVO certVO = new CertVO();
|
|
certVO.setName(SeedUtils.setReplaceNull(session.getAttribute("certNm")));
|
|
certVO.setPhone(SeedUtils.setReplaceNull(session.getAttribute("certHpNo")));
|
|
|
|
return certVO;
|
|
}
|
|
|
|
/**
|
|
* @methodName : emailSend
|
|
* @author : JunHo Lee
|
|
* @date : 2024.11.28
|
|
* @description :
|
|
* @param receiver 수신자(', '구분자를 통해 여러명에게 발송 가능)
|
|
* @param content 내용
|
|
* @param subject 제목
|
|
* @return
|
|
*/
|
|
public static Boolean emailSend(
|
|
String receiver
|
|
, String content
|
|
, String subject
|
|
) {
|
|
|
|
EmailGlobalSet emailGlobalSet = new EmailGlobalSet();
|
|
|
|
// SMTP 서버 정보 설정
|
|
String smtpHost = emailGlobalSet.getSmtpHost();
|
|
int smtpPort = emailGlobalSet.getSmtpPort();
|
|
final String username = emailGlobalSet.getUsername();
|
|
final String password = emailGlobalSet.getPassword();
|
|
|
|
// 이메일 정보 설정
|
|
String fromEmail = "caseadmin@kofair.or.kr";
|
|
String toEmail = receiver;
|
|
|
|
// SMTP 세션 설정
|
|
Properties props = new Properties();
|
|
props.put("mail.smtp.host", smtpHost);
|
|
props.put("mail.smtp.port", String.valueOf(smtpPort));
|
|
props.put("mail.smtp.auth", "true");
|
|
props.put("mail.smtp.starttls.enable", "true");
|
|
|
|
Session session = Session.getInstance(props,
|
|
new javax.mail.Authenticator() {
|
|
protected PasswordAuthentication getPasswordAuthentication() {
|
|
return new PasswordAuthentication(username, password);
|
|
}
|
|
});
|
|
|
|
try {
|
|
// 이메일 메시지 작성
|
|
Message message = new MimeMessage(session);
|
|
message.setFrom(new InternetAddress(fromEmail));
|
|
message.setRecipients(
|
|
Message.RecipientType.TO,
|
|
InternetAddress.parse(toEmail)
|
|
);
|
|
message.setSubject(subject);
|
|
message.setText(content);
|
|
|
|
// 이메일 전송
|
|
Transport.send(message);
|
|
|
|
System.out.println("이메일이 성공적으로 전송되었습니다.");
|
|
|
|
return true;
|
|
} catch (MessagingException e) {
|
|
System.out.println(e.getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @methodName : searchApplication
|
|
* @author : JunHo Lee
|
|
* @date : 2024.12.02
|
|
* @description :
|
|
* @param searchType :
|
|
* application - 조정신청 (미사용)
|
|
* , board - 게시판
|
|
* , completed - 사건종료관리
|
|
* , conference - 협의회관리
|
|
* , counsel - 상담관리
|
|
* , process - 사건처리관리
|
|
* @param searchKeyword : 검색어
|
|
* @param pagingSize : 페이징 크기 (무한: -1)
|
|
* @param page : 페이지
|
|
* @return
|
|
*/
|
|
public static Map<String, Object> searchApplication(
|
|
String searchType
|
|
, String searchKeyword
|
|
, String pagingSize
|
|
, int page
|
|
) {
|
|
|
|
String url = new SearchGlobalSet().getHost()
|
|
+ "/srch_resultjson?"
|
|
+ "w=" + searchType
|
|
+ "&q=" + searchKeyword
|
|
+ "&outmax=" + pagingSize
|
|
+ "§ion="
|
|
+ "&pg=" + page;
|
|
try {
|
|
String response = new RestTemplate().getForObject(url, String.class);
|
|
JsonNode root = new ObjectMapper().readTree(response);
|
|
JsonNode listNode = root.path("section_list")
|
|
.path(0)
|
|
.path("section")
|
|
.path(0);
|
|
if (listNode.path("att_list").isArray()) {
|
|
List<SearchVO> searchList = new ObjectMapper().convertValue(
|
|
listNode.path("att_list"), new TypeReference<List<SearchVO>>() {}
|
|
);
|
|
Map<String, Object> result = new HashMap<String, Object>();
|
|
|
|
result.put("totcnt", ((TextNode) listNode.get("totcnt")).asText());
|
|
result.put("list", searchList);
|
|
return result;
|
|
}
|
|
} catch (Exception e) {
|
|
System.out.println(e.getMessage());
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static Boolean getPpurioToken(SendAtVO sendAtVO) {
|
|
|
|
StringBuffer result = new StringBuffer();
|
|
|
|
String input = null;
|
|
|
|
PpurioGlobalSet ppurioGlobalSet = new PpurioGlobalSet();
|
|
|
|
try {
|
|
|
|
/** SSL 인증서 무시 : 비즈뿌리오 API 운영을 접속하는 경우 해당 코드 필요 없음 **/
|
|
if(ppurioGlobalSet.getHost().contains("https://api.bizppurio.com")) {
|
|
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
|
|
public X509Certificate[] getAcceptedIssuers() { return null; }
|
|
public void checkClientTrusted(X509Certificate[] chain, String authType) { }
|
|
public void checkServerTrusted(X509Certificate[] chain, String authType) { } } };
|
|
SSLContext sc = SSLContext.getInstance("SSL");
|
|
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
|
}
|
|
|
|
URL url = new URL(ppurioGlobalSet.getHost() + "/v1/token");
|
|
|
|
/** Connection 설정 **/
|
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
connection.setRequestMethod("POST");
|
|
connection.addRequestProperty("Content-Type", "application/json");
|
|
connection.addRequestProperty("Accept-Charset", "UTF-8");
|
|
|
|
//Base64 인코딩
|
|
String idpw = ppurioGlobalSet.getId() + ":" + ppurioGlobalSet.getPw();
|
|
String authData = Base64.getEncoder().encodeToString(idpw.getBytes());
|
|
|
|
connection.addRequestProperty("Authorization", "Basic " + authData);
|
|
|
|
connection.setDoInput(true);
|
|
connection.setDoOutput(true);
|
|
connection.setUseCaches(false);
|
|
connection.setConnectTimeout(15000);
|
|
|
|
/** Request **/
|
|
OutputStream os = connection.getOutputStream();
|
|
os.flush();
|
|
|
|
/** Response **/
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
|
|
|
while ((input = in.readLine()) != null) {
|
|
result.append(input);
|
|
}
|
|
connection.disconnect();
|
|
|
|
if (result.length() > 0) {
|
|
JSONObject jObject = new JSONObject(result.toString());
|
|
if (
|
|
jObject.has("accesstoken")
|
|
&& !jObject.isNull("accesstoken")
|
|
&& jObject.has("type")
|
|
&& !jObject.isNull("type")
|
|
&& jObject.has("expired")
|
|
&& !jObject.isNull("expired")
|
|
) {
|
|
sendAtVO.setAccesstoken(jObject.getString("accesstoken"));
|
|
sendAtVO.setType(jObject.getString("type"));
|
|
sendAtVO.setExpired(jObject.getString("expired"));
|
|
} else {
|
|
System.out.println("response data not found or is null");
|
|
return false;
|
|
}
|
|
} else {
|
|
System.out.println("Empty response");
|
|
return false;
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
System.out.println(e.getMessage());
|
|
return false;
|
|
} catch (KeyManagementException e) {
|
|
System.out.println(e.getMessage());
|
|
return false;
|
|
} catch (NoSuchAlgorithmException e) {
|
|
System.out.println(e.getMessage());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
public static String sendAt(SendAtVO sendAtVO) {
|
|
|
|
StringBuffer result = new StringBuffer();
|
|
|
|
String input = null;
|
|
|
|
PpurioGlobalSet ppurioGlobalSet = new PpurioGlobalSet();
|
|
|
|
try {
|
|
|
|
/** SSL 인증서 무시 : 비즈뿌리오 API 운영을 접속하는 경우 해당 코드 필요 없음 **/
|
|
if(ppurioGlobalSet.getHost().contains("https://api.bizppurio.com")) {
|
|
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
|
|
public X509Certificate[] getAcceptedIssuers() { return null; }
|
|
public void checkClientTrusted(X509Certificate[] chain, String authType) { }
|
|
public void checkServerTrusted(X509Certificate[] chain, String authType) { } } };
|
|
SSLContext sc = SSLContext.getInstance("SSL");
|
|
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
|
}
|
|
|
|
URL url = new URL(ppurioGlobalSet.getHost() + "/v3/message");
|
|
|
|
/** Connection 설정 **/
|
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
connection.setRequestMethod("POST");
|
|
connection.addRequestProperty("Content-Type", "application/json");
|
|
connection.addRequestProperty("Accept-Charset", "UTF-8");
|
|
connection.addRequestProperty("Authorization", "Bearer " + sendAtVO.getAccesstoken());
|
|
connection.setDoInput(true);
|
|
connection.setDoOutput(true);
|
|
connection.setUseCaches(false);
|
|
connection.setConnectTimeout(15000);
|
|
|
|
|
|
/** Request **/
|
|
At at = sendAtVO.getContent().getAt();
|
|
at = messageSet(at, sendAtVO.getChihwan());
|
|
|
|
sendAtVO = sendAtVO.builder()
|
|
.account(ppurioGlobalSet.getId())
|
|
.refkey(sendAtVO.getRefkey())
|
|
.type("at")
|
|
.from(ppurioGlobalSet.getFrom())
|
|
.to(sendAtVO.getTo())
|
|
.content(Content.builder()
|
|
.at(At.builder()
|
|
.senderkey(ppurioGlobalSet.getSenderKey())
|
|
.templatecode(at.getTemplatecode())
|
|
.message(at.getMessage())
|
|
.build()
|
|
)
|
|
.build()
|
|
)
|
|
.build();
|
|
|
|
// Request body 전송
|
|
try (OutputStream os = connection.getOutputStream()) {
|
|
os.write(sendAtVO.toJson().getBytes("UTF-8"));
|
|
os.flush();
|
|
}
|
|
|
|
// 서버 응답 처리
|
|
int responseCode = connection.getResponseCode();
|
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"))) {
|
|
while ((input = reader.readLine()) != null) {
|
|
result.append(input);
|
|
}
|
|
}
|
|
} else {
|
|
// 오류 응답 처리
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getErrorStream(), "UTF-8"))) {
|
|
StringBuilder errorResponse = new StringBuilder();
|
|
while ((input = reader.readLine()) != null) {
|
|
errorResponse.append(input);
|
|
}
|
|
System.out.println("Error Response: " + errorResponse.toString());
|
|
return "Error: " + errorResponse.toString();
|
|
}
|
|
}
|
|
connection.disconnect();
|
|
|
|
System.out.println("Response : " + result.toString());
|
|
|
|
JSONObject jObject = new JSONObject(result.toString());
|
|
// status = jObject.getString("description");
|
|
|
|
|
|
} catch (IOException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
} catch (KeyManagementException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
} catch (NoSuchAlgorithmException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
// return status;
|
|
}
|
|
|
|
private static At messageSet(
|
|
At at,
|
|
Map<String, String> chihwan
|
|
) {
|
|
String content = "";
|
|
Map<String, String[]> requiredPlaceholders = new HashMap<>();
|
|
|
|
switch (at.getTemplatecode()) {
|
|
case "TEMPLATE_APP_JUBSU": // 신청인_접수확인_1
|
|
at.setTemplatecode("bizp_2024112810423519814410026");
|
|
content = "[한국공정거래조정원] \r\n"
|
|
+ "귀사(하)의 조정신청이 접수 완료되었습니다.\r\n"
|
|
+ "향후 담당부서 및 담당자가 배정될 예정입니다.";
|
|
break;
|
|
case "TEMPLATE_APP_BAEJUNG": // 신청인_담당자배정_1
|
|
at.setTemplatecode("bizp_2024112810423516931294012");
|
|
content = "[한국공정거래조정원]\r\n"
|
|
+ "귀사(하)가 (피신청인 상호명)을(를) 상대로 신청한 사건의 사건번호는 #{caseNo}, 담당자는 #{team}팀 #{examiner} 조사관(유선전화:#{tel}, 메일주소 #{email})입니다.\r\n"
|
|
+ "향후 담당 조사관이 공문 등을 통해 연락드릴 예정입니다.";
|
|
requiredPlaceholders.put(at.getTemplatecode(), new String[]{"caseNo", "team", "examiner", "tel", "email"});
|
|
break;
|
|
case "TEMPLATE_BOTH_SANGJUNG": // 양당사자_분쟁조정협의회 안건상정
|
|
at.setTemplatecode("bizp_2024112810492919814837182");
|
|
content = "[한국공정거래조정원]\r\n"
|
|
+ "귀사(하)가 진행 중인 분쟁조정 사건 [사건번호 #{caseNo}]이 향후 개최될 #{cfrnc}분쟁조정협의회에 상정될 예정입니다.\r\n"
|
|
+ "#{cfrnc}분쟁조정협의회 기일은 담당 조사관(유선전화:#{tel}, 메일주소 #{email})에게 문의주시면 안내드리겠습니다.";
|
|
requiredPlaceholders.put(at.getTemplatecode(), new String[]{"caseNo", "cfrnc", "tel", "email"});
|
|
break;
|
|
case "TEMPLATE_BOTH_CHULSUK": // 양당사자_출석요구 n차
|
|
at.setTemplatecode("bizp_2024112810492916931760451");
|
|
content = "[한국공정거래조정원]\r\n"
|
|
+ "귀사(하)가 진행 중인 분쟁조정 사건 [사건번호 #{caseNo}]의 출석조사(#{nCha}}차) 기일이 확정되었습니다. \r\n"
|
|
+ "[https://fairnet.kofair.or.kr]에서 확인해주시기 바랍니다.";
|
|
requiredPlaceholders.put(at.getTemplatecode(), new String[]{"caseNo", "nCha"});
|
|
break;
|
|
case "TEMPLATE_BOTH_TONGJI": // 양당사자_통지
|
|
at.setTemplatecode("bizp_2024112810492916931854671");
|
|
content = "[한국공정거래조정원]\r\n"
|
|
+ "귀사(하)가 진행 중인 분쟁조정 사건 [사건번호 #{caseNo}]에 대한 #{cfrnc}분쟁조정협의회 의결이 완료되었습니다.\r\n"
|
|
+ "[https://fairnet.kofair.or.kr]에서 해당 내용을 확인해주시기 바랍니다.";
|
|
requiredPlaceholders.put(at.getTemplatecode(), new String[]{"caseNo", "cfrnc"});
|
|
break;
|
|
case "TEMPLATE_APP_BOWAN": // 신청인_보완요구 n차
|
|
at.setTemplatecode("bizp_2024112810522719814540186");
|
|
content = "[한국공정거래조정원]\r\n"
|
|
+ "귀사(하)가 신청한 분쟁조정 신청사건(사건번호 #{caseNo})에 대한 보완(#{nCha}차)이 필요합니다.\r\n"
|
|
+ "[https://fairnet.kofair.or.kr]에서 확인해주시기 바랍니다.";
|
|
requiredPlaceholders.put(at.getTemplatecode(), new String[]{"caseNo", "nCha"});
|
|
break;
|
|
}
|
|
|
|
String[] placeholders = requiredPlaceholders.get(at.getTemplatecode());
|
|
if (placeholders != null) {
|
|
for (String placeholder : placeholders) {
|
|
String value = chihwan.get(placeholder);
|
|
if (value == null || value.isEmpty()) {
|
|
throw new IllegalArgumentException(placeholder + " 값이 없습니다.");
|
|
}
|
|
content = content.replace("#{" + placeholder + "}", value);
|
|
}
|
|
}
|
|
|
|
at.setMessage(content);
|
|
return at;
|
|
}
|
|
|
|
public static String sendSms(SendSmsVO sendSmsVO) {
|
|
|
|
StringBuffer result = new StringBuffer();
|
|
|
|
String input = null;
|
|
|
|
PpurioGlobalSet ppurioGlobalSet = new PpurioGlobalSet();
|
|
|
|
try {
|
|
|
|
/** SSL 인증서 무시 : 비즈뿌리오 API 운영을 접속하는 경우 해당 코드 필요 없음 **/
|
|
if(ppurioGlobalSet.getHost().contains("https://api.bizppurio.com")) {
|
|
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
|
|
public X509Certificate[] getAcceptedIssuers() { return null; }
|
|
public void checkClientTrusted(X509Certificate[] chain, String authType) { }
|
|
public void checkServerTrusted(X509Certificate[] chain, String authType) { } } };
|
|
SSLContext sc = SSLContext.getInstance("SSL");
|
|
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
|
}
|
|
|
|
URL url = new URL(ppurioGlobalSet.getHost() + "/v3/message");
|
|
|
|
/** Connection 설정 **/
|
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
connection.setRequestMethod("POST");
|
|
connection.addRequestProperty("Content-Type", "application/json");
|
|
connection.addRequestProperty("Accept-Charset", "UTF-8");
|
|
connection.addRequestProperty("Authorization", "Bearer " + sendSmsVO.getAccesstoken());
|
|
connection.setDoInput(true);
|
|
connection.setDoOutput(true);
|
|
connection.setUseCaches(false);
|
|
connection.setConnectTimeout(15000);
|
|
|
|
JSONObject lms = new JSONObject();
|
|
lms.put("message", sendSmsVO.getSmsContent());
|
|
lms.put("subject", sendSmsVO.getSubject());
|
|
|
|
JSONObject content = new JSONObject();
|
|
content.put("lms", lms);
|
|
|
|
JSONObject json = new JSONObject();
|
|
json.put("account", ppurioGlobalSet.getId());
|
|
json.put("type", "lms");
|
|
json.put("from", "15881490");
|
|
json.put("to", sendSmsVO.getTo());
|
|
json.put("content", content);
|
|
json.put("refkey", "test1234");
|
|
|
|
String body = json.toString();
|
|
|
|
// Request body 전송
|
|
try (OutputStream os = connection.getOutputStream()) {
|
|
os.write(body.getBytes("UTF-8"));
|
|
os.flush();
|
|
}
|
|
|
|
// 서버 응답 처리
|
|
int responseCode = connection.getResponseCode();
|
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"))) {
|
|
while ((input = reader.readLine()) != null) {
|
|
result.append(input);
|
|
}
|
|
}
|
|
} else {
|
|
// 오류 응답 처리
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getErrorStream(), "UTF-8"))) {
|
|
StringBuilder errorResponse = new StringBuilder();
|
|
while ((input = reader.readLine()) != null) {
|
|
errorResponse.append(input);
|
|
}
|
|
System.out.println("Error Response: " + errorResponse.toString());
|
|
return "Error: " + errorResponse.toString();
|
|
}
|
|
}
|
|
connection.disconnect();
|
|
|
|
System.out.println("Response : " + result.toString());
|
|
|
|
JSONObject jObject = new JSONObject(result.toString());
|
|
// status = jObject.getString("description");
|
|
|
|
|
|
} catch (IOException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
} catch (KeyManagementException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
} catch (NoSuchAlgorithmException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
// return status;
|
|
}
|
|
} |