diff --git a/escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java b/escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java index cc2530826f..9516473697 100644 --- a/escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java +++ b/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 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"; } diff --git a/escheduler-alert/src/main/java/cn/escheduler/alert/utils/QiyeWeixinUtils.java b/escheduler-alert/src/main/java/cn/escheduler/alert/utils/EnterpriseWeChatUtils.java similarity index 75% rename from escheduler-alert/src/main/java/cn/escheduler/alert/utils/QiyeWeixinUtils.java rename to escheduler-alert/src/main/java/cn/escheduler/alert/utils/EnterpriseWeChatUtils.java index 5af6baa4fc..169977b01e 100644 --- a/escheduler-alert/src/main/java/cn/escheduler/alert/utils/QiyeWeixinUtils.java +++ b/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 */ -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 String qiyeWeixinTokenUrlReplace = qiyeWeixinTokenUrl - .replaceAll("\\$weixinCorpId", qiyeWeixinCorpId) - .replaceAll("\\$weixinSecret", qiyeWeixinSecret); + 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 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 @@ -67,7 +67,7 @@ public class QiyeWeixinUtils { String resp; CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpGet httpGet = new HttpGet(qiyeWeixinTokenUrlReplace); + HttpGet httpGet = new HttpGet(enterpriseWeChatTokenUrlReplace); CloseableHttpResponse response = httpClient.execute(httpGet); try { HttpEntity entity = response.getEntity(); @@ -91,7 +91,7 @@ public class QiyeWeixinUtils { * @return weixin send message */ public String makeTeamSendMsg(String toParty, String agentId, String msg) { - return qiyeWeixinTeamSendMsg.replaceAll("\\$toParty", toParty) + return enterpriseWeChatTeamSendMsg.replaceAll("\\$toParty", toParty) .replaceAll("\\$agentId", agentId) .replaceAll("\\$msg", msg); } @@ -105,7 +105,7 @@ public class QiyeWeixinUtils { */ public String makeTeamSendMsg(Collection toParty, String agentId, String msg) { String listParty = FuncUtils.mkString(toParty, "|"); - return qiyeWeixinTeamSendMsg.replaceAll("\\$toParty", listParty) + return enterpriseWeChatTeamSendMsg.replaceAll("\\$toParty", listParty) .replaceAll("\\$agentId", agentId) .replaceAll("\\$msg", msg); } @@ -118,7 +118,7 @@ public class QiyeWeixinUtils { * @return weixin send message */ public String makeUserSendMsg(String toUser, String agentId, String msg) { - return qiyeWeixinUserSendMsg.replaceAll("\\$toUser", toUser) + return enterpriseWeChatUserSendMsg.replaceAll("\\$toUser", toUser) .replaceAll("\\$agentId", agentId) .replaceAll("\\$msg", msg); } @@ -132,7 +132,7 @@ public class QiyeWeixinUtils { */ public String makeUserSendMsg(Collection toUser, String agentId, String msg) { String listUser = FuncUtils.mkString(toUser, "|"); - return qiyeWeixinUserSendMsg.replaceAll("\\$toUser", listUser) + return enterpriseWeChatUserSendMsg.replaceAll("\\$toUser", listUser) .replaceAll("\\$agentId", agentId) .replaceAll("\\$msg", msg); } @@ -146,10 +146,10 @@ public class QiyeWeixinUtils { * @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(); - HttpPost httpPost = new HttpPost(qiyeWeixinPushUrlReplace); + HttpPost httpPost = new HttpPost(enterpriseWeChatPushUrlReplace); httpPost.setEntity(new StringEntity(data, charset)); CloseableHttpResponse response = httpclient.execute(httpPost); String resp; @@ -160,7 +160,7 @@ public class QiyeWeixinUtils { } finally { response.close(); } - logger.info("qiye weixin send [{}], param:{}, resp:{}", qiyeWeixinPushUrl, data, resp); + logger.info("qiye weixin send [{}], param:{}, resp:{}", enterpriseWeChatPushUrl, data, resp); return resp; } diff --git a/escheduler-alert/src/main/resources/alert.properties b/escheduler-alert/src/main/resources/alert.properties index 31265c2200..09bd286b82 100644 --- a/escheduler-alert/src/main/resources/alert.properties +++ b/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=/opt/xls -# qiye weixin configuration -qiye.weixin.corp.id=xxxxxxx -qiye.weixin.secret=xxxxxxx -qiye.weixin.token.url=https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$weixinCorpId&corpsecret=$weixinSecret -qiye.weixin.push.url=https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$weixinToken -qiye.weixin.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 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\"} diff --git a/escheduler-alert/src/test/java/cn/escheduler/alert/utils/QiyeWeixinUtilsTest.java b/escheduler-alert/src/test/java/cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java similarity index 82% rename from escheduler-alert/src/test/java/cn/escheduler/alert/utils/QiyeWeixinUtilsTest.java rename to escheduler-alert/src/test/java/cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java index 051f3bccd1..2a45196aed 100644 --- a/escheduler-alert/src/test/java/cn/escheduler/alert/utils/QiyeWeixinUtilsTest.java +++ b/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. * file: alert.properties - * qiye.weixin.corp.id - * qiye.weixin.secret - * qiye.weixin.token.url - * qiye.weixin.push.url - * qiye.weixin.send.msg + * enterprise.wechat.corp.id + * enterprise.wechat.secret + * enterprise.wechat.token.url + * enterprise.wechat.push.url + * enterprise.wechat.send.msg */ -public class QiyeWeixinUtilsTest { +public class EnterpriseWeChatUtilsTest { // Please change private String agentId = "1000002"; // app id @@ -44,8 +44,8 @@ public class QiyeWeixinUtilsTest { private Collection listUserId = Arrays.asList("test1","test2"); @Test - public void testSendSingleTeamWeixin() { - QiyeWeixinUtils wx = new QiyeWeixinUtils(); + public void testSendSingleTeamWeChat() { + EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils(); try { String token = wx.getToken(); @@ -60,8 +60,8 @@ public class QiyeWeixinUtilsTest { } @Test - public void testSendMultiTeamWeixin() { - QiyeWeixinUtils wx = new QiyeWeixinUtils(); + public void testSendMultiTeamWeChat() { + EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils(); try { String token = wx.getToken(); @@ -76,8 +76,8 @@ public class QiyeWeixinUtilsTest { } @Test - public void testSendSingleUserWeixin() { - QiyeWeixinUtils wx = new QiyeWeixinUtils(); + public void testSendSingleUserWeChat() { + EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils(); try { String token = wx.getToken(); @@ -92,8 +92,8 @@ public class QiyeWeixinUtilsTest { } @Test - public void testSendMultiUserWeixin() { - QiyeWeixinUtils wx = new QiyeWeixinUtils(); + public void testSendMultiUserWeChat() { + EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils(); try { String token = wx.getToken();