Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
淡淡忧伤的程序员
DolphinScheduler
提交
46459544
DolphinScheduler
项目概览
淡淡忧伤的程序员
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
48
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,发现更多精彩内容 >>
未验证
提交
46459544
编写于
7月 02, 2019
作者:
L
lgcareer
提交者:
GitHub
7月 02, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #288 from feloxx/feature/qiye_weixin
Feature/qiye_weixin.
上级
9ddc9a04
1d624172
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
341 addition
and
0 deletion
+341
-0
escheduler-alert/pom.xml
escheduler-alert/pom.xml
+11
-0
escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java
...rt/src/main/java/cn/escheduler/alert/utils/Constants.java
+12
-0
escheduler-alert/src/main/java/cn/escheduler/alert/utils/EnterpriseWeChatUtils.java
...java/cn/escheduler/alert/utils/EnterpriseWeChatUtils.java
+167
-0
escheduler-alert/src/main/java/cn/escheduler/alert/utils/FuncUtils.java
...rt/src/main/java/cn/escheduler/alert/utils/FuncUtils.java
+34
-0
escheduler-alert/src/main/resources/alert.properties
escheduler-alert/src/main/resources/alert.properties
+7
-0
escheduler-alert/src/test/java/cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java
.../cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java
+110
-0
未找到文件。
escheduler-alert/pom.xml
浏览文件 @
46459544
...
...
@@ -102,6 +102,17 @@
<artifactId>
escheduler-dao
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpcore
</artifactId>
<version>
4.4.6
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5.5
</version>
</dependency>
</dependencies>
<build>
...
...
escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java
浏览文件 @
46459544
...
...
@@ -128,4 +128,16 @@ public class Constants {
public
static
final
String
TH_END
=
"</th>"
;
public
static
final
int
ALERT_SCAN_INTERVEL
=
5000
;
public
static
final
String
ENTERPRISE_WECHAT_CORP_ID
=
"enterprise.wechat.corp.id"
;
public
static
final
String
ENTERPRISE_WECHAT_SECRET
=
"enterprise.wechat.secret"
;
public
static
final
String
ENTERPRISE_WECHAT_TOKEN_URL
=
"enterprise.wechat.token.url"
;
public
static
final
String
ENTERPRISE_WECHAT_PUSH_URL
=
"enterprise.wechat.push.url"
;
public
static
final
String
ENTERPRISE_WECHAT_TEAM_SEND_MSG
=
"enterprise.wechat.team.send.msg"
;
public
static
final
String
ENTERPRISE_WECHAT_USER_SEND_MSG
=
"enterprise.wechat.user.send.msg"
;
}
escheduler-alert/src/main/java/cn/escheduler/alert/utils/EnterpriseWeChatUtils.java
0 → 100644
浏览文件 @
46459544
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn.escheduler.alert.utils
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.reflect.TypeToken
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.Map
;
import
static
cn
.
escheduler
.
alert
.
utils
.
PropertyUtils
.
getString
;
/**
* qiye weixin utils
*/
public
class
EnterpriseWeChatUtils
{
public
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
EnterpriseWeChatUtils
.
class
);
private
static
final
String
enterpriseWeChatCorpId
=
getString
(
Constants
.
ENTERPRISE_WECHAT_CORP_ID
);
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
.
replaceAll
(
"\\$corpId"
,
enterpriseWeChatCorpId
)
.
replaceAll
(
"\\$secret"
,
enterpriseWeChatSecret
);
private
static
final
String
enterpriseWeChatPushUrl
=
getString
(
Constants
.
ENTERPRISE_WECHAT_PUSH_URL
);
private
static
final
String
enterpriseWeChatTeamSendMsg
=
getString
(
Constants
.
ENTERPRISE_WECHAT_TEAM_SEND_MSG
);
private
static
final
String
enterpriseWeChatUserSendMsg
=
getString
(
Constants
.
ENTERPRISE_WECHAT_USER_SEND_MSG
);
/**
* get winxin token info
* @return token string info
* @throws IOException
*/
public
String
getToken
()
throws
IOException
{
String
resp
;
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
HttpGet
httpGet
=
new
HttpGet
(
enterpriseWeChatTokenUrlReplace
);
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpGet
);
try
{
HttpEntity
entity
=
response
.
getEntity
();
resp
=
EntityUtils
.
toString
(
entity
,
"utf-8"
);
EntityUtils
.
consume
(
entity
);
}
finally
{
response
.
close
();
}
Map
<
String
,
Object
>
map
=
JSON
.
parseObject
(
resp
,
new
TypeToken
<
Map
<
String
,
Object
>>()
{
}.
getType
());
return
map
.
get
(
"access_token"
).
toString
();
}
/**
* make team single weixin message
* @param toParty
* @param agentId
* @param msg
* @return weixin send message
*/
public
String
makeTeamSendMsg
(
String
toParty
,
String
agentId
,
String
msg
)
{
return
enterpriseWeChatTeamSendMsg
.
replaceAll
(
"\\$toParty"
,
toParty
)
.
replaceAll
(
"\\$agentId"
,
agentId
)
.
replaceAll
(
"\\$msg"
,
msg
);
}
/**
* make team multi weixin message
* @param toParty
* @param agentId
* @param msg
* @return weixin send message
*/
public
String
makeTeamSendMsg
(
Collection
<
String
>
toParty
,
String
agentId
,
String
msg
)
{
String
listParty
=
FuncUtils
.
mkString
(
toParty
,
"|"
);
return
enterpriseWeChatTeamSendMsg
.
replaceAll
(
"\\$toParty"
,
listParty
)
.
replaceAll
(
"\\$agentId"
,
agentId
)
.
replaceAll
(
"\\$msg"
,
msg
);
}
/**
* make team single user message
* @param toUser
* @param agentId
* @param msg
* @return weixin send message
*/
public
String
makeUserSendMsg
(
String
toUser
,
String
agentId
,
String
msg
)
{
return
enterpriseWeChatUserSendMsg
.
replaceAll
(
"\\$toUser"
,
toUser
)
.
replaceAll
(
"\\$agentId"
,
agentId
)
.
replaceAll
(
"\\$msg"
,
msg
);
}
/**
* make team multi user message
* @param toUser
* @param agentId
* @param msg
* @return weixin send message
*/
public
String
makeUserSendMsg
(
Collection
<
String
>
toUser
,
String
agentId
,
String
msg
)
{
String
listUser
=
FuncUtils
.
mkString
(
toUser
,
"|"
);
return
enterpriseWeChatUserSendMsg
.
replaceAll
(
"\\$toUser"
,
listUser
)
.
replaceAll
(
"\\$agentId"
,
agentId
)
.
replaceAll
(
"\\$msg"
,
msg
);
}
/**
* send weixin
* @param charset
* @param data
* @param token
* @return weixin resp, demo: {"errcode":0,"errmsg":"ok","invaliduser":""}
* @throws IOException
*/
public
String
sendQiyeWeixin
(
String
charset
,
String
data
,
String
token
)
throws
IOException
{
String
enterpriseWeChatPushUrlReplace
=
enterpriseWeChatPushUrl
.
replaceAll
(
"\\$token"
,
token
);
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
HttpPost
httpPost
=
new
HttpPost
(
enterpriseWeChatPushUrlReplace
);
httpPost
.
setEntity
(
new
StringEntity
(
data
,
charset
));
CloseableHttpResponse
response
=
httpclient
.
execute
(
httpPost
);
String
resp
;
try
{
HttpEntity
entity
=
response
.
getEntity
();
resp
=
EntityUtils
.
toString
(
entity
,
charset
);
EntityUtils
.
consume
(
entity
);
}
finally
{
response
.
close
();
}
logger
.
info
(
"qiye weixin send [{}], param:{}, resp:{}"
,
enterpriseWeChatPushUrl
,
data
,
resp
);
return
resp
;
}
}
escheduler-alert/src/main/java/cn/escheduler/alert/utils/FuncUtils.java
0 → 100644
浏览文件 @
46459544
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn.escheduler.alert.utils
;
public
class
FuncUtils
{
static
public
String
mkString
(
Iterable
<
String
>
list
,
String
split
)
{
StringBuilder
sb
=
new
StringBuilder
();
boolean
first
=
true
;
for
(
String
item
:
list
)
{
if
(
first
)
first
=
false
;
else
sb
.
append
(
split
);
sb
.
append
(
item
);
}
return
sb
.
toString
();
}
}
escheduler-alert/src/main/resources/alert.properties
浏览文件 @
46459544
...
...
@@ -16,6 +16,13 @@ mail.smtp.ssl.enable=true
#xls file path,need create if not exist
xls.file.path
=
/tmp/xls
# Enterprise WeChat configuration
enterprise.wechat.corp.id
=
xxxxxxx
enterprise.wechat.secret
=
xxxxxxx
enterprise.wechat.token.url
=
https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpId&corpsecret=$secret
enterprise.wechat.push.url
=
https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$token
enterprise.wechat.team.send.msg
=
{
\"
toparty
\"
:
\"
$toParty
\"
,
\"
agentid
\"
:
\"
$agentId
\"
,
\"
msgtype
\"
:
\"
text
\"
,
\"
text
\"
:{
\"
content
\"
:
\"
$msg
\"
},
\"
safe
\"
:
\"
0
\"
}
enterprise.wechat.user.send.msg
=
{
\"
touser
\"
:
\"
$toUser
\"
,
\"
agentid
\"
:
\"
$agentId
\"
,
\"
msgtype
\"
:
\"
text
\"
,
\"
text
\"
:{
\"
content
\"
:
\"
$msg
\"
},
\"
safe
\"
:
\"
0
\"
}
escheduler-alert/src/test/java/cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java
0 → 100644
浏览文件 @
46459544
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn.escheduler.alert.utils
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
com.alibaba.fastjson.JSON
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.Collection
;
/**
* Please manually modify the configuration file before testing.
* file: alert.properties
* enterprise.wechat.corp.id
* enterprise.wechat.secret
* enterprise.wechat.token.url
* enterprise.wechat.push.url
* enterprise.wechat.send.msg
*/
public
class
EnterpriseWeChatUtilsTest
{
// Please change
private
String
agentId
=
"1000002"
;
// app id
private
String
partyId
=
"2"
;
private
Collection
<
String
>
listPartyId
=
Arrays
.
asList
(
"2"
,
"4"
);
private
String
userId
=
"test1"
;
private
Collection
<
String
>
listUserId
=
Arrays
.
asList
(
"test1"
,
"test2"
);
@Test
public
void
testSendSingleTeamWeChat
()
{
EnterpriseWeChatUtils
wx
=
new
EnterpriseWeChatUtils
();
try
{
String
token
=
wx
.
getToken
();
String
msg
=
wx
.
makeTeamSendMsg
(
partyId
,
agentId
,
"hello world"
);
String
resp
=
wx
.
sendQiyeWeixin
(
"utf-8"
,
msg
,
token
);
String
errmsg
=
JSON
.
parseObject
(
resp
).
getString
(
"errmsg"
);
Assert
.
assertEquals
(
errmsg
,
"ok"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
testSendMultiTeamWeChat
()
{
EnterpriseWeChatUtils
wx
=
new
EnterpriseWeChatUtils
();
try
{
String
token
=
wx
.
getToken
();
String
msg
=
wx
.
makeTeamSendMsg
(
listPartyId
,
agentId
,
"hello world"
);
String
resp
=
wx
.
sendQiyeWeixin
(
"utf-8"
,
msg
,
token
);
String
errmsg
=
JSON
.
parseObject
(
resp
).
getString
(
"errmsg"
);
Assert
.
assertEquals
(
errmsg
,
"ok"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
testSendSingleUserWeChat
()
{
EnterpriseWeChatUtils
wx
=
new
EnterpriseWeChatUtils
();
try
{
String
token
=
wx
.
getToken
();
String
msg
=
wx
.
makeUserSendMsg
(
userId
,
agentId
,
"hello world"
);
String
resp
=
wx
.
sendQiyeWeixin
(
"utf-8"
,
msg
,
token
);
String
errmsg
=
JSON
.
parseObject
(
resp
).
getString
(
"errmsg"
);
Assert
.
assertEquals
(
errmsg
,
"ok"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
testSendMultiUserWeChat
()
{
EnterpriseWeChatUtils
wx
=
new
EnterpriseWeChatUtils
();
try
{
String
token
=
wx
.
getToken
();
String
msg
=
wx
.
makeUserSendMsg
(
listUserId
,
agentId
,
"hello world"
);
String
resp
=
wx
.
sendQiyeWeixin
(
"utf-8"
,
msg
,
token
);
String
errmsg
=
JSON
.
parseObject
(
resp
).
getString
(
"errmsg"
);
Assert
.
assertEquals
(
errmsg
,
"ok"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录