tanghc 6 years ago
parent 842a8a4a0b
commit 45ab847197
  1. 9
      doc/docs/files/10095_SDK开发.md
  2. 2
      sop-sdk/sdk-java/pom.xml
  3. 8
      sop-sdk/sdk-java/readme.md
  4. 4
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenRequest.java
  5. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java
  6. 33
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/JsonUtil.java
  7. 3
      sop-sdk/sdk-java/src/test/java/com/gitee/sop/sdk/SdkTest.java

@ -6,10 +6,10 @@
## sdk-java
开放平台对应的sdk,适用于Android。SDK依赖了三个jar包
SDK依赖了三个jar包
- okhttp.jar 用于网络请求
- fastjson-android.jar 用于json处理
- fastjson.jar 用于json处理
- commons-logging.jar 日志处理
### 接口封装步骤
@ -104,9 +104,10 @@ public void testGet() {
if (response.isSuccess()) {
// 返回结果
System.out.println(response);
System.out.println(String.format("成功!response:%s\n响应原始内容:%s",
JSON.toJSONString(response), response.getBody()));
} else {
System.out.println(response);
System.out.println("错误,subCode:" + response.getSubCode() + ", subMsg:" + response.getSubMsg());
}
}
```

@ -24,7 +24,7 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.68.android</version>
<version>1.2.56</version>
</dependency>
<dependency>

@ -3,11 +3,11 @@
sdk for java
开放平台对应的sdk,适用于Android。SDK只依赖了三个jar包
SDK只依赖了三个jar包
- okhttp.jar
- fastjson-android.jar
- commons-logging.jar
- okhttp.jar 用于网络请求
- fastjson.jar 用于json处理
- commons-logging.jar 日志处理
## 接口封装步骤

@ -1,10 +1,10 @@
package com.gitee.sop.sdk.client;
import com.alibaba.fastjson.JSON;
import com.gitee.sop.sdk.common.OpenConfig;
import com.gitee.sop.sdk.common.RequestForm;
import com.gitee.sop.sdk.common.UploadFile;
import com.gitee.sop.sdk.response.BaseResponse;
import com.gitee.sop.sdk.util.JsonUtil;
import java.io.IOException;
import java.util.List;
@ -49,7 +49,7 @@ public class OpenRequest {
result.setSubCode(HTTP_ERROR_CODE);
result.setSubMsg(e.getMessage());
result.setMsg(e.getMessage());
return JsonUtil.toJSONString(result);
return JSON.toJSONString(result);
}
static class ErrorResponse extends BaseResponse {

@ -28,8 +28,10 @@ public abstract class BaseResponse {
private String subCode;
@JSONField(name = "sub_msg")
private String subMsg;
@JSONField(serialize = false)
private String body;
@JSONField(serialize = false)
public boolean isSuccess() {
return StringUtils.isEmpty(subCode);
}

@ -1,33 +0,0 @@
package com.gitee.sop.sdk.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
public class JsonUtil {
/**
* 对象转json
* @param obj
* @return
*/
public static String toJSONString(Object obj) {
if(obj == null) {
return "{}";
}
return JSON.toJSONString(obj);
}
/**
* json转对象
* @param json
* @param clazz
* @return
*/
public static <T> T parseObject(String json, Class<T> clazz) {
return JSON.parseObject(json, clazz);
}
public static JSONObject parseJSONObject(String json) {
return JSON.parseObject(json);
}
}

@ -39,7 +39,8 @@ public class SdkTest extends TestCase {
if (response.isSuccess()) {
// 返回结果
System.out.println(response);
System.out.println(String.format("成功!response:%s\n响应原始内容:%s",
JSON.toJSONString(response), response.getBody()));
} else {
System.out.println("错误,subCode:" + response.getSubCode() + ", subMsg:" + response.getSubMsg());
}

Loading…
Cancel
Save