발송 개발

This commit is contained in:
leejunho 2024-12-09 17:29:25 +09:00
parent f1ce2adacd
commit e745af6399
13 changed files with 688 additions and 57 deletions

View File

@ -0,0 +1,89 @@
package kcc.com.snd.service;
import java.io.Serializable;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* @packageName : kcc.com.snd.service
* @templatecode
* @신청인_접수확인_1 :
* TEMPLATE_APP_JUBSU
* @chihwan : 없음
* @신청인_담당자배정_1 :
* TEMPLATE_APP_BAEJUNG
* @chihwan : "caseNo", "team", "examiner", "tel", "email"
* @양당사자_분쟁조정협의회 안건상정 :
* TEMPLATE_BOTH_SANGJUNG
* @chihwan : "caseNo", "cfrnc", "tel", "email"
* @양당사자_출석요구 n차 :
* TEMPLATE_BOTH_CHULSUK
* @chihwan : "caseNo", "nCha"
* @양당사자_통지 :
* TEMPLATE_BOTH_TONGJI
* @chihwan : "caseNo", "cfrnc"
* @신청인_보완요구 n차 :
* TEMPLATE_APP_BOWAN
* @chihwan : "caseNo", "nCha"
*
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendAtVO implements Serializable {
private static final long serialVersionUID = 1L;
@JsonIgnore
private String accesstoken;
private String type;
@JsonIgnore
private String expired;
private String account;
private String refkey;
private String from;
private String to;
private Content content;
@JsonIgnore
private Map<String, String> chihwan;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public static class Content {
private At at;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public static class At {
private String senderkey;
private String templatecode;
private String message;
}
}
public String toJson() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(this);
}
}

View File

@ -1,5 +1,41 @@
package kcc.com.snd.service;
import java.util.Map;
public interface SendService {
public void sendAt(SendVO sendVO) throws Exception;
/**
* @methodName : sendAt
* @author : JunHo Lee
* @date : 2024.12.09
* @description :
* @param to
* @param templateCode
* @param chihwan
*
* @packageName : kcc.com.snd.service
* @templatecode
* @신청인_접수확인_1 :
* TEMPLATE_APP_JUBSU
* @chihwan : 없음
* @신청인_담당자배정_1 :
* TEMPLATE_APP_BAEJUNG
* @chihwan : "caseNo", "team", "examiner", "tel", "email"
* @양당사자_분쟁조정협의회 안건상정 :
* TEMPLATE_BOTH_SANGJUNG
* @chihwan : "caseNo", "cfrnc", "tel", "email"
* @양당사자_출석요구 n차 :
* TEMPLATE_BOTH_CHULSUK
* @chihwan : "caseNo", "nCha"
* @양당사자_통지 :
* TEMPLATE_BOTH_TONGJI
* @chihwan : "caseNo", "cfrnc"
* @신청인_보완요구 n차 :
* TEMPLATE_APP_BOWAN
* @chihwan : "caseNo", "nCha"
*
*/
void sendAt(String to, String templateCode, Map<String, String> chihwan) throws Exception;
void sendSms(String to, String subject, String smsContent) throws Exception;
}

View File

@ -0,0 +1,48 @@
package kcc.com.snd.service;
import java.io.Serializable;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* @packageName : kcc.com.snd.service
* @templatecode
* @신청인_접수확인_1 :
* TEMPLATE_APP_JUBSU
* @chihwan : 없음
* @신청인_담당자배정_1 :
* TEMPLATE_APP_BAEJUNG
* @chihwan : "caseNo", "team", "examiner", "tel", "email"
* @양당사자_분쟁조정협의회 안건상정 :
* TEMPLATE_BOTH_SANGJUNG
* @chihwan : "caseNo", "cfrnc", "tel", "email"
* @양당사자_출석요구 n차 :
* TEMPLATE_BOTH_CHULSUK
* @chihwan : "caseNo", "nCha"
* @양당사자_통지 :
* TEMPLATE_BOTH_TONGJI
* @chihwan : "caseNo", "cfrnc"
* @신청인_보완요구 n차 :
* TEMPLATE_APP_BOWAN
* @chihwan : "caseNo", "nCha"
*
*/
@Getter
@Setter
public class SendSmsVO extends SendAtVO implements Serializable {
private static final long serialVersionUID = 1L;
private String subject;
private String smsContent;
}

View File

@ -1,22 +0,0 @@
package kcc.com.snd.service;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonProperty;
import kcc.com.cmm.ComDefaultVO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class SendVO implements Serializable {
private static final long serialVersionUID = 1L;
private String accesstoken;
private String type;
private String expired;
}

View File

