jyy
2021-03-16 2511686fa3bcc154dad551a4bc8ef6839037a8c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.matrix.core.tools;
 
import java.io.IOException;
import java.util.List;
 
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
 
/**
 * 钉钉机器人工具
 * 
 * @author 李广林
 * @email 935090232@qq.com
 * @date 2018年5月9日
 */
public class ExceptionReportUtil {
 
    public static void sendMsg(String exceptionCenterUrl , String content) {
        HttpClient httpclient = HttpClients.createDefault();
        HttpPost httppost = new HttpPost(exceptionCenterUrl);
        httppost.addHeader("Content-Type", "application/x-www-form-urlencoded");
        try {
            StringEntity se = new StringEntity(content, "utf-8");
            se.setContentType("application/x-www-form-urlencoded");
            httppost.setEntity(se);
            HttpResponse response;
            response = httpclient.execute(httppost);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                String result = EntityUtils.toString(response.getEntity(), "utf-8");
                LogUtil.debug("消息发送结果=" + result);
 
            } else {
                LogUtil.info("消息发送失败网络错误 状态码={}", response.getStatusLine().getStatusCode());
            }
        } catch (IOException e) {
            LogUtil.error("消息发送失败", e, "");
        }
    }
 
 
 
}