이지우 - 처리상세 페이지 > SMS 팝업 > 문자 기능 구현

This commit is contained in:
JIWOO 2025-02-13 16:52:50 +09:00
parent e3a058e585
commit b70ddcd63f
4 changed files with 57 additions and 19 deletions

View File

@ -40,7 +40,7 @@ public interface SendService {
*/ */
void sendAt(String to, String templateCode, Map<String, String> chihwan) throws Exception; void sendAt(String to, String templateCode, Map<String, String> chihwan) throws Exception;
void sendSms(String to, String subject, String smsContent) throws Exception; Map<String, Object> sendSms(String to, String subject, String smsContent, String type) throws Exception;
SendSmsVO selectSendSet() throws Exception; SendSmsVO selectSendSet() throws Exception;

View File

@ -2,6 +2,7 @@ package kcc.com.snd.service.impl;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -68,11 +69,14 @@ public class SendServiceImpl extends EgovAbstractServiceImpl implements SendServ
} }
@Override @Override
public void sendSms( public Map<String, Object> sendSms(
String to String to
, String subject , String subject
, String smsContent , String smsContent
, String type
) throws Exception{ ) throws Exception{
Boolean success = true;
int successCnt = 0;
SendAtVO vo = new SendAtVO(); SendAtVO vo = new SendAtVO();
vo = sendDAO.selectToken(); vo = sendDAO.selectToken();
@ -89,14 +93,26 @@ public class SendServiceImpl extends EgovAbstractServiceImpl implements SendServ
} }
SendSmsVO smsVO = new SendSmsVO(); SendSmsVO smsVO = new SendSmsVO();
BeanUtils.copyProperties(smsVO, vo); BeanUtils.copyProperties(smsVO, vo);
smsVO.setTo(to);
smsVO.setSubject(subject); smsVO.setSubject(subject);
smsVO.setSmsContent(smsContent); smsVO.setSmsContent(smsContent);
smsVO.setType(type);
FairnetUtils.sendSms(smsVO); String[] phoneNums = to.split(",");
for(String phone : phoneNums) {
smsVO.setTo(phone);
boolean result = FairnetUtils.sendSms(smsVO);
if(result) {
successCnt++;
}else {
success = false;
System.out.println("문자 발송 실패: " + phone);
}
}
System.out.println("test"); Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success" , success);
resultMap.put("successCnt" , successCnt);
return resultMap;
} }
@Override @Override

View File

@ -691,7 +691,9 @@ public class FairnetUtils {
return at; return at;
} }
public static String sendSms(SendSmsVO sendSmsVO) { public static Boolean sendSms(SendSmsVO sendSmsVO) {
Boolean success = true;
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
@ -725,16 +727,22 @@ public class FairnetUtils {
connection.setUseCaches(false); connection.setUseCaches(false);
connection.setConnectTimeout(15000); connection.setConnectTimeout(15000);
JSONObject lms = new JSONObject(); /*SMS LMS 구분처리*/
lms.put("message", sendSmsVO.getSmsContent()); JSONObject sms = new JSONObject();
lms.put("subject", sendSmsVO.getSubject()); sms.put("message", sendSmsVO.getSmsContent());
if("LMS".equals(sendSmsVO.getType())) {
sms.put("subject", sendSmsVO.getSubject());
}
JSONObject content = new JSONObject(); JSONObject content = new JSONObject();
content.put("lms", lms); if("SMS".equals(sendSmsVO.getType())) {
content.put("sms", sms);
}else {
content.put("lms", sms);
}
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("account", ppurioGlobalSet.getId()); json.put("account", ppurioGlobalSet.getId());
json.put("type", "lms"); json.put("type", sendSmsVO.getType().toLowerCase());
json.put("from", "15881490"); json.put("from", "15881490");
json.put("to", sendSmsVO.getTo()); json.put("to", sendSmsVO.getTo());
json.put("content", content); json.put("content", content);
@ -764,7 +772,8 @@ public class FairnetUtils {
errorResponse.append(input); errorResponse.append(input);
} }
System.out.println("Error Response: " + errorResponse.toString()); System.out.println("Error Response: " + errorResponse.toString());
return "Error: " + errorResponse.toString(); success = false;
//return "Error: " + errorResponse.toString();
} }
} }
connection.disconnect(); connection.disconnect();
@ -778,14 +787,17 @@ public class FairnetUtils {
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
success = false;
} catch (KeyManagementException e) { } catch (KeyManagementException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
success = false;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
success = false;
} }
return null; return success;
// return status; // return status;
} }

View File

@ -11,6 +11,9 @@
<%@ include file="/WEB-INF/jsp/seed/_extra/dao/smsDao.jsp"%> <%@ include file="/WEB-INF/jsp/seed/_extra/dao/smsDao.jsp"%>
<%@ include file="/WEB-INF/jsp/seed/_extra/dao/commonFileDao.jsp"%> <%@ include file="/WEB-INF/jsp/seed/_extra/dao/commonFileDao.jsp"%>
<%@ include file="/WEB-INF/jsp/seed/_extra/common/commonFileUtil.jsp"%> <%@ include file="/WEB-INF/jsp/seed/_extra/common/commonFileUtil.jsp"%>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="kcc.com.snd.service.SendService" %>
<% <%
@ -60,7 +63,8 @@
String smsContents = SeedUtils.setReplaceNull(request.getParameter("smsContents")); String smsContents = SeedUtils.setReplaceNull(request.getParameter("smsContents"));
String lmsContents = SeedUtils.setReplaceNull(request.getParameter("lmsContents")); String lmsContents = SeedUtils.setReplaceNull(request.getParameter("lmsContents"));
String phone = SeedUtils.setReplaceNull(request.getParameter("phoneNums")); String phone = SeedUtils.setReplaceNull(request.getParameter("phoneNums"));
int successCnt = 0;
if((smsContents.equals("") && lmsContents.equals("")) || phone.equals("")){ if((smsContents.equals("") && lmsContents.equals("")) || phone.equals("")){
message = "정상적인 요청이 아닙니다."; message = "정상적인 요청이 아닙니다.";
@ -83,7 +87,13 @@
System.out.println("lmsContents:" + lmsContents); System.out.println("lmsContents:" + lmsContents);
//실제 전송 DB에 저장 //실제 전송 DB에 저장
if(success){ if(success){
if(type.equals("SMS")){
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);
SendService sendService = (SendService) context.getBean("SendService");
Map<String, Object> resultMap = sendService.sendSms(phone, "", smsContents, type);
success = (Boolean)resultMap.get("success");
successCnt = (Integer)resultMap.get("successCnt");
/* if(type.equals("SMS")){
Object[] objData2 = { Object[] objData2 = {
smsContents, phone smsContents, phone
}; };
@ -93,14 +103,14 @@
smsContents, phone smsContents, phone
}; };
success = setLmsRealRegProc(seedSqlCon, objData2); success = setLmsRealRegProc(seedSqlCon, objData2);
} } */
} }
if(success){ if(success){
message = "SMS이 발송 되었습니다."; message = "SMS이 발송 되었습니다.";
}else{ }else{
message = "SMS이 실패 되었습니다."; message = "SMS이 실패 되었습니다."+successCnt+"건만 발송 되었습니다.";
} }
} }