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
d12f3c47
Commit
d12f3c47
authored
Jul 20, 2018
by
Junling Bu
Browse files
chore[litemall-core]: 调整notify和express代码结果,以及调整配置命名以litemall开始
parent
29751a5f
Changes
33
Hide whitespace changes
Inline
Side-by-side
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java
View file @
d12f3c47
...
...
@@ -3,15 +3,14 @@ package org.linlinjava.litemall.admin.web;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.linlinjava.litemall.admin.annotation.LoginAdmin
;
import
org.linlinjava.litemall.core.notify.
Litemall
NotifyService
;
import
org.linlinjava.litemall.core.notify.
util.ConfigUtil
;
import
org.linlinjava.litemall.core.notify.NotifyService
;
import
org.linlinjava.litemall.core.notify.
NotifyType
;
import
org.linlinjava.litemall.core.util.JacksonUtil
;
import
org.linlinjava.litemall.db.domain.*
;
import
org.linlinjava.litemall.db.service.LitemallOrderGoodsService
;
import
org.linlinjava.litemall.db.service.LitemallOrderService
;
import
org.linlinjava.litemall.db.service.LitemallProductService
;
import
org.linlinjava.litemall.db.service.LitemallUserService
;
import
org.linlinjava.litemall.db.util.OrderHandleOption
;
import
org.linlinjava.litemall.db.util.OrderUtil
;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -46,7 +45,7 @@ public class AdminOrderController {
private
LitemallUserService
userService
;
@Autowired
private
Litemall
NotifyService
litemallN
otifyService
;
private
NotifyService
n
otifyService
;
@GetMapping
(
"/list"
)
public
Object
list
(
@LoginAdmin
Integer
adminId
,
...
...
@@ -153,7 +152,7 @@ public class AdminOrderController {
* 注意订单号只发后6位
*
*/
litemallN
otifyService
.
notifyS
MS
Template
(
order
.
getMobile
(),
ConfigUtil
.
NotifyType
.
REFUND
,
new
String
[]{
order
.
getOrderSn
().
substring
(
8
,
14
)});
n
otifyService
.
notifyS
ms
Template
(
order
.
getMobile
(),
NotifyType
.
REFUND
,
new
String
[]{
order
.
getOrderSn
().
substring
(
8
,
14
)});
txManager
.
commit
(
status
);
...
...
@@ -207,7 +206,7 @@ public class AdminOrderController {
* 您的订单已经发货,快递公司 {1},快递单 {2} ,请注意查收
*
*/
litemallN
otifyService
.
notifyS
MS
Template
(
order
.
getMobile
(),
ConfigUtil
.
NotifyType
.
SHIP
,
new
String
[]{
shipChannel
,
shipSn
});
n
otifyService
.
notifyS
ms
Template
(
order
.
getMobile
(),
NotifyType
.
SHIP
,
new
String
[]{
shipChannel
,
shipSn
});
return
ResponseUtil
.
ok
();
}
...
...
litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/AdminConfigTest.java
View file @
d12f3c47
...
...
@@ -18,7 +18,7 @@ public class AdminConfigTest {
@Test
public
void
test
()
{
// 测试获取application-core.yml配置信息
System
.
out
.
println
(
environment
.
getProperty
(
"express.appId"
));
System
.
out
.
println
(
environment
.
getProperty
(
"
litemall.
express.appId"
));
// 测试获取application-db.yml配置信息
System
.
out
.
println
(
environment
.
getProperty
(
"spring.datasource.druid.url"
));
// 测试获取application-admin.yml配置信息
...
...
litemall-all/src/test/java/org/linlinjava/litemall/allinone/AllinoneConfigTest.java
View file @
d12f3c47
...
...
@@ -18,7 +18,7 @@ public class AllinoneConfigTest {
@Test
public
void
test
()
{
// 测试获取application-core.yml配置信息
System
.
out
.
println
(
environment
.
getProperty
(
"express.appId"
));
System
.
out
.
println
(
environment
.
getProperty
(
"
litemall.
express.appId"
));
// 测试获取application-db.yml配置信息
System
.
out
.
println
(
environment
.
getProperty
(
"spring.datasource.druid.url"
));
// 测试获取application-wx.yml配置信息
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java
View file @
d12f3c47
package
org.linlinjava.litemall.core.express
;
import
org.linlinjava.litemall.core.express.config.Express
Config
;
import
org.linlinjava.litemall.core.express.config.Express
Properties
;
import
org.linlinjava.litemall.core.util.HttpUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.Base64Utils
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.security.MessageDigest
;
import
java.util.HashMap
;
...
...
@@ -17,13 +16,19 @@ import java.util.Map;
* <p>
* 3831775044640 韵达快递(YD)
*/
@Service
public
class
ExpressService
{
//请求url
private
String
ReqURL
=
"http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx"
;
@Autowired
ExpressConfig
config
;
private
ExpressProperties
properties
;
public
ExpressProperties
getProperties
()
{
return
properties
;
}
public
void
setProperties
(
ExpressProperties
properties
)
{
this
.
properties
=
properties
;
}
/**
* 获取物流供应商名
...
...
@@ -32,7 +37,7 @@ public class ExpressService {
* @return
*/
public
String
getVendorName
(
String
vendooCode
)
{
for
(
Map
<
String
,
String
>
item
:
config
.
getVendors
())
{
for
(
Map
<
String
,
String
>
item
:
properties
.
getVendors
())
{
if
(
item
.
get
(
"code"
).
equals
(
vendooCode
))
return
item
.
get
(
"name"
);
}
...
...
@@ -45,13 +50,17 @@ public class ExpressService {
* @throws Exception
*/
public
String
getOrderTracesByJson
(
String
expCode
,
String
expNo
)
throws
Exception
{
if
(!
properties
.
isEnable
()){
return
null
;
}
String
requestData
=
"{'OrderCode':'','ShipperCode':'"
+
expCode
+
"','LogisticCode':'"
+
expNo
+
"'}"
;
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
params
.
put
(
"RequestData"
,
URLEncoder
.
encode
(
requestData
,
"UTF-8"
));
params
.
put
(
"EBusinessID"
,
config
.
getAppId
());
params
.
put
(
"EBusinessID"
,
properties
.
getAppId
());
params
.
put
(
"RequestType"
,
"1002"
);
String
dataSign
=
encrypt
(
requestData
,
config
.
getAppKey
(),
"UTF-8"
);
String
dataSign
=
encrypt
(
requestData
,
properties
.
getAppKey
(),
"UTF-8"
);
params
.
put
(
"DataSign"
,
URLEncoder
.
encode
(
dataSign
,
"UTF-8"
));
params
.
put
(
"DataType"
,
"2"
);
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/ExpressAutoConfiguration.java
0 → 100644
View file @
d12f3c47
package
org.linlinjava.litemall.core.express.config
;
import
com.github.qcloudsms.SmsSingleSender
;
import
org.linlinjava.litemall.core.express.ExpressService
;
import
org.linlinjava.litemall.core.notify.NotifyService
;
import
org.linlinjava.litemall.core.notify.TencentSmsSender
;
import
org.linlinjava.litemall.core.notify.WxTemplateSender
;
import
org.linlinjava.litemall.core.notify.config.NotifyProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.mail.javamail.JavaMailSenderImpl
;
@Configuration
@EnableConfigurationProperties
(
ExpressProperties
.
class
)
public
class
ExpressAutoConfiguration
{
private
final
ExpressProperties
properties
;
public
ExpressAutoConfiguration
(
ExpressProperties
properties
)
{
this
.
properties
=
properties
;
}
@Bean
public
ExpressService
expressService
(){
ExpressService
expressService
=
new
ExpressService
();
expressService
.
setProperties
(
properties
);
return
expressService
;
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/Express
Config
.java
→
litemall-core/src/main/java/org/linlinjava/litemall/core/express/config/Express
Properties
.java
View file @
d12f3c47
package
org.linlinjava.litemall.core.express.config
;
import
org.linlinjava.litemall.core.util.YmlPropertyFactory
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
@Component
@Configuration
@ConfigurationProperties
(
prefix
=
"express"
)
public
class
ExpressConfig
{
@ConfigurationProperties
(
prefix
=
"litemall.express"
)
public
class
ExpressProperties
{
private
boolean
enable
;
public
boolean
isEnable
()
{
return
enable
;
}
public
void
setEnable
(
boolean
enable
)
{
this
.
enable
=
enable
;
}
private
String
appId
;
private
String
appKey
;
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/LitemallNotifyService.java
deleted
100644 → 0
View file @
29751a5f
package
org.linlinjava.litemall.core.notify
;
import
org.linlinjava.litemall.core.notify.util.ConfigUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
/**
* Litemall商城通知服务类
*/
@Service
(
"litemallNotifyService"
)
public
class
LitemallNotifyService
{
@Autowired
private
MailSendService
mailSendService
;
@Autowired
private
SMSSendService
smsSendService
;
@Autowired
private
WXTemplateSendService
wxTemplateSendService
;
@Async
public
void
notifySMSMessage
(
String
phoneNumber
,
String
message
)
{
if
(!
smsSendService
.
config
.
isEnable
())
return
;
smsSendService
.
sendSMS
(
phoneNumber
,
message
);
}
/**
* 微信模版消息通知
* @param token 通过wxMAService获取token或者通过url请求token
* @param touser 接收者openId
* @param formId 表单ID或者 prepayId
* @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
public
void
notifyWXTemplate
(
String
token
,
String
touser
,
String
formId
,
ConfigUtil
.
NotifyType
notifyType
,
String
[]
params
)
{
if
(!
wxTemplateSendService
.
config
.
isEnable
())
return
;
String
templateId
=
ConfigUtil
.
getTemplateId
(
notifyType
,
wxTemplateSendService
.
config
.
getTemplate
());
if
(
templateId
!=
""
)
wxTemplateSendService
.
sendWechatMsg
(
token
,
touser
,
templateId
,
formId
,
""
,
""
,
params
);
}
/**
* 短信模版通知
*
* @param phoneNumber 接收通知的电话号码
* @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
public
void
notifySMSTemplate
(
String
phoneNumber
,
ConfigUtil
.
NotifyType
notifyType
,
String
[]
params
)
{
if
(!
smsSendService
.
config
.
isEnable
())
return
;
int
templateId
=
Integer
.
parseInt
(
ConfigUtil
.
getTemplateId
(
notifyType
,
smsSendService
.
config
.
getTemplate
()));
if
(
templateId
!=
-
1
)
smsSendService
.
sendSMSWithTemplate
(
phoneNumber
,
templateId
,
params
);
}
/**
* 短信模版通知
*
* @param phoneNumber 接收通知的电话号码
* @param templateId 模板ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
public
void
notifySMSTemplate
(
String
phoneNumber
,
int
templateId
,
String
[]
params
)
{
if
(!
smsSendService
.
config
.
isEnable
())
return
;
smsSendService
.
sendSMSWithTemplate
(
phoneNumber
,
templateId
,
params
);
}
/**
* 发送邮件通知,接收者在spring.mail.sendto中指定
*
* @param setSubject 邮件标题
* @param setText 邮件内容
*/
@Async
public
void
notifyMailMessage
(
String
setSubject
,
String
setText
)
{
if
(!
mailSendService
.
config
.
isEnable
())
return
;
mailSendService
.
sendEmail
(
setSubject
,
setText
);
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/MailSendService.java
deleted
100644 → 0
View file @
29751a5f
package
org.linlinjava.litemall.core.notify
;
import
org.linlinjava.litemall.core.notify.config.MailNotifyConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.mail.javamail.JavaMailSenderImpl
;
import
org.springframework.mail.javamail.MimeMessageHelper
;
import
org.springframework.stereotype.Service
;
import
javax.mail.internet.MimeMessage
;
@Service
(
"mailSendService"
)
class
MailSendService
{
@Autowired
MailNotifyConfig
config
;
private
JavaMailSenderImpl
mailSender
;
private
JavaMailSenderImpl
getMailSender
()
{
if
(
mailSender
==
null
)
{
mailSender
=
new
JavaMailSenderImpl
();
mailSender
.
setHost
(
config
.
getHost
());
mailSender
.
setUsername
(
config
.
getUsername
());
mailSender
.
setPassword
(
config
.
getPassword
());
}
return
mailSender
;
}
/**
* 发送邮件通知
*
* @param setSubject 邮件标题
* @param setText 邮件内容
*/
public
void
sendEmail
(
String
setSubject
,
String
setText
)
{
try
{
final
MimeMessage
mimeMessage
=
getMailSender
().
createMimeMessage
();
final
MimeMessageHelper
message
=
new
MimeMessageHelper
(
mimeMessage
);
message
.
setFrom
(
config
.
getUsername
());
message
.
setTo
(
config
.
getSendto
());
message
.
setSubject
(
setSubject
);
message
.
setText
(
setText
);
getMailSender
().
send
(
mimeMessage
);
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyService.java
0 → 100644
View file @
d12f3c47
package
org.linlinjava.litemall.core.notify
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.mail.MailSender
;
import
org.springframework.mail.SimpleMailMessage
;
import
org.springframework.scheduling.annotation.Async
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* 商城通知服务类
*/
public
class
NotifyService
{
private
MailSender
mailSender
;
private
String
sendFrom
;
private
String
sendTo
;
private
SmsSender
smsSender
;
private
List
<
Map
<
String
,
String
>>
smsTemplate
=
new
ArrayList
<>();
private
WxTemplateSender
wxTemplateSender
;
private
List
<
Map
<
String
,
String
>>
wxTemplate
=
new
ArrayList
<>();
/**
* 短信消息通知
*
* @param phoneNumber 接收通知的电话号码
* @param message 短消息内容,这里短消息内容必须已经在短信平台审核通过
*/
@Async
public
void
notifySms
(
String
phoneNumber
,
String
message
)
{
if
(
mailSender
==
null
)
return
;
smsSender
.
send
(
phoneNumber
,
message
);
}
/**
* 短信模版消息通知
*
* @param phoneNumber 接收通知的电话号码
* @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
public
void
notifySmsTemplate
(
String
phoneNumber
,
NotifyType
notifyType
,
String
[]
params
)
{
if
(
wxTemplateSender
==
null
)
return
;
int
templateId
=
Integer
.
parseInt
(
getTemplateId
(
notifyType
,
smsTemplate
));
smsSender
.
sendWithTemplate
(
phoneNumber
,
templateId
,
params
);
}
/**
* 微信模版消息通知
*
* @param token 通过wxMAService获取token或者通过url请求token
* @param touser 接收者openId
* @param formId 表单ID或者 prepayId
* @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
public
void
notifyWxTemplate
(
String
token
,
String
touser
,
String
formId
,
NotifyType
notifyType
,
String
[]
params
)
{
if
(
wxTemplateSender
==
null
)
return
;
String
templateId
=
getTemplateId
(
notifyType
,
wxTemplate
);
wxTemplateSender
.
sendWechatMsg
(
token
,
touser
,
templateId
,
formId
,
""
,
""
,
params
);
}
/**
* 邮件消息通知,
* 接收者在spring.mail.sendto中指定
*
* @param subject 邮件标题
* @param content 邮件内容
*/
@Async
public
void
notifyMail
(
String
subject
,
String
content
)
{
if
(
mailSender
==
null
)
return
;
SimpleMailMessage
message
=
new
SimpleMailMessage
();
message
.
setFrom
(
sendFrom
);
message
.
setTo
(
sendTo
);
message
.
setSubject
(
subject
);
message
.
setText
(
content
);
mailSender
.
send
(
message
);
}
private
String
getTemplateId
(
NotifyType
notifyType
,
List
<
Map
<
String
,
String
>>
values
)
{
for
(
Map
<
String
,
String
>
item
:
values
)
{
String
notifyTypeStr
=
notifyType
.
getType
();
if
(
item
.
get
(
"name"
).
equals
(
notifyTypeStr
))
return
item
.
get
(
"templateId"
);
}
return
null
;
}
public
MailSender
getMailSender
()
{
return
mailSender
;
}
public
void
setMailSender
(
MailSender
mailSender
)
{
this
.
mailSender
=
mailSender
;
}
public
String
getSendFrom
()
{
return
sendFrom
;
}
public
void
setSendFrom
(
String
sendFrom
)
{
this
.
sendFrom
=
sendFrom
;
}
public
String
getSendTo
()
{
return
sendTo
;
}
public
void
setSendTo
(
String
sendTo
)
{
this
.
sendTo
=
sendTo
;
}
public
SmsSender
getSmsSender
()
{
return
smsSender
;
}
public
void
setSmsSender
(
SmsSender
smsSender
)
{
this
.
smsSender
=
smsSender
;
}
public
List
<
Map
<
String
,
String
>>
getSmsTemplate
()
{
return
smsTemplate
;
}
public
void
setSmsTemplate
(
List
<
Map
<
String
,
String
>>
smsTemplate
)
{
this
.
smsTemplate
=
smsTemplate
;
}
public
WxTemplateSender
getWxTemplateSender
()
{
return
wxTemplateSender
;
}
public
void
setWxTemplateSender
(
WxTemplateSender
wxTemplateSender
)
{
this
.
wxTemplateSender
=
wxTemplateSender
;
}
public
List
<
Map
<
String
,
String
>>
getWxTemplate
()
{
return
wxTemplate
;
}
public
void
setWxTemplate
(
List
<
Map
<
String
,
String
>>
wxTemplate
)
{
this
.
wxTemplate
=
wxTemplate
;
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/NotifyType.java
0 → 100644
View file @
d12f3c47
package
org.linlinjava.litemall.core.notify
;
public
enum
NotifyType
{
PAY_SUCCEED
(
"paySucceed"
),
SHIP
(
"ship"
),
REFUND
(
"refund"
),
CAPTCHA
(
"captcha"
);
NotifyType
(
String
type
)
{
this
.
type
=
type
;
}
private
String
type
;
public
String
getType
()
{
return
this
.
type
;
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/SMSSendService.java
deleted
100644 → 0
View file @
29751a5f
package
org.linlinjava.litemall.core.notify
;
import
com.github.qcloudsms.SmsSingleSender
;
import
com.github.qcloudsms.SmsSingleSenderResult
;
import
com.github.qcloudsms.httpclient.HTTPException
;
import
org.json.JSONException
;
import
org.linlinjava.litemall.core.notify.config.SMSNotifyConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
@Service
(
"smsSendService"
)
class
SMSSendService
{
@Autowired
SMSNotifyConfig
config
;
public
void
sendSMS
(
String
phoneNumber
,
String
content
)
{
try
{
SmsSingleSender
ssender
=
new
SmsSingleSender
(
config
.
getAppid
(),
config
.
getAppkey
());
SmsSingleSenderResult
result
=
ssender
.
send
(
0
,
"86"
,
phoneNumber
,
content
,
""
,
""
);
// System.out.println(result);
}
catch
(
HTTPException
e
)
{
// HTTP响应码错误
e
.
printStackTrace
();
}
catch
(
JSONException
e
)
{
// json解析错误
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
// 网络IO错误
e
.
printStackTrace
();
}
}
/**
* 通过模版发送短信息
* @param phoneNumber
* @param templateId
* @param params
*/
public
void
sendSMSWithTemplate
(
String
phoneNumber
,
int
templateId
,
String
[]
params
)
{
try
{
SmsSingleSender
ssender
=
new
SmsSingleSender
(
config
.
getAppid
(),
config
.
getAppkey
());
SmsSingleSenderResult
result
=
ssender
.
sendWithParam
(
"86"
,
phoneNumber
,
templateId
,
params
,
config
.
getSign
(),
""
,
""
);
// 签名参数未提供或者为空时,会使用默认签名发送短信
// System.out.println(result);
}
catch
(
HTTPException
e
)
{
// HTTP响应码错误
e
.
printStackTrace
();
}
catch
(
JSONException
e
)
{
// json解析错误
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
// 网络IO错误
e
.
printStackTrace
();
}
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/SmsSender.java
0 → 100644
View file @
d12f3c47
package
org.linlinjava.litemall.core.notify
;
public
interface
SmsSender
{
/**
* 发送短信息
*
* @param phone 接收通知的电话号码
* @param content 短消息内容
*/
void
send
(
String
phone
,
String
content
);
/**
* 通过短信模版发送短信息
*
* @param phone 接收通知的电话号码
* @param templateId 通知模板ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
void
sendWithTemplate
(
String
phone
,
int
templateId
,
String
[]
params
);
}
\ No newline at end of file
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/TencentSmsSender.java
0 → 100644
View file @
d12f3c47
package
org.linlinjava.litemall.core.notify
;
import
com.github.qcloudsms.SmsSingleSender
;
import
com.github.qcloudsms.SmsSingleSenderResult
;
import
com.github.qcloudsms.httpclient.HTTPException
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
java.io.IOException
;
/*
* 腾讯云短信服务
*/
public
class
TencentSmsSender
implements
SmsSender
{
private
final
Log
logger
=
LogFactory
.
getLog
(
TencentSmsSender
.
class
);
private
SmsSingleSender
sender
;
public
SmsSingleSender
getSender
()
{
return
sender
;
}
public
void
setSender
(
SmsSingleSender
sender
)
{
this
.
sender
=
sender
;
}
@Override
public
void
send
(
String
phone
,
String
content
)
{
try
{
SmsSingleSenderResult
result
=
sender
.
send
(
0
,
"86"
,
phone
,
content
,
""
,
""
);
logger
.
debug
(
result
);
}
catch
(
HTTPException
|
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Override
public
void
sendWithTemplate
(
String
phone
,
int
templateId
,
String
[]
params
)
{
try
{
SmsSingleSenderResult
result
=
sender
.
sendWithParam
(
"86"
,
phone
,
templateId
,
params
,
""
,
""
,
""
);
logger
.
debug
(
result
);
}
catch
(
HTTPException
|
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/W
X
TemplateSend
S
er
vice
.java
→
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/W
x
TemplateSender.java
View file @
d12f3c47
package
org.linlinjava.litemall.core.notify
;
import
org.json.JSONObject
;
import
org.linlinjava.litemall.core.notify.config.WXNotifyConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -19,10 +18,7 @@ import java.security.cert.X509Certificate;
/**
* 微信模版消息通知
*/
@Service
(
"wxTemplateMsgSendService"
)
class
WXTemplateSendService
{
@Autowired
WXNotifyConfig
config
;
public
class
WxTemplateSender
{
/**
* 发送微信消息(模板消息)
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/MailNotifyConfig.java
deleted
100644 → 0
View file @
29751a5f
package
org.linlinjava.litemall.core.notify.config
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
@Component
@ConfigurationProperties
(
prefix
=
"MailNotifyConfig"
)
public
class
MailNotifyConfig
{
private
boolean
enable
;
private
String
host
;
private
String
username
;
private
String
password
;
private
String
sendto
;
public
boolean
isEnable
()
{
return
enable
;
}
public
void
setEnable
(
boolean
enable
)
{
this
.
enable
=
enable
;
}
public
String
getHost
()
{
return
host
;
}
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getSendto
()
{
return
sendto
;
}
public
void
setSendto
(
String
sendto
)
{
this
.
sendto
=
sendto
;
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/NotifyAutoConfiguration.java
0 → 100644
View file @
d12f3c47
package
org.linlinjava.litemall.core.notify.config
;
import
com.github.qcloudsms.SmsSingleSender
;
import
org.linlinjava.litemall.core.notify.NotifyService
;
import
org.linlinjava.litemall.core.notify.TencentSmsSender
;
import
org.linlinjava.litemall.core.notify.WxTemplateSender
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.mail.javamail.JavaMailSenderImpl
;
@Configuration
@EnableConfigurationProperties
(
NotifyProperties
.
class
)
public
class
NotifyAutoConfiguration
{
private
final
NotifyProperties
properties
;
public
NotifyAutoConfiguration
(
NotifyProperties
properties
)
{
this
.
properties
=
properties
;
}
@Bean
public
NotifyService
notifyService
(){
NotifyService
notifyService
=
new
NotifyService
();
NotifyProperties
.
Mail
mailConfig
=
properties
.
getMail
();
if
(
mailConfig
.
isEnable
())
{
JavaMailSenderImpl
mailSender
=
new
JavaMailSenderImpl
();
mailSender
.
setHost
(
mailConfig
.
getHost
());
mailSender
.
setUsername
(
mailConfig
.
getUsername
());
mailSender
.
setPassword
(
mailConfig
.
getPassword
());
notifyService
.
setMailSender
(
mailSender
);
notifyService
.
setSendFrom
(
mailConfig
.
getSendfrom
());
notifyService
.
setSendTo
(
mailConfig
.
getSendto
());
}
NotifyProperties
.
Sms
smsConfig
=
properties
.
getSms
();
if
(
smsConfig
.
isEnable
()){
TencentSmsSender
smsSender
=
new
TencentSmsSender
();
smsSender
.
setSender
(
new
SmsSingleSender
(
smsConfig
.
getAppid
(),
smsConfig
.
getAppkey
()));
notifyService
.
setSmsSender
(
smsSender
);
notifyService
.
setSmsTemplate
(
smsConfig
.
getTemplate
());
}
NotifyProperties
.
Wx
wxConfig
=
properties
.
getWx
();
if
(
wxConfig
.
isEnable
()){
WxTemplateSender
wxTemplateSender
=
new
WxTemplateSender
();
notifyService
.
setWxTemplateSender
(
wxTemplateSender
);
notifyService
.
setWxTemplate
(
wxConfig
.
getTemplate
());
}
return
notifyService
;
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/NotifyProperties.java
0 → 100644
View file @
d12f3c47
package
org.linlinjava.litemall.core.notify.config
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
@ConfigurationProperties
(
prefix
=
"litemall.notify"
)
public
class
NotifyProperties
{
private
Mail
mail
;
private
Sms
sms
;
private
Wx
wx
;
public
Mail
getMail
()
{
return
mail
;
}
public
void
setMail
(
Mail
mail
)
{
this
.
mail
=
mail
;
}
public
Sms
getSms
()
{
return
sms
;
}
public
void
setSms
(
Sms
sms
)
{
this
.
sms
=
sms
;
}
public
Wx
getWx
()
{
return
wx
;
}
public
void
setWx
(
Wx
wx
)
{
this
.
wx
=
wx
;
}
public
static
class
Mail
{
private
boolean
enable
;
private
String
host
;
private
String
username
;
private
String
password
;
private
String
sendfrom
;
private
String
sendto
;
public
boolean
isEnable
()
{
return
enable
;
}
public
void
setEnable
(
boolean
enable
)
{
this
.
enable
=
enable
;
}
public
String
getHost
()
{
return
host
;
}
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getSendfrom
()
{
return
sendfrom
;
}
public
void
setSendfrom
(
String
sendfrom
)
{
this
.
sendfrom
=
sendfrom
;
}
public
String
getSendto
()
{
return
sendto
;
}
public
void
setSendto
(
String
sendto
)
{
this
.
sendto
=
sendto
;
}
}
public
static
class
Sms
{
private
boolean
enable
;
private
int
appid
;
private
String
appkey
;
private
List
<
Map
<
String
,
String
>>
template
=
new
ArrayList
<>();
public
boolean
isEnable
()
{
return
enable
;
}
public
void
setEnable
(
boolean
enable
)
{
this
.
enable
=
enable
;
}
public
int
getAppid
()
{
return
appid
;
}
public
void
setAppid
(
int
appid
)
{
this
.
appid
=
appid
;
}
public
String
getAppkey
()
{
return
appkey
;
}
public
void
setAppkey
(
String
appkey
)
{
this
.
appkey
=
appkey
;
}
public
List
<
Map
<
String
,
String
>>
getTemplate
()
{
return
template
;
}
public
void
setTemplate
(
List
<
Map
<
String
,
String
>>
template
)
{
this
.
template
=
template
;
}
}
public
static
class
Wx
{
private
boolean
enable
;
private
List
<
Map
<
String
,
String
>>
template
=
new
ArrayList
<>();
public
boolean
isEnable
()
{
return
enable
;
}
public
void
setEnable
(
boolean
enable
)
{
this
.
enable
=
enable
;
}
public
List
<
Map
<
String
,
String
>>
getTemplate
()
{
return
template
;
}
public
void
setTemplate
(
List
<
Map
<
String
,
String
>>
template
)
{
this
.
template
=
template
;
}
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/SMSNotifyConfig.java
deleted
100644 → 0
View file @
29751a5f
package
org.linlinjava.litemall.core.notify.config
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
@Component
@ConfigurationProperties
(
prefix
=
"SMSNotifyConfig"
)
public
class
SMSNotifyConfig
{
private
boolean
enable
;
private
int
appid
;
private
String
appkey
;
private
String
sign
;
private
List
<
Map
<
String
,
String
>>
template
=
new
ArrayList
<>();
public
boolean
isEnable
()
{
return
enable
;
}
public
void
setEnable
(
boolean
enable
)
{
this
.
enable
=
enable
;
}
public
int
getAppid
()
{
return
appid
;
}
public
void
setAppid
(
int
appid
)
{
this
.
appid
=
appid
;
}
public
String
getAppkey
()
{
return
appkey
;
}
public
void
setAppkey
(
String
appkey
)
{
this
.
appkey
=
appkey
;
}
public
String
getSign
()
{
return
sign
;
}
public
void
setSign
(
String
sign
)
{
this
.
sign
=
sign
;
}
public
List
<
Map
<
String
,
String
>>
getTemplate
()
{
return
template
;
}
public
void
setTemplate
(
List
<
Map
<
String
,
String
>>
template
)
{
this
.
template
=
template
;
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/config/WXNotifyConfig.java
deleted
100644 → 0
View file @
29751a5f
package
org.linlinjava.litemall.core.notify.config
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
@Component
@ConfigurationProperties
(
prefix
=
"WXNotifyConfig"
)
public
class
WXNotifyConfig
{
private
boolean
enable
;
private
List
<
Map
<
String
,
String
>>
template
=
new
ArrayList
<>();
public
boolean
isEnable
()
{
return
enable
;
}
public
void
setEnable
(
boolean
enable
)
{
this
.
enable
=
enable
;
}
public
List
<
Map
<
String
,
String
>>
getTemplate
()
{
return
template
;
}
public
void
setTemplate
(
List
<
Map
<
String
,
String
>>
template
)
{
this
.
template
=
template
;
}
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/util/ConfigUtil.java
deleted
100644 → 0
View file @
29751a5f
package
org.linlinjava.litemall.core.notify.util
;
import
java.util.List
;
import
java.util.Map
;
public
class
ConfigUtil
{
/**
* 通过枚举获取对应的 templateId,注意 application.yaml 里字段名必须一致
*
* @param notifyType
* @param values
* @return
*/
public
static
String
getTemplateId
(
NotifyType
notifyType
,
List
<
Map
<
String
,
String
>>
values
)
{
for
(
Map
<
String
,
String
>
item
:
values
)
{
String
notifyTypeStr
=
getNotifyType
(
notifyType
);
if
(
item
.
get
(
"name"
).
equals
(
notifyTypeStr
))
return
item
.
get
(
"templateId"
);
}
return
""
;
}
/**
* 该处字符串对应 application.yaml 里 template.name 的值,请注意
*
* @param notifyType
* @return
*/
private
static
String
getNotifyType
(
NotifyType
notifyType
)
{
switch
(
notifyType
)
{
case
PAY_SUCCEED:
return
"paySucceed"
;
case
CAPTCHA:
return
"captcha"
;
case
SHIP:
return
"ship"
;
case
REFUND:
return
"refund"
;
}
return
""
;
}
/**
* 该枚举定义了所有的需要通知的事件,调用通知时作为参数
* <p>
* PAY_SUCCEED 支付成功,通常用于用户支付成功
* CAPTCHA 验证码,通常用于登录、注册、找回密码
*/
public
enum
NotifyType
{
PAY_SUCCEED
,
SHIP
,
REFUND
,
CAPTCHA
}
}
Prev
1
2
Next
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