This commit is contained in:
tanghc
2019-07-26 17:36:09 +08:00
parent d42c9e9ba4
commit fdf9f341fd
50 changed files with 262 additions and 46 deletions

View File

@@ -44,14 +44,17 @@ public class OpenHttp {
protected void initHttpClient(OpenConfig openConfig) {
httpClient = new OkHttpClient.Builder()
.connectTimeout(openConfig.getConnectTimeoutSeconds(), TimeUnit.SECONDS) // 设置链接超时时间默认10秒
// 设置链接超时时间
.connectTimeout(openConfig.getConnectTimeoutSeconds(), TimeUnit.SECONDS)
.readTimeout(openConfig.getReadTimeoutSeconds(), TimeUnit.SECONDS)
.writeTimeout(openConfig.getWriteTimeoutSeconds(), TimeUnit.SECONDS)
.cookieJar(new CookieJar() {
@Override
public void saveFromResponse(HttpUrl httpUrl, List<Cookie> list) {
cookieStore.put(httpUrl.host(), list);
}
@Override
public List<Cookie> loadForRequest(HttpUrl httpUrl) {
List<Cookie> cookies = cookieStore.get(httpUrl.host());
return cookies != null ? cookies : new ArrayList<Cookie>();
@@ -79,8 +82,9 @@ public class OpenHttp {
/**
* 请求json数据contentType=application/json
* @param url 请求路径
* @param json json数据
*
* @param url 请求路径
* @param json json数据
* @param header header
* @return 返回响应结果
* @throws IOException
@@ -188,9 +192,14 @@ public class OpenHttp {
bodyBuilder.setType(MultipartBody.FORM);
for (UploadFile uploadFile : files) {
bodyBuilder.addFormDataPart(uploadFile.getName(), // 请求的名字
uploadFile.getFileName(), // 文件的文字,服务器端用来解析的
RequestBody.create(null, uploadFile.getFileData()) // 创建RequestBody把上传的文件放入
bodyBuilder.addFormDataPart(
// 请求的名字
uploadFile.getName(),
// 文件的文字,服务器端用来解析的
uploadFile.getFileName(),
// 创建RequestBody把上传的文件放入
RequestBody.create(null, uploadFile.getFileData())
);
}

View File

@@ -6,6 +6,10 @@ import lombok.Setter;
import java.util.List;
import java.util.Map;
/**
* 请求form
* @author thc
*/
@Getter
@Setter
public class RequestForm {

View File

@@ -1,5 +1,9 @@
package com.gitee.sop.sdk.common;
/**
* 请求方法枚举
* @author thc
*/
public enum RequestMethod {
GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE

View File

@@ -2,6 +2,7 @@ package com.gitee.sop.sdk.common;
/**
* @deprecated 已废弃使用com.gitee.sop.sdk.common.OpenConfig
* @author thc
*/
@Deprecated
public class SdkConfig {

View File

@@ -1,5 +1,8 @@
package com.gitee.sop.sdk.common;
/**
* @author thc
*/
public class SopSdkConstants {
public static String DATA_SUFFIX = "_response";

View File

@@ -1,5 +1,8 @@
package com.gitee.sop.sdk.exception;
/**
* @author thc
*/
public class SdkException extends RuntimeException {
private static final long serialVersionUID = -1108392076700488161L;

View File

@@ -31,6 +31,8 @@ import java.util.Map;
* biz_content String 是 请求参数的集合,最大长度不限,除公共参数外所有请求参数都必须放在这个参数中传递,具体参照各产品快速接入文档
*
* @param <T> 对应的Response对象
*
* @author thc
*/
public abstract class BaseRequest<T extends BaseResponse> {
@@ -47,6 +49,10 @@ public abstract class BaseRequest<T extends BaseResponse> {
private Class<T> responseClass = (Class<T>) ClassUtil.getSuperClassGenricType(this.getClass(), 0);;
/**
* 定义接口名称
* @return 接口名称
*/
protected abstract String method();
public BaseRequest() {
@@ -80,7 +86,7 @@ public abstract class BaseRequest<T extends BaseResponse> {
public RequestForm createRequestForm(OpenConfig openConfig) {
// 公共请求参数
Map<String, String> params = new HashMap<String, String>();
Map<String, String> params = new HashMap<String, String>(16);
params.put(openConfig.getMethodName(), this.method);
params.put(openConfig.getFormatName(), openConfig.getFormatType());
params.put(openConfig.getCharsetName(), openConfig.getCharset());

View File

@@ -16,7 +16,7 @@ import lombok.Setter;
* },
* "sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
* }
*
* @author thc
*/
@Setter
@Getter

View File

@@ -77,6 +77,7 @@ public abstract class BaseNCodec {
* @return a String useful for debugging.
*/
@SuppressWarnings("boxing") // OK to ignore boxing here
@Override
public String toString() {
return String.format("%s[buffer=%s, currentLinePos=%s, eof=%s, ibitWorkArea=%s, lbitWorkArea=%s, " +
"modulus=%s, pos=%s, readPos=%s]", this.getClass().getSimpleName(), Arrays.toString(buffer),

View File

@@ -7,6 +7,10 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
* 文件工具类
* @author thc
*/
public class FileUtil {
/**

View File

@@ -1,5 +1,9 @@
package com.gitee.sop.sdk.util;
/**
* hex工具类
* @author thc
*/
public class HexUtil {
private static final String ZERO = "0";
private static final String CHARS = "0123456789ABCDEF";
@@ -30,7 +34,7 @@ public class HexUtil {
* @return byte[]
*/
public static byte[] hex2bytes(String hexString) {
if (hexString == null || hexString.equals("")) {
if (hexString == null || "".equalsIgnoreCase(hexString)) {
return null;
}
hexString = hexString.toUpperCase();

View File

@@ -2,6 +2,10 @@ package com.gitee.sop.sdk.util;
import java.security.MessageDigest;
/**
* MD5工具类
* @author thc
*/
public class MD5Util {
private static final String MD5 = "MD5";