Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
ops
Commits
1e620732
Commit
1e620732
authored
Aug 29, 2024
by
wujipeng
Browse files
邮箱通知模板修改
parent
fd03f574
Changes
5
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
1e620732
...
...
@@ -89,6 +89,23 @@
<artifactId>
swagger-models
</artifactId>
<version>
1.5.16
</version>
</dependency>
<!-- 阿里短信 -->
<dependency>
<groupId>
com.aliyun
</groupId>
<artifactId>
aliyun-java-sdk-core
</artifactId>
<version>
4.0.6
</version>
</dependency>
<dependency>
<groupId>
com.aliyun
</groupId>
<artifactId>
aliyun-java-sdk-dysmsapi
</artifactId>
<version>
1.1.0
</version>
</dependency>
<!-- Alibaba FastJSON 依赖 -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.83
</version>
<!-- 请检查最新版本 -->
</dependency>
</dependencies>
<repositories>
...
...
src/main/java/com/ruzhoukj/sms/task/ProjectTask.java
View file @
1e620732
...
...
@@ -30,6 +30,7 @@ public class ProjectTask {
//每天执行一次,七天内要到期的项目
@Scheduled
(
cron
=
"0 0 10 * * ?"
)
// @Scheduled(cron = "*/10 * * * * *")
public
void
projectRemind
()
{
List
<
ProjectEntity
>
sevenDaysProject
=
projectService
.
selectSevenDaysProject
();
//有要到期的合同,需要邮箱提醒
...
...
src/main/java/com/ruzhoukj/sms/util/DateUtils.java
View file @
1e620732
...
...
@@ -4,6 +4,7 @@ import java.text.SimpleDateFormat;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.temporal.ChronoUnit
;
import
java.util.Date
;
/**
...
...
@@ -50,6 +51,23 @@ public class DateUtils {
return
sdf
.
format
(
date
);
}
/**
* 计算两个日期之间的天数差。
*
* @param date1 第一个日期
* @param date2 第二个日期
* @return 两个日期之间的天数差
*/
public
static
long
daysBetween
(
Date
date1
,
Date
date2
)
{
// 将Date对象转换为LocalDate对象
LocalDate
localDate1
=
date1
.
toInstant
().
atZone
(
ZoneId
.
systemDefault
()).
toLocalDate
();
LocalDate
localDate2
=
date2
.
toInstant
().
atZone
(
ZoneId
.
systemDefault
()).
toLocalDate
();
// 计算两个日期之间的天数差
return
Math
.
abs
(
ChronoUnit
.
DAYS
.
between
(
localDate1
,
localDate2
));
}
public
static
void
main
(
String
[]
args
)
{
Date
[]
dates
=
getStartAndEndDateOfCurrentMonth
();
System
.
out
.
println
(
"Start date of this month: "
+
dates
[
0
]);
...
...
src/main/java/com/ruzhoukj/sms/util/EmailUtil.java
View file @
1e620732
...
...
@@ -10,6 +10,7 @@ import javax.mail.Session;
import
javax.mail.Transport
;
import
javax.mail.internet.InternetAddress
;
import
javax.mail.internet.MimeMessage
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Properties
;
import
java.util.StringJoiner
;
...
...
@@ -156,12 +157,13 @@ public class EmailUtil {
InternetAddress
.
parse
(
String
.
join
(
", "
,
toAddresses
)));
StringJoiner
stringJoiner
=
new
StringJoiner
(
"\n"
);
stringJoiner
.
add
(
name
+
"您好,以下项目即将在七天内到期
"
);
stringJoiner
.
add
(
"
项目名
:"
+
projectEntity
.
getProjectName
());
stringJoiner
.
add
(
"
项目开始
时间:"
+
DateUtils
.
formatDate
(
projectEntity
.
get
Start
Time
()));
stringJoiner
.
add
(
"
项目结束时间:"
+
DateUtils
.
format
Date
(
projectEntity
.
getEndTime
()));
stringJoiner
.
add
(
"尊敬的"
+
name
+
",
"
);
stringJoiner
.
add
(
"
您当前注册的
:"
+
projectEntity
.
getProjectName
()
+
"即将到期。"
);
stringJoiner
.
add
(
"
具体到期
时间
为
:"
+
DateUtils
.
formatDate
(
projectEntity
.
get
End
Time
())
+
","
);
stringJoiner
.
add
(
"
距今还有:"
+
(
int
)
DateUtils
.
daysBetween
(
new
Date
(
),
projectEntity
.
getEndTime
())
+
"天"
);
stringJoiner
.
add
(
"备注:"
+
projectEntity
.
getDescribe
());
stringJoiner
.
add
(
"请及时处理"
);
stringJoiner
.
add
(
"请您及时进行处理,以确保服务的连续性。"
);
stringJoiner
.
add
(
"From:研发部"
);
message
.
setText
(
stringJoiner
.
toString
());
...
...
src/main/java/com/ruzhoukj/sms/util/SmsUtil.java
0 → 100644
View file @
1e620732
package
com.ruzhoukj.sms.util
;
import
com.alibaba.fastjson.JSON
;
import
com.aliyuncs.CommonRequest
;
import
com.aliyuncs.CommonResponse
;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.IAcsClient
;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.profile.DefaultProfile
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.Map
;
@Slf4j
public
class
SmsUtil
{
public
static
boolean
sendMsg
(
String
phoneNum
,
String
template
,
Map
<
String
,
String
>
param
)
{
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
"cn-hangzhou"
,
//accessKeyId
"LTAI5tENboKK5bcuqHfPvEdr"
,
//accessSecret
"Q006EvMzC63i1ozDiVNxEAxo8eH9zA"
);
IAcsClient
client
=
new
DefaultAcsClient
(
profile
);
CommonRequest
request
=
new
CommonRequest
();
request
.
setMethod
(
MethodType
.
POST
);
request
.
setDomain
(
"dysmsapi.aliyuncs.com"
);
request
.
setVersion
(
"2017-05-25"
);
request
.
setAction
(
"SendSms"
);
request
.
putQueryParameter
(
"RegionId"
,
"cn-hangzhou"
);
//接收号码
request
.
putQueryParameter
(
"PhoneNumbers"
,
phoneNum
);
//短信签名(如某某科技有限公司)
request
.
putQueryParameter
(
"SignName"
,
"如昼科技"
);
//短信模板
request
.
putQueryParameter
(
"TemplateCode"
,
template
);
//验证码
request
.
putQueryParameter
(
"TemplateParam"
,
JSON
.
toJSONString
(
param
));
CommonResponse
response
;
try
{
response
=
client
.
getCommonResponse
(
request
);
}
catch
(
com
.
aliyuncs
.
exceptions
.
ClientException
e
)
{
throw
new
RuntimeException
(
e
);
}
log
.
info
(
response
.
getData
());
return
true
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment