Merge branch 'hylee'

This commit is contained in:
hylee 2023-06-08 11:07:18 +09:00
commit 77322f863e
11 changed files with 550 additions and 15 deletions

15
pom.xml
View File

@ -71,7 +71,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<!-- <optional>true</optional>-->
</dependency>
<!-- DB Logback -->
@ -135,6 +135,19 @@
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.3</version>
</dependency>
</dependencies>
<build>

View File

@ -106,7 +106,6 @@ public class LogAspect {
public void afterReturning(JoinPoint joinPoint, Object returnValue) throws Exception {
log.info(" :: AfterReturning :: ");
String resutlCode = "";
// HttpServletRequest 객체를 가져옴
HttpServletRequest request = this.getHttpServletRequest();
// @Befer에서 저장한 logId를 가져옴
@ -117,9 +116,7 @@ public class LogAspect {
LettnAccessLogVO lettnAccessLogVO = new LettnAccessLogVO()
.builder()
.logId(logId)
// .resCn(this.getJsonToString(returnValue))
.resCn(this.getJsonToString(returnValue))
.resCode(resutlCode)
.build();
lettnAccessLogMapper.update(lettnAccessLogVO);
}

View File

@ -0,0 +1,38 @@
package com.itn.mjonApi.etc.ganpandaum.mapper.domain;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* packageName : com.itn.mjonApi.etc.ganpandaum.mapper.domain
* fileName : GdVO
* author : hylee
* date : 2023-06-07
* description :
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-06-07 hylee 최초 생성
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class GdVO {
private String gdName;
private String gdCompany;
private String gdPhone;
private String gdEmail;
private String gdAddr;
private String gdContent;
private List<MultipartFile> fileInfo;
}

View File

@ -0,0 +1,21 @@
package com.itn.mjonApi.etc.ganpandaum.service;
import com.itn.mjonApi.cmn.msg.RestResponse;
import com.itn.mjonApi.etc.ganpandaum.mapper.domain.GdVO;
import java.io.IOException;
/**
* packageName : com.itn.mjonApi.etc.ganpandaum.service
* fileName : GdService
* author : hylee
* date : 2023-06-07
* description :
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-06-07 hylee 최초 생성
*/
public interface GdService {
RestResponse sendEstimateEmail(GdVO gdVO) throws IOException;
}

View File

@ -0,0 +1,131 @@
package com.itn.mjonApi.etc.ganpandaum.service.impl;
import com.itn.mjonApi.cmn.msg.RestResponse;
import com.itn.mjonApi.etc.ganpandaum.mapper.domain.GdVO;
import com.itn.mjonApi.etc.ganpandaum.service.GdService;
import com.itn.mjonApi.util.Email.EmailVO;
import com.itn.mjonApi.util.Email.SendMail;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.jsoup.Jsoup;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.LocalDate;
/**
* packageName : com.itn.mjonApi.etc.ganpandaum.service.impl
* fileName : GdServiceImpl
* author : hylee
* date : 2023-06-07
* description :
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-06-07 hylee 최초 생성
*/
@Service
@Slf4j
public class GdServiceImpl implements GdService {
@Value("${Ganpandaup.estimate.template.url}")
private String GANPANDAUP_ESTIMATE_TEMPLATE_URL;
@Value("${respone.status.success}")
private String RESPONE_STATUS_SUCCESS;
@Value("${Ganpandaup.receiver.email}")
private String GANPANDAUP_RECEIVER_EMAIL;
@Override
public RestResponse sendEstimateEmail(GdVO gdVO) throws IOException {
log.info("gdVO: [{}]", gdVO.toString());
log.info("gdVO: [{}]", gdVO.getFileInfo().get(0).getOriginalFilename());
MultipartFile multipartFile = gdVO.getFileInfo().get(0);
// File p_file = new File(multipartFile.getOriginalFilename());
// multipartFile.transferTo(p_file);
// File p_file = multipartFile.transferTo(p_file);
File p_file = getFile(gdVO, multipartFile);
String returnMsg = "문의해 주셔서 감사합니다.\n빠른 시일 내에 답변해 드리겠습니다.";
HttpStatus status = HttpStatus.OK;
String emailContent = "";
SendMail sMail = new SendMail();
try {
emailContent = Jsoup.connect(GANPANDAUP_ESTIMATE_TEMPLATE_URL)
.data("query", "Java")
.userAgent("Mozilla")
.cookie("auth", "token")
.timeout(3000)
.post()
.toString();
// ./src/main/resources/templates/estimate.html
emailContent = emailContent
.replace("[[_Company_]]", gdVO.getGdCompany())
.replace("[[_Name_]]", gdVO.getGdName())
.replace("[[_Phone_]]", gdVO.getGdPhone())
.replace("[[_Email_]]", gdVO.getGdEmail())
.replace("[[_Addr_]]", gdVO.getGdAddr())
.replace("[[_Content_]]", gdVO.getGdContent())
;
// 메일 첨부파일을 위한 절대경로
// 메일 제목
String mailTitle = "[간판다움 견적의뢰] "+gdVO.getGdName()+"["+gdVO.getGdCompany()+"]님의 견적 의뢰입니다._"+LocalDate.now();
sMail.itnSendMail(
EmailVO.builder()
.title(mailTitle)
.contents(emailContent)
.fileInfo(p_file)
.atch_file_name(p_file.getName())
.send_to(GANPANDAUP_RECEIVER_EMAIL)
.send_from("noreply@munjaon.co.kr")
.build()
);
}
catch (IOException e) {
e.printStackTrace();
return new RestResponse("STAT_1099");
}
catch (Exception e) {
e.printStackTrace();
return new RestResponse("STAT_1099");
}
// return null;
return new RestResponse(RESPONE_STATUS_SUCCESS);
}
@NotNull
private static File getFile(GdVO gdVO, MultipartFile multipartFile) throws IOException {
File p_file = new File(gdVO.getFileInfo().get(0).getOriginalFilename());
p_file.createNewFile();
FileOutputStream fos = new FileOutputStream(p_file);
fos.write(multipartFile.getBytes());
fos.close();
return p_file;
}
}

View File

@ -0,0 +1,53 @@
package com.itn.mjonApi.etc.ganpandaum.web;
import com.itn.mjonApi.cmn.msg.RestResponse;
import com.itn.mjonApi.etc.ganpandaum.mapper.domain.GdVO;
import com.itn.mjonApi.etc.ganpandaum.service.GdService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* packageName : com.itn.mjonApi.etc.ganpandaum.web
* fileName : SendRestController
* author : hylee
* date : 2023-02-15
* description :
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-02-15 hylee 최초 생성
*/
// 치환문자가 있으면 , => § 치환
@Slf4j
@RestController
public class GdRestController {
@Autowired
private GdService gdService;
/**
*
* @param gdVO
* @Discription [문자 발송] 같은 내용으로 여려명에게 보냄
* @return
*/
@CrossOrigin("*") // 모든 요청에 접근 허용
@PostMapping("/etc/ganpandaum/sendEstimateEmail")
@ApiOperation(value= "단문 문자 전송", notes = " 같은 내용으로 여러명에게 보냄")
public ResponseEntity<RestResponse> sendEstimateEmail(GdVO gdVO) throws Exception {
return ResponseEntity.ok().body(gdService.sendEstimateEmail(gdVO));
}
}

View File

@ -1,20 +1,17 @@
package com.itn.mjonApi.mjon.api.send.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.itn.mjonApi.cmn.msg.RestResponse;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgsRequestVO;
import com.itn.mjonApi.mjon.api.send.service.SendService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
/**
* packageName : com.itn.mjonApi.mjon.send.web

View File

@ -0,0 +1,44 @@
package com.itn.mjonApi.util.Email;
import lombok.*;
import java.io.File;
import java.util.Date;
/**
* packageName : com.itn.mjonApi.util.Email
* fileName : EmailVO
* author : hylee
* date : 2023-06-07
* description :
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-06-07 hylee 최초 생성
*/
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EmailVO {
private int idx;
private int pro_idx;
private String title;
private String category;
private String contents;
private String send_from;
private String send_to;
private Date senddate;
private Date regdate;
private String status;
private String flag;
private String target;
private String atch_file_id;
private String atch_file_name;
private String atch_file_path;
private File fileInfo;
}

View File

@ -0,0 +1,28 @@
package com.itn.mjonApi.util.Email;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
/**
* packageName : com.itn.mjonApi.util.Email
* fileName : SMTPAuthenticator
* author : hylee
* date : 2023-06-07
* description :
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-06-07 hylee 최초 생성
*/
public class SMTPAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
//https://myaccount.google.com/lesssecureapps 에서 보안 수준 낮은 앱의 액세스 허용 해줘야함(인증 오류날때)
// String username = "itn0801@gmail.com"; // gmail 사용자;
String username = "noreply@munjaon.co.kr"; // naverworks 사용자;
/*String password = "easytour7!"; // 패스워드;*/
// String password = "jpkofmptitmqvbhc"; // 패스워드;
String password = "iEWkihhyZipl"; // 패스워드;
return new PasswordAuthentication(username, password);
}
}

View File

@ -0,0 +1,208 @@
package com.itn.mjonApi.util.Email;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Date;
import java.util.Properties;
/**
* packageName : com.itn.mjonApi.util
* fileName : SendMail
* author : hylee
* date : 2023-06-07
* description :
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-06-07 hylee 최초 생성
*/
public class SendMail {
public void sendMail(EmailVO vo) throws Exception {
try {
Properties props = new Properties();
/*
* props.put("mail.transport.protocol", "smtp");// 프로토콜 설정
* props.put("mail.smtp.host", "smtp.gmail.com");// gmail SMTP 서비스 주소(호스트)
* props.put("mail.smtp.port", "465");// gmail SMTP 서비스 포트 설정
* props.put("mail.smtp.starttls.enable","true"); // gmail 인증용 Secure Socket
* Layer(SSL) 설정 props.setProperty("mail.smtp.socketFactory.class",
* "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true");//
* SMTP 인증을 설정 props.put("mail.debug", "true"); // log를 위한 debug 옵션 추가
*/
props.put("mail.smtp.auth", "true");// SMTP 인증을 설정
props.put("mail.smtp.starttls.enable", "true");
// props.put("mail.transport.protocol", "smtp");// 프로토콜 설정
props.put("mail.smtp.host", "smtp.gmail.com");// gmail SMTP 서비스 주소(호스트)
props.put("mail.smtp.port", "587");// gmail SMTP 서비스 포트 설정
props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
// props.put("mail.smtp.debug", "true");
// gmail 인증용 Secure Socket Layer(SSL) 설정
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
// 인증정보
Authenticator auth = new SMTPAuthenticator();
Session mailSession = Session.getDefaultInstance(props, auth);
// MimeMessage mailMessage = mailImpl.createMimeMessage();
MimeMessage message = new MimeMessage(mailSession);
InternetAddress from = new InternetAddress(vo.getSend_from());
message.setFrom(from);
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(vo.getSend_to()));
message.setSubject(vo.getTitle());
message.setContent(vo.getContents(), "text/html;charset=UTF-8");
// message.setText(vo.getContents());
message.setSentDate(new Date());
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
public void sendMail2(EmailVO vo) throws Exception {
try {
Properties props = new Properties();
/*
* props.put("mail.transport.protocol", "smtp");// 프로토콜 설정
* props.put("mail.smtp.host", "smtp.gmail.com");// gmail SMTP 서비스 주소(호스트)
* props.put("mail.smtp.port", "465");// gmail SMTP 서비스 포트 설정
* props.put("mail.smtp.starttls.enable","true"); // gmail 인증용 Secure Socket
* Layer(SSL) 설정 props.setProperty("mail.smtp.socketFactory.class",
* "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true");//
* SMTP 인증을 설정 props.put("mail.debug", "true"); // log를 위한 debug 옵션 추가
*/
// props.put("mail.smtp.auth", "true");// SMTP 인증을 설정
// props.put("mail.smtp.starttls.enable","true");
// //props.put("mail.transport.protocol", "smtp");// 프로토콜 설정
// props.put("mail.smtp.host", "smtp.worksmobile.com");// gmail SMTP 서비스 주소(호스트)
// props.put("mail.smtp.port", "587");// gmail SMTP 서비스 포트 설정
// /*props.put("mail.smtp.ssl.trust","smtp.gmail.com");
// props.put("mail.smtp.ssl.protocols", "TLSv1.2");*/
// props.put("mail.smtp.starttls.enable","true");
// props.put("mail.smtp.debug", "true");
// gmail 인증용 Secure Socket Layer(SSL) 설정
// props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
// worksmobile 계정 설정
props.put("mail.smtp.host", "smtp.worksmobile.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.ssl.trust", "smtp.worksmobile.com");
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
// props.put("mail.smtp.debug", "true");
// 인증정보
Authenticator auth = new SMTPAuthenticator();
Session mailSession = Session.getDefaultInstance(props, auth);
/*
* Session mailSession = Session.getInstance(props, new
* javax.mail.Authenticator() { protected PasswordAuthentication
* getPasswordAuthentication() { return new
* PasswordAuthentication("noreply@munjaon.co.kr", "easytour7!"); } });
*/
// mailSession.setDebug(true);
// MimeMessage mailMessage = mailImpl.createMimeMessage();
MimeMessage message = new MimeMessage(mailSession);
InternetAddress from = new InternetAddress(vo.getSend_from());
message.setFrom(from);
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(vo.getSend_to()));
message.setSubject(vo.getTitle());
message.setContent(vo.getContents(), "text/html;charset=UTF-8");
// message.setText(vo.getContents());
message.setSentDate(new Date());
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
// public SuccessResponse itnSendMail(EmailVO vo) throws Exception {
public void itnSendMail(EmailVO vo) throws Exception {
Properties props = new Properties();
String returnMsg = "지원해 주셔서 감사합니다.";
HttpStatus status = HttpStatus.OK;
// worksmobile 계정 설정
props.put("mail.smtp.host", "smtp.worksmobile.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.ssl.trust", "smtp.worksmobile.com");
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
// props.put("mail.smtp.debug", "true");
// 인증정보
Authenticator auth = new SMTPAuthenticator();
Session mailSession = Session.getDefaultInstance(props, auth);
Multipart mp = new MimeMultipart();
// 파일 영역
if(StringUtils.isNotEmpty(vo.getAtch_file_name()))
{
MimeBodyPart mailFile = new MimeBodyPart();
FileDataSource fds = new FileDataSource(vo.getFileInfo());
// FileDataSource fds = new FileDataSource(new File(vo.getAtch_file_path()).getAbsolutePath());
mailFile.setDataHandler(new DataHandler(fds));
mailFile.setFileName(MimeUtility.encodeText(vo.getAtch_file_name(), "euc-kr","B"));
mp.addBodyPart(mailFile);
}
//메일 영역
MimeBodyPart mailInfo = new MimeBodyPart();
mailInfo.setContent(vo.getContents(), "text/html; charset=UTF-8");
mp.addBodyPart(mailInfo);
// mailSession.setDebug(true);
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(vo.getSend_from()));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(vo.getSend_to()));
message.setSubject(vo.getTitle());
message.setContent(vo.getContents(), "text/html;charset=UTF-8");
message.setSentDate(new Date());
message.setContent(mp);
Transport.send(message);
// return new SuccessResponse(status, returnMsg, LocalDateTime.now());
}
}

View File

@ -23,3 +23,8 @@ server.error.whitelabel.enabled=false
# respone success status code
respone.status.success=STAT_0
#
Ganpandaup.estimate.template.url=https://www.munjaon.co.kr/publish/email_form_ganpandaum_contact.html
Ganpandaup.receiver.email=hylee250@kakao.com