Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibznotify
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibznotify
提交
ce01c4bc
提交
ce01c4bc
编写于
8月 18, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
钉钉、微信、阿里消息集成
上级
17e4038f
变更
2
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
50 行增加
和
51 行删除
+50
-51
Msg.java
.../src/main/java/cn/ibizlab/core/extensions/domain/Msg.java
+3
-2
NotifyCoreService.java
...cn/ibizlab/core/extensions/service/NotifyCoreService.java
+47
-49
未找到文件。
ibznotify-core/src/main/java/cn/ibizlab/core/extensions/domain/Msg.java
浏览文件 @
ce01c4bc
...
...
@@ -3,6 +3,7 @@ package cn.ibizlab.core.extensions.domain;
import
lombok.Data
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.util.Map
;
@Data
...
...
@@ -14,8 +15,8 @@ public class Msg {
@NotBlank
(
message
=
"模板标识不能为空"
)
private
String
templateid
;
@Not
Blank
(
message
=
"模板类型不能为空"
)
private
String
msgtypes
;
@Not
Null
(
message
=
"模板类型不能为空"
)
private
int
msgtypes
;
@NotBlank
(
message
=
"用户标识不能为空"
)
private
String
userids
;
...
...
ibznotify-core/src/main/java/cn/ibizlab/core/extensions/service/NotifyCoreService.java
浏览文件 @
ce01c4bc
...
...
@@ -14,7 +14,6 @@ import com.alibaba.fastjson.JSONObject;
import
com.aliyuncs.CommonRequest
;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.IAcsClient
;
import
com.aliyuncs.dm.model.v20151123.BatchSendMailRequest
;
import
com.aliyuncs.dm.model.v20151123.SingleSendMailRequest
;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.profile.DefaultProfile
;
...
...
@@ -65,14 +64,6 @@ public class NotifyCoreService {
* 阿里短信服务单处理行为
*/
private
final
String
aliSendSmsAction
=
"SendSms"
;
/**
* 阿里短信服批处理行为
*/
private
final
String
aliSendBatchSmsAction
=
"SendBatchSms"
;
/**
* 阿里邮件批处理行为
*/
private
final
String
aliBatchSendMailAction
=
"BatchSendMail"
;
/**
* 消息类型
*/
...
...
@@ -81,6 +72,15 @@ public class NotifyCoreService {
aliyun
,
wechat
,
}
/**
* 平台消息类型代码表
*/
private
static
Map
<
Integer
,
String
>
msgTypes
=
new
HashMap
(){{
put
(
2
,
"email"
);
put
(
4
,
"sms"
);
put
(
32
,
"wechat"
);
put
(
64
,
"dingtalk"
);
}};
@Autowired
@Lazy
...
...
@@ -170,16 +170,7 @@ public class NotifyCoreService {
CommonRequest
request
=
new
CommonRequest
();
request
.
setSysMethod
(
MethodType
.
POST
);
request
.
setSysDomain
(
aliSmsDomain
);
if
(
authUserId
.
contains
(
","
)){
request
.
setSysAction
(
aliSendBatchSmsAction
);
request
.
putQueryParameter
(
"RegionId"
,
region
);
request
.
putQueryParameter
(
"PhoneNumbers"
,
Arrays
.
asList
(
authUserId
.
split
(
","
)).
toString
());
request
.
putQueryParameter
(
"SignName"
,
Arrays
.
asList
(
template
.
getTemplateName
().
split
(
","
)).
toString
());
request
.
putQueryParameter
(
"TemplateCode"
,
template
.
getTemplateId
());
request
.
putQueryParameter
(
"TemplateParam"
,
templParams
.
toString
());
client
.
getCommonResponse
(
request
);
}
else
{
request
.
setSysAction
(
aliSendSmsAction
);
request
.
putQueryParameter
(
"RegionId"
,
region
);
request
.
putQueryParameter
(
"PhoneNumbers"
,
authUserId
);
...
...
@@ -187,7 +178,6 @@ public class NotifyCoreService {
request
.
putQueryParameter
(
"TemplateCode"
,
template
.
getTemplateId
());
request
.
putQueryParameter
(
"TemplateParam"
,
templParams
.
toString
());
client
.
getCommonResponse
(
request
);
}
log
.
info
(
String
.
format
(
"成功向用户[%s]发送一条短信"
,
authUserId
));
return
true
;
}
...
...
@@ -209,15 +199,6 @@ public class NotifyCoreService {
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
StringUtils
.
isEmpty
(
region
)?
"cn-hangzhou"
:
region
,
accessKey
,
accessSecret
);
IAcsClient
client
=
new
DefaultAcsClient
(
profile
);
if
(
authUserId
.
contains
(
","
)){
BatchSendMailRequest
request
=
new
BatchSendMailRequest
();
request
.
setTemplateName
(
template
.
getTemplateName
());
request
.
setAccountName
(
template
.
getTemplateId
());
request
.
setReceiversName
(
authUserId
);
request
.
setAddressType
(
1
);
request
.
setActionName
(
aliBatchSendMailAction
);
}
else
{
SingleSendMailRequest
request
=
new
SingleSendMailRequest
();
request
.
setAccountName
(
template
.
getTemplateId
());
request
.
setAddressType
(
1
);
...
...
@@ -226,7 +207,6 @@ public class NotifyCoreService {
request
.
setSubject
(
template
.
getTemplateName
());
request
.
setHtmlBody
(
template
.
getContent
());
client
.
getAcsResponse
(
request
);
}
log
.
info
(
String
.
format
(
"成功向用户[%s]发送一条邮件"
,
authUserId
));
return
true
;
}
...
...
@@ -245,6 +225,10 @@ public class NotifyCoreService {
paramMap
.
put
(
"template_id"
,
template
.
getTemplateId
());
paramMap
.
put
(
"touser"
,
authUserId
);
paramMap
.
put
(
"data"
,
templParams
);
JSONObject
obj
=
new
JSONObject
();
obj
.
put
(
"value"
,
"birdle test"
);
templParams
.
put
(
"result"
,
obj
);
HttpEntity
request
=
new
HttpEntity
(
paramMap
);
ResponseEntity
<
String
>
result
=
restTemplate
.
postForEntity
(
String
.
format
(
weChatSendMsgApi
,
openAccess
.
getAccessToken
()),
request
,
String
.
class
);
getResult
(
result
.
getBody
());
...
...
@@ -372,20 +356,19 @@ public class NotifyCoreService {
public
boolean
sendMsg
(
Msg
msg
){
String
system
=
msg
.
getSystem
();
String
templateId
=
msg
.
getTemplateid
();
String
msgTypes
=
msg
.
getMsgtypes
();
String
userIds
=
msg
.
getUserids
();
Map
templParams
=
msg
.
getTemplparams
();
for
(
String
msgType:
msgTypes
.
split
(
","
)){
for
(
String
msgType:
getMsgType
(
msg
.
getMsgtypes
()
)){
MsgTemplate
msgTemplate
=
templateService
.
getById
(
system
+
templateId
+
msgType
);
if
(
msgTemplate
==
null
){
throw
new
BadRequestAlertException
(
String
.
format
(
"发送消息失败,无法获取到[%s]对应的rt模板"
,
templateId
),
""
,
""
);
}
else
{
switch
(
msgType
){
case
"
aliyun-
sms"
:
case
"sms"
:
sendAliSms
(
msgTemplate
.
getTid
(),
userIds
,
templParams
);
break
;
case
"
aliyun-
email"
:
case
"email"
:
sendAliEMail
(
msgTemplate
.
getTid
(),
userIds
);
break
;
case
"dingtalk"
:
...
...
@@ -402,4 +385,19 @@ public class NotifyCoreService {
return
true
;
}
/**
* 解析数值代码表获取消息类型
* @param msgType
* @return
*/
private
List
<
String
>
getMsgType
(
int
msgType
){
List
<
String
>
useMsg
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
Integer
,
String
>
msg
:
msgTypes
.
entrySet
()){
if
((
msgType
&
msg
.
getKey
())
==
msg
.
getKey
()){
useMsg
.
add
(
msg
.
getValue
());
}
}
return
useMsg
;
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录