|
|
@@ -50,10 +50,10 @@ public class JibeApiClient {
|
|
|
public static void main(String[] args) throws JsonProcessingException, ApiException {
|
|
|
// 1. 拉取 JiBe 下发的 RFQ / PO
|
|
|
// try {
|
|
|
- ApiResponse response = pullJson("RFQ","pull_json");
|
|
|
-// ApiResponse response = pullJson("PO","pull_json");
|
|
|
- System.out.println("拉取成功:");
|
|
|
- System.out.println(response.getFormattedBody());
|
|
|
+// ApiResponse response = pullJson("RFQ","pull_json");
|
|
|
+//// ApiResponse response = pullJson("PO","pull_json");
|
|
|
+// System.out.println("拉取成功:");
|
|
|
+// System.out.println(response.getFormattedBody());
|
|
|
//
|
|
|
// String responseBody = response.getFormattedBody();
|
|
|
//
|
|
|
@@ -127,57 +127,57 @@ public class JibeApiClient {
|
|
|
|
|
|
//=====================返回报价=====================
|
|
|
// // 构建请求体
|
|
|
-// Map<String, Object> requestBody = buildRequestBody2("quotation", SUPPLIER_UID, CLIENT_UID);
|
|
|
-//
|
|
|
-// String jsonBody = null;
|
|
|
-// try {
|
|
|
-// jsonBody = OBJECT_MAPPER.writeValueAsString(requestBody);
|
|
|
-// System.err.println("==========================");
|
|
|
-// System.out.println(jsonBody);
|
|
|
-// } catch (Exception e) {
|
|
|
-// System.err.println("==========================");
|
|
|
-// System.out.println("构建请求体失败: " + e.getMessage());
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 构建请求
|
|
|
-// RequestBody body = RequestBody.create(JSON_MEDIA_TYPE, jsonBody);
|
|
|
-// Request request = new Request.Builder()
|
|
|
-// .url(BASE_URL + "/" + "quotation_response/")
|
|
|
-// .post(body)
|
|
|
-// .addHeader("token", TOKEN)
|
|
|
-// .addHeader("Content-Type", "application/json")
|
|
|
-// .build();
|
|
|
-//
|
|
|
-// // 执行请求
|
|
|
-// try (Response response = HTTP_CLIENT.newCall(request).execute()) {
|
|
|
-// String responseBody = response.body() != null ? response.body().string() : "";
|
|
|
-//
|
|
|
-// // 格式化响应
|
|
|
-// String formattedBody = formatJson(responseBody);
|
|
|
-//
|
|
|
-// ApiResponse apiResponse = new ApiResponse(
|
|
|
-// response.code(),
|
|
|
-// response.message(),
|
|
|
-// responseBody,
|
|
|
-// formattedBody,
|
|
|
-// response.isSuccessful()
|
|
|
-// );
|
|
|
-//
|
|
|
-// if (!response.isSuccessful()) {
|
|
|
-// System.out.println("HTTP请求失败: " + response.code() + " " + response.message());
|
|
|
-// }
|
|
|
-//
|
|
|
-// System.err.println("============1==============");
|
|
|
-// System.out.println(apiResponse.getFormattedBody());
|
|
|
-// System.err.println("============2==============");
|
|
|
-// System.out.println(apiResponse);
|
|
|
-//
|
|
|
-// } catch (IOException e) {
|
|
|
-// System.err.println("==========================");
|
|
|
-// System.out.println("网络请求异常: " + e.getMessage());
|
|
|
-// }
|
|
|
-// System.err.println("==========================");
|
|
|
-// System.err.println(jsonBody);
|
|
|
+ Map<String, Object> requestBody = buildRequestBody2("quotation", SUPPLIER_UID, CLIENT_UID);
|
|
|
+
|
|
|
+ String jsonBody = null;
|
|
|
+ try {
|
|
|
+ jsonBody = OBJECT_MAPPER.writeValueAsString(requestBody);
|
|
|
+ System.err.println("==========================");
|
|
|
+ System.out.println(jsonBody);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("==========================");
|
|
|
+ System.out.println("构建请求体失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建请求
|
|
|
+ RequestBody body = RequestBody.create(JSON_MEDIA_TYPE, jsonBody);
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(BASE_URL + "/" + "quotation_response/")
|
|
|
+ .post(body)
|
|
|
+ .addHeader("token", TOKEN)
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ // 执行请求
|
|
|
+ try (Response response = HTTP_CLIENT.newCall(request).execute()) {
|
|
|
+ String responseBody = response.body() != null ? response.body().string() : "";
|
|
|
+
|
|
|
+ // 格式化响应
|
|
|
+ String formattedBody = formatJson(responseBody);
|
|
|
+
|
|
|
+ ApiResponse apiResponse = new ApiResponse(
|
|
|
+ response.code(),
|
|
|
+ response.message(),
|
|
|
+ responseBody,
|
|
|
+ formattedBody,
|
|
|
+ response.isSuccessful()
|
|
|
+ );
|
|
|
+
|
|
|
+ if (!response.isSuccessful()) {
|
|
|
+ System.out.println("HTTP请求失败: " + response.code() + " " + response.message());
|
|
|
+ }
|
|
|
+
|
|
|
+ System.err.println("============1==============");
|
|
|
+ System.out.println(apiResponse.getFormattedBody());
|
|
|
+ System.err.println("============2==============");
|
|
|
+ System.out.println(apiResponse);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.err.println("==========================");
|
|
|
+ System.out.println("网络请求异常: " + e.getMessage());
|
|
|
+ }
|
|
|
+ System.err.println("==========================");
|
|
|
+ System.err.println(jsonBody);
|
|
|
|
|
|
// System.out.println(buildRequestBodyConfirmPo(SUPPLIER_UID, CLIENT_UID));
|
|
|
|
|
|
@@ -301,7 +301,8 @@ public class JibeApiClient {
|
|
|
bodyContent.put("supplier_quotation_reference",billCode);// "SQ2603529"
|
|
|
bodyContent.put("quotation_creator", "GMS ENGINEERING LIMITED");
|
|
|
bodyContent.put("delivery_terms", "NSA");//交货条款
|
|
|
- bodyContent.put("quoted_items_number", saleQuotationProduct.size());
|
|
|
+// bodyContent.put("delivery_terms", "EX WORK – UNPACKED");//交货条款
|
|
|
+ bodyContent.put("quoted_items_number", String.valueOf(saleQuotationProduct.size()+5));
|
|
|
bodyContent.put("quoted_currency", currency);
|
|
|
|
|
|
|
|
|
@@ -338,10 +339,13 @@ public class JibeApiClient {
|
|
|
jsonBody = OBJECT_MAPPER.writeValueAsString(body);
|
|
|
System.err.println("==========================");
|
|
|
System.out.println(jsonBody);
|
|
|
+
|
|
|
+ result.put("jsonBody",jsonBody);
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("==========================");
|
|
|
System.out.println("构建请求体失败: " + e.getMessage());
|
|
|
|
|
|
+ result.put("jsonBody",jsonBody);
|
|
|
result.put("result","构建请求体失败: " + e.getMessage());
|
|
|
result.put("httpSt","error");
|
|
|
}
|
|
|
@@ -509,11 +513,11 @@ public class JibeApiClient {
|
|
|
System.err.println("============2==============");
|
|
|
System.out.println(apiResponse);
|
|
|
|
|
|
- return formattedBody;
|
|
|
+ return "报文:"+jsonBody+";响应"+formattedBody;
|
|
|
} catch (IOException e) {
|
|
|
System.err.println("==========================");
|
|
|
System.out.println("网络请求异常: " + e.getMessage());
|
|
|
- return e.getMessage();
|
|
|
+ return "异常报文:"+jsonBody+";响应"+e.getMessage();
|
|
|
}
|
|
|
}
|
|
|
/**
|