Skip to content

Commit

Permalink
[feat] : Slack On
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackBean99 committed Sep 3, 2023
1 parent 8afcfc8 commit 6368a59
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
package com.econovation.recruit.api.applicant.handler;
import com.econovation.recruit.api.card.usecase.BoardRegisterUseCase;
Expand Down Expand Up @@ -47,6 +48,7 @@ public void handle(ApplicantRegisterEvent applicantRegistEvent) {
// applicantRegistEvent.getUserName());
// emailSenderService.sendEmail(mimeMessage);
*/
/* private SimpleMailMessage generateConfirmRegisterEmail(
String email, String userName) {
SimpleMailMessage message = emailSenderService.
Expand All @@ -60,7 +62,8 @@ public void handle(ApplicantRegisterEvent applicantRegistEvent) {
log.error("메일 content 생성에 실패하였습니다.. {}", e.getMessage());
}
return message;
}*/
}*//*
private String generateConfirmRegisterEmailBody(String userName) {
return String.format(
Expand All @@ -75,3 +78,4 @@ private String generateConfirmRegisterEmailBody(String userName) {
userName);
}
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ public void updateColumnLocation(UpdateLocationColumnDto updateLocationDto) {
}

private void updateNextColumnIds(Columns currentColumn, Columns targetColumn) {
if (currentColumn.getId() == targetColumn.getId() || targetColumn.getNextColumnsId() == currentColumn.getId())
throw BoardSameLocationException.EXCEPTION;
columnLoadPort
.getByNextColumnsId(currentColumn.getId())
.ifPresent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void handle(ApplicantRegisterEvent applicantRegistEvent) {
applicantRegistEvent.getApplicantId(),
applicantRegistEvent.getHopeField(),
card.getId());
// slackMessageProvider.sendMessage(slackProperties.getUrl(), message);
slackMessageProvider.sendMessage(slackProperties.getUrl(), message);
}

private String generateApplicantRegisterMessage(ApplicantRegisterEvent applicantRegistEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package com.econovation.recruit.api.user.helper;

import com.econovation.recruitcommon.annotation.Helper;
import com.econovation.recruitcommon.exception.RecruitDynamicException;
import com.econovation.recruitinfrastructure.ncp.NcpClient;
import com.econovation.recruitinfrastructure.ncp.NcpProperties;
import com.econovation.recruitinfrastructure.ses.RecipientForRequest;
import com.econovation.recruitinfrastructure.ses.SendRawEmailDto;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.codec.binary.Base64;

@Helper
@RequiredArgsConstructor
Expand All @@ -34,37 +31,33 @@ public class NcpMailHelper {
@SneakyThrows
public void sendMail(String title, String body, String recipientAddress) {
String timeStamp = String.valueOf(Instant.now().toEpochMilli());
String signature = makeSignature(ncpProperties.getAccessKey(), ncpProperties.getSecretKey(), "/api/v1/mails", timeStamp);
ncpClient.sendMail(ncpProperties.getAccessKey(), timeStamp, signature, createSendRawEmailDto(title, body, recipientAddress));
String signature = makeSignature(timeStamp, ncpProperties.getAccessKey(), ncpProperties.getSecretKey());
ncpClient.createMailRequest(ncpProperties.getAccessKey(), timeStamp, signature,"ko-KR", createSendRawEmailDto(title, body, recipientAddress));
}
public String makeSignature(
String accessKey, String secretKey, String url, String timeStamp) {
String result;
try {
String message =
new StringBuilder()
.append(method)
.append(space)
.append(url)
.append(newLine)
.append(timeStamp)
.append(newLine)
.append(accessKey)
.toString();
public String makeSignature(String timeStamp, String accessKey, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException {
String space = " "; // 공백
String newLine = "\n"; // 줄바꿈
String method = "POST"; // HTTP 메소드
String url = "/api/v1/mails"; // 도메인을 제외한 "/" 아래 전체 url (쿼리스트링 포함)
String message = new StringBuilder()
.append(method)
.append(space)
.append(url)
.append(newLine)
.append(timeStamp)
.append(newLine)
.append(accessKey)
.toString();

SecretKeySpec signingKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(signingKey);
SecretKeySpec signingKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(signingKey);

byte[] rawHmac = mac.doFinal(message.getBytes("UTF-8"));
String encodeBase64String = Base64.encodeBase64String(rawHmac);
byte[] rawHmac = mac.doFinal(message.getBytes("UTF-8"));
String encodeBase64String = Base64.getEncoder().encodeToString(rawHmac);

result = encodeBase64String;
return encodeBase64String;

} catch (Exception ex) {
throw new RecruitDynamicException(0, "400", ex.getMessage());
}
return result;
}
public SendRawEmailDto createSendRawEmailDto(String title, String body, String recipientAddress) {
return SendRawEmailDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public interface NcpClient {
@PostMapping(
path = "/api/v1/mails",
consumes = "application/json; charset=UTF-8")
ResponseEntity<Response> sendMail(
ResponseEntity<Response> createMailRequest(
@RequestHeader("x-ncp-iam-access-key") String accessKey,
@RequestHeader("x-ncp-apigw-timestamp") String timestamp,
@RequestHeader("x-ncp-apigw-signature-v2") String signature,
@RequestHeader("x-ncp-lang") String lang,
@RequestBody SendRawEmailDto sendRawEmailDto);
}

0 comments on commit 6368a59

Please sign in to comment.