mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 07:02:14 +08:00
4.0.2
This commit is contained in:
@@ -2,6 +2,7 @@ package com.gitee.sop.sdk.client;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.gitee.sop.sdk.common.DataNameBuilder;
|
||||
import com.gitee.sop.sdk.common.OpenConfig;
|
||||
import com.gitee.sop.sdk.common.RequestForm;
|
||||
@@ -36,17 +37,17 @@ public class OpenClient {
|
||||
/**
|
||||
* 接口请求url
|
||||
*/
|
||||
private String url;
|
||||
private final String url;
|
||||
|
||||
/**
|
||||
* 平台提供的appId
|
||||
*/
|
||||
private String appId;
|
||||
private final String appId;
|
||||
|
||||
/**
|
||||
* 开放平台提供的私钥
|
||||
*/
|
||||
private String privateKey;
|
||||
private final String privateKey;
|
||||
|
||||
/**
|
||||
* 开放平台提供的公钥
|
||||
@@ -56,17 +57,17 @@ public class OpenClient {
|
||||
/**
|
||||
* 配置项
|
||||
*/
|
||||
private OpenConfig openConfig;
|
||||
private final OpenConfig openConfig;
|
||||
|
||||
/**
|
||||
* 请求对象
|
||||
*/
|
||||
private OpenRequest openRequest;
|
||||
private final OpenRequest openRequest;
|
||||
|
||||
/**
|
||||
* 节点处理
|
||||
*/
|
||||
private DataNameBuilder dataNameBuilder;
|
||||
private final DataNameBuilder dataNameBuilder;
|
||||
|
||||
/**
|
||||
* 构建请求客户端
|
||||
@@ -193,7 +194,7 @@ public class OpenClient {
|
||||
protected <T extends BaseResponse> T parseResponse(String resp, BaseRequest<T> request) {
|
||||
String method = request.getMethod();
|
||||
String rootNodeName = dataNameBuilder.build(method);
|
||||
JSONObject jsonObject = JSON.parseObject(resp);
|
||||
JSONObject jsonObject = JSON.parseObject(resp, Feature.OrderedField);
|
||||
String errorResponseName = this.openConfig.getErrorResponseName();
|
||||
boolean errorResponse = jsonObject.containsKey(errorResponseName);
|
||||
if (errorResponse) {
|
||||
@@ -210,7 +211,7 @@ public class OpenClient {
|
||||
}
|
||||
}
|
||||
T t = data.toJavaObject(request.getResponseClass());
|
||||
t.setBody(data.toJSONString());
|
||||
t.setBody(jsonObject.getString(rootNodeName));
|
||||
return t;
|
||||
}
|
||||
|
||||
|
@@ -8,6 +8,6 @@ import com.gitee.sop.sdk.response.DemoFileUploadResponse;
|
||||
public class DemoFileUploadRequest extends BaseRequest<DemoFileUploadResponse> {
|
||||
@Override
|
||||
protected String method() {
|
||||
return "demo.file.upload";
|
||||
return "file.upload";
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import com.gitee.sop.sdk.response.GetStoryResponse;
|
||||
public class GetStoryRequest extends BaseRequest<GetStoryResponse> {
|
||||
@Override
|
||||
protected String method() {
|
||||
return "alipay.story.find";
|
||||
return "story.get";
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,6 +22,8 @@ import lombok.Setter;
|
||||
@Getter
|
||||
public abstract class BaseResponse {
|
||||
|
||||
@JSONField(name = "request_id")
|
||||
private String requestId;
|
||||
private String code;
|
||||
private String msg;
|
||||
@JSONField(name = "sub_code")
|
||||
|
@@ -48,19 +48,19 @@ public class SdkTest extends TestCase {
|
||||
|
||||
if (response.isSuccess()) {
|
||||
// 返回结果
|
||||
System.out.println(String.format("成功!response:%s\n响应原始内容:%s",
|
||||
JSON.toJSONString(response), response.getBody()));
|
||||
System.out.println(String.format("response:%s",
|
||||
JSON.toJSONString(response)));
|
||||
} else {
|
||||
System.out.println("错误,subCode:" + response.getSubCode() + ", subMsg:" + response.getSubMsg());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 懒人版,如果不想添加Request,Response,Model。可以用这种方式,返回全部是String,后续自己处理json
|
||||
// 懒人版,如果不想添加Request,Response,可以用这种方式,返回全部是String,后续自己处理json
|
||||
@Test
|
||||
public void testLazy() {
|
||||
// 创建请求对象
|
||||
CommonRequest request = new CommonRequest("alipay.story.find");
|
||||
CommonRequest request = new CommonRequest("story.get");
|
||||
// 请求参数
|
||||
Map<String, Object> bizModel = new HashMap<>();
|
||||
bizModel.put("name", "白雪公主");
|
||||
|
Reference in New Issue
Block a user