@ -3,12 +3,16 @@ package kcc.com.snd.service.impl;
import org.springframework.stereotype.Repository;
import kcc.com.cmm.service.impl.EgovComAbstractDAO;
import kcc.com.snd.service.SendVO;
import kcc.com.snd.service.SendAtVO;
@Repository("sendDAO")
public class SendDAO extends EgovComAbstractDAO {
public SendVO selectToken(SendVO sendVO) throws Exception{
return (SendVO) select("sendDAO.selectToken", sendVO);
public SendAtVO selectToken() throws Exception{
return (SendAtVO) select("sendDAO.selectToken");
}
public void updateToken(SendAtVO SendAtVO) throws Exception{
update("sendDAO.updateToken", SendAtVO);
}
}

View File

@ -1,12 +1,21 @@
package kcc.com.snd.service.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Service;
import egovframework.rte.fdl.cmmn.EgovAbstractServiceImpl;
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.SendService;
import kcc.com.snd.service.SendVO;
import kcc.com.snd.service.SendSmsVO;
import seed.utils.FairnetUtils;
@Service("SendService")
public class SendServiceImpl extends EgovAbstractServiceImpl implements SendService {
@ -15,8 +24,105 @@ public class SendServiceImpl extends EgovAbstractServiceImpl implements SendServ
private SendDAO sendDAO;
@Override
public void sendAt(SendVO sendVO) throws Exception{
sendDAO.selectToken(sendVO);
public void sendAt(
String to
, String templateCode
, Map<String, String> chihwan
) throws Exception{
SendAtVO vo = new SendAtVO();
vo = sendDAO.selectToken();
//이전 발급 토큰이 만료되었는지 시간비교
if(timeDiffBefore(vo.getExpired())) {
//토큰 발급
if(FairnetUtils.getPpurioToken(vo)) {
//토큰 갱신
sendDAO.updateToken(vo);
}else {
System.out.println("토큰 갱신 실패");
throw new Exception();
}
}
vo = vo.builder()
.accesstoken(vo.getAccesstoken())
.expired(vo.getExpired())
.refkey("test1234")
.type(vo.getType())
.to(to)
.content(Content.builder()
.at(At.builder()
.templatecode(templateCode)
.build()
)
.build()
)
.chihwan(chihwan)
.build()
;
FairnetUtils.sendAt(vo);
System.out.println("test");
}
@Override
public void sendSms(
String to
, String subject
, String smsContent
) throws Exception{
SendAtVO vo = new SendAtVO();
vo = sendDAO.selectToken();
//이전 발급 토큰이 만료되었는지 시간비교
if(timeDiffBefore(vo.getExpired())) {
//토큰 발급
if(FairnetUtils.getPpurioToken(vo)) {
//토큰 갱신
sendDAO.updateToken(vo);
}else {
System.out.println("토큰 갱신 실패");
throw new Exception();
}
}
SendSmsVO smsVO = new SendSmsVO();
BeanUtils.copyProperties(smsVO, vo);
smsVO.setTo(to);
smsVO.setSubject(subject);
smsVO.setSmsContent(smsContent);
FairnetUtils.sendSms(smsVO);
System.out.println("test");
}
/**
* @methodName : timeDiffBefore
* @author : JunHo Lee
* @date : 2024.12.09
* @description :
* @param str
* @return :
* !str이 현재 시간보다 이전이면 true
* !str이 현재 시간보다 이후이면 false
*/
private Boolean timeDiffBefore(String str) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
Date diffDate = sdf.parse(str);
Date currentDate = new Date();
if (diffDate.before(currentDate)) {
return true;
} else {
return false;
}
} catch (Exception e) {
return false;
}
}
}

View File

@ -1,6 +1,7 @@
package kcc.xxx.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
import kcc.com.cmm.CmmUtil;
import kcc.com.snd.service.SendService;
import kcc.utill.CertSettingUtill;
import kcc.utill.OzUtill;
import kcc.xxx.service.XxxService;
@ -35,6 +37,9 @@ public class XxxController {
@Resource(name = "XxxService")
private XxxService xxxService;
@Resource(name = "SendService")
private SendService sendService;
@Resource
private OzUtill ozUtill;
@ -225,8 +230,68 @@ public class XxxController {
}
@RequestMapping("/web/xxx/xxxPpurioTest.do")
public String xxxEmailAjax() {
FairnetUtils.getPpurioToken_dev2();
public String xxxPpurioTest() {
try {
//신청인_접수확인_1
{
Map<String, String> chihwan = new HashMap<String, String>();
sendService.sendAt("01030266269","TEMPLATE_APP_JUBSU", chihwan);
}
//신청인_담당자배정_1
{
Map<String, String> chihwan = new HashMap<String, String>();
chihwan.put("caseNo", "사건번호");
chihwan.put("team", "조사관 팀");
chihwan.put("examiner", "조사관이름");
chihwan.put("tel", "조사관유선전화");
chihwan.put("email", "조사관이메일");
sendService.sendAt("01030266269","TEMPLATE_APP_BAEJUNG", chihwan);
}
//양당사자_분쟁조정협의회 안건상정
{
Map<String, String> chihwan = new HashMap<String, String>();
chihwan.put("caseNo", "사건번호");
chihwan.put("cfrnc", "협의회명");
chihwan.put("tel", "조사관유선전화");
chihwan.put("email", "조사관이메일");
sendService.sendAt("01030266269","TEMPLATE_BOTH_SANGJUNG", chihwan);
}
//양당사자_출석요구 n차
{
Map<String, String> chihwan = new HashMap<String, String>();
chihwan.put("caseNo", "사건번호");
chihwan.put("nCha", "기일차수");
sendService.sendAt("01030266269","TEMPLATE_BOTH_CHULSUK", chihwan);
}
//양당사자_조정결과 통지
{
Map<String, String> chihwan = new HashMap<String, String>();
chihwan.put("caseNo", "사건번호");
chihwan.put("cfrnc", "협의회명");
sendService.sendAt("01030266269","TEMPLATE_BOTH_TONGJI", chihwan);
}
//신청인_보완요구 n차
{
Map<String, String> chihwan = new HashMap<String, String>();
chihwan.put("caseNo", "사건번호");
chihwan.put("nCha", "기일차수");
sendService.sendAt("01030266269","TEMPLATE_APP_BOWAN", chihwan);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@RequestMapping("/web/xxx/xxxSmsTest.do")
public String xxxSmsTest() {
try {
sendService.sendSms("01030266269", "제목입니다.", "내용입니다.");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -4,6 +4,7 @@ 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;
@ -31,16 +32,7 @@ import javax.net.ssl.X509TrustManager;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.json.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.ui.ModelMap;
import org.springframework.web.client.RestTemplate;
@ -50,6 +42,10 @@ 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;
@ -397,20 +393,18 @@ public class FairnetUtils {
return null;
}
public static String getPpurioToken_dev2() {
public static Boolean getPpurioToken(SendAtVO sendAtVO) {
StringBuffer result = new StringBuffer();
String input = null;
String token = "";
PpurioGlobalSet ppurioGlobalSet = new PpurioGlobalSet();
try {
/** SSL 인증서 무시 : 비즈뿌리오 API 운영을 접속하는 경우 해당 코드 필요 없음 **/
// if(!"real".equals(isLocal)) {
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) { }
@ -418,7 +412,7 @@ public class FairnetUtils {
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");
@ -451,19 +445,306 @@ public class FairnetUtils {
}
connection.disconnect();
System.out.println("Response : " + result.toString());
JSONObject jObject = new JSONObject(result.toString());
token = jObject.getString("accesstoken");
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;
}
return token;
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;
}
}

View File

@ -17,6 +17,8 @@ public class PpurioGlobalSet {
private static String templateCode5;
private static String templateCode6;
private static String from;
@Value("#{globalSettings['ppurio.id']}")
public void setId(String id) {
PpurioGlobalSet.id = id;
@ -107,4 +109,13 @@ public class PpurioGlobalSet {
return templateCode6;
}
@Value("#{globalSettings['ppurio.from']}")
public void setFrom(String from) {
PpurioGlobalSet.from = from;
}
public static String getFrom() {
return from;
}
}

View File

@ -244,7 +244,7 @@ search.host=http://192.168.0.60:7578
#\uc54c\ub9bc\ud1a1
ppurio.id=kofair
ppurio.pw=kofa2024@
ppurio.host=https://dev-api.bizppurio.com
ppurio.host=https://api.bizppurio.com
ppurio.senderKey=953031f0c131963c2fa9cd004f9965f9d487bdc5
ppurio.templateCode1=bizp_2024112810423519814410026
ppurio.templateCode2=bizp_2024112810423516931294012
@ -252,3 +252,4 @@ ppurio.templateCode3=bizp_2024112810492919814837182
ppurio.templateCode4=bizp_2024112810492916931760451
ppurio.templateCode5=bizp_2024112810492916931854671
ppurio.templateCode6=bizp_2024112810522719814540186
ppurio.from=15881490

View File

@ -257,3 +257,4 @@ ppurio.templateCode3=bizp_2024112810492919814837182
ppurio.templateCode4=bizp_2024112810492916931760451
ppurio.templateCode5=bizp_2024112810492916931854671
ppurio.templateCode6=bizp_2024112810522719814540186
ppurio.from=15881490

View File

@ -431,3 +431,4 @@ ppurio.templateCode3=bizp_2024112810492919814837182
ppurio.templateCode4=bizp_2024112810492916931760451
ppurio.templateCode5=bizp_2024112810492916931854671
ppurio.templateCode6=bizp_2024112810522719814540186
ppurio.from=15881490

View File

@ -4,16 +4,26 @@
<sqlMap namespace="Send">
<typeAlias alias="egovMap" type="egovframework.rte.psl.dataaccess.util.EgovMap"/>
<typeAlias alias="sendVO" type="kcc.com.snd.service.SendVO"/>
<typeAlias alias="sendAtVO" type="kcc.com.snd.service.SendAtVO"/>
<select id="sendDAO.selectToken" resultClass="sendVO">
<select id="sendDAO.selectToken" resultClass="sendAtVO">
SELECT
A.ACCESSTOKEN,
A.TYPE,
A.EXPIRED
FROM
PPURIO_TOKEN A
UNP_PPURIO_TOKEN A
</select>
<update id="sendDAO.updateToken" parameterClass="sendAtVO">
UPDATE UNP_PPURIO_TOKEN
SET
ACCESSTOKEN = #accesstoken#,
TYPE = #type#,
EXPIRED = #expired#
</update>
</sqlMap>