提交 b0acf056 作者: 沈振路

链接被替换时发送报警

上级 6abc7608
package com.yaoyaozw.customer.dto;
import lombok.Data;
import java.util.List;
/**
* @Author: Dwl
* @Date: 2024/09/09/12:17
* @ClassName: WoComDTO
* @Version: V3.2.0
* @Description: 文本类型请求模型
*/
@Data
public class WeChatTextDTO {
private static final String TEXT = "text";
private String msgtype = TEXT;
private Text text;
public WeChatTextDTO cover(String content, List<String> openList, List<String> openIdList) {
WeChatTextDTO woComTextDTO = new WeChatTextDTO();
this.text = new Text();
this.text.setContent(content);
if (openList != null && !openList.isEmpty()) {
this.text.setMentioned_mobile_list(openList);
}
if (openIdList != null && !openIdList.isEmpty()) {
this.text.setMentioned_list(openIdList);
}
woComTextDTO.setText(this.text);
return woComTextDTO;
}
@Data
private static class Text {
private String content;
private List<String> mentioned_mobile_list;
private List<String> mentioned_list;
}
}
...@@ -3,12 +3,14 @@ package com.yaoyaozw.customer.listener; ...@@ -3,12 +3,14 @@ package com.yaoyaozw.customer.listener;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.dto.AcquisitionExceptionHandleParam; import com.yaoyaozw.customer.dto.AcquisitionExceptionHandleParam;
import com.yaoyaozw.customer.dto.WeChatTextDTO;
import com.yaoyaozw.customer.entity.AuthorizerInfo; import com.yaoyaozw.customer.entity.AuthorizerInfo;
import com.yaoyaozw.customer.entity.CustomerGraphicsDelay; import com.yaoyaozw.customer.entity.CustomerGraphicsDelay;
import com.yaoyaozw.customer.entity.ReferralEntity; import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.event.AcquisitionExceptionEvent; import com.yaoyaozw.customer.event.AcquisitionExceptionEvent;
import com.yaoyaozw.customer.service.CustomerGraphicsDelayService; import com.yaoyaozw.customer.service.CustomerGraphicsDelayService;
import com.yaoyaozw.customer.service.ReferralEntityService; import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.utils.WeChatUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
...@@ -86,11 +88,20 @@ public class DelayCustomerAcquisitionListener implements ApplicationListener<Acq ...@@ -86,11 +88,20 @@ public class DelayCustomerAcquisitionListener implements ApplicationListener<Acq
updateReferralList.add(item); updateReferralList.add(item);
} }
}); });
boolean update = false;
if (CollectionUtil.isNotEmpty(updateGraphicsList)) { if (CollectionUtil.isNotEmpty(updateGraphicsList)) {
customerGraphicsDelayService.updateBatchById(updateGraphicsList); customerGraphicsDelayService.updateBatchById(updateGraphicsList);
update = true;
} }
if (CollectionUtil.isNotEmpty(updateReferralList)) { if (CollectionUtil.isNotEmpty(updateReferralList)) {
referralEntityService.updateBatchById(updateReferralList); referralEntityService.updateBatchById(updateReferralList);
update = true;
}
if (update) {
// 发送报警信息
String msg = "【延时客服-获客链接替换】公众号:" + authorizerInfo.getAppid() + " 获客链接:" + fromPath + " 已被替换为:" + toPath;
WeChatTextDTO cover = new WeChatTextDTO().cover(msg, null, null);
WeChatUtils.sendErrorMessage(cover, "9934244e-9694-4a0c-95dd-ddd6ca4bd959");
} }
} }
......
...@@ -3,6 +3,7 @@ package com.yaoyaozw.customer.listener; ...@@ -3,6 +3,7 @@ package com.yaoyaozw.customer.listener;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.dto.AcquisitionExceptionHandleParam; import com.yaoyaozw.customer.dto.AcquisitionExceptionHandleParam;
import com.yaoyaozw.customer.dto.WeChatTextDTO;
import com.yaoyaozw.customer.entity.AuthorizerInfo; import com.yaoyaozw.customer.entity.AuthorizerInfo;
import com.yaoyaozw.customer.entity.CustomerFollowReply; import com.yaoyaozw.customer.entity.CustomerFollowReply;
import com.yaoyaozw.customer.entity.ReferralEntity; import com.yaoyaozw.customer.entity.ReferralEntity;
...@@ -10,6 +11,7 @@ import com.yaoyaozw.customer.event.AcquisitionExceptionEvent; ...@@ -10,6 +11,7 @@ import com.yaoyaozw.customer.event.AcquisitionExceptionEvent;
import com.yaoyaozw.customer.service.CustomerFollowReplyService; import com.yaoyaozw.customer.service.CustomerFollowReplyService;
import com.yaoyaozw.customer.service.CustomerFollowReplyService; import com.yaoyaozw.customer.service.CustomerFollowReplyService;
import com.yaoyaozw.customer.service.ReferralEntityService; import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.utils.WeChatUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
...@@ -89,14 +91,25 @@ public class FollowReplyAcquisitionListener implements ApplicationListener<Acqui ...@@ -89,14 +91,25 @@ public class FollowReplyAcquisitionListener implements ApplicationListener<Acqui
updateReferralList.add(item); updateReferralList.add(item);
} }
}); });
boolean update = false;
if (CollectionUtil.isNotEmpty(updateGraphicsList)) { if (CollectionUtil.isNotEmpty(updateGraphicsList)) {
customerFollowReplyService.updateBatchById(updateGraphicsList); customerFollowReplyService.updateBatchById(updateGraphicsList);
update = true;
} }
if (CollectionUtil.isNotEmpty(updateReferralList)) { if (CollectionUtil.isNotEmpty(updateReferralList)) {
referralEntityService.updateBatchById(updateReferralList); referralEntityService.updateBatchById(updateReferralList);
update = true;
} }
// 刷新缓存数据 // 刷新缓存数据
customerFollowReplyService.putMaterialToRedis(authorizerInfo.getAppid(), null); customerFollowReplyService.putMaterialToRedis(authorizerInfo.getAppid(), null);
if (update) {
// 发送报警信息
String msg = "【关回-获客链接替换】公众号:" + authorizerInfo.getAppid() + " 获客链接:" + fromPath + " 已被替换为:" + toPath;
WeChatTextDTO cover = new WeChatTextDTO().cover(msg, null, null);
WeChatUtils.sendErrorMessage(cover, "9934244e-9694-4a0c-95dd-ddd6ca4bd959");
}
} }
} }
...@@ -3,6 +3,7 @@ package com.yaoyaozw.customer.listener; ...@@ -3,6 +3,7 @@ package com.yaoyaozw.customer.listener;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.dto.AcquisitionExceptionHandleParam; import com.yaoyaozw.customer.dto.AcquisitionExceptionHandleParam;
import com.yaoyaozw.customer.dto.WeChatTextDTO;
import com.yaoyaozw.customer.entity.AuthorizerInfo; import com.yaoyaozw.customer.entity.AuthorizerInfo;
import com.yaoyaozw.customer.entity.CustomerGraphicsDelay; import com.yaoyaozw.customer.entity.CustomerGraphicsDelay;
import com.yaoyaozw.customer.entity.CustomerKeyword; import com.yaoyaozw.customer.entity.CustomerKeyword;
...@@ -10,6 +11,7 @@ import com.yaoyaozw.customer.entity.ReferralEntity; ...@@ -10,6 +11,7 @@ import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.event.AcquisitionExceptionEvent; import com.yaoyaozw.customer.event.AcquisitionExceptionEvent;
import com.yaoyaozw.customer.service.CustomerKeywordService; import com.yaoyaozw.customer.service.CustomerKeywordService;
import com.yaoyaozw.customer.service.ReferralEntityService; import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.utils.WeChatUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
...@@ -88,13 +90,24 @@ public class KeywordAcquisitionListener implements ApplicationListener<Acquisiti ...@@ -88,13 +90,24 @@ public class KeywordAcquisitionListener implements ApplicationListener<Acquisiti
updateReferralList.add(item); updateReferralList.add(item);
} }
}); });
boolean update = false;
if (CollectionUtil.isNotEmpty(updateGraphicsList)) { if (CollectionUtil.isNotEmpty(updateGraphicsList)) {
customerKeywordService.updateBatchById(updateGraphicsList); customerKeywordService.updateBatchById(updateGraphicsList);
update = true;
} }
if (CollectionUtil.isNotEmpty(updateReferralList)) { if (CollectionUtil.isNotEmpty(updateReferralList)) {
referralEntityService.updateBatchById(updateReferralList); referralEntityService.updateBatchById(updateReferralList);
update = true;
} }
// 刷新缓存数据 // 刷新缓存数据
customerKeywordService.putMaterialToRedis(authorizerInfo.getAppid()); customerKeywordService.putMaterialToRedis(authorizerInfo.getAppid());
if (update) {
// 发送报警信息
String msg = "【关键词-获客链接替换】公众号:" + authorizerInfo.getAppid() + " 获客链接:" + fromPath + " 已被替换为:" + toPath;
WeChatTextDTO cover = new WeChatTextDTO().cover(msg, null, null);
WeChatUtils.sendErrorMessage(cover, "9934244e-9694-4a0c-95dd-ddd6ca4bd959");
}
} }
} }
package com.yaoyaozw.customer.utils; package com.yaoyaozw.customer.utils;
import cn.hutool.core.lang.UUID; import cn.hutool.core.lang.UUID;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
...@@ -593,4 +595,102 @@ public class HttpClientUtil { ...@@ -593,4 +595,102 @@ public class HttpClientUtil {
} }
return result.toString(); return result.toString();
} }
public static <T> T allElementPost(String url, String json, Map<String, String> urlParams, Map<String, String> headers, Class<T> responseClass) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse httpResponse = null;
String resultString = "";
try {
// 创建uri
URIBuilder builder = new URIBuilder(url);
if (urlParams != null) {
for (Map.Entry<String, String> param : urlParams.entrySet()) {
builder.addParameter(param.getKey(), param.getValue());
}
}
URI uri = builder.build();
//创建post方法连接实例,在post方法中传入待连接地址
HttpPost httpPost = new HttpPost(uri);
if (headers != null) {
// 设置请求头
for (Map.Entry<String, String> head : headers.entrySet()) {
httpPost.addHeader(head.getKey(), head.getValue());
}
}
// 创建请求内容
if (json != null) {
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
}
// 执行http请求
httpResponse = httpClient.execute(httpPost);
resultString = EntityUtils.toString(httpResponse.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpResponse != null) {
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (StringUtils.isNotEmpty(resultString) && responseClass != null) {
return JSONUtil.toBean(resultString, responseClass);
}
return null;
}
public static <T> T allElementGet(String url, Map<String, String> urlParams, Map<String, String> headers, Class<T> responseClass) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse httpResponse = null;
String resultString = "";
try {
// 创建uri
URIBuilder builder = new URIBuilder(url);
if (urlParams != null) {
for (Map.Entry<String, String> param : urlParams.entrySet()) {
builder.addParameter(param.getKey(), param.getValue());
}
}
URI uri = builder.build();
//创建post方法连接实例,在post方法中传入待连接地址
HttpGet httpGet = new HttpGet(uri);
if (headers != null) {
// 设置请求头
for (Map.Entry<String, String> head : headers.entrySet()) {
httpGet.addHeader(head.getKey(), head.getValue());
}
}
// 执行http请求
httpResponse = httpClient.execute(httpGet);
resultString = EntityUtils.toString(httpResponse.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpResponse != null) {
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (StringUtils.isNotEmpty(resultString) && responseClass != null) {
return JSONUtil.toBean(resultString, responseClass);
}
return null;
}
} }
package com.yaoyaozw.customer.utils;
import cn.hutool.json.JSONUtil;
import com.yaoyaozw.customer.dto.WeChatTextDTO;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: Dwl
* @Date: 2024/09/09/12:10
* @ClassName: WoComUtils
* @Version: V3.2.0
* @Description:
*/
@Slf4j
public class WeChatUtils {
private static final String WO_COM_API_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send";
private static Map<String, String> getParams(String key) {
Map<String, String> headers = new HashMap<>();
headers.put("key", key);
return headers;
}
public static void sendErrorMessage(String message, String key) {
Map<String, String> params = getParams(key);
try {
String s = HttpClientUtil.allElementPost(WO_COM_API_URL, message, params, null, String.class);
log.info("sendErrorMessage response: {}", s);
} catch (Exception e) {
log.error("sendErrorMessage error: {}", e.getMessage());
}
}
public static void sendErrorMessage(WeChatTextDTO woComDTO, String key) {
log.info("报警机器人请求参数: {}", JSONUtil.toJsonStr(woComDTO));
sendErrorMessage(JSONUtil.toJsonStr(woComDTO), key);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论