From 6384c997ad5bc43434cdd01be46d353b023be582 Mon Sep 17 00:00:00 2001 From: LingandRX Date: Wed, 4 Jun 2025 00:38:34 +0800 Subject: [PATCH] init workflow project --- .gitignore | 38 ++++++ .idea/.gitignore | 10 ++ .idea/encodings.xml | 7 ++ .idea/misc.xml | 14 +++ .idea/vcs.xml | 6 + pom.xml | 118 ++++++++++++++++++ .../asia/yulinling/workflow/WorkFlowMain.java | 12 ++ .../workflow/service/MailService.java | 59 +++++++++ .../service/impl/MailServiceImpl.java | 92 ++++++++++++++ src/main/resources/application.yml | 23 ++++ .../asia/yulinling/workflow/PasswordTest.java | 29 +++++ .../yulinling/workflow/WorkFlowMainTests.java | 18 +++ 12 files changed, 426 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 src/main/java/asia/yulinling/workflow/WorkFlowMain.java create mode 100644 src/main/java/asia/yulinling/workflow/service/MailService.java create mode 100644 src/main/java/asia/yulinling/workflow/service/impl/MailServiceImpl.java create mode 100644 src/main/resources/application.yml create mode 100644 src/test/java/asia/yulinling/workflow/PasswordTest.java create mode 100644 src/test/java/asia/yulinling/workflow/WorkFlowMainTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..7d05e99 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# 依赖于环境的 Maven 主目录路径 +/mavenHomeManager.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..30eedac --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ba288ea --- /dev/null +++ b/pom.xml @@ -0,0 +1,118 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.5.0 + + + asia.yulinling + workflow + 0.0.1-SNAPSHOT + workflow + Demo project for Spring Boot + + + + + + + + + + + + + + + 17 + 1.6.2 + + + + org.springframework.boot + spring-boot-starter + + + + com.github.ulisesbocchio + jasypt-spring-boot-starter + 2.1.1 + + + org.springframework.boot + spring-boot-starter-mail + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + cn.hutool + hutool-all + 5.8.38 + + + com.sun.mail + javax.mail + ${mail.version} + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + junit + junit + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/src/main/java/asia/yulinling/workflow/WorkFlowMain.java b/src/main/java/asia/yulinling/workflow/WorkFlowMain.java new file mode 100644 index 0000000..dd8b718 --- /dev/null +++ b/src/main/java/asia/yulinling/workflow/WorkFlowMain.java @@ -0,0 +1,12 @@ +package asia.yulinling.workflow; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +@SpringBootApplication +public class WorkFlowMain { + public static void main(String[] args) { + SpringApplication.run(WorkFlowMain.class, args); + } +} \ No newline at end of file diff --git a/src/main/java/asia/yulinling/workflow/service/MailService.java b/src/main/java/asia/yulinling/workflow/service/MailService.java new file mode 100644 index 0000000..57f8cee --- /dev/null +++ b/src/main/java/asia/yulinling/workflow/service/MailService.java @@ -0,0 +1,59 @@ +package asia.yulinling.workflow.service; + +import javax.mail.MessagingException; + +/** + *

+ * 邮件接口 + *

+ * + * @author yulinling + * @date Create in 2025/6/3 22:49 + */ +public interface MailService { + /** + * 发送文本邮件 + * + * @param to 收件人地址 + * @param subject 邮件主题 + * @param content 邮件内容 + * @param cc 抄送地址 + */ + void sendSimpleMail(String to, String subject, String content, String... cc); + + /** + * 发送HTML邮件 + * + * @param to 收件人地址 + * @param subject 邮件主题 + * @param content 邮件内容 + * @param cc 抄送地址 + * @throws MessagingException 邮件发送异常 + */ + void sendHtmlMail(String to, String subject, String content, String... cc) throws MessagingException; + + + /** + * 发送带附件邮件 + * + * @param to 收件人地址 + * @param subject 邮件主题 + * @param content 邮件内容 + * @param filePath 附件地址 + * @param cc 抄送地址 + * @throws MessagingException 邮件发送异常 + */ + void sendAttachmentsMail(String to, String subject, String content, String filePath, String... cc) throws MessagingException; + + /** + * 发送带附件邮件 + * + * @param to 收件人地址 + * @param subject 邮件主题 + * @param content 邮件内容 + * @param rscPath 静态资源地址 + * @param cc 抄送地址 + * @throws MessagingException 邮件发送异常 + */ + void sendResourceMail(String to, String subject, String content, String rscPath, String... cc) throws MessagingException; +} diff --git a/src/main/java/asia/yulinling/workflow/service/impl/MailServiceImpl.java b/src/main/java/asia/yulinling/workflow/service/impl/MailServiceImpl.java new file mode 100644 index 0000000..5a3046b --- /dev/null +++ b/src/main/java/asia/yulinling/workflow/service/impl/MailServiceImpl.java @@ -0,0 +1,92 @@ +package asia.yulinling.workflow.service.impl; + +import asia.yulinling.workflow.service.MailService; +import cn.hutool.core.util.ArrayUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.stereotype.Service; + +import javax.mail.MessagingException; + +/** + *

+ * 邮件接口 + *

+ * + * @author yulinling + * @date Create in 2025/6/3 22:49 + */ +@Service +@RequiredArgsConstructor +public class MailServiceImpl implements MailService { + + private final JavaMailSender mailSender; + @Value("${spring.mail.username}") + private String from; + /** + * 发送文本邮件 + * + * @param to 收件人地址 + * @param subject 邮件主题 + * @param content 邮件内容 + * @param cc 抄送地址 + */ + @Override + public void sendSimpleMail(String to, String subject, String content, String... cc) { + SimpleMailMessage message = new SimpleMailMessage(); + message.setFrom(from); + message.setTo(to); + message.setSubject(subject); + message.setText(content); + if (ArrayUtil.isNotEmpty(cc)) { + message.setCc(cc); + } + mailSender.send(message); + } + + /** + * 发送HTML邮件 + * + * @param to 收件人地址 + * @param subject 邮件主题 + * @param content 邮件内容 + * @param cc 抄送地址 + * @throws MessagingException 邮件发送异常 + */ + @Override + public void sendHtmlMail(String to, String subject, String content, String... cc) throws MessagingException { + + } + + /** + * 发送带附件邮件 + * + * @param to 收件人地址 + * @param subject 邮件主题 + * @param content 邮件内容 + * @param filePath 附件地址 + * @param cc 抄送地址 + * @throws MessagingException 邮件发送异常 + */ + @Override + public void sendAttachmentsMail(String to, String subject, String content, String filePath, String... cc) throws MessagingException { + + } + + /** + * 发送带附件邮件 + * + * @param to 收件人地址 + * @param subject 邮件主题 + * @param content 邮件内容 + * @param rscPath 静态资源地址 + * @param cc 抄送地址 + * @throws MessagingException 邮件发送异常 + */ + @Override + public void sendResourceMail(String to, String subject, String content, String rscPath, String... cc) throws MessagingException { + + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..81f727c --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,23 @@ +spring: + mail: + host: smtp.qq.com + port: 587 + username: 2712495353@qq.com + # 使用 jasypt 加密密码,使用com.xkcoding.email.PasswordTest.testGeneratePassword 生成加密密码,替换 ENC(加密密码) +# password: ENC(OT0qGOpXrr1Iog1W+fjOiIDCJdBjHyhy) + password: xlwpmlbawpjjdghb + protocol: smtp + test-connection: false + default-encoding: UTF-8 + properties: + mail.smtp.auth: true + mail.smtp.starttls.enable: true + mail.smtp.starttls.required: true + mail.smtp.ssl.enable: false + mail.display.sendmail: spring-boot-demo +# 为 jasypt 配置解密秘钥 +jasypt: + encryptor: + bean: jasyptStringEncryptor + password: spring-boot-demo + algorithm: PBEWITHHMACSHA512ANDAES_256 diff --git a/src/test/java/asia/yulinling/workflow/PasswordTest.java b/src/test/java/asia/yulinling/workflow/PasswordTest.java new file mode 100644 index 0000000..ee1d7f3 --- /dev/null +++ b/src/test/java/asia/yulinling/workflow/PasswordTest.java @@ -0,0 +1,29 @@ +package asia.yulinling.workflow; + +import org.jasypt.encryption.StringEncryptor; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * 密码加密测试 + */ +public class PasswordTest extends WorkFlowMainTests { + @Autowired + private StringEncryptor encryptor; + + /** + * 生成加密密码 + */ + @Test + public void testGeneratePassword() { + // 你的邮箱密码 + String password = "Just4Test!"; + // 加密后的密码(注意:配置上去的时候需要加 ENC(加密密码)) + String encryptPassword = encryptor.encrypt(password); + String decryptPassword = encryptor.decrypt(encryptPassword); + + System.out.println("password = " + password); + System.out.println("encryptPassword = " + encryptPassword); + System.out.println("decryptPassword = " + decryptPassword); + } +} \ No newline at end of file diff --git a/src/test/java/asia/yulinling/workflow/WorkFlowMainTests.java b/src/test/java/asia/yulinling/workflow/WorkFlowMainTests.java new file mode 100644 index 0000000..b503a75 --- /dev/null +++ b/src/test/java/asia/yulinling/workflow/WorkFlowMainTests.java @@ -0,0 +1,18 @@ +package asia.yulinling.workflow; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest +public class WorkFlowMainTests { + + @Test + public void contextLoads() { + + } + +} \ No newline at end of file