星空对接接口开发:序列化对象修改
This commit is contained in:
parent
c387616fe5
commit
e1ce92d937
|
@ -78,7 +78,7 @@ public class ApiPostBack {
|
||||||
throw new RuntimeException("JSON序列化失败:" + e.getMessage());
|
throw new RuntimeException("JSON序列化失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
String resultJSON = sendPostRequest(url, jsonInputString);
|
String resultJSON = sendPostRequest(url, jsonInputString,"save");
|
||||||
JSONObject jsonObject = JSONObject.parseObject(resultJSON);
|
JSONObject jsonObject = JSONObject.parseObject(resultJSON);
|
||||||
// 获取 Result.NeedReturnData 数组,更新fid ,fentryid的值
|
// 获取 Result.NeedReturnData 数组,更新fid ,fentryid的值
|
||||||
JSONArray needReturnDataArray = jsonObject.getJSONObject("Result").getJSONArray("NeedReturnData");
|
JSONArray needReturnDataArray = jsonObject.getJSONObject("Result").getJSONArray("NeedReturnData");
|
||||||
|
@ -131,7 +131,7 @@ public class ApiPostBack {
|
||||||
throw new RuntimeException("JSON序列化失败:" + e.getMessage());
|
throw new RuntimeException("JSON序列化失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
String resultJSON = sendPostRequest(url, jsonInputString);
|
String resultJSON = sendPostRequest(url, jsonInputString,"save");
|
||||||
JSONObject jsonObject = JSONObject.parseObject(resultJSON);
|
JSONObject jsonObject = JSONObject.parseObject(resultJSON);
|
||||||
// 获取 Result.NeedReturnData 数组,更新fid ,fentryid的值
|
// 获取 Result.NeedReturnData 数组,更新fid ,fentryid的值
|
||||||
JSONArray needReturnDataArray = jsonObject.getJSONObject("Result").getJSONArray("NeedReturnData");
|
JSONArray needReturnDataArray = jsonObject.getJSONObject("Result").getJSONArray("NeedReturnData");
|
||||||
|
@ -193,10 +193,10 @@ public class ApiPostBack {
|
||||||
throw new RuntimeException("JSON序列化失败:" + e.getMessage());
|
throw new RuntimeException("JSON序列化失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
sendPostRequest(url, jsonInputString);
|
sendPostRequest(url, jsonInputString,"save");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String sendPostRequest(String url, String jsonBody) throws IOException {
|
private String sendPostRequest(String url, String jsonBody,String sendType) throws IOException {
|
||||||
StringBuilder errorLog = new StringBuilder();
|
StringBuilder errorLog = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
URL apiUrl = new URL(url);
|
URL apiUrl = new URL(url);
|
||||||
|
@ -221,36 +221,38 @@ public class ApiPostBack {
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
try (BufferedReader br = new BufferedReader(
|
try (BufferedReader br = new BufferedReader(
|
||||||
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
|
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
|
||||||
StringBuilder response = new StringBuilder();
|
StringBuilder response = new StringBuilder();
|
||||||
String responseLine;
|
String responseLine;
|
||||||
while ((responseLine = br.readLine()) != null) {
|
while ((responseLine = br.readLine()) != null) {
|
||||||
response.append(responseLine.trim());
|
response.append(responseLine.trim());
|
||||||
}
|
|
||||||
// 解析响应 JSON
|
|
||||||
JSONObject jsonResponse = JSONObject.parseObject(response.toString());
|
|
||||||
// 获取 Result 节点
|
|
||||||
JSONObject resultObj = jsonResponse.getJSONObject("Result");
|
|
||||||
if (resultObj == null) {
|
|
||||||
throw new RuntimeException("响应中未找到 'Result' 字段,请检查接口返回格式!");
|
|
||||||
}
|
|
||||||
// 获取 ResponseStatus 节点
|
|
||||||
JSONObject responseStatus = resultObj.getJSONObject("ResponseStatus");
|
|
||||||
if (responseStatus == null) {
|
|
||||||
throw new RuntimeException("响应中未找到 'ResponseStatus' 字段,请检查接口返回格式!");
|
|
||||||
}
|
|
||||||
// 判断 IsSuccess
|
|
||||||
Boolean isSuccess = responseStatus.getBoolean("IsSuccess");
|
|
||||||
if (isSuccess != null && !isSuccess) {
|
|
||||||
// 提取错误信息并抛出异常
|
|
||||||
JSONArray errors = responseStatus.getJSONArray("Errors");
|
|
||||||
if (errors != null && !errors.isEmpty()) {
|
|
||||||
String errorMessage = errors.getJSONObject(0).getString("Message");
|
|
||||||
throw new RuntimeException("接口返回错误: " + errorMessage);
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("接口返回错误,但未找到具体的错误信息。");
|
|
||||||
}
|
}
|
||||||
}
|
if (sendType.equals("save")) {
|
||||||
return response.toString();
|
// 解析响应 JSON
|
||||||
|
JSONObject jsonResponse = JSONObject.parseObject(response.toString());
|
||||||
|
// 获取 Result 节点
|
||||||
|
JSONObject resultObj = jsonResponse.getJSONObject("Result");
|
||||||
|
if (resultObj == null) {
|
||||||
|
throw new RuntimeException("响应中未找到 'Result' 字段,请检查接口返回格式!");
|
||||||
|
}
|
||||||
|
// 获取 ResponseStatus 节点
|
||||||
|
JSONObject responseStatus = resultObj.getJSONObject("ResponseStatus");
|
||||||
|
if (responseStatus == null) {
|
||||||
|
throw new RuntimeException("响应中未找到 'ResponseStatus' 字段,请检查接口返回格式!");
|
||||||
|
}
|
||||||
|
// 判断 IsSuccess
|
||||||
|
Boolean isSuccess = responseStatus.getBoolean("IsSuccess");
|
||||||
|
if (isSuccess != null && !isSuccess) {
|
||||||
|
// 提取错误信息并抛出异常
|
||||||
|
JSONArray errors = responseStatus.getJSONArray("Errors");
|
||||||
|
if (errors != null && !errors.isEmpty()) {
|
||||||
|
String errorMessage = errors.getJSONObject(0).getString("Message");
|
||||||
|
throw new RuntimeException("接口返回错误: " + errorMessage);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("接口返回错误,但未找到具体的错误信息。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return response.toString();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("请求失败,响应码:" + responseCode);
|
throw new RuntimeException("请求失败,响应码:" + responseCode);
|
||||||
|
@ -304,7 +306,7 @@ public class ApiPostBack {
|
||||||
|
|
||||||
if (jsonInputString.isEmpty()) return result;
|
if (jsonInputString.isEmpty()) return result;
|
||||||
|
|
||||||
String oaData = sendPostRequest(url, jsonInputString);
|
String oaData = sendPostRequest(url, jsonInputString,"ExecuteBillQuery");
|
||||||
|
|
||||||
//查询的参数为FJoinOutQty/FInStockJoinQty,这两者如果有存在大于0的情况或者存在什么也没查到的情况就返回true
|
//查询的参数为FJoinOutQty/FInStockJoinQty,这两者如果有存在大于0的情况或者存在什么也没查到的情况就返回true
|
||||||
JSONArray dataList = JSONArray.parseArray(oaData);
|
JSONArray dataList = JSONArray.parseArray(oaData);
|
||||||
|
@ -338,7 +340,7 @@ public class ApiPostBack {
|
||||||
" \"IsVerifyProcInst\": \"true\"\n" +
|
" \"IsVerifyProcInst\": \"true\"\n" +
|
||||||
"}\n" +
|
"}\n" +
|
||||||
"}";
|
"}";
|
||||||
String oaData = sendPostRequest(url, jsonInputString);
|
String oaData = sendPostRequest(url, jsonInputString,"save");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -356,7 +358,7 @@ public class ApiPostBack {
|
||||||
"\t\t\"NetworkCtrl\": \"false\"\n" +
|
"\t\t\"NetworkCtrl\": \"false\"\n" +
|
||||||
"\t}\n" +
|
"\t}\n" +
|
||||||
"}";
|
"}";
|
||||||
sendPostRequest(url, jsonInputString);
|
sendPostRequest(url, jsonInputString,"save");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue