欢迎来到SpringWater的博客

人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。

腾讯企业机器人,异常报警工具类

1.首先先在腾讯企业微信,创建一个多人群,添加机器人

 2、按照步骤完成创建机器人后,会有一个地址,就是工具类中需要的地址url,复制地址

 

 3、直接调用工具类就可以了。

4、工具类具体内容,亲测有用。

/**   
* Copyright © 2020 HK. All rights reserved.
*
* @Title: ChatRobotMessageUtil.java
* @Prject: huida-common
* @Package: com.huida.platform.common.util
* @Description: TODO
* @author: yzh dxx_yzh@163.com
* @date: 2020年2月24日 上午9:44:55
* @version: V1.0
*/
package cn.com.hyundai.mms.chatbot.util;

import cn.com.hyundai.mms.chatbot.dto.SendResult;
import cn.com.hyundai.mms.chatbot.dto.TextMessage;
import cn.com.hyundai.mms.chatbot.WxChatbotClient;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;


import java.util.ArrayList;
import java.util.List;

/**
* @ClassName: ChatRobotMessageUtil
* @Description: TODO
* @author: w
* @date: 2021年5月19日 19:03:10
*/
@Slf4j
public class ChatRobotMessageUtil {

private static WxChatbotClient client = new WxChatbotClient();

@SuppressWarnings("static-access")
public static void robotSendOfTextMessage(String textMessage, String mobilePhone, String robotUrl) throws Exception {
robotSendOfTextMessage(textMessage, mobilePhone, robotUrl, false);
}


public static void robotSendOfTextMessage(String textMessage, String mobilePhone, String robotUrl, Boolean atAll) throws Exception {
log.info("机器人预警信息,请求手机号:{}", mobilePhone);
TextMessage message = new TextMessage(textMessage);
List<String> mentionedMobileList = new ArrayList<String>();
if (atAll) {
message.setIsAtAll(true);
} else {
message.setIsAtAll(false);
if (StringUtils.isNotBlank(mobilePhone)) {
String[] mobileList = mobilePhone.split(",");
log.info("机器人预警信息,分隔完成手机号:{}", JSONObject.toJSON(mobileList));
for (String mobile : mobileList) {
mentionedMobileList.add(mobile);//@群内成员 手机号
}
message.setMentionedMobileList(mentionedMobileList);
}
}
log.info("机器人预警信息,组装预警信息:{}", JSONObject.toJSON(message));
SendResult result = client.send(robotUrl, message);
log.info("机器人发送结果:" + result);
}
}
posted @ 2021-07-23 15:00  骑ZHU看夕阳```  阅读(83)  评论(0编辑  收藏  举报