UMS 정리
This commit is contained in:
@@ -76,8 +76,8 @@ public class ApiStatusService {
|
||||
String event = entry.getKey();
|
||||
List<String> apiIds = entry.getValue();
|
||||
|
||||
String message = getSwingChatMessage(event, apiIds);
|
||||
ums.sendMessenger("api-monitor", MessageCode.API_STATUS_CHANGED, message);
|
||||
HashMap<String, Object> params = getSwingChatMessage(event, apiIds);
|
||||
ums.send("api-monitor", MessageCode.API_STATUS_CHANGED, params);
|
||||
|
||||
//제휴사 웹훅 발송
|
||||
ums.sendWebhook(event, apiIds);
|
||||
@@ -103,7 +103,7 @@ public class ApiStatusService {
|
||||
}
|
||||
|
||||
|
||||
private String getSwingChatMessage(String event, List<String> apiIds) {
|
||||
private HashMap<String, Object> getSwingChatMessage(String event, List<String> apiIds) {
|
||||
String message = "";
|
||||
switch (event) {
|
||||
case "CONTROL_START":
|
||||
@@ -126,9 +126,18 @@ public class ApiStatusService {
|
||||
break;
|
||||
default:
|
||||
message = "";
|
||||
}
|
||||
}
|
||||
|
||||
return message + "\n- " + String.join(",", apiIds);
|
||||
if (apiIds.size() > 1) {
|
||||
message += "\n" + apiIds.get(0) + "외 " + (apiIds.size()-1) + "종";
|
||||
} else {
|
||||
message += "\n- " + apiIds.get(0);
|
||||
}
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put("message", message);
|
||||
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,14 +29,13 @@ public class UmsManager {
|
||||
private final WebhookService webhookService;
|
||||
|
||||
/**
|
||||
* role 역할을 가진 내부직원에게 메신저(Swing chat) 발송
|
||||
* roleId에 해당하는 역할을 가진 내부직원에게 UMS(sms,email,messenger) 발송
|
||||
* @param role
|
||||
* @param messageCode
|
||||
* @param message
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public void sendMessenger(String roleId, MessageCode messageCode, String message) {
|
||||
|
||||
public void send(String roleId, MessageCode messageCode, HashMap<String, Object> params) {
|
||||
List<UserInfo> users = userInfoService.findAllByRoleId(roleId);
|
||||
if (users.isEmpty()) {
|
||||
log.info("sendMessenger: no users found for role '{}'", roleId);
|
||||
@@ -44,36 +43,36 @@ public class UmsManager {
|
||||
}
|
||||
|
||||
for (UserInfo user : users) {
|
||||
String cleanedPhone = user.getCphnno().replaceAll("[^0-9]", "").trim();
|
||||
MessageRecipient recipient = MessageRecipient.builder()
|
||||
.userId(user.getUserid())
|
||||
.username(user.getUsername())
|
||||
.email(user.getEmad())
|
||||
.phone(cleanedPhone)
|
||||
.messengerId(user.getUserid())
|
||||
.build();
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put("message", message);
|
||||
|
||||
messageHandlerService.publishEvent(messageCode, recipient, params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 내부직원에게 메신저 발송
|
||||
* 직원 또는 회원에게 UMS(sms,email,messenger) 발송
|
||||
* @param user
|
||||
* @param messageCode
|
||||
* @param message
|
||||
* @param params
|
||||
*/
|
||||
public void sendMessenger(UserInfo user, MessageCode messageCode, String message) {
|
||||
public void send(UserInfo user, MessageCode messageCode, HashMap<String, Object> params) {
|
||||
String cleanedPhone = user.getCphnno().replaceAll("[^0-9]", "").trim();
|
||||
MessageRecipient recipient = MessageRecipient.builder()
|
||||
.userId(user.getUserid())
|
||||
.username(user.getUsername())
|
||||
.userId(user.getUserid())
|
||||
.username(user.getUsername())
|
||||
.email(user.getEmad())
|
||||
.phone(cleanedPhone)
|
||||
.messengerId(user.getUserid())
|
||||
.build();
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put("message", message);
|
||||
|
||||
messageHandlerService.publishEvent(messageCode, recipient, params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* event를 구독중인 제휴사에게 웹훅 발송 (비동기)
|
||||
* @param event
|
||||
|
||||
@@ -56,7 +56,7 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
|
||||
// 인증번호 생성 및 발송
|
||||
String authCode = getSmsAuthService().generateAuthCode();
|
||||
boolean sent = getSmsAuthService().sendAuthCode(userInfo.getCphnno(), authCode);
|
||||
boolean sent = getSmsAuthService().sendAuthCode(userInfo, authCode);
|
||||
|
||||
if (sent) {
|
||||
// 세션에 인증번호 저장 (기존 UserInfo, LoginVo 유지)
|
||||
@@ -106,7 +106,7 @@ public class SmsAuthController implements InterceptorSkipController {
|
||||
|
||||
// 새 인증번호 생성 및 발송
|
||||
String authCode = getSmsAuthService().generateAuthCode();
|
||||
boolean sent = getSmsAuthService().sendAuthCode(userInfo.getCphnno(), authCode);
|
||||
boolean sent = getSmsAuthService().sendAuthCode(userInfo, authCode);
|
||||
|
||||
if (sent) {
|
||||
LoginVo loginVo = getSmsAuthService().getLoginVoFromSession(session);
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
package com.eactive.eai.rms.ext.kjb.smsauth;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.eactive.apim.portal.template.entity.MessageCode;
|
||||
import com.eactive.apim.portal.user.entity.UserInfo;
|
||||
import com.eactive.eai.rms.common.login.LoginVo;
|
||||
import com.eactive.eai.rms.ext.djb.ums.UmsManager;
|
||||
import com.eactive.ext.kjb.common.KjbProperty;
|
||||
import com.eactive.ext.kjb.common.KjbPropertyHolder;
|
||||
import com.eactive.ext.kjb.common.KjbUmsException;
|
||||
import com.eactive.ext.kjb.ums.KjbUmsService;
|
||||
import com.eactive.ext.kjb.ums.UmsBizWorkCode;
|
||||
import com.eactive.ext.kjb.ums.gson.GsonUtil;
|
||||
import com.eactive.ext.kjb.ums.gson.VerifyPhoneUmsTemplate;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class SmsAuthService {
|
||||
@@ -38,6 +41,9 @@ public class SmsAuthService {
|
||||
public static final String MODE_FIXED = "fixed";
|
||||
|
||||
private final SecureRandom random = new SecureRandom();
|
||||
|
||||
@Autowired
|
||||
private UmsManager ums;
|
||||
|
||||
private SmsAuthService() {
|
||||
// 싱글톤
|
||||
@@ -116,20 +122,25 @@ public class SmsAuthService {
|
||||
/**
|
||||
* SMS 인증번호 발송
|
||||
*/
|
||||
public boolean sendAuthCode(String phone, String authCode) {
|
||||
public boolean sendAuthCode(UserInfo userInfo, String authCode) {
|
||||
try {
|
||||
String cleanedPhone = phone.replaceAll("[^0-9]", "").trim();
|
||||
String guid = String.format("EAPIM_EMS-%s",
|
||||
DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS").format(LocalDateTime.now()));
|
||||
|
||||
JsonObject content = GsonUtil.toJsonObject(VerifyPhoneUmsTemplate.builder().authNumber(authCode).build());
|
||||
|
||||
getUmsService().sendKakaoAlimTalk(guid, UmsBizWorkCode.VERIFY_PHONE, cleanedPhone, content);
|
||||
log.info("SMS 인증번호 발송 완료 - guid: {}, phone: {}****{}",
|
||||
guid, cleanedPhone.substring(0, 3), cleanedPhone.substring(cleanedPhone.length() - 4));
|
||||
log.debug("SMS 인증번호 발송 - authCode: {}", authCode);
|
||||
// String cleanedPhone = phone.replaceAll("[^0-9]", "").trim();
|
||||
// String guid = String.format("EAPIM_EMS-%s",
|
||||
// DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS").format(LocalDateTime.now()));
|
||||
//
|
||||
// JsonObject content = GsonUtil.toJsonObject(VerifyPhoneUmsTemplate.builder().authNumber(authCode).build());
|
||||
//
|
||||
// getUmsService().sendKakaoAlimTalk(guid, UmsBizWorkCode.VERIFY_PHONE, cleanedPhone, content);
|
||||
// log.info("SMS 인증번호 발송 완료 - guid: {}, phone: {}****{}",
|
||||
// guid, cleanedPhone.substring(0, 3), cleanedPhone.substring(cleanedPhone.length() - 4));
|
||||
// log.debug("SMS 인증번호 발송 - authCode: {}", authCode);
|
||||
|
||||
HashMap<String,Object> params = new HashMap<String, Object>();
|
||||
params.put("authNumber", authCode);
|
||||
|
||||
ums.send(userInfo, MessageCode.USER_VERIFICATION_MOBILEPHONE, params);
|
||||
return true;
|
||||
} catch (KjbUmsException e) {
|
||||
} catch (Exception e) {
|
||||
log.error("SMS 인증번호 발송 실패", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user