Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibznotify
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibznotify
提交
01d85850
提交
01d85850
编写于
9月 06, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
同步lab环境代码
上级
4535a485
变更
4
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
383 行增加
和
336 行删除
+383
-336
DevBootSecurityConfig.java
...rc/main/java/cn/ibizlab/config/DevBootSecurityConfig.java
+1
-6
NotifyCoreService.java
...cn/ibizlab/core/extensions/service/NotifyCoreService.java
+359
-306
apiSecurityConfig.java
...rc/main/java/cn/ibizlab/api/config/apiSecurityConfig.java
+1
-6
NotifyCoreResource.java
...va/cn/ibizlab/api/rest/extensions/NotifyCoreResource.java
+22
-18
未找到文件。
ibznotify-boot/src/main/java/cn/ibizlab/config/DevBootSecurityConfig.java
浏览文件 @
01d85850
...
@@ -115,12 +115,7 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -115,12 +115,7 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
.
antMatchers
(
"/"
+
uploadpath
).
permitAll
()
.
antMatchers
(
"/"
+
uploadpath
).
permitAll
()
.
antMatchers
(
"/"
+
previewpath
+
"/**"
).
permitAll
()
.
antMatchers
(
"/"
+
previewpath
+
"/**"
).
permitAll
()
//消息发送请求
//消息发送请求
.
antMatchers
(
"/SendMsg"
).
permitAll
()
.
antMatchers
(
"/notify/**"
).
permitAll
()
.
antMatchers
(
"/createMsgTemplate"
).
permitAll
()
.
antMatchers
(
"/trade/pagepay"
).
permitAll
()
.
antMatchers
(
"/dingtalk/sendlinkmsg"
).
permitAll
()
.
antMatchers
(
"/dingtalk/createworkrecord"
).
permitAll
()
.
antMatchers
(
"/dingtalk/finishworkrecord"
).
permitAll
()
.
anyRequest
().
authenticated
()
.
anyRequest
().
authenticated
()
// 防止iframe 造成跨域
// 防止iframe 造成跨域
...
...
ibznotify-core/src/main/java/cn/ibizlab/core/extensions/service/NotifyCoreService.java
浏览文件 @
01d85850
package
cn
.
ibizlab
.
core
.
extensions
.
service
;
package
cn
.
ibizlab
.
core
.
extensions
.
service
;
import
cn.ibizlab.core.extensions.domain.Msg
;
import
cn.ibizlab.core.extensions.domain.Template
;
import
cn.ibizlab.core.extensions.domain.Template
;
import
cn.ibizlab.core.notify.domain.MsgBody
;
import
cn.ibizlab.core.notify.domain.MsgOpenAccess
;
import
cn.ibizlab.core.notify.domain.MsgOpenAccess
;
import
cn.ibizlab.core.notify.domain.MsgTemplate
;
import
cn.ibizlab.core.notify.domain.MsgTemplate
;
import
cn.ibizlab.core.notify.domain.MsgUserAccount
;
import
cn.ibizlab.core.notify.domain.MsgUserAccount
;
import
cn.ibizlab.core.notify.service.IMsgBodyService
;
import
cn.ibizlab.core.notify.service.IMsgOpenAccessService
;
import
cn.ibizlab.core.notify.service.IMsgOpenAccessService
;
import
cn.ibizlab.core.notify.service.IMsgTemplateService
;
import
cn.ibizlab.core.notify.service.IMsgTemplateService
;
import
cn.ibizlab.core.notify.service.IMsgUserAccountService
;
import
cn.ibizlab.core.notify.service.IMsgUserAccountService
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
c
om.alibaba.fastjson.JSON
;
import
c
n.ibizlab.util.helper.CachedBeanCopier
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.aliyuncs.CommonRequest
;
import
com.aliyuncs.CommonRequest
;
...
@@ -17,27 +18,33 @@ import com.aliyuncs.CommonResponse;
...
@@ -17,27 +18,33 @@ import com.aliyuncs.CommonResponse;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.IAcsClient
;
import
com.aliyuncs.IAcsClient
;
import
com.aliyuncs.dm.model.v20151123.SingleSendMailRequest
;
import
com.aliyuncs.dm.model.v20151123.SingleSendMailRequest
;
import
com.aliyuncs.dm.model.v20151123.SingleSendMailResponse
;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.profile.DefaultProfile
;
import
com.aliyuncs.profile.DefaultProfile
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.dingtalk.api.DefaultDingTalkClient
;
import
com.dingtalk.api.DefaultDingTalkClient
;
import
com.dingtalk.api.DingTalkClient
;
import
com.dingtalk.api.DingTalkClient
;
import
com.dingtalk.api.request.OapiGettokenRequest
;
import
com.dingtalk.api.request.OapiGettokenRequest
;
import
com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request
;
import
com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request
;
import
com.dingtalk.api.request.OapiWorkrecordAddRequest
;
import
com.dingtalk.api.request.OapiWorkrecordAddRequest
;
import
com.dingtalk.api.request.OapiWorkrecordUpdateRequest
;
import
com.dingtalk.api.request.OapiWorkrecordUpdateRequest
;
import
com.dingtalk.api.response.*
;
import
com.dingtalk.api.response.OapiGettokenResponse
;
import
com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response
;
import
com.dingtalk.api.response.OapiWorkrecordAddResponse
;
import
com.dingtalk.api.response.OapiWorkrecordUpdateResponse
;
import
com.google.gson.Gson
;
import
lombok.SneakyThrows
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.scheduling.annotation.
Async
;
import
org.springframework.scheduling.annotation.
Scheduled
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.util.*
;
import
java.util.*
;
...
@@ -81,16 +88,6 @@ public class NotifyCoreService {
...
@@ -81,16 +88,6 @@ public class NotifyCoreService {
* 阿里短信服务单处理行为
* 阿里短信服务单处理行为
*/
*/
private
static
final
String
aliSendSmsVersion
=
"2017-05-25"
;
private
static
final
String
aliSendSmsVersion
=
"2017-05-25"
;
/**
* 消息类型
*/
enum
MsgType
{
dingtalk
,
aliyun
,
wechat
,
}
/**
/**
* 平台消息类型代码表
* 平台消息类型代码表
*/
*/
...
@@ -127,7 +124,11 @@ public class NotifyCoreService {
...
@@ -127,7 +124,11 @@ public class NotifyCoreService {
@Autowired
@Autowired
@Lazy
@Lazy
NotifyCoreService
notifyCoreService
;
NotifyCoreService
proxyService
;
@Autowired
@Lazy
IMsgBodyService
msgBodyService
;
/**
/**
* 获取钉钉token
* 获取钉钉token
...
@@ -160,19 +161,101 @@ public class NotifyCoreService {
...
@@ -160,19 +161,101 @@ public class NotifyCoreService {
return
result
.
getBody
();
return
result
.
getBody
();
}
}
/**
* 设置新token及过期时间
* @param openAccess
* @return
*/
public
MsgOpenAccess
refreshToken
(
MsgOpenAccess
openAccess
){
String
tempToken
=
null
;
switch
(
openAccess
.
getOpenType
()){
case
"wechat"
:
tempToken
=
getWeChatToken
(
openAccess
);
break
;
case
"dingtalk"
:
tempToken
=
getDingTalkToken
(
openAccess
);
break
;
}
if
(!
StringUtils
.
isEmpty
(
tempToken
)){
JSONObject
objToken
=
JSONObject
.
parseObject
(
tempToken
);
if
(
objToken
!=
null
){
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
new
Date
());
calendar
.
add
(
Calendar
.
SECOND
,
Integer
.
parseInt
(
objToken
.
getString
(
"expires_in"
)));
Date
date
=
calendar
.
getTime
();
openAccess
.
setAccessToken
(
objToken
.
getString
(
"access_token"
));
openAccess
.
setExpiresTime
(
new
Timestamp
(
date
.
getTime
()));
}
}
return
openAccess
;
}
/**
* 发送消息服务
*/
@Scheduled
(
fixedRate
=
60000
)
public
void
sendMsgService
()
{
List
<
MsgBody
>
msgList
=
msgBodyService
.
list
(
Wrappers
.<
MsgBody
>
lambdaQuery
().
eq
(
MsgBody:
:
getIsSend
,
0
).
eq
(
MsgBody:
:
getIsError
,
0
));
List
<
MsgBody
>
dingtalk
=
new
ArrayList
<>();
List
<
MsgBody
>
wechat
=
new
ArrayList
<>();
List
<
MsgBody
>
email
=
new
ArrayList
<>();
List
<
MsgBody
>
sms
=
new
ArrayList
<>();
List
<
MsgBody
>
dingtalk_link
=
new
ArrayList
<>();
List
<
MsgBody
>
dingtalk_workRecord
=
new
ArrayList
<>();
for
(
MsgBody
msg:
msgList
){
switch
(
msg
.
getMsgType
()){
case
2
:
email
.
add
(
msg
);
break
;
case
4
:
sms
.
add
(
msg
);
break
;
case
32
:
wechat
.
add
(
msg
);
break
;
case
64
:
dingtalk
.
add
(
msg
);
break
;
case
65
:
dingtalk_link
.
add
(
msg
);
break
;
case
66
:
dingtalk_workRecord
.
add
(
msg
);
break
;
}
}
for
(
MsgBody
msg
:
email
){
aliEMailService
(
msg
);
}
for
(
MsgBody
msg
:
sms
){
aliSmsService
(
msg
);
}
for
(
MsgBody
msg
:
wechat
){
weChatMsgService
(
msg
);
}
for
(
MsgBody
msg
:
dingtalk
){
dingTalkMsgService
(
msg
);
}
for
(
MsgBody
msg
:
dingtalk_link
){
dingtalkLinkMsgService
(
msg
);
}
for
(
MsgBody
msg
:
dingtalk_workRecord
){
dingtalkWorkRecordService
(
msg
);
}
}
/**
/**
* 发送钉钉消息
* 发送钉钉消息
* @param msg
* @param msg
* @param tid
*/
*/
@SneakyThrows
@SneakyThrows
private
boolean
sendDingTalkMsg
(
Msg
msg
,
String
tid
){
private
boolean
dingTalkMsgService
(
MsgBody
msg
){
String
authUserId
=
getAuthUserId
(
msg
.
getUserids
(),
MsgType
.
dingtalk
);
String
msgUsers
=
getMsgUsers
(
msg
);
MsgTemplate
template
=
templateService
.
getById
(
tid
);
MsgTemplate
template
=
templateService
.
getById
(
msg
.
getTemplateId
()
);
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
OapiMessageCorpconversationAsyncsendV2Request
req
=
new
OapiMessageCorpconversationAsyncsendV2Request
();
OapiMessageCorpconversationAsyncsendV2Request
req
=
new
OapiMessageCorpconversationAsyncsendV2Request
();
req
.
setAgentId
(
Long
.
parseLong
(
template
.
getTemplateId
()));
req
.
setAgentId
(
Long
.
parseLong
(
template
.
getTemplateId
()));
req
.
setUseridList
(
authUserId
);
req
.
setUseridList
(
msgUsers
);
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
dingtalkMsg
=
new
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
();
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
dingtalkMsg
=
new
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
();
dingtalkMsg
.
setMsgtype
(
"text"
);
dingtalkMsg
.
setMsgtype
(
"text"
);
OapiMessageCorpconversationAsyncsendV2Request
.
Text
obj2
=
new
OapiMessageCorpconversationAsyncsendV2Request
.
Text
();
OapiMessageCorpconversationAsyncsendV2Request
.
Text
obj2
=
new
OapiMessageCorpconversationAsyncsendV2Request
.
Text
();
...
@@ -180,19 +263,19 @@ public class NotifyCoreService {
...
@@ -180,19 +263,19 @@ public class NotifyCoreService {
dingtalkMsg
.
setText
(
obj2
);
dingtalkMsg
.
setText
(
obj2
);
req
.
setMsg
(
dingtalkMsg
);
req
.
setMsg
(
dingtalkMsg
);
OapiMessageCorpconversationAsyncsendV2Response
rsp
=
sendMsgClient
.
execute
(
req
,
openAccess
.
getAccessToken
());
OapiMessageCorpconversationAsyncsendV2Response
rsp
=
sendMsgClient
.
execute
(
req
,
openAccess
.
getAccessToken
());
getResult
(
rsp
.
getBody
());
saveCallResult
(
msg
,
rsp
.
getBody
());
return
true
;
return
true
;
}
}
/**
/**
* 发送阿里短信
* 发送阿里短信
* @param
tid
* @param
msg
* @
param userId
* @
return
*/
*/
@SneakyThrows
@SneakyThrows
private
boolean
sendAliSms
(
String
tid
,
String
userId
,
Map
templParams
){
private
boolean
aliSmsService
(
MsgBody
msg
){
String
authUserId
=
getAuthUserId
(
userId
,
MsgType
.
aliyun
);
String
msgUsers
=
getMsgUsers
(
msg
);
MsgTemplate
template
=
templateService
.
getById
(
tid
);
MsgTemplate
template
=
templateService
.
getById
(
msg
.
getTemplateId
()
);
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
String
region
=
openAccess
.
getRegionId
();
String
region
=
openAccess
.
getRegionId
();
String
accessKey
=
openAccess
.
getAccessKey
();
String
accessKey
=
openAccess
.
getAccessKey
();
...
@@ -205,26 +288,26 @@ public class NotifyCoreService {
...
@@ -205,26 +288,26 @@ public class NotifyCoreService {
request
.
setSysAction
(
aliSendSmsAction
);
request
.
setSysAction
(
aliSendSmsAction
);
request
.
putQueryParameter
(
"RegionId"
,
region
);
request
.
putQueryParameter
(
"RegionId"
,
region
);
request
.
putQueryParameter
(
"PhoneNumbers"
,
authUserId
);
request
.
putQueryParameter
(
"PhoneNumbers"
,
msgUsers
);
request
.
putQueryParameter
(
"SignName"
,
template
.
getTemplateName
());
request
.
putQueryParameter
(
"SignName"
,
template
.
getTemplateName
());
request
.
putQueryParameter
(
"Version"
,
aliSendSmsVersion
);
request
.
putQueryParameter
(
"Version"
,
aliSendSmsVersion
);
request
.
putQueryParameter
(
"TemplateCode"
,
template
.
getTemplateId
());
request
.
putQueryParameter
(
"TemplateCode"
,
template
.
getTemplateId
());
request
.
putQueryParameter
(
"TemplateParam"
,
templParams
.
toString
());
request
.
putQueryParameter
(
"TemplateParam"
,
msg
.
getTemplateParams
());
CommonResponse
response
=
client
.
getCommonResponse
(
request
);
CommonResponse
response
=
client
.
getCommonResponse
(
request
);
log
.
info
(
String
.
format
(
"成功向用户[%s]发送一条短信"
,
authUserId
));
saveCallResult
(
msg
,
new
Gson
().
toJson
(
response
));
log
.
info
(
String
.
format
(
"成功向用户[%s]发送一条短信"
,
msgUsers
));
return
true
;
return
true
;
}
}
/**
/**
* 发送阿里邮件
* 发送阿里邮件
* @param
tid
* @param
msg
* @
param userId
* @
return
*/
*/
@SneakyThrows
@SneakyThrows
private
boolean
sendAliEMail
(
String
tid
,
String
userId
){
private
boolean
aliEMailService
(
MsgBody
msg
){
String
msgUsers
=
getMsgUsers
(
msg
);
String
authUserId
=
getAuthUserId
(
userId
,
MsgType
.
aliyun
);
MsgTemplate
template
=
templateService
.
getById
(
msg
.
getTemplateId
());
MsgTemplate
template
=
templateService
.
getById
(
tid
);
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
String
region
=
openAccess
.
getRegionId
();
String
region
=
openAccess
.
getRegionId
();
String
accessKey
=
openAccess
.
getAccessKey
();
String
accessKey
=
openAccess
.
getAccessKey
();
...
@@ -236,367 +319,337 @@ public class NotifyCoreService {
...
@@ -236,367 +319,337 @@ public class NotifyCoreService {
request
.
setAccountName
(
template
.
getTemplateId
());
request
.
setAccountName
(
template
.
getTemplateId
());
request
.
setAddressType
(
1
);
request
.
setAddressType
(
1
);
request
.
setReplyToAddress
(
false
);
request
.
setReplyToAddress
(
false
);
request
.
setToAddress
(
authUserId
);
request
.
setToAddress
(
msgUsers
);
request
.
setSubject
(
template
.
getTemplateName
());
request
.
setSubject
(
template
.
getTemplateName
());
request
.
setHtmlBody
(
template
.
getContent
());
request
.
setHtmlBody
(
template
.
getContent
());
client
.
getAcsResponse
(
request
);
SingleSendMailResponse
response
=
client
.
getAcsResponse
(
request
);
log
.
info
(
String
.
format
(
"成功向用户[%s]发送一条邮件"
,
authUserId
));
saveCallResult
(
msg
,
new
Gson
().
toJson
(
response
));
log
.
info
(
String
.
format
(
"成功向用户[%s]发送一条邮件"
,
msgUsers
));
return
true
;
return
true
;
}
}
/**
/**
* 发送微信消息
* 发送微信消息
* @param
tid
* @param
msg
* @
param userId
* @
return
*/
*/
private
boolean
sendWeChatMsg
(
String
tid
,
String
userId
,
Map
templParams
){
private
boolean
weChatMsgService
(
MsgBody
msg
){
String
authUserId
=
getAuthUserId
(
userId
,
MsgType
.
wechat
);
String
msgUsers
=
getMsgUsers
(
msg
);
MsgTemplate
template
=
templateService
.
getById
(
tid
);
MsgTemplate
template
=
templateService
.
getById
(
msg
.
getTemplateId
()
);
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
Map
templParams
=
new
HashMap
();
Map
paramMap
=
new
HashMap
();
Map
paramMap
=
new
HashMap
();
paramMap
.
put
(
"template_id"
,
template
.
getTemplateId
());
paramMap
.
put
(
"template_id"
,
template
.
getTemplateId
());
paramMap
.
put
(
"touser"
,
authUserId
);
paramMap
.
put
(
"touser"
,
msgUsers
);
paramMap
.
put
(
"data"
,
templParams
);
paramMap
.
put
(
"data"
,
msg
.
getTemplateParams
()
);
JSONObject
obj
=
new
JSONObject
();
JSONObject
obj
=
new
JSONObject
();
obj
.
put
(
"value"
,
"
birdle
test"
);
obj
.
put
(
"value"
,
"test"
);
templParams
.
put
(
"result"
,
obj
);
templParams
.
put
(
"result"
,
obj
);
HttpEntity
request
=
new
HttpEntity
(
paramMap
);
HttpEntity
request
=
new
HttpEntity
(
paramMap
);
ResponseEntity
<
String
>
result
=
restTemplate
.
postForEntity
(
String
.
format
(
weChatSendMsgApi
,
openAccess
.
getAccessToken
()),
request
,
String
.
class
);
ResponseEntity
<
String
>
result
=
restTemplate
.
postForEntity
(
String
.
format
(
weChatSendMsgApi
,
openAccess
.
getAccessToken
()),
request
,
String
.
class
);
getResult
(
result
.
getBody
());
saveCallResult
(
msg
,
result
.
getBody
());
return
true
;
return
true
;
}
}
/**
/**
* 获取第三方用户标识
* 发送钉钉链接消息
* @param userId
* @return
* @return
*/
*/
private
String
getAuthUserId
(
String
userId
,
MsgType
type
){
@SneakyThrows
QueryWrapper
<
MsgUserAccount
>
qw
=
new
QueryWrapper
();
public
Long
dingtalkLinkMsgService
(
MsgBody
msg
){
qw
.
eq
(
"identity_type"
,
type
);
String
msgUsers
=
getMsgUsers
(
msg
);
if
(
userId
.
contains
(
","
)){
MsgTemplate
template
=
templateService
.
getById
(
msg
.
getTemplateId
());
qw
.
in
(
"userid"
,
userId
.
split
(
","
));
if
(
template
==
null
){
List
<
MsgUserAccount
>
userAccounts
=
userAccountService
.
list
(
qw
);
throw
new
BadRequestAlertException
(
String
.
format
(
"发送链接消息失败,无法获取到[%s]对应的rt模板"
,
msg
.
getTemplateId
()),
""
,
""
);
if
(
userAccounts
==
null
||
userAccounts
.
size
()==
0
)
throw
new
BadRequestAlertException
(
"未能获取到授权用户"
,
"NotifyCoreService"
,
"sendDingTalkMsg"
);
StringBuffer
authUserIds
=
new
StringBuffer
();
for
(
MsgUserAccount
userAccount:
userAccounts
){
if
(
StringUtils
.
isEmpty
(
authUserIds
.
toString
())){
authUserIds
.
append
(
userAccount
.
getIdentifier
());
}
else
{
authUserIds
.
append
(
","
+
userAccount
.
getIdentifier
());
}
}
}
return
authUserIds
.
toString
();
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
}
else
{
if
(
openAccess
==
null
){
qw
.
eq
(
"userid"
,
userId
);
openAccess
=
openAccessService
.
get
(
template
.
getAccessId
());
MsgUserAccount
userAccount
=
userAccountService
.
getOne
(
qw
);
if
(
userAccount
==
null
||
StringUtils
.
isEmpty
(
userAccount
.
getIdentifier
()))
throw
new
BadRequestAlertException
(
"未能获取到授权用户"
,
"NotifyCoreService"
,
"sendDingTalkMsg"
);
return
userAccount
.
getIdentifier
();
}
}
OapiMessageCorpconversationAsyncsendV2Request
req
=
new
OapiMessageCorpconversationAsyncsendV2Request
();
req
.
setAgentId
(
Long
.
parseLong
(
template
.
getTemplateId
()));
req
.
setUseridList
(
msgUsers
);
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
dingtalkMsg
=
new
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
();
dingtalkMsg
.
setMsgtype
(
"link"
);
dingtalkMsg
.
setLink
(
new
OapiMessageCorpconversationAsyncsendV2Request
.
Link
());
dingtalkMsg
.
getLink
().
setTitle
(
StringUtils
.
isEmpty
(
msg
.
getSubject
())?
template
.
getTemplateName
():
msg
.
getSubject
());
dingtalkMsg
.
getLink
().
setText
(
StringUtils
.
isEmpty
(
msg
.
getContent
())?
template
.
getContent
():
msg
.
getContent
());
dingtalkMsg
.
getLink
().
setMessageUrl
(
StringUtils
.
isEmpty
(
msg
.
getMsgLink
())?
template
.
getTemplateUrl
():
msg
.
getMsgLink
());
dingtalkMsg
.
getLink
().
setPicUrl
(
"test"
);
req
.
setMsg
(
dingtalkMsg
);
OapiMessageCorpconversationAsyncsendV2Response
rsp
=
sendMsgClient
.
execute
(
req
,
openAccess
.
getAccessToken
());
saveCallResult
(
msg
,
rsp
.
getBody
());
return
rsp
.
getTaskId
();
}
}
/**
/**
*
解析接口返回结果
*
发送钉钉待办
* @param
result
* @param
msg
*/
*/
private
void
getResult
(
String
result
){
@SneakyThrows
JSONObject
resultJo
=
JSONObject
.
parseObject
(
result
);
public
void
dingtalkWorkRecordService
(
MsgBody
msg
){
if
(
resultJo
.
containsKey
(
"errcode"
)
&&
resultJo
.
getInteger
(
"errcode"
)!=
0
)
String
msgUsers
=
getMsgUsers
(
msg
);
throw
new
BadRequestAlertException
(
String
.
format
(
"发送消息失败,%s"
,
resultJo
.
toString
()),
""
,
""
);
OapiWorkrecordAddRequest
req
=
new
OapiWorkrecordAddRequest
();
else
MsgTemplate
template
=
templateService
.
getById
(
msg
.
getTemplateId
());
log
.
info
(
"发送消息成功"
);
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
req
.
setUserid
(
msgUsers
);
req
.
setCreateTime
(
new
Date
().
getTime
());
req
.
setTitle
(
StringUtils
.
isEmpty
(
msg
.
getSubject
())?
template
.
getTemplateName
():
msg
.
getSubject
());
req
.
setUrl
(
StringUtils
.
isEmpty
(
msg
.
getMsgLink
())?
template
.
getTemplateUrl
():
msg
.
getMsgLink
());
req
.
setPcUrl
(
StringUtils
.
isEmpty
(
msg
.
getMsgLinkPc
())?
template
.
getTemplateUrl
():
msg
.
getMsgLinkPc
());
List
<
OapiWorkrecordAddRequest
.
FormItemVo
>
list2
=
new
ArrayList
<>();
OapiWorkrecordAddRequest
.
FormItemVo
obj3
=
new
OapiWorkrecordAddRequest
.
FormItemVo
();
list2
.
add
(
obj3
);
obj3
.
setTitle
(
StringUtils
.
isEmpty
(
msg
.
getSubject
())?
template
.
getTemplateName
():
msg
.
getSubject
());
obj3
.
setContent
(
StringUtils
.
isEmpty
(
msg
.
getContent
())?
template
.
getContent
():
msg
.
getContent
());
req
.
setFormItemList
(
list2
);
OapiWorkrecordAddResponse
rsp
=
createWorkRecordClient
.
execute
(
req
,
openAccess
.
getAccessToken
());
if
(
rsp
.
isSuccess
()){
msg
.
setUserData
(
rsp
.
getRecordId
());
}
saveCallResult
(
msg
,
rsp
.
getBody
());
}
}
/**
/**
*
设置新token及过期时间
*
存储消息进消息表
* @param
openAccess
* @param
msg
* @return
* @return
*/
*/
public
MsgOpenAccess
refreshToken
(
MsgOpenAccess
openAccess
){
public
boolean
sendMsg
(
MsgBody
msg
){
String
tempToken
=
null
;
String
templateId
=
msg
.
getTemplateId
();
switch
(
openAccess
.
getOpenType
()){
String
userIds
=
msg
.
getToUsers
();
case
"wechat"
:
List
<
MsgBody
>
msgList
=
new
ArrayList
<>();
tempToken
=
getWeChatToken
(
openAccess
);
for
(
int
msgType:
getMsgType
(
msg
.
getMsgType
())){
break
;
MsgTemplate
msgTemplate
=
getMsgTempLate
(
templateId
);
case
"dingtalk"
:
msg
.
setMsgName
(
msg
.
getSubject
());
tempToken
=
getDingTalkToken
(
openAccess
);
msg
.
setTemplateId
(
msgTemplate
.
getTid
());
break
;
msg
.
setToUsers
(
userIds
);
}
msg
.
setMsgType
(
msgType
);
if
(!
StringUtils
.
isEmpty
(
tempToken
)){
msgList
.
add
(
msg
);
JSONObject
objToken
=
JSONObject
.
parseObject
(
tempToken
);
}
if
(
objToken
!=
null
){
if
(
msgList
.
size
()>
0
)
Calendar
calendar
=
Calendar
.
getInstance
();
msgBodyService
.
createBatch
(
msgList
);
calendar
.
setTime
(
new
Date
());
return
true
;
calendar
.
add
(
Calendar
.
SECOND
,
Integer
.
parseInt
(
objToken
.
getString
(
"expires_in"
)));
Date
date
=
calendar
.
getTime
();
openAccess
.
setAccessToken
(
objToken
.
getString
(
"access_token"
));
openAccess
.
setExpiresTime
(
new
Timestamp
(
date
.
getTime
()));
}
}
/**
* 存储钉钉消息进消息表
* @param msg
* @return
*/
@SneakyThrows
public
boolean
sendDingTalkLinkMsg
(
MsgBody
msg
){
getMsgTempLate
(
msg
.
getTemplateId
());
msg
.
setMsgName
(
msg
.
getSubject
());
msg
.
setMsgType
(
65
);
return
msgBodyService
.
create
(
msg
);
}
}
return
openAccess
;
/**
* 存储钉钉待办进消息表
* @param msg
* @return
*/
@SneakyThrows
public
String
createDingTalkWorkRecord
(
MsgBody
msg
){
if
(
StringUtils
.
isEmpty
(
msg
.
getToUsers
()))
throw
new
BadRequestAlertException
(
"无法获取到用户信息"
,
""
,
""
);
getMsgTempLate
(
msg
.
getTemplateId
());
msg
.
setMsgName
(
msg
.
getSubject
());
msg
.
setMsgType
(
66
);
msg
.
setMsgId
(
String
.
valueOf
(
msg
.
getDefaultKey
(
true
)));
msgBodyService
.
create
(
msg
);
return
msg
.
getMsgId
();
}
}
/**
/**
* 创建模板
* 创建
消息
模板
* @param template
* @param template
* @return
* @return
*/
*/
public
boolean
createMsgTemplate
(
Template
template
){
public
synchronized
boolean
createMsgTemplate
(
Template
template
){
JSONArray
templates
=
template
.
getTemplate
();
JSONArray
templates
=
template
.
getTemplate
();
for
(
int
a
=
0
;
a
<
templates
.
size
();
a
++){
for
(
int
a
=
0
;
a
<
templates
.
size
();
a
++){
List
<
MsgOpenAccess
>
openAccesses
=
new
ArrayList
<>();
List
<
MsgTemplate
>
newTempList
=
new
ArrayList
<>();
List
<
MsgTemplate
>
msgTemplates
=
new
ArrayList
<>();
MsgTemplate
newTempl
=
JSONObject
.
toJavaObject
(
templates
.
getJSONObject
(
a
),
MsgTemplate
.
class
);
MsgTemplate
msgTempl
=
JSONObject
.
toJavaObject
(
templates
.
getJSONObject
(
a
),
MsgTemplate
.
class
);
boolean
isExist
=
checkMsgTemplate
(
msgTempl
);
if
(!
isExist
){
//rt预置消息类型
Collection
<
String
>
templTypes
=
templateType
.
values
();
Collection
<
String
>
templTypes
=
templateType
.
values
();
//创建开放平台
for
(
String
openAccessType:
getOpenAccessType
(
templTypes
)){
String
openAccessId
=
String
.
format
(
"%s-%s"
,
msgTempl
.
getTid
(),
openAccessType
);
MsgOpenAccess
openAccess
=
openAccessService
.
getById
(
openAccessId
);
if
(
openAccess
==
null
)
{
openAccess
=
new
MsgOpenAccess
();
openAccess
.
setId
(
openAccessId
);
openAccess
.
setName
(
openAccessType
);
openAccess
.
setDisabled
(
0
);
openAccess
.
setOpenType
(
openAccessType
);
openAccesses
.
add
(
openAccess
);
}
}
//创建消息模板
//创建消息模板
for
(
String
templateType
:
templTypes
){
for
(
String
templateType
:
templTypes
){
String
tid
=
String
.
format
(
"%s-%s"
,
newTempl
.
getTid
(),
templateType
);
MsgTemplate
templ
=
templateService
.
getById
(
tid
);
if
(
templ
!=
null
){
log
.
info
(
String
.
format
(
"消息模板[%s]已存在,忽略发布!"
,
tid
));
continue
;
}
MsgTemplate
msgTemplate
=
new
MsgTemplate
();
MsgTemplate
msgTemplate
=
new
MsgTemplate
();
String
openAccessType
=
templateType
.
contains
(
"-"
)?
templateType
.
substring
(
0
,
templateType
.
indexOf
(
"-"
)):
templateType
;
// String openAccessType=templateType.contains("-")?templateType.substring(0,templateType.indexOf("-")):templateType;
msgTemplate
.
setAccessId
(
String
.
format
(
"%s-%s"
,
msgTempl
.
getTid
(),
openAccessType
));
CachedBeanCopier
.
copy
(
newTempl
,
msgTemplate
);
msgTemplate
.
setOpenType
(
openAccessType
);
// msgTemplate.setOpenType(openAccessType);
msgTemplate
.
setTid
(
tid
);
msgTemplate
.
setTemplateType
(
templateType
);
msgTemplate
.
setTemplateType
(
templateType
);
msgTemplate
.
setTid
(
String
.
format
(
"%s-%s"
,
msgTempl
.
getTid
(),
templateType
));
// msgTemplate.setAccessId(String.format("%s-%s",msgTempl.getTid(),openAccessType));
msgTemplate
.
setTemplateName
(
msgTempl
.
getTemplateName
());
newTempList
.
add
(
msgTemplate
);
msgTemplate
.
setContent
(
msgTempl
.
getContent
());
msgTemplates
.
add
(
msgTemplate
);
}
if
(
openAccesses
.
size
()>
0
)
openAccessService
.
createBatch
(
openAccesses
);
if
(
msgTemplates
.
size
()>
0
)
templateService
.
createBatch
(
msgTemplates
);
}
}
if
(
newTempList
.
size
()>
0
)
templateService
.
createBatch
(
newTempList
);
}
}
return
true
;
return
true
;
}
}
/**
/**
*
检查模板是否存在
*
完成钉钉待办
* @param msg
Template
* @param msg
Id
* @return
* @return
*/
*/
private
boolean
checkMsgTemplate
(
MsgTemplate
msgTemplate
)
{
@SneakyThrows
boolean
isExist
=
false
;
public
boolean
finishDingTalkWorkRecord
(
String
msgId
){
if
(!
ObjectUtils
.
isEmpty
(
msgTemplate
.
getTid
())){
if
(
StringUtils
.
isEmpty
(
msgId
)){
QueryWrapper
<
MsgOpenAccess
>
qw
=
new
QueryWrapper
();
throw
new
BadRequestAlertException
(
"无法获取到消息标识"
,
""
,
""
);
qw
.
likeRight
(
"accessid"
,
msgTemplate
.
getTid
());
if
(
openAccessService
.
count
(
qw
)>
0
){
isExist
=
true
;
log
.
info
(
String
.
format
(
"消息模板[%s]已存在,忽略发布!"
,
msgTemplate
.
getTemplateName
()));
}
}
return
isExist
;
}
/**
* 获取开放平台
* @param templTypes
* @return
*/
private
List
<
String
>
getOpenAccessType
(
Collection
<
String
>
templTypes
){
List
openAccess
=
new
ArrayList
();
if
(
templTypes
.
size
()==
0
)
return
openAccess
;
for
(
String
template:
templTypes
){
if
(
template
.
contains
(
"-"
)){
String
openAccessType
=
template
.
substring
(
0
,
template
.
indexOf
(
"-"
));
if
(!
openAccess
.
contains
(
openAccessType
)){
openAccess
.
add
(
openAccessType
);
}
}
}
MsgBody
msg
=
msgBodyService
.
getById
(
msgId
);
if
(
msg
==
null
){
throw
new
BadRequestAlertException
(
"无法获取消息"
,
""
,
""
);
}
}
return
openAccess
;
String
msgUsers
=
getMsgUsers
(
msg
);
MsgTemplate
template
=
templateService
.
getById
(
msg
.
getTemplateId
());
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
OapiWorkrecordUpdateRequest
req
=
new
OapiWorkrecordUpdateRequest
();
req
.
setUserid
(
msgUsers
);
req
.
setRecordId
(
msg
.
getUserData
());
OapiWorkrecordUpdateResponse
rsp
=
finishWorkRecordClient
.
execute
(
req
,
openAccess
.
getAccessToken
());
msg
.
setUserData2
(
rsp
.
getBody
());
msgBodyService
.
update
(
msg
);
return
rsp
.
getResult
();
}
}
/**
/**
*
发送消息
*
获取消息类型
* @param msg
* @param msg
Type
* @return
* @return
*/
*/
public
boolean
sendMsg
(
Msg
msg
){
private
String
getIdentityType
(
int
msgType
)
{
String
templateId
=
msg
.
getTemplateid
();
String
identityType
=
""
;
String
userIds
=
msg
.
getUserids
();
Map
templParams
=
msg
.
getTemplparams
();
for
(
String
msgType:
getMsgType
(
msg
.
getMsgtypes
())){
MsgTemplate
msgTemplate
=
templateService
.
getById
(
templateId
+
"-"
+
msgType
);
if
(
msgTemplate
==
null
){
throw
new
BadRequestAlertException
(
String
.
format
(
"发送消息失败,无法获取到[%s]对应的rt模板"
,
templateId
),
""
,
""
);
}
else
{
switch
(
msgType
){
switch
(
msgType
){
case
"aliyun-sms"
:
case
2
:
sendAliSms
(
msgTemplate
.
getTid
(),
userIds
,
templParams
==
null
?
null
:
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
templParams
)))
;
identityType
=
"aliyun"
;
break
;
break
;
case
"aliyun-email"
:
case
4
:
sendAliEMail
(
msgTemplate
.
getTid
(),
userIds
)
;
identityType
=
"aliyun"
;
break
;
break
;
case
"dingtalk-msg"
:
case
32
:
sendDingTalkMsg
(
msg
,
msgTemplate
.
getTid
())
;
identityType
=
"wechat"
;
break
;
break
;
case
"wechat-msg"
:
case
64
:
sendWeChatMsg
(
msgTemplate
.
getTid
(),
userIds
,
getWechatMsgTemplParams
(
templParams
));
identityType
=
"dingtalk"
;
break
;
case
65
:
identityType
=
"dingtalk"
;
break
;
case
66
:
identityType
=
"dingtalk"
;
break
;
break
;
default
:
throw
new
BadRequestAlertException
(
String
.
format
(
"发送消息失败,尚未提供[%s]类型对应的消息服务"
,
msgType
),
""
,
""
);
}
}
}
}
return
tru
e
;
return
identityTyp
e
;
}
}
/**
/**
* 获取
微信消息模板参数
* 获取
消息账户
* @param
templParams
* @param
msg
* @return
* @return
*/
*/
private
JSONObject
getWechatMsgTemplParams
(
Map
<
String
,
Object
>
templParams
){
private
String
getMsgUsers
(
MsgBody
msg
){
String
userId
=
msg
.
getToUsers
();
if
(
templParams
==
null
)
String
msgType
=
getIdentityType
(
msg
.
getMsgType
());
return
null
;
QueryWrapper
<
MsgUserAccount
>
qw
=
new
QueryWrapper
();
qw
.
eq
(
"identity_type"
,
msgType
);
if
(
userId
.
contains
(
","
)){
qw
.
in
(
"userid"
,
userId
.
split
(
","
));
List
<
MsgUserAccount
>
userAccounts
=
userAccountService
.
list
(
qw
);
if
(
userAccounts
==
null
||
userAccounts
.
size
()==
0
)
throw
new
BadRequestAlertException
(
"未能获取到授权用户"
,
"NotifyCoreService"
,
"sendDingTalkMsg"
);
JSONObject
params
=
new
JSONObject
();
StringBuffer
authUserIds
=
new
StringBuffer
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
templParams
.
entrySet
())
{
for
(
MsgUserAccount
userAccount:
userAccounts
){
JSONObject
param
=
new
JSONObject
();
if
(
StringUtils
.
isEmpty
(
authUserIds
.
toString
())){
param
.
put
(
"value"
,
entry
.
getValue
());
authUserIds
.
append
(
userAccount
.
getIdentifier
());
params
.
put
(
entry
.
getKey
(),
param
);
}
else
{
}
authUserIds
.
append
(
","
+
userAccount
.
getIdentifier
());
return
params
;
}
}
/**
* 解析数值代码表获取消息类型
* @param msgType
* @return
*/
private
List
<
String
>
getMsgType
(
int
msgType
){
List
<
String
>
useMsg
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
Integer
,
String
>
msg
:
templateType
.
entrySet
()){
if
((
msgType
&
msg
.
getKey
())
==
msg
.
getKey
()){
useMsg
.
add
(
msg
.
getValue
());
}
}
return
authUserIds
.
toString
();
}
else
{
qw
.
eq
(
"userid"
,
userId
);
MsgUserAccount
userAccount
=
userAccountService
.
getOne
(
qw
);
if
(
userAccount
==
null
||
StringUtils
.
isEmpty
(
userAccount
.
getIdentifier
()))
throw
new
BadRequestAlertException
(
"未能获取到授权用户"
,
"NotifyCoreService"
,
"sendDingTalkMsg"
);
return
userAccount
.
getIdentifier
();
}
}
return
useMsg
;
}
}
/**
/**
*
发送钉钉链接消息
*
解析接口返回结果
* @
return
* @
param result
*/
*/
@SneakyThrows
private
void
getResult
(
String
result
){
public
Long
sendLinkMsg
(
Msg
msg
){
JSONObject
resultJo
=
JSONObject
.
parseObject
(
result
);
String
authUserId
=
getAuthUserId
(
msg
.
getUserids
(),
MsgType
.
dingtalk
);
if
(
resultJo
.
containsKey
(
"errcode"
)
&&
resultJo
.
getInteger
(
"errcode"
)!=
0
)
MsgTemplate
template
=
templateService
.
getById
(
msg
.
getTemplateid
());
throw
new
BadRequestAlertException
(
String
.
format
(
"发送消息失败,%s"
,
resultJo
.
toString
()),
""
,
""
);
if
(
template
==
null
){
else
throw
new
BadRequestAlertException
(
String
.
format
(
"发送链接消息失败,无法获取到[%s]对应的rt模板"
,
msg
.
getTemplateid
()),
""
,
""
);
log
.
info
(
"发送消息成功"
);
}
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
if
(
openAccess
==
null
){
openAccess
=
openAccessService
.
get
(
template
.
getAccessId
());
}
OapiMessageCorpconversationAsyncsendV2Request
req
=
new
OapiMessageCorpconversationAsyncsendV2Request
();
req
.
setAgentId
(
Long
.
parseLong
(
template
.
getTemplateId
()));
req
.
setUseridList
(
authUserId
);
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
dingtalkMsg
=
new
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
();
dingtalkMsg
.
setMsgtype
(
"link"
);
dingtalkMsg
.
setLink
(
new
OapiMessageCorpconversationAsyncsendV2Request
.
Link
());
dingtalkMsg
.
getLink
().
setTitle
(
StringUtils
.
isEmpty
(
msg
.
getTitle
())?
template
.
getTemplateName
():
msg
.
getTitle
());
dingtalkMsg
.
getLink
().
setText
(
StringUtils
.
isEmpty
(
msg
.
getContent
())?
template
.
getContent
():
msg
.
getContent
());
dingtalkMsg
.
getLink
().
setMessageUrl
(
StringUtils
.
isEmpty
(
msg
.
getUrl
())?
template
.
getTemplateUrl
():
msg
.
getUrl
());
dingtalkMsg
.
getLink
().
setPicUrl
(
"test"
);
req
.
setMsg
(
dingtalkMsg
);
OapiMessageCorpconversationAsyncsendV2Response
rsp
=
sendMsgClient
.
execute
(
req
,
openAccess
.
getAccessToken
());
getResult
(
rsp
.
getBody
());
return
rsp
.
getTaskId
();
}
}
/**
/**
*
建立待办
*
保存接口返回结果
* @param msg
* @param msg
* @
return
* @
param result
*/
*/
@SneakyThrows
private
void
saveCallResult
(
MsgBody
msg
,
String
result
){
public
Boolean
createWorkRecord
(
Msg
msg
){
JSONObject
resultJo
=
JSONObject
.
parseObject
(
result
);
String
authUserId
=
getAuthUserId
(
msg
.
getUserids
(),
MsgType
.
dingtalk
);
if
(
resultJo
.
containsKey
(
"errcode"
)
&&
resultJo
.
getInteger
(
"errcode"
)!=
0
){
MsgTemplate
template
=
templateService
.
getById
(
msg
.
getTemplateid
()
);
msg
.
setIsError
(
1
);
if
(
template
==
null
){
msg
.
setErrorInfo
(
resultJo
.
toString
());
throw
new
BadRequestAlertException
(
String
.
format
(
"创建待办失败,无法获取到[%s]对应的rt模板"
,
msg
.
getTemplateid
()),
""
,
"
"
);
log
.
info
(
"发送消息失败
"
);
}
}
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
else
{
if
(
openAccess
==
null
){
msg
.
setIsError
(
0
);
openAccess
=
openAccessService
.
get
(
template
.
getAccessId
()
);
log
.
info
(
"发送消息成功"
);
}
}
notifyCoreService
.
createWorkRecordByUserIds
(
authUserId
,
msg
,
template
,
openAccess
);
msg
.
setIsSend
(
1
);
return
true
;
msgBodyService
.
update
(
msg
)
;
}
}
/**
/**
* 异步创建待办
* 获取消息模板
* @param userIds
* @param templateId
* @param msg
* @return
* @param template
* @param openAccess
*/
*/
@Async
private
MsgTemplate
getMsgTempLate
(
String
templateId
){
@SneakyThrows
MsgTemplate
msgTemplate
=
templateService
.
getById
(
templateId
);
public
void
createWorkRecordByUserIds
(
String
userIds
,
Msg
msg
,
MsgTemplate
template
,
MsgOpenAccess
openAccess
){
if
(
msgTemplate
==
null
){
for
(
String
userId:
userIds
.
split
(
","
)){
throw
new
BadRequestAlertException
(
String
.
format
(
"发送消息失败,无法获取到[%s]对应的rt模板"
,
templateId
),
""
,
""
);
OapiWorkrecordAddRequest
req
=
new
OapiWorkrecordAddRequest
();
req
.
setUserid
(
userId
);
req
.
setCreateTime
(
new
Date
().
getTime
());
req
.
setTitle
(
StringUtils
.
isEmpty
(
msg
.
getTitle
())?
template
.
getTemplateName
():
msg
.
getTitle
());
req
.
setUrl
(
StringUtils
.
isEmpty
(
msg
.
getUrl
())?
template
.
getTemplateUrl
():
msg
.
getUrl
());
List
<
OapiWorkrecordAddRequest
.
FormItemVo
>
list2
=
new
ArrayList
<>();
OapiWorkrecordAddRequest
.
FormItemVo
obj3
=
new
OapiWorkrecordAddRequest
.
FormItemVo
();
list2
.
add
(
obj3
);
obj3
.
setTitle
(
StringUtils
.
isEmpty
(
msg
.
getTitle
())?
template
.
getTemplateName
():
msg
.
getTitle
());
obj3
.
setContent
(
StringUtils
.
isEmpty
(
msg
.
getContent
())?
template
.
getContent
():
msg
.
getContent
());
req
.
setFormItemList
(
list2
);
OapiWorkrecordAddResponse
rsp
=
createWorkRecordClient
.
execute
(
req
,
openAccess
.
getAccessToken
());
getResult
(
rsp
.
getBody
());
}
}
String
openAccessId
=
msgTemplate
.
getAccessId
();
if
(
StringUtils
.
isEmpty
(
openAccessId
)){
throw
new
BadRequestAlertException
(
String
.
format
(
"发送消息失败,无法获取到消息模板[%s]对应的开放平台[%s]"
,
templateId
,
openAccessId
),
""
,
""
);
}
return
msgTemplate
;
}
}
/**
/**
*
完成待办
*
解析数值代码表获取消息类型
* @param msg
* @param msg
Type
* @return
* @return
*/
*/
@SneakyThrows
private
List
<
Integer
>
getMsgType
(
int
msgType
){
public
boolean
finishWorkRecord
(
Msg
msg
){
List
<
Integer
>
useMsg
=
new
ArrayList
<>();
String
authUserId
=
getAuthUserId
(
msg
.
getUserids
(),
MsgType
.
dingtalk
);
for
(
Map
.
Entry
<
Integer
,
String
>
msg
:
templateType
.
entrySet
()){
MsgTemplate
template
=
templateService
.
getById
(
msg
.
getTemplateid
());
if
((
msgType
&
msg
.
getKey
())
==
msg
.
getKey
()){
if
(
template
==
null
){
useMsg
.
add
(
msg
.
getKey
());
throw
new
BadRequestAlertException
(
String
.
format
(
"完成待办失败,无法获取到[%s]对应的rt模板"
,
msg
.
getTemplateid
()),
""
,
""
);
}
}
MsgOpenAccess
openAccess
=
template
.
getOpenaccess
();
}
OapiWorkrecordUpdateRequest
req
=
new
OapiWorkrecordUpdateRequest
();
return
useMsg
;
req
.
setUserid
(
authUserId
);
req
.
setRecordId
(
msg
.
getRecordid
());
OapiWorkrecordUpdateResponse
rsp
=
finishWorkRecordClient
.
execute
(
req
,
openAccess
.
getAccessToken
());
getResult
(
rsp
.
getBody
());
return
rsp
.
getResult
();
}
}
}
}
ibznotify-provider/ibznotify-provider-api/src/main/java/cn/ibizlab/api/config/apiSecurityConfig.java
浏览文件 @
01d85850
...
@@ -120,12 +120,7 @@ public class apiSecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -120,12 +120,7 @@ public class apiSecurityConfig extends WebSecurityConfigurerAdapter {
.
antMatchers
(
"/"
+
uploadpath
).
permitAll
()
.
antMatchers
(
"/"
+
uploadpath
).
permitAll
()
.
antMatchers
(
"/"
+
previewpath
+
"/**"
).
permitAll
()
.
antMatchers
(
"/"
+
previewpath
+
"/**"
).
permitAll
()
//消息发送请求
//消息发送请求
.
antMatchers
(
"/SendMsg"
).
permitAll
()
.
antMatchers
(
"/notify/**"
).
permitAll
()
.
antMatchers
(
"/createMsgTemplate"
).
permitAll
()
.
antMatchers
(
"/trade/pagepay"
).
permitAll
()
.
antMatchers
(
"/dingtalk/sendlinkmsg"
).
permitAll
()
.
antMatchers
(
"/dingtalk/createworkrecord"
).
permitAll
()
.
antMatchers
(
"/dingtalk/finishworkrecord"
).
permitAll
()
// 所有请求都需要认证
// 所有请求都需要认证
.
anyRequest
().
authenticated
()
.
anyRequest
().
authenticated
()
// 防止iframe 造成跨域
// 防止iframe 造成跨域
...
...
ibznotify-provider/ibznotify-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/NotifyCoreResource.java
浏览文件 @
01d85850
package
cn
.
ibizlab
.
api
.
rest
.
extensions
;
package
cn
.
ibizlab
.
api
.
rest
.
extensions
;
import
cn.ibizlab.core.extensions.domain.Msg
;
import
cn.ibizlab.api.dto.MsgBodyDTO
;
import
cn.ibizlab.api.mapping.MsgBodyMapping
;
import
cn.ibizlab.core.extensions.domain.Template
;
import
cn.ibizlab.core.extensions.domain.Template
;
import
cn.ibizlab.core.extensions.service.NotifyCoreService
;
import
cn.ibizlab.core.extensions.service.NotifyCoreService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -15,50 +16,53 @@ public class NotifyCoreResource {
...
@@ -15,50 +16,53 @@ public class NotifyCoreResource {
@Autowired
@Autowired
NotifyCoreService
notifyCoreService
;
NotifyCoreService
notifyCoreService
;
@Autowired
MsgBodyMapping
mapping
;
/**
/**
* 发送工作流消息
* 发送工作流消息
* @param
msg
* @param
dto
* @return
* @return
*/
*/
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/
SendM
sg"
)
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/
notify/sendm
sg"
)
public
ResponseEntity
<
Boolean
>
SendMsg
(
@Validated
@RequestBody
Msg
msg
){
public
ResponseEntity
<
Boolean
>
sendMsg
(
@Validated
@RequestBody
MsgBodyDTO
dto
){
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
notifyCoreService
.
sendMsg
(
m
sg
));
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
notifyCoreService
.
sendMsg
(
m
apping
.
toDomain
(
dto
)
));
}
}
/**
/**
* 建立消息模板
* 建立消息模板
* @param template
* @param template
* @return
* @return
*/
*/
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/
createMsgTemplate
"
)
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/
notify/createmsgtempl
"
)
public
ResponseEntity
<
Boolean
>
createMsgTemplate
(
@Validated
@RequestBody
Template
template
){
public
ResponseEntity
<
Boolean
>
createMsgTemplate
(
@Validated
@RequestBody
Template
template
){
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
notifyCoreService
.
createMsgTemplate
(
template
));
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
notifyCoreService
.
createMsgTemplate
(
template
));
}
}
/**
/**
* 发送钉钉链接消息
* 发送钉钉链接消息
* @param
msg
* @param
dto
* @return
* @return
*/
*/
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/dingtalk/sendlinkmsg"
)
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/
notify/
dingtalk/sendlinkmsg"
)
public
ResponseEntity
<
Long
>
sendDingTalkLinkMsg
(
@RequestBody
Msg
msg
){
public
ResponseEntity
<
Boolean
>
sendDingTalkLinkMsg
(
@RequestBody
MsgBodyDTO
dto
){
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
notifyCoreService
.
send
LinkMsg
(
msg
));
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
notifyCoreService
.
send
DingTalkLinkMsg
(
mapping
.
toDomain
(
dto
)
));
}
}
/**
/**
* 创建钉钉待办
* 创建钉钉待办
* @param
msg
* @param
dto
* @return
* @return
*/
*/
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/dingtalk/createworkrecord"
)
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/
notify/
dingtalk/createworkrecord"
)
public
ResponseEntity
<
Boolean
>
createDingTalkWorkRecord
(
@RequestBody
Msg
msg
){
public
ResponseEntity
<
String
>
createDingTalkWorkRecord
(
@RequestBody
MsgBodyDTO
dto
){
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
notifyCoreService
.
create
WorkRecord
(
msg
));
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
notifyCoreService
.
create
DingTalkWorkRecord
(
mapping
.
toDomain
(
dto
)
));
}
}
/**
/**
* 完成钉钉待办
* 完成钉钉待办
* @param
msg
* @param
* @return
* @return
*/
*/
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/
dingtalk/finishworkrecord
"
)
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/
notify/dingtalk/finishworkrecord/{msgid}
"
)
public
ResponseEntity
<
Boolean
>
finishDingTalkWorkRecord
(
@
RequestBody
Msg
msg
){
public
ResponseEntity
<
Boolean
>
finishDingTalkWorkRecord
(
@
PathVariable
(
"msgid"
)
String
msgId
){
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
notifyCoreService
.
finish
WorkRecord
(
msg
));
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
notifyCoreService
.
finish
DingTalkWorkRecord
(
msgId
));
}
}
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录