Skip to content

Commit

Permalink
perf: update dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0730 committed Jun 20, 2022
1 parent faea080 commit 994e982
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 64 deletions.
16 changes: 12 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
<dependency>
<groupId>com.hb0730</groupId>
<artifactId>https</artifactId>
<version>3.1.2</version>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
<groupId>com.hb0730</groupId>
<artifactId>jsons</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -72,6 +72,14 @@
<version>1.18.24</version>
<optional>true</optional>
</dependency>


<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/io/github/group/robot/weixin/RobotResult.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.github.group.robot.weixin;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.hb0730.jsons.SimpleJsonProxy;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.Map;

/**
* result
Expand All @@ -19,16 +20,22 @@ public class RobotResult implements Serializable {
/**
* error code
*/
@JsonAlias("errcode")
private Integer errorCode;
/**
* '
* error msg
*/
@JsonAlias("errmsg")
private String errorMsg;

public boolean isSuccess() {
return this.errorCode == 0;
}

public static RobotResult toObject(String json) {
Map resultMap = SimpleJsonProxy.json.fromJson(json, Map.class);
RobotResult result = new RobotResult();
result.setErrorCode(Integer.valueOf(resultMap.get("errcode").toString()));
result.setErrorMsg(resultMap.get("errmsg").toString());
return result;
}
}
16 changes: 7 additions & 9 deletions src/main/java/io/github/group/robot/weixin/RobotSend.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import cn.hutool.core.util.StrUtil;
import com.hb0730.https.HttpHeader;
import com.hb0730.https.Https;
import com.hb0730.https.SimpleHttp;
import com.hb0730.https.constants.Constants;
import com.hb0730.https.inter.SyncHttp;
import com.hb0730.https.support.SimpleHttpResponse;
import io.github.group.robot.weixin.commons.JacksonUtil;
import com.hb0730.jsons.SimpleJsonProxy;
import io.github.group.robot.weixin.exception.WeixiuRobotException;
import io.github.group.robot.weixin.model.Message;
import lombok.Getter;
Expand Down Expand Up @@ -50,19 +49,18 @@ public RobotResult send(Message message) {
throw new WeixiuRobotException("message missing");
}
if (StrUtil.isBlank(this.webhook)) {
throw new WeixiuRobotException("webhook missing");
throw new WeixiuRobotException("url missing");
}
SyncHttp http = Https.SYNC.getHttp();
String body = JacksonUtil.toStr(message.toMessageMap());
SimpleHttpResponse response = http.post(webhook, body,
String jsonStr = SimpleJsonProxy.json.toJson(message.toMessageMap());
SimpleHttpResponse response = SimpleHttp.HTTP.post(webhook, jsonStr,
HttpHeader.builder().add(Constants.CONTENT_TYPE,
Constants.CONTENT_TYPE_JSON_UTF_8));
if (log.isDebugEnabled()) {
log.info("request body:{}", body);
log.info("request body:{}", jsonStr);
log.info("response status: {},body:{}", response.isSuccess(), response.isSuccess() ? response.getBodyStr() :
"");
}
return JacksonUtil.toObj(response.getBodyStr(), RobotResult.class);
return RobotResult.toObject(response.getBodyStr());
}

}

This file was deleted.

0 comments on commit 994e982

Please sign in to comment.