腾讯企业机器人,异常报警工具类
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);
}
}
作者:SpringWater
出处:https://www.cnblogs.com/springwater/
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
博主的文章没有高度、深度和广度,只是凑字数。由于博主的水平不高,不足和错误之处在所难免,希望大家能够批评指出。
博主是利用读书、参考、引用、抄袭、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个无耻的文档搬运工!