Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
5b84c83c
Commit
5b84c83c
authored
Apr 11, 2020
by
邓实川
Committed by
chenzg
Jul 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
短信模板枚举类,阿里云短信常量优化
parent
19cdac75
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
59 deletions
+75
-59
src/main/java/cn/timer/api/config/enums/PinType.java
+27
-0
src/main/java/cn/timer/api/utils/AliyunSMS.java
+43
-54
src/main/java/cn/timer/api/utils/RemindUtil.java
+5
-5
No files found.
src/main/java/cn/timer/api/config/enums/PinType.java
0 → 100644
View file @
5b84c83c
package
cn
.
timer
.
api
.
config
.
enums
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
/**
* @title 短信模板
* @author dsc
*
*/
@Getter
@AllArgsConstructor
public
enum
PinType
{
AUTHENTICATION
(
"SMS_178485364"
,
"身份验证"
),
LOGIN_CONFIRMATION
(
"SMS_178485363"
,
"登录确认"
),
LOGIN_ABNORMAL
(
"SMS_178485362"
,
"登录异常"
),
REGISTER
(
"SMS_178485361"
,
"用户注册"
),
CHANGE_PASSWORD
(
"SMS_178485360"
,
"修改密码"
),
CHANGE_INFORMATION
(
"SMS_178485359"
,
"信息变更"
),
REMIND
(
"SMS_180347486"
,
"短信提醒"
);
private
final
String
code
;
private
final
String
message
;
}
src/main/java/cn/timer/api/utils/AliyunSMS.java
View file @
5b84c83c
...
@@ -12,6 +12,7 @@ import com.aliyuncs.exceptions.ServerException;
...
@@ -12,6 +12,7 @@ import com.aliyuncs.exceptions.ServerException;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.profile.DefaultProfile
;
import
com.aliyuncs.profile.DefaultProfile
;
import
cn.timer.api.config.enums.PinType
;
import
cn.timer.api.dto.qyzx.EntRegisterDto
;
import
cn.timer.api.dto.qyzx.EntRegisterDto
;
/**
/**
...
@@ -22,11 +23,18 @@ import cn.timer.api.dto.qyzx.EntRegisterDto;
...
@@ -22,11 +23,18 @@ import cn.timer.api.dto.qyzx.EntRegisterDto;
*/
*/
public
class
AliyunSMS
{
public
class
AliyunSMS
{
final
String
name
=
"TemplateCode"
;
// 模板参数
final
static
String
CODE_NAME
=
"TemplateCode"
;
// 短信模板代码参数名
final
String
regionId
=
"cn-shenzhen"
;
// 地区参数
final
static
String
REGION_ID
=
"cn-shenzhen"
;
// 地区参数
final
String
projectName
=
"8小时人事管家"
;
// 项目名
final
static
String
PROJECT_NAME
=
"8小时人事管家"
;
// 项目名
final
String
accessKeyId
=
"LTAI4FuaShJWQ1dggsFWG5CC"
;
final
static
String
ACCESSKEY_ID
=
"LTAI4FuaShJWQ1dggsFWG5CC"
;
final
String
secret
=
"EJ6qToT4T4u0B5Rb6qrta9WkyGHvGR"
;
final
static
String
SECRET
=
"EJ6qToT4T4u0B5Rb6qrta9WkyGHvGR"
;
final
static
String
TEMPLATE_PARAM
=
"TemplateParam"
;
// 自定义参数
final
static
String
DOMAIN
=
"dysmsapi.aliyuncs.com"
;
final
static
String
VERSION
=
"2017-05-25"
;
final
static
String
ACTION_SEND
=
"SendSms"
;
// 发短信
final
static
String
ACTION_QUERY
=
"QuerySendDetails"
;
// 短信查询
final
static
String
PAGE_SIZE
=
"1"
;
final
static
String
CURRENT_PAGE
=
"1"
;
/**
/**
*
*
...
@@ -40,48 +48,42 @@ public class AliyunSMS {
...
@@ -40,48 +48,42 @@ public class AliyunSMS {
String
phone
=
entRegisterDto
.
getPhone
();
String
phone
=
entRegisterDto
.
getPhone
();
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
regionId
,
accessKeyId
,
secret
);
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
REGION_ID
,
ACCESSKEY_ID
,
SECRET
);
IAcsClient
client
=
new
DefaultAcsClient
(
profile
);
IAcsClient
client
=
new
DefaultAcsClient
(
profile
);
CommonRequest
request
=
new
CommonRequest
();
CommonRequest
request
=
new
CommonRequest
();
request
.
setMethod
(
MethodType
.
POST
);
request
.
setMethod
(
MethodType
.
POST
);
request
.
setDomain
(
"dysmsapi.aliyuncs.com"
);
request
.
setDomain
(
DOMAIN
);
request
.
setVersion
(
"2017-05-25"
);
request
.
setVersion
(
VERSION
);
request
.
setAction
(
"SendSms"
);
request
.
setAction
(
ACTION_SEND
);
request
.
putQueryParameter
(
"RegionId"
,
regionId
);
request
.
putQueryParameter
(
"RegionId"
,
REGION_ID
);
request
.
putQueryParameter
(
"PhoneNumbers"
,
phone
);
request
.
putQueryParameter
(
"PhoneNumbers"
,
phone
);
request
.
putQueryParameter
(
"SignName"
,
projectName
);
request
.
putQueryParameter
(
"SignName"
,
PROJECT_NAME
);
switch
(
templateCode
)
{
switch
(
templateCode
)
{
// 1."身份验证验证码"
case
1
:
case
1
:
request
.
putQueryParameter
(
name
,
"SMS_178485364"
);
request
.
putQueryParameter
(
CODE_NAME
,
PinType
.
AUTHENTICATION
.
getCode
()
);
break
;
break
;
// 2."登录确认验证码"
case
2
:
case
2
:
request
.
putQueryParameter
(
name
,
"SMS_178485363"
);
request
.
putQueryParameter
(
CODE_NAME
,
PinType
.
LOGIN_CONFIRMATION
.
getCode
()
);
break
;
break
;
// 3."登录异常验证码"
case
3
:
case
3
:
request
.
putQueryParameter
(
name
,
"SMS_178485362"
);
request
.
putQueryParameter
(
CODE_NAME
,
PinType
.
LOGIN_ABNORMAL
.
getCode
()
);
break
;
break
;
// 4."用户注册验证码"
case
4
:
case
4
:
request
.
putQueryParameter
(
name
,
"SMS_178485361"
);
request
.
putQueryParameter
(
CODE_NAME
,
PinType
.
REGISTER
.
getCode
()
);
break
;
break
;
// 5."修改密码验证码"
case
5
:
case
5
:
request
.
putQueryParameter
(
name
,
"SMS_178485360"
);
request
.
putQueryParameter
(
CODE_NAME
,
PinType
.
CHANGE_PASSWORD
.
getCode
()
);
break
;
break
;
// 6."信息变更验证码"
case
6
:
case
6
:
request
.
putQueryParameter
(
name
,
"SMS_178485359"
);
request
.
putQueryParameter
(
CODE_NAME
,
PinType
.
CHANGE_INFORMATION
.
getCode
()
);
break
;
break
;
default
:
default
:
request
.
putQueryParameter
(
name
,
"SMS_178485364"
);
request
.
putQueryParameter
(
CODE_NAME
,
PinType
.
AUTHENTICATION
.
getCode
()
);
}
}
// 【8小时人事管家】验证码934169,您正在尝试修改登录密码,请妥善保管账户信息。
// 【8小时人事管家】验证码934169,您正在尝试修改登录密码,请妥善保管账户信息。
request
.
putQueryParameter
(
"TemplateParam"
,
"{\"code\":\""
+
code
+
"\"}"
);
request
.
putQueryParameter
(
TEMPLATE_PARAM
,
"{\"code\":\""
+
code
+
"\"}"
);
CommonResponse
response
=
null
;
CommonResponse
response
=
null
;
try
{
try
{
response
=
client
.
getCommonResponse
(
request
);
response
=
client
.
getCommonResponse
(
request
);
...
@@ -99,20 +101,19 @@ public class AliyunSMS {
...
@@ -99,20 +101,19 @@ public class AliyunSMS {
*/
*/
@SuppressWarnings
(
"deprecation"
)
@SuppressWarnings
(
"deprecation"
)
public
String
QuerySendDetails
(
String
phone
,
String
date
,
String
bizId
)
{
public
String
QuerySendDetails
(
String
phone
,
String
date
,
String
bizId
)
{
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
"cn-shenzhen"
,
"LTAI4FuaShJWQ1dggsFWG5CC"
,
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
REGION_ID
,
ACCESSKEY_ID
,
SECRET
);
"EJ6qToT4T4u0B5Rb6qrta9WkyGHvGR"
);
IAcsClient
client
=
new
DefaultAcsClient
(
profile
);
IAcsClient
client
=
new
DefaultAcsClient
(
profile
);
CommonRequest
request
=
new
CommonRequest
();
CommonRequest
request
=
new
CommonRequest
();
request
.
setMethod
(
MethodType
.
POST
);
request
.
setMethod
(
MethodType
.
POST
);
request
.
setDomain
(
"dysmsapi.aliyuncs.com"
);
request
.
setDomain
(
DOMAIN
);
request
.
setVersion
(
"2017-05-25"
);
request
.
setVersion
(
VERSION
);
request
.
setAction
(
"QuerySendDetails"
);
request
.
setAction
(
ACTION_QUERY
);
request
.
putQueryParameter
(
"RegionId"
,
"cn-shenzhen"
);
request
.
putQueryParameter
(
"RegionId"
,
REGION_ID
);
request
.
putQueryParameter
(
"PhoneNumber"
,
phone
);
request
.
putQueryParameter
(
"PhoneNumber"
,
phone
);
request
.
putQueryParameter
(
"SendDate"
,
date
);
request
.
putQueryParameter
(
"SendDate"
,
date
);
request
.
putQueryParameter
(
"PageSize"
,
"1"
);
request
.
putQueryParameter
(
"PageSize"
,
PAGE_SIZE
);
request
.
putQueryParameter
(
"CurrentPage"
,
"1"
);
request
.
putQueryParameter
(
"CurrentPage"
,
CURRENT_PAGE
);
request
.
putQueryParameter
(
"BizId"
,
bizId
);
request
.
putQueryParameter
(
"BizId"
,
bizId
);
String
a
=
null
;
String
a
=
null
;
try
{
try
{
...
@@ -139,21 +140,20 @@ public class AliyunSMS {
...
@@ -139,21 +140,20 @@ public class AliyunSMS {
* @param phone
* @param phone
*/
*/
@SuppressWarnings
(
"deprecation"
)
@SuppressWarnings
(
"deprecation"
)
public
static
void
tx
(
String
name
,
String
htname
,
String
time
,
String
phone
)
{
public
static
void
remind
(
String
name
,
String
htname
,
String
time
,
String
phone
)
{
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
"cn-shenzhen"
,
"LTAI4FuaShJWQ1dggsFWG5CC"
,
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
REGION_ID
,
ACCESSKEY_ID
,
SECRET
);
"EJ6qToT4T4u0B5Rb6qrta9WkyGHvGR"
);
IAcsClient
client
=
new
DefaultAcsClient
(
profile
);
IAcsClient
client
=
new
DefaultAcsClient
(
profile
);
CommonRequest
request
=
new
CommonRequest
();
CommonRequest
request
=
new
CommonRequest
();
request
.
setMethod
(
MethodType
.
POST
);
request
.
setMethod
(
MethodType
.
POST
);
request
.
setDomain
(
"dysmsapi.aliyuncs.com"
);
request
.
setDomain
(
DOMAIN
);
request
.
setVersion
(
"2017-05-25"
);
request
.
setVersion
(
VERSION
);
request
.
setAction
(
"SendSms"
);
request
.
setAction
(
ACTION_SEND
);
request
.
putQueryParameter
(
"RegionId"
,
"cn-shenzhen"
);
request
.
putQueryParameter
(
"RegionId"
,
REGION_ID
);
request
.
putQueryParameter
(
"PhoneNumbers"
,
phone
);
request
.
putQueryParameter
(
"PhoneNumbers"
,
phone
);
request
.
putQueryParameter
(
"SignName"
,
"8小时人事管家"
);
request
.
putQueryParameter
(
"SignName"
,
PROJECT_NAME
);
request
.
putQueryParameter
(
"TemplateCode"
,
"SMS_180347486"
);
request
.
putQueryParameter
(
CODE_NAME
,
PinType
.
REMIND
.
getCode
()
);
request
.
putQueryParameter
(
"TemplateParam"
,
request
.
putQueryParameter
(
TEMPLATE_PARAM
,
"{\"name\":\""
+
name
+
"\", \"htname\":\""
+
htname
+
"\",\"time\":\""
+
time
+
"\"}"
);
"{\"name\":\""
+
name
+
"\", \"htname\":\""
+
htname
+
"\",\"time\":\""
+
time
+
"\"}"
);
try
{
try
{
CommonResponse
response
=
client
.
getCommonResponse
(
request
);
CommonResponse
response
=
client
.
getCommonResponse
(
request
);
...
@@ -165,15 +165,4 @@ public class AliyunSMS {
...
@@ -165,15 +165,4 @@ public class AliyunSMS {
}
}
}
}
// public static void main(String[] args) {
// AliyunSMS a = new AliyunSMS();
// EntRegisterDto entRegisterDto = new EntRegisterDto();
// entRegisterDto.setPhone("18711519124");
// String a1 = a.yzm(entRegisterDto, 1, 123456);
// JSONObject json = new JSONObject(a1);
// String bizId = (String) json.get("BizId");
// // 流水号
// System.err.println("bizId:"+bizId);
// }
}
}
src/main/java/cn/timer/api/utils/RemindUtil.java
View file @
5b84c83c
...
@@ -30,7 +30,7 @@ public class RemindUtil {
...
@@ -30,7 +30,7 @@ public class RemindUtil {
private
static
final
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"HH:mm:ss"
);
private
static
final
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"HH:mm:ss"
);
/**
/**
* 间隔时间提醒
1
0min/次
* 间隔时间提醒
3
0min/次
*/
*/
@Scheduled
(
fixedRate
=
30
*
60
*
1000
)
@Scheduled
(
fixedRate
=
30
*
60
*
1000
)
private
void
now
()
{
private
void
now
()
{
...
@@ -64,13 +64,13 @@ public class RemindUtil {
...
@@ -64,13 +64,13 @@ public class RemindUtil {
System
.
err
.
println
(
betweenDay
);
System
.
err
.
println
(
betweenDay
);
if
(
sjc
>
0
)
{
if
(
sjc
>
0
)
{
if
(
betweenDay
<=
1
)
{
if
(
betweenDay
<=
1
)
{
AliyunSMS
.
tx
(
name
,
htname
,
time
,
phone
);
// 少于1天短信提醒
AliyunSMS
.
remind
(
name
,
htname
,
time
,
phone
);
// 少于1天短信提醒
}
else
if
(
betweenDay
==
3
)
{
}
else
if
(
betweenDay
==
3
)
{
AliyunSMS
.
tx
(
name
,
htname
,
time
,
phone
);
// 少于3天短信提醒
AliyunSMS
.
remind
(
name
,
htname
,
time
,
phone
);
// 少于3天短信提醒
}
else
if
(
betweenDay
==
7
)
{
}
else
if
(
betweenDay
==
7
)
{
AliyunSMS
.
tx
(
name
,
htname
,
time
,
phone
);
// 少于7天短信提醒
AliyunSMS
.
remind
(
name
,
htname
,
time
,
phone
);
// 少于7天短信提醒
}
else
if
(
betweenDay
==
30
)
{
}
else
if
(
betweenDay
==
30
)
{
AliyunSMS
.
tx
(
name
,
htname
,
time
,
phone
);
// 少于30天短信提醒
AliyunSMS
.
remind
(
name
,
htname
,
time
,
phone
);
// 少于30天短信提醒
}
}
}
else
{
}
else
{
...
...
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