[Feature-7460][Alert] Wechat alert add send to group chat (#7465)
* feature_7460 * feature_7460 Co-authored-by: SbloodyS <sbloodys@qq.com>
This commit is contained in:
parent
fc162826d9
commit
86b476a160
|
|
@ -76,6 +76,13 @@ public final class WeChatAlertChannelFactory implements AlertChannelFactory {
|
|||
.build())
|
||||
.build();
|
||||
|
||||
RadioParam sendType = RadioParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_SEND_TYPE, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_SEND_TYPE)
|
||||
.addParamsOptions(new ParamsOptions(WeChatType.APP.getDescp(), WeChatType.APP.getDescp(), false))
|
||||
.addParamsOptions(new ParamsOptions(WeChatType.APPCHAT.getDescp(), WeChatType.APPCHAT.getDescp(), false))
|
||||
.setValue(WeChatType.APP.getDescp())
|
||||
.addValidate(Validate.newBuilder().setRequired(true).build())
|
||||
.build();
|
||||
|
||||
RadioParam showType = RadioParam.newBuilder(AlertConstants.NAME_SHOW_TYPE, AlertConstants.SHOW_TYPE)
|
||||
.addParamsOptions(new ParamsOptions(ShowType.TABLE.getDescp(), ShowType.TABLE.getDescp(), false))
|
||||
.addParamsOptions(new ParamsOptions(ShowType.TEXT.getDescp(), ShowType.TEXT.getDescp(), false))
|
||||
|
|
@ -83,7 +90,7 @@ public final class WeChatAlertChannelFactory implements AlertChannelFactory {
|
|||
.addValidate(Validate.newBuilder().setRequired(true).build())
|
||||
.build();
|
||||
|
||||
return Arrays.asList(corpIdParam, secretParam, usersParam, userSendMsgParam, agentIdParam, showType);
|
||||
return Arrays.asList(corpIdParam, secretParam, usersParam, userSendMsgParam, agentIdParam, sendType, showType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ public final class WeChatAlertConstants {
|
|||
|
||||
static final String WE_CHAT_PUSH_URL = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={token}";
|
||||
|
||||
static final String WE_CHAT_APP_CHAT_PUSH_URL = "https://qyapi.weixin.qq.com/cgi-bin/appchat/send?access_token" +
|
||||
"={token}";
|
||||
|
||||
static final String WE_CHAT_TOKEN_URL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpId}&corpsecret={secret}";
|
||||
|
||||
private WeChatAlertConstants() {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ public final class WeChatAlertParamsConstants {
|
|||
static final String ENTERPRISE_WE_CHAT_USERS = "$t('users')";
|
||||
static final String NAME_ENTERPRISE_WE_CHAT_USERS = "users";
|
||||
|
||||
static final String NAME_ENTERPRISE_WE_CHAT_SEND_TYPE = "sendType";
|
||||
|
||||
static final String ENTERPRISE_WE_CHAT_SEND_TYPE = "send.type";
|
||||
|
||||
private WeChatAlertParamsConstants() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ public final class WeChatSender {
|
|||
private final String weChatUserSendMsg;
|
||||
private final String weChatTokenUrlReplace;
|
||||
private final String weChatToken;
|
||||
private final String sendType;
|
||||
private final String showType;
|
||||
|
||||
WeChatSender(Map<String, String> config) {
|
||||
|
|
@ -72,6 +73,7 @@ public final class WeChatSender {
|
|||
String weChatSecret = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_SECRET);
|
||||
String weChatTokenUrl = WeChatAlertConstants.WE_CHAT_TOKEN_URL;
|
||||
weChatUserSendMsg = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USER_SEND_MSG);
|
||||
sendType = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_SEND_TYPE);
|
||||
showType = config.get(AlertConstants.NAME_SHOW_TYPE);
|
||||
requireNonNull(showType, AlertConstants.NAME_SHOW_TYPE + MUST_NOT_NULL);
|
||||
weChatTokenUrlReplace = weChatTokenUrl
|
||||
|
|
@ -257,7 +259,12 @@ public final class WeChatSender {
|
|||
alertResult.setStatus(ALERT_STATUS);
|
||||
return alertResult;
|
||||
}
|
||||
String enterpriseWeChatPushUrlReplace = WeChatAlertConstants.WE_CHAT_PUSH_URL.replace(TOKEN_REGEX, weChatToken);
|
||||
String enterpriseWeChatPushUrlReplace = "";
|
||||
if (sendType.equals(WeChatType.APP.getDescp())) {
|
||||
enterpriseWeChatPushUrlReplace = WeChatAlertConstants.WE_CHAT_PUSH_URL.replace(TOKEN_REGEX, weChatToken);
|
||||
} else if (sendType.equals(WeChatType.APPCHAT.getDescp())) {
|
||||
enterpriseWeChatPushUrlReplace = WeChatAlertConstants.WE_CHAT_APP_CHAT_PUSH_URL.replace(TOKEN_REGEX, weChatToken);
|
||||
}
|
||||
|
||||
try {
|
||||
return checkWeChatSendMsgResult(post(enterpriseWeChatPushUrlReplace, msg));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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 org.apache.dolphinscheduler.plugin.alert.wechat;
|
||||
|
||||
public enum WeChatType {
|
||||
APP(1, "应用"),
|
||||
APPCHAT(2, "群聊"),
|
||||
;
|
||||
|
||||
private final int code;
|
||||
private final String descp;
|
||||
|
||||
WeChatType(int code, String descp) {
|
||||
this.code = code;
|
||||
this.descp = descp;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescp() {
|
||||
return descp;
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ public class WeChatAlertChannelFactoryTest {
|
|||
WeChatAlertChannelFactory weChatAlertChannelFactory = new WeChatAlertChannelFactory();
|
||||
List<PluginParams> params = weChatAlertChannelFactory.params();
|
||||
JSONUtils.toJsonString(params);
|
||||
Assert.assertEquals(6, params.size());
|
||||
Assert.assertEquals(7, params.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue