mirror of
https://github.com/yanlongqi/jhinno-openapi-java-sdk.git
synced 2026-03-22 06:15:10 +08:00
客户端的优化
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package com.jhinno.sdk.openapi.api;
|
||||
|
||||
import cn.hutool.crypto.symmetric.AES;
|
||||
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.jhinno.sdk.openapi.ArgsException;
|
||||
import com.jhinno.sdk.openapi.CommonConstant;
|
||||
import com.jhinno.sdk.openapi.ServiceException;
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.jhinno.sdk.openapi.api;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author yanlongqi
|
||||
* @date 2024/1/31 10:16
|
||||
*/
|
||||
public class ResponseResult<T> {
|
||||
@Data
|
||||
public class ResponseResult<T> {
|
||||
|
||||
|
||||
/**
|
||||
@@ -27,76 +30,4 @@ public class ResponseResult<T> {
|
||||
*/
|
||||
private T data;
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求编号
|
||||
*
|
||||
* @return 请求编号
|
||||
*/
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求编号
|
||||
*
|
||||
* @param code 请求编号
|
||||
*/
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求状态
|
||||
*
|
||||
* @return 请求状态
|
||||
*/
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求状态
|
||||
*
|
||||
* @param result 请求状态
|
||||
*/
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求信息
|
||||
*
|
||||
* @return 请求信息
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求信息
|
||||
*
|
||||
* @param message 请求信息
|
||||
*/
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求数据
|
||||
*
|
||||
* @return 请求数据
|
||||
*/
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置去就去数据
|
||||
*
|
||||
* @param data 请求数据
|
||||
*/
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.jhinno.sdk.openapi.api.app;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import lombok.Getter;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 会话启动信息
|
||||
@@ -9,7 +8,7 @@ import lombok.Getter;
|
||||
* @author yanlongqi
|
||||
* @date 2024/2/1 18:39
|
||||
*/
|
||||
@Getter
|
||||
@Data
|
||||
public class AppStartedInfo {
|
||||
|
||||
/**
|
||||
@@ -30,9 +29,4 @@ public class AppStartedInfo {
|
||||
* 会话id
|
||||
*/
|
||||
private String desktopId;
|
||||
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return JSON.toJSONString(this);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.jhinno.sdk.openapi.api.app;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.jhinno.sdk.openapi.CommonConstant;
|
||||
import com.jhinno.sdk.openapi.ServiceException;
|
||||
import com.jhinno.sdk.openapi.api.JHApiExecution;
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.jhinno.sdk.openapi.api.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 请求令牌,用户请求其他接口
|
||||
*
|
||||
* @author yanlongqi
|
||||
* @date 2024/1/31 10:30
|
||||
*/
|
||||
@Data
|
||||
public class Token {
|
||||
|
||||
/**
|
||||
@@ -13,21 +16,4 @@ public class Token {
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 获取令牌
|
||||
*
|
||||
* @return 令牌
|
||||
*/
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置令牌
|
||||
*
|
||||
* @param token 令牌
|
||||
*/
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.jhinno.sdk.openapi.client;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jhinno.sdk.openapi.ClientErrorCode;
|
||||
import com.jhinno.sdk.openapi.ClientException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -21,9 +21,9 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.KeyManagementException;
|
||||
@@ -216,8 +216,9 @@ public class JHApiClient {
|
||||
*/
|
||||
public <T> T request(HttpRequestBase httpRequest, Map<String, String> headers, TypeReference<T> type) {
|
||||
try {
|
||||
String result = EntityUtils.toString(request(httpRequest, headers));
|
||||
return type.parseObject(result);
|
||||
InputStream content = request(httpRequest, headers).getContent();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.readValue(content, type);
|
||||
} catch (Exception e) {
|
||||
throw new ClientException(e.getMessage());
|
||||
}
|
||||
@@ -309,7 +310,9 @@ public class JHApiClient {
|
||||
HttpPost httpPost = new HttpPost(baseUrl + path);
|
||||
try {
|
||||
if (body != null) {
|
||||
httpPost.setEntity(new StringEntity(JSONObject.toJSONString(body), "utf-8"));
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String bodyStr = mapper.writeValueAsString(body);
|
||||
httpPost.setEntity(new StringEntity(bodyStr, "utf-8"));
|
||||
}
|
||||
return request(httpPost, headers, type);
|
||||
} catch (Exception e) {
|
||||
@@ -336,7 +339,9 @@ public class JHApiClient {
|
||||
HttpPut httpPost = new HttpPut(baseUrl + path);
|
||||
try {
|
||||
if (body != null) {
|
||||
httpPost.setEntity(new StringEntity(JSONObject.toJSONString(body), "utf-8"));
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String bodyStr = mapper.writeValueAsString(body);
|
||||
httpPost.setEntity(new StringEntity(bodyStr, "utf-8"));
|
||||
}
|
||||
return request(httpPost, headers, type);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.jhinno.sdk.openapi.client;
|
||||
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
|
||||
/**
|
||||
* @author yanlongqi
|
||||
* @date 2024/1/30 19:35
|
||||
*/
|
||||
public class ResultType<T> extends TypeReference<T> {
|
||||
}
|
||||
Reference in New Issue
Block a user