🔥 弃用 hutool 的json处理器
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package com.hccake.extend.dingtalk;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 钉钉返回信息
|
||||
@@ -12,16 +15,26 @@ import lombok.Setter;
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
public class DingTalkResponse {
|
||||
|
||||
public static final String SUCCESS_CODE = "0";
|
||||
public static final Long SUCCESS_CODE = 0L;
|
||||
|
||||
private String errCode;
|
||||
@SneakyThrows
|
||||
public DingTalkResponse(String res) {
|
||||
Map resMap = new ObjectMapper().readValue(res.getBytes(), Map.class);
|
||||
this.response = res;
|
||||
this.code = Convert.toLong(resMap.get("errcode"));
|
||||
this.message = Convert.toStr(resMap.get("errmsg"));
|
||||
this.success = SUCCESS_CODE.equals(this.code);
|
||||
}
|
||||
|
||||
private Long code;
|
||||
|
||||
/**
|
||||
* 值为ok表示无异常
|
||||
*/
|
||||
private String errMsg;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 钉钉返回信息
|
||||
@@ -33,16 +46,6 @@ public class DingTalkResponse {
|
||||
*/
|
||||
private boolean success;
|
||||
|
||||
public static DingTalkResponse getInstance(String res) {
|
||||
JSONObject json = JSONUtil.parseObj(res);
|
||||
DingTalkResponse response = new DingTalkResponse();
|
||||
response.errCode = json.getStr("errcode");
|
||||
response.errMsg = json.getStr("errmsg");
|
||||
response.response = res;
|
||||
response.success = SUCCESS_CODE.equalsIgnoreCase(response.errCode);
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return response;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class DingTalkSender {
|
||||
* @author lingting 2020-06-11 00:09:23
|
||||
*/
|
||||
public DingTalkResponse sendNormalMessage(DingTalkMessage message) {
|
||||
return DingTalkResponse.getInstance(request.body(message.generate()).execute().body());
|
||||
return new DingTalkResponse(request.body(message.generate()).execute().body());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +79,7 @@ public class DingTalkSender {
|
||||
*/
|
||||
@SneakyThrows
|
||||
public DingTalkResponse sendSecretMessage(DingTalkMessage message) {
|
||||
return DingTalkResponse.getInstance(
|
||||
return new DingTalkResponse(
|
||||
request.setUrl(secret(System.currentTimeMillis())).body(message.generate()).execute().body());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user