Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
禁878
DolphinScheduler
提交
9cefd2e8
DolphinScheduler
项目概览
禁878
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9cefd2e8
编写于
7月 04, 2019
作者:
L
lgcareer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add markdown style utils
上级
184b21be
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
101 addition
and
20 deletion
+101
-20
escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java
...rt/src/main/java/cn/escheduler/alert/utils/Constants.java
+4
-0
escheduler-alert/src/main/java/cn/escheduler/alert/utils/EnterpriseWeChatUtils.java
...java/cn/escheduler/alert/utils/EnterpriseWeChatUtils.java
+97
-20
未找到文件。
escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java
浏览文件 @
9cefd2e8
...
...
@@ -129,6 +129,10 @@ public class Constants {
public
static
final
int
ALERT_SCAN_INTERVEL
=
5000
;
public
static
final
String
MARKDOWN_QUOTE
=
">"
;
public
static
final
String
MARKDOWN_ENTER
=
"\n"
;
public
static
final
String
ENTERPRISE_WECHAT_CORP_ID
=
"enterprise.wechat.corp.id"
;
public
static
final
String
ENTERPRISE_WECHAT_SECRET
=
"enterprise.wechat.secret"
;
...
...
escheduler-alert/src/main/java/cn/escheduler/alert/utils/EnterpriseWeChatUtils.java
浏览文件 @
9cefd2e8
...
...
@@ -16,9 +16,12 @@
*/
package
cn.escheduler.alert.utils
;
import
cn.escheduler.common.enums.ShowType
;
import
cn.escheduler.dao.model.Alert
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.reflect.TypeToken
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
...
...
@@ -31,13 +34,12 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.Map
;
import
java.util.*
;
import
static
cn
.
escheduler
.
alert
.
utils
.
PropertyUtils
.
getString
;
/**
*
qiye weixin
utils
*
Enterprise WeChat
utils
*/
public
class
EnterpriseWeChatUtils
{
...
...
@@ -48,7 +50,7 @@ public class EnterpriseWeChatUtils {
private
static
final
String
enterpriseWeChatSecret
=
getString
(
Constants
.
ENTERPRISE_WECHAT_SECRET
);
private
static
final
String
enterpriseWeChatTokenUrl
=
getString
(
Constants
.
ENTERPRISE_WECHAT_TOKEN_URL
);
private
String
enterpriseWeChatTokenUrlReplace
=
enterpriseWeChatTokenUrl
private
static
String
enterpriseWeChatTokenUrlReplace
=
enterpriseWeChatTokenUrl
.
replaceAll
(
"\\$corpId"
,
enterpriseWeChatCorpId
)
.
replaceAll
(
"\\$secret"
,
enterpriseWeChatSecret
);
...
...
@@ -59,11 +61,11 @@ public class EnterpriseWeChatUtils {
private
static
final
String
enterpriseWeChatUserSendMsg
=
getString
(
Constants
.
ENTERPRISE_WECHAT_USER_SEND_MSG
);
/**
* get
winxin
token info
* get
Enterprise WeChat
token info
* @return token string info
* @throws IOException
*/
public
String
getToken
()
throws
IOException
{
public
static
String
getToken
()
throws
IOException
{
String
resp
;
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
...
...
@@ -71,7 +73,7 @@ public class EnterpriseWeChatUtils {
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpGet
);
try
{
HttpEntity
entity
=
response
.
getEntity
();
resp
=
EntityUtils
.
toString
(
entity
,
"utf-8"
);
resp
=
EntityUtils
.
toString
(
entity
,
Constants
.
UTF_8
);
EntityUtils
.
consume
(
entity
);
}
finally
{
response
.
close
();
...
...
@@ -84,26 +86,26 @@ public class EnterpriseWeChatUtils {
}
/**
* make team single
weixin
message
* make team single
Enterprise WeChat
message
* @param toParty
* @param agentId
* @param msg
* @return
weixin
send message
* @return
Enterprise WeChat
send message
*/
public
String
makeTeamSendMsg
(
String
toParty
,
String
agentId
,
String
msg
)
{
public
static
String
makeTeamSendMsg
(
String
toParty
,
String
agentId
,
String
msg
)
{
return
enterpriseWeChatTeamSendMsg
.
replaceAll
(
"\\$toParty"
,
toParty
)
.
replaceAll
(
"\\$agentId"
,
agentId
)
.
replaceAll
(
"\\$msg"
,
msg
);
}
/**
* make team multi
weixin
message
* make team multi
Enterprise WeChat
message
* @param toParty
* @param agentId
* @param msg
* @return
weixin
send message
* @return
Enterprise WeChat
send message
*/
public
String
makeTeamSendMsg
(
Collection
<
String
>
toParty
,
String
agentId
,
String
msg
)
{
public
static
String
makeTeamSendMsg
(
Collection
<
String
>
toParty
,
String
agentId
,
String
msg
)
{
String
listParty
=
FuncUtils
.
mkString
(
toParty
,
"|"
);
return
enterpriseWeChatTeamSendMsg
.
replaceAll
(
"\\$toParty"
,
listParty
)
.
replaceAll
(
"\\$agentId"
,
agentId
)
...
...
@@ -115,9 +117,9 @@ public class EnterpriseWeChatUtils {
* @param toUser
* @param agentId
* @param msg
* @return
weixin
send message
* @return
Enterprise WeChat
send message
*/
public
String
makeUserSendMsg
(
String
toUser
,
String
agentId
,
String
msg
)
{
public
static
String
makeUserSendMsg
(
String
toUser
,
String
agentId
,
String
msg
)
{
return
enterpriseWeChatUserSendMsg
.
replaceAll
(
"\\$toUser"
,
toUser
)
.
replaceAll
(
"\\$agentId"
,
agentId
)
.
replaceAll
(
"\\$msg"
,
msg
);
...
...
@@ -128,9 +130,9 @@ public class EnterpriseWeChatUtils {
* @param toUser
* @param agentId
* @param msg
* @return
weixin
send message
* @return
Enterprise WeChat
send message
*/
public
String
makeUserSendMsg
(
Collection
<
String
>
toUser
,
String
agentId
,
String
msg
)
{
public
static
String
makeUserSendMsg
(
Collection
<
String
>
toUser
,
String
agentId
,
String
msg
)
{
String
listUser
=
FuncUtils
.
mkString
(
toUser
,
"|"
);
return
enterpriseWeChatUserSendMsg
.
replaceAll
(
"\\$toUser"
,
listUser
)
.
replaceAll
(
"\\$agentId"
,
agentId
)
...
...
@@ -142,10 +144,10 @@ public class EnterpriseWeChatUtils {
* @param charset
* @param data
* @param token
* @return
weixin
resp, demo: {"errcode":0,"errmsg":"ok","invaliduser":""}
* @return
Enterprise WeChat
resp, demo: {"errcode":0,"errmsg":"ok","invaliduser":""}
* @throws IOException
*/
public
String
sendQiyeWeixin
(
String
charset
,
String
data
,
String
token
)
throws
IOException
{
public
static
String
sendQiyeWeixin
(
String
charset
,
String
data
,
String
token
)
throws
IOException
{
String
enterpriseWeChatPushUrlReplace
=
enterpriseWeChatPushUrl
.
replaceAll
(
"\\$token"
,
token
);
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
...
...
@@ -160,8 +162,83 @@ public class EnterpriseWeChatUtils {
}
finally
{
response
.
close
();
}
logger
.
info
(
"
qiye weixin
send [{}], param:{}, resp:{}"
,
enterpriseWeChatPushUrl
,
data
,
resp
);
logger
.
info
(
"
Enterprise WeChat
send [{}], param:{}, resp:{}"
,
enterpriseWeChatPushUrl
,
data
,
resp
);
return
resp
;
}
/**
* convert table to markdown style
* @param title
* @param content
* @return
*/
public
static
String
markdownTable
(
String
title
,
String
content
){
List
<
LinkedHashMap
>
mapItemsList
=
JSONUtils
.
toList
(
content
,
LinkedHashMap
.
class
);
StringBuilder
contents
=
new
StringBuilder
(
200
);
for
(
LinkedHashMap
mapItems
:
mapItemsList
){
Set
<
Map
.
Entry
<
String
,
String
>>
entries
=
mapItems
.
entrySet
();
Iterator
<
Map
.
Entry
<
String
,
String
>>
iterator
=
entries
.
iterator
();
StringBuilder
t
=
new
StringBuilder
(
String
.
format
(
"`%s`%s"
,
title
,
Constants
.
MARKDOWN_ENTER
));
while
(
iterator
.
hasNext
()){
Map
.
Entry
<
String
,
String
>
entry
=
iterator
.
next
();
t
.
append
(
Constants
.
MARKDOWN_QUOTE
);
t
.
append
(
entry
.
getKey
()).
append
(
":"
).
append
(
entry
.
getValue
());
t
.
append
(
Constants
.
MARKDOWN_ENTER
);
}
contents
.
append
(
t
);
}
return
contents
.
toString
();
}
/**
* convert text to markdown style
* @param title
* @param content
* @return
*/
public
static
String
markdownText
(
String
title
,
String
content
){
if
(
StringUtils
.
isNotEmpty
(
content
)){
List
<
String
>
list
;
try
{
list
=
JSONUtils
.
toList
(
content
,
String
.
class
);
}
catch
(
Exception
e
){
logger
.
error
(
"json format exception"
,
e
);
return
null
;
}
StringBuilder
contents
=
new
StringBuilder
(
100
);
contents
.
append
(
String
.
format
(
"`%s`\n"
,
title
));
for
(
String
str
:
list
){
contents
.
append
(
Constants
.
MARKDOWN_QUOTE
);
contents
.
append
(
str
);
contents
.
append
(
Constants
.
MARKDOWN_ENTER
);
}
return
contents
.
toString
();
}
return
null
;
}
/**
* Determine the mardown style based on the show type of the alert
* @param alert
* @return
*/
public
static
String
markdownByAlert
(
Alert
alert
){
String
result
=
""
;
if
(
alert
.
getShowType
()
==
ShowType
.
TABLE
)
{
result
=
markdownTable
(
alert
.
getTitle
(),
alert
.
getContent
());
}
else
if
(
alert
.
getShowType
()
==
ShowType
.
TEXT
){
result
=
markdownText
(
alert
.
getTitle
(),
alert
.
getContent
());
}
return
result
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录