|
@@ -0,0 +1,53 @@
|
|
|
+package com.tzld.longarticle.recommend.server.util;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.tzld.longarticle.recommend.server.common.HttpPoolFactory;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.client.utils.URIBuilder;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+
|
|
|
+import javax.crypto.Mac;
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.security.InvalidKeyException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+public class LarkRobotUtil {
|
|
|
+
|
|
|
+
|
|
|
+ private static final CloseableHttpClient client = HttpPoolFactory.defaultPool();
|
|
|
+ private static final String URL = "https://open.feishu.cn/open-apis/bot/v2/hook/93787b70-33d3-42c1-beae-c09310c9b38b";
|
|
|
+
|
|
|
+
|
|
|
+ public static void sendMessage(String msg) {
|
|
|
+ sendMessage("text", "公众号自动回复报警:" + msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void sendMessage(String type, String msg) {
|
|
|
+ try {
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("msg_type", type);
|
|
|
+ JSONObject content = new JSONObject();
|
|
|
+ content.put("text", msg);
|
|
|
+ param.put("content", content);
|
|
|
+ HttpPost httpPost = new HttpPost(URL);
|
|
|
+ StringEntity entity = new StringEntity(param.toJSONString(), StandardCharsets.UTF_8);
|
|
|
+ entity.setContentEncoding("UTF-8");
|
|
|
+ entity.setContentType("application/json");
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ client.execute(httpPost);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Lark sendMessage error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|