Browse Source

Change name

pull/2/head
chendapao 6 years ago
parent
commit
1d62417256
  1. 12
      escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java
  2. 38
      escheduler-alert/src/main/java/cn/escheduler/alert/utils/EnterpriseWeChatUtils.java
  3. 14
      escheduler-alert/src/main/resources/alert.properties
  4. 28
      escheduler-alert/src/test/java/cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java

12
escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java

@ -127,15 +127,15 @@ public class Constants {
public static final int ALERT_SCAN_INTERVEL = 5000; public static final int ALERT_SCAN_INTERVEL = 5000;
public static final String QIYE_WEIXIN_CORP_ID = "qiye.weixin.corp.id"; public static final String ENTERPRISE_WECHAT_CORP_ID = "enterprise.wechat.corp.id";
public static final String QIYE_WEIXIN_SECRET = "qiye.weixin.secret"; public static final String ENTERPRISE_WECHAT_SECRET = "enterprise.wechat.secret";
public static final String QIYE_WEIXIN_TOKEN_URL = "qiye.weixin.token.url"; public static final String ENTERPRISE_WECHAT_TOKEN_URL = "enterprise.wechat.token.url";
public static final String QIYE_WEIXIN_PUSH_URL = "qiye.weixin.push.url"; public static final String ENTERPRISE_WECHAT_PUSH_URL = "enterprise.wechat.push.url";
public static final String QIYE_WEIXIN_TEAM_SEND_MSG = "qiye.weixin.team.send.msg"; public static final String ENTERPRISE_WECHAT_TEAM_SEND_MSG = "enterprise.wechat.team.send.msg";
public static final String QIYE_WEIXIN_USER_SEND_MSG = "qiye.weixin.user.send.msg"; public static final String ENTERPRISE_WECHAT_USER_SEND_MSG = "enterprise.wechat.user.send.msg";
} }

38
escheduler-alert/src/main/java/cn/escheduler/alert/utils/QiyeWeixinUtils.java → escheduler-alert/src/main/java/cn/escheduler/alert/utils/EnterpriseWeChatUtils.java

@ -39,24 +39,24 @@ import static cn.escheduler.alert.utils.PropertyUtils.getString;
/** /**
* qiye weixin utils * qiye weixin utils
*/ */
public class QiyeWeixinUtils { public class EnterpriseWeChatUtils {
public static final Logger logger = LoggerFactory.getLogger(QiyeWeixinUtils.class); public static final Logger logger = LoggerFactory.getLogger(EnterpriseWeChatUtils.class);
private static final String qiyeWeixinCorpId = getString(Constants.QIYE_WEIXIN_CORP_ID); private static final String enterpriseWeChatCorpId = getString(Constants.ENTERPRISE_WECHAT_CORP_ID);
private static final String qiyeWeixinSecret = getString(Constants.QIYE_WEIXIN_SECRET); private static final String enterpriseWeChatSecret = getString(Constants.ENTERPRISE_WECHAT_SECRET);
private static final String qiyeWeixinTokenUrl = getString(Constants.QIYE_WEIXIN_TOKEN_URL); private static final String enterpriseWeChatTokenUrl = getString(Constants.ENTERPRISE_WECHAT_TOKEN_URL);
private String qiyeWeixinTokenUrlReplace = qiyeWeixinTokenUrl private String enterpriseWeChatTokenUrlReplace = enterpriseWeChatTokenUrl
.replaceAll("\\$weixinCorpId", qiyeWeixinCorpId) .replaceAll("\\$corpId", enterpriseWeChatCorpId)
.replaceAll("\\$weixinSecret", qiyeWeixinSecret); .replaceAll("\\$secret", enterpriseWeChatSecret);
private static final String qiyeWeixinPushUrl = getString(Constants.QIYE_WEIXIN_PUSH_URL); private static final String enterpriseWeChatPushUrl = getString(Constants.ENTERPRISE_WECHAT_PUSH_URL);
private static final String qiyeWeixinTeamSendMsg = getString(Constants.QIYE_WEIXIN_TEAM_SEND_MSG); private static final String enterpriseWeChatTeamSendMsg = getString(Constants.ENTERPRISE_WECHAT_TEAM_SEND_MSG);
private static final String qiyeWeixinUserSendMsg = getString(Constants.QIYE_WEIXIN_USER_SEND_MSG); private static final String enterpriseWeChatUserSendMsg = getString(Constants.ENTERPRISE_WECHAT_USER_SEND_MSG);
/** /**
* get winxin token info * get winxin token info
@ -67,7 +67,7 @@ public class QiyeWeixinUtils {
String resp; String resp;
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(qiyeWeixinTokenUrlReplace); HttpGet httpGet = new HttpGet(enterpriseWeChatTokenUrlReplace);
CloseableHttpResponse response = httpClient.execute(httpGet); CloseableHttpResponse response = httpClient.execute(httpGet);
try { try {
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
@ -91,7 +91,7 @@ public class QiyeWeixinUtils {
* @return weixin send message * @return weixin send message
*/ */
public String makeTeamSendMsg(String toParty, String agentId, String msg) { public String makeTeamSendMsg(String toParty, String agentId, String msg) {
return qiyeWeixinTeamSendMsg.replaceAll("\\$toParty", toParty) return enterpriseWeChatTeamSendMsg.replaceAll("\\$toParty", toParty)
.replaceAll("\\$agentId", agentId) .replaceAll("\\$agentId", agentId)
.replaceAll("\\$msg", msg); .replaceAll("\\$msg", msg);
} }
@ -105,7 +105,7 @@ public class QiyeWeixinUtils {
*/ */
public String makeTeamSendMsg(Collection<String> toParty, String agentId, String msg) { public String makeTeamSendMsg(Collection<String> toParty, String agentId, String msg) {
String listParty = FuncUtils.mkString(toParty, "|"); String listParty = FuncUtils.mkString(toParty, "|");
return qiyeWeixinTeamSendMsg.replaceAll("\\$toParty", listParty) return enterpriseWeChatTeamSendMsg.replaceAll("\\$toParty", listParty)
.replaceAll("\\$agentId", agentId) .replaceAll("\\$agentId", agentId)
.replaceAll("\\$msg", msg); .replaceAll("\\$msg", msg);
} }
@ -118,7 +118,7 @@ public class QiyeWeixinUtils {
* @return weixin send message * @return weixin send message
*/ */
public String makeUserSendMsg(String toUser, String agentId, String msg) { public String makeUserSendMsg(String toUser, String agentId, String msg) {
return qiyeWeixinUserSendMsg.replaceAll("\\$toUser", toUser) return enterpriseWeChatUserSendMsg.replaceAll("\\$toUser", toUser)
.replaceAll("\\$agentId", agentId) .replaceAll("\\$agentId", agentId)
.replaceAll("\\$msg", msg); .replaceAll("\\$msg", msg);
} }
@ -132,7 +132,7 @@ public class QiyeWeixinUtils {
*/ */
public String makeUserSendMsg(Collection<String> toUser, String agentId, String msg) { public String makeUserSendMsg(Collection<String> toUser, String agentId, String msg) {
String listUser = FuncUtils.mkString(toUser, "|"); String listUser = FuncUtils.mkString(toUser, "|");
return qiyeWeixinUserSendMsg.replaceAll("\\$toUser", listUser) return enterpriseWeChatUserSendMsg.replaceAll("\\$toUser", listUser)
.replaceAll("\\$agentId", agentId) .replaceAll("\\$agentId", agentId)
.replaceAll("\\$msg", msg); .replaceAll("\\$msg", msg);
} }
@ -146,10 +146,10 @@ public class QiyeWeixinUtils {
* @throws IOException * @throws IOException
*/ */
public String sendQiyeWeixin(String charset, String data, String token) throws IOException { public String sendQiyeWeixin(String charset, String data, String token) throws IOException {
String qiyeWeixinPushUrlReplace = qiyeWeixinPushUrl.replaceAll("\\$weixinToken", token); String enterpriseWeChatPushUrlReplace = enterpriseWeChatPushUrl.replaceAll("\\$token", token);
CloseableHttpClient httpclient = HttpClients.createDefault(); CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(qiyeWeixinPushUrlReplace); HttpPost httpPost = new HttpPost(enterpriseWeChatPushUrlReplace);
httpPost.setEntity(new StringEntity(data, charset)); httpPost.setEntity(new StringEntity(data, charset));
CloseableHttpResponse response = httpclient.execute(httpPost); CloseableHttpResponse response = httpclient.execute(httpPost);
String resp; String resp;
@ -160,7 +160,7 @@ public class QiyeWeixinUtils {
} finally { } finally {
response.close(); response.close();
} }
logger.info("qiye weixin send [{}], param:{}, resp:{}", qiyeWeixinPushUrl, data, resp); logger.info("qiye weixin send [{}], param:{}, resp:{}", enterpriseWeChatPushUrl, data, resp);
return resp; return resp;
} }

14
escheduler-alert/src/main/resources/alert.properties

@ -11,13 +11,13 @@ mail.passwd=xxxxxxx
#xls file path,need create if not exist #xls file path,need create if not exist
xls.file.path=/opt/xls xls.file.path=/opt/xls
# qiye weixin configuration # Enterprise WeChat configuration
qiye.weixin.corp.id=xxxxxxx enterprise.wechat.corp.id=xxxxxxx
qiye.weixin.secret=xxxxxxx enterprise.wechat.secret=xxxxxxx
qiye.weixin.token.url=https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$weixinCorpId&corpsecret=$weixinSecret enterprise.wechat.token.url=https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpId&corpsecret=$secret
qiye.weixin.push.url=https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$weixinToken enterprise.wechat.push.url=https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$token
qiye.weixin.team.send.msg={\"toparty\":\"$toParty\",\"agentid\":\"$agentId\",\"msgtype\":\"text\",\"text\":{\"content\":\"$msg\"},\"safe\":\"0\"} enterprise.wechat.team.send.msg={\"toparty\":\"$toParty\",\"agentid\":\"$agentId\",\"msgtype\":\"text\",\"text\":{\"content\":\"$msg\"},\"safe\":\"0\"}
qiye.weixin.user.send.msg={\"touser\":\"$toUser\",\"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\"}

28
escheduler-alert/src/test/java/cn/escheduler/alert/utils/QiyeWeixinUtilsTest.java → escheduler-alert/src/test/java/cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java

@ -28,13 +28,13 @@ import java.util.Collection;
/** /**
* Please manually modify the configuration file before testing. * Please manually modify the configuration file before testing.
* file: alert.properties * file: alert.properties
* qiye.weixin.corp.id * enterprise.wechat.corp.id
* qiye.weixin.secret * enterprise.wechat.secret
* qiye.weixin.token.url * enterprise.wechat.token.url
* qiye.weixin.push.url * enterprise.wechat.push.url
* qiye.weixin.send.msg * enterprise.wechat.send.msg
*/ */
public class QiyeWeixinUtilsTest { public class EnterpriseWeChatUtilsTest {
// Please change // Please change
private String agentId = "1000002"; // app id private String agentId = "1000002"; // app id
@ -44,8 +44,8 @@ public class QiyeWeixinUtilsTest {
private Collection<String> listUserId = Arrays.asList("test1","test2"); private Collection<String> listUserId = Arrays.asList("test1","test2");
@Test @Test
public void testSendSingleTeamWeixin() { public void testSendSingleTeamWeChat() {
QiyeWeixinUtils wx = new QiyeWeixinUtils(); EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils();
try { try {
String token = wx.getToken(); String token = wx.getToken();
@ -60,8 +60,8 @@ public class QiyeWeixinUtilsTest {
} }
@Test @Test
public void testSendMultiTeamWeixin() { public void testSendMultiTeamWeChat() {
QiyeWeixinUtils wx = new QiyeWeixinUtils(); EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils();
try { try {
String token = wx.getToken(); String token = wx.getToken();
@ -76,8 +76,8 @@ public class QiyeWeixinUtilsTest {
} }
@Test @Test
public void testSendSingleUserWeixin() { public void testSendSingleUserWeChat() {
QiyeWeixinUtils wx = new QiyeWeixinUtils(); EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils();
try { try {
String token = wx.getToken(); String token = wx.getToken();
@ -92,8 +92,8 @@ public class QiyeWeixinUtilsTest {
} }
@Test @Test
public void testSendMultiUserWeixin() { public void testSendMultiUserWeChat() {
QiyeWeixinUtils wx = new QiyeWeixinUtils(); EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils();
try { try {
String token = wx.getToken(); String token = wx.getToken();
Loading…
Cancel
Save