You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/03/28 01:38:13 UTC

[GitHub] [dolphinscheduler] caishunfeng commented on a change in pull request #9225: [Bug] [ALERT-9224] fix wechat alert functions: app and group chat

caishunfeng commented on a change in pull request #9225:
URL: https://github.com/apache/dolphinscheduler/pull/9225#discussion_r836000229



##########
File path: dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WechatAppMessage.java
##########
@@ -0,0 +1,83 @@
+package org.apache.dolphinscheduler.plugin.alert.wechat;

Review comment:
       need license header

##########
File path: dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java
##########
@@ -228,46 +222,36 @@ private static AlertResult checkWeChatSendMsgResult(String result) {
         return alertResult;
     }
 
-    /**
-     * make user multi user message
-     *
-     * @param toUser the toUser
-     * @param agentId the agentId
-     * @param msg the msg
-     * @return Enterprise WeChat send message
-     */
-    private String makeUserSendMsg(Collection<String> toUser, String agentId, String msg) {
-        String listUser = mkString(toUser);
-        return weChatUserSendMsg.replace(USER_REG_EXP, listUser)
-                                .replace(AGENT_ID_REG_EXP, agentId)
-                                .replace(MSG_REG_EXP, msg);
-    }
-
     /**
      * send Enterprise WeChat
      *
      * @return Enterprise WeChat resp, demo: {"errcode":0,"errmsg":"ok","invaliduser":""}
      */
     public AlertResult sendEnterpriseWeChat(String title, String content) {
         AlertResult alertResult;
-        List<String> userList = Arrays.asList(weChatUsers.split(","));
         String data = markdownByAlert(title, content);
-        String msg = makeUserSendMsg(userList, weChatAgentId, data);
         if (null == weChatToken) {
             alertResult = new AlertResult();
             alertResult.setMessage("send we chat alert fail,get weChat token error");
             alertResult.setStatus(ALERT_STATUS);
             return alertResult;
         }
         String enterpriseWeChatPushUrlReplace = "";
+        Map<String,String> contentMap=new HashMap<>();
+        contentMap.put(WeChatAlertConstants.WE_CHAT_CONTENT_KEY,data);
+        String msgJson="";
         if (sendType.equals(WeChatType.APP.getDescp())) {
             enterpriseWeChatPushUrlReplace = WeChatAlertConstants.WE_CHAT_PUSH_URL.replace(TOKEN_REGEX, weChatToken);
+            WechatAppMessage wechatAppMessage=new WechatAppMessage(weChatUsers, WE_CHAT_MESSAGE_TYPE_TEXT, Integer.valueOf(weChatAgentId),contentMap, WE_CHAT_MESSAGE_SAFE_PUBLICITY, WE_CHAT_ENABLE_ID_TRANS, WE_CHAT_DUPLICATE_CHECK_INTERVAL_ZERO);
+            msgJson=JSONUtils.toJsonString(wechatAppMessage);
         } else if (sendType.equals(WeChatType.APPCHAT.getDescp())) {
             enterpriseWeChatPushUrlReplace = WeChatAlertConstants.WE_CHAT_APP_CHAT_PUSH_URL.replace(TOKEN_REGEX, weChatToken);
+            WechatAppChatMessage wechatAppChatMessage=new WechatAppChatMessage(weChatChatId, WE_CHAT_MESSAGE_TYPE_TEXT, contentMap, WE_CHAT_MESSAGE_SAFE_PUBLICITY);
+            msgJson=JSONUtils.toJsonString(wechatAppChatMessage);
         }
 

Review comment:
       ```suggestion
   if (StringUtils.isEmpty(msgJson)) {
       // 
   }
   ```

##########
File path: dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WechatAppChatMessage.java
##########
@@ -0,0 +1,53 @@
+package org.apache.dolphinscheduler.plugin.alert.wechat;

Review comment:
       need license header




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org