|
@@ -9,12 +9,9 @@ import com.winhc.dataworks.flow.touch.bean.DingMsg;
|
|
|
import com.winhc.dataworks.flow.touch.bean.Entry;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import okhttp3.*;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.net.URLEncoder;
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @Author: XuJiakai
|
|
@@ -25,8 +22,7 @@ import java.util.Objects;
|
|
|
@Component
|
|
|
public class DingUtils {
|
|
|
@Autowired
|
|
|
- private OkHttpClient client;
|
|
|
- private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
+ private OkHttpUtils client;
|
|
|
private static final String URL = "https://oapi.dingtalk.com/robot/send?access_token=2773b742b74d84599c4f05f7b42cacd6714b10c33cd4c74402649019fa7e56c8";
|
|
|
@Value("${ding-secret}")
|
|
|
private String dingSecret;
|
|
@@ -43,7 +39,7 @@ public class DingUtils {
|
|
|
Entry<Long, String> sign = getSign();
|
|
|
String query = "×tamp=" + sign.getKey() + "&sign=" + sign.getValue();
|
|
|
try {
|
|
|
- String post = post(URL + query, body);
|
|
|
+ String post = client.post(URL + query, body);
|
|
|
log.info(post);
|
|
|
return post.contains("ok");
|
|
|
} catch (Exception e) {
|
|
@@ -53,26 +49,6 @@ public class DingUtils {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private String post(String url, String json) throws IOException {
|
|
|
- RequestBody body = RequestBody.create(JSON, json);
|
|
|
- try (Response response = client.newCall((new Request.Builder()).url(url).post(body).build()).execute()) {
|
|
|
- return parseBody(response);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return "";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private String get(String url) throws IOException {
|
|
|
- try (Response response = client.newCall(new Request.Builder().url(url).get().build()).execute()) {
|
|
|
- return parseBody(response);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static String parseBody(Response response) throws IOException {
|
|
|
- return response == null ? "" : response.isSuccessful() ? Objects.requireNonNull(response.body()).string() : "";
|
|
|
- }
|
|
|
-
|
|
|
private static String getMdBody(String msg) {
|
|
|
return String.format("{\"msgtype\":\"markdown\",\"markdown\":{\"title\":\"%s\",\"text\":\"%s\"}}", "任务通知", DingMsg.msg2Md(msg));
|
|
|
}
|