Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
80cf0a24
Commit
80cf0a24
authored
Jul 15, 2018
by
Junling Bu
Browse files
chore[litemall-core]:短信消息类型重新命名以及添加测试类
parent
2ad061a7
Changes
6
Hide whitespace changes
Inline
Side-by-side
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/ExecutorConfig.java
View file @
80cf0a24
...
...
@@ -26,8 +26,8 @@ class ExecutorConfig {
@Value
(
"${spring.notify.queueCapacity}"
)
private
int
queueCapacity
;
@Bean
(
name
=
"no
fit
yAsync"
)
public
Executor
no
fit
yAsync
()
{
@Bean
(
name
=
"no
tif
yAsync"
)
public
Executor
no
tif
yAsync
()
{
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
();
executor
.
setCorePoolSize
(
corePoolSize
);
executor
.
setMaxPoolSize
(
maxPoolSize
);
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/LitemallNotifyService.java
View file @
80cf0a24
...
...
@@ -34,20 +34,20 @@ public class LitemallNotifyService {
/**
* 短信模版通知
* @param phoneNumber 接收通知的电话号码
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
* @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
public
void
notifySMSTemplate
(
String
phoneNumber
,
String
[]
params
,
NotifyUtils
.
NotifyType
notifyType
)
{
public
void
notifySMSTemplate
(
String
phoneNumber
,
NotifyUtils
.
NotifyType
notifyType
,
String
[]
params
)
{
if
(!
sendSMSEnable
)
return
;
int
templateId
=
-
1
;
switch
(
notifyType
)
{
case
PAY_
COMPLAT
ED:
templateId
=
Integer
.
parseInt
(
environment
.
getProperty
(
"spring.sms.template.pay
.complat
ed"
));
case
PAY_
SUCCE
ED:
templateId
=
Integer
.
parseInt
(
environment
.
getProperty
(
"spring.sms.template.pay
Succe
ed"
));
break
;
case
VERIFICATIONCODE
:
templateId
=
Integer
.
parseInt
(
environment
.
getProperty
(
"spring.sms.template.
verificationcode
"
));
case
CAPTCHA
:
templateId
=
Integer
.
parseInt
(
environment
.
getProperty
(
"spring.sms.template.
captcha
"
));
break
;
}
...
...
@@ -55,6 +55,19 @@ public class LitemallNotifyService {
smsSendService
.
sendSMSWithTemplate
(
phoneNumber
,
templateId
,
params
);
}
/**
* 短信模版通知
* @param phoneNumber 接收通知的电话号码
* @param templateId 模板ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
public
void
notifySMSTemplate
(
String
phoneNumber
,
int
templateId
,
String
[]
params
)
{
if
(!
sendSMSEnable
)
return
;
smsSendService
.
sendSMSWithTemplate
(
phoneNumber
,
templateId
,
params
);
}
/**
* 发送邮件通知,接收者在spring.mail.sendto中指定
* @param setSubject 邮件标题
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/MailSendService.java
View file @
80cf0a24
...
...
@@ -27,7 +27,7 @@ class MailSendService {
* @param setSubject 邮件标题
* @param setText 邮件内容
*/
@Async
(
"no
fit
yAsync"
)
@Async
(
"no
tif
yAsync"
)
public
void
sendEmail
(
String
setSubject
,
String
setText
)
{
try
{
final
MimeMessage
mimeMessage
=
mailSender
.
createMimeMessage
();
...
...
@@ -40,7 +40,7 @@ class MailSendService {
mailSender
.
send
(
mimeMessage
);
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyUtils.java
View file @
80cf0a24
...
...
@@ -3,8 +3,12 @@ package org.linlinjava.litemall.core.notify;
public
class
NotifyUtils
{
/**
* 该枚举定义了所有的需要通知的事件,调用通知时作为参数
*
* PAY_SUCCEED 支付成功,通常用于用户支付成功
* CAPTCHA 验证码,通常用于登录、注册、找回密码
*/
public
enum
NotifyType
{
PAY_COMPLATED
,
REGISTER
,
VERIFICATIONCODE
,
PAY_SUCCEED
,
CAPTCHA
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/SMSSendService.java
View file @
80cf0a24
...
...
@@ -23,14 +23,14 @@ class SMSSendService {
@Value
(
"${spring.sms.sign}"
)
private
String
smsSign
;
@Async
(
"no
fit
yAsync"
)
@Async
(
"no
tif
yAsync"
)
public
void
sendSMS
(
String
phoneNumber
,
String
content
)
{
try
{
SmsSingleSender
ssender
=
new
SmsSingleSender
(
appid
,
appkey
);
SmsSingleSenderResult
result
=
ssender
.
send
(
0
,
"86"
,
phoneNumber
,
content
,
""
,
""
);
System
.
out
.
println
(
result
);
//
System.out.println(result);
}
catch
(
HTTPException
e
)
{
// HTTP响应码错误
e
.
printStackTrace
();
...
...
@@ -43,13 +43,13 @@ class SMSSendService {
}
}
@Async
(
"no
fit
yAsync"
)
@Async
(
"no
tif
yAsync"
)
public
void
sendSMSWithTemplate
(
String
phoneNumber
,
int
templateId
,
String
[]
params
)
{
try
{
SmsSingleSender
ssender
=
new
SmsSingleSender
(
appid
,
appkey
);
SmsSingleSenderResult
result
=
ssender
.
sendWithParam
(
"86"
,
phoneNumber
,
templateId
,
params
,
smsSign
,
""
,
""
);
// 签名参数未提供或者为空时,会使用默认签名发送短信
System
.
out
.
println
(
result
);
//
System.out.println(result);
}
catch
(
HTTPException
e
)
{
// HTTP响应码错误
e
.
printStackTrace
();
...
...
litemall-core/src/main/resources/notify.properties
View file @
80cf0a24
# 邮件发送配置
sprint.mail.enable
=
false
spring.mail.host
=
smtp.exmail.qq.com
spring.mail.username
=
ex@ex.com.cn
spring.mail.username
=
xxxxxx
spring.mail.password
=
xxxxxx
spring.mail.sendto
=
ex@qq.com
spring.mail.sendto
=
ex
ample
@qq.com
# 短信发送配置
spring.sms.enable
=
false
...
...
@@ -12,10 +12,10 @@ spring.sms.appkey=xxxxxx
spring.sms.sign
=
xxxxxx
# 短信模板消息配置
# 请在腾讯短信平台配置通知消息模板,然后模板ID
这里参数
# 请在腾讯短信平台配置通知消息模板,然后
这里设置不同短信
模板ID
# 请参考LitemallNotifyService.notifySMSTemplate
spring.sms.template.pay
.complat
ed
=
111111
spring.sms.template.
verificationcode
=
111111
spring.sms.template.pay
Succe
ed
=
111111
spring.sms.template.
captcha
=
222222
# 发送线程池配置
spring.notify.corePoolSize
=
5
...
...
Write
Preview
Supports
Markdown
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