parent
678acaa982
commit
db267ed2c3
|
@ -10,11 +10,13 @@ import kd.bos.logging.LogFactory;
|
||||||
import kd.bos.orm.query.QCP;
|
import kd.bos.orm.query.QCP;
|
||||||
import kd.bos.orm.query.QFilter;
|
import kd.bos.orm.query.QFilter;
|
||||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import okhttp3.*;
|
||||||
|
|
||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
@ -587,54 +589,28 @@ public class ApiService {
|
||||||
* @return 调用接口返回信息
|
* @return 调用接口返回信息
|
||||||
*/
|
*/
|
||||||
private static String submitBill(String token, String linkUrl, String requestBody) {
|
private static String submitBill(String token, String linkUrl, String requestBody) {
|
||||||
try {
|
OkHttpClient client = new OkHttpClient();
|
||||||
// 请求URL
|
|
||||||
URL url = new URL(linkUrl + "?access_token=" + token);
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
|
|
||||||
// 设置请求方法为POST
|
MediaType mediaType = MediaType.parse("application/json");
|
||||||
connection.setRequestMethod("POST");
|
RequestBody body = RequestBody.create(mediaType, requestBody);
|
||||||
|
|
||||||
// 设置请求头
|
Request request = new Request.Builder()
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
.url(linkUrl + "?access_token=" + token)
|
||||||
|
.post(body)
|
||||||
|
.addHeader("Content-Type", "application/json")
|
||||||
|
.build();
|
||||||
|
|
||||||
// 允许输出
|
try (Response response = client.newCall(request).execute()) {
|
||||||
connection.setDoOutput(true);
|
if (response.isSuccessful()) {
|
||||||
|
String responseBody = String.valueOf(response.body());
|
||||||
// 写入请求体
|
logger.info("提交接口调用成功,响应成功信息:{}", responseBody);
|
||||||
try (OutputStream os = connection.getOutputStream()) {
|
return "提交接口 → 响应成功: " + responseBody;
|
||||||
byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
|
|
||||||
os.write(input, 0, input.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取响应码
|
|
||||||
int responseCode = connection.getResponseCode();
|
|
||||||
|
|
||||||
// 读取响应内容
|
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) { // 成功响应
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
|
|
||||||
String inputLine;
|
|
||||||
StringBuilder content = new StringBuilder();
|
|
||||||
while ((inputLine = in.readLine()) != null) {
|
|
||||||
content.append(inputLine);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
// 替换 \n 为实际的换行符
|
|
||||||
logger.info("提交接口调用成功,响应成功信息:{}", content);
|
|
||||||
return "提交接口 → 响应成功: " + content.toString();
|
|
||||||
} else {
|
} else {
|
||||||
// 读取错误流
|
String errorBody = String.valueOf(response.body());
|
||||||
BufferedReader errorReader = new BufferedReader(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8));
|
logger.info("提交接口调用失败,响应失败信息:{}", errorBody);
|
||||||
String errorLine;
|
return "提交接口 → 响应失败: " + errorBody;
|
||||||
StringBuilder errorContent = new StringBuilder();
|
|
||||||
while ((errorLine = errorReader.readLine()) != null) {
|
|
||||||
errorContent.append(errorLine);
|
|
||||||
}
|
|
||||||
errorReader.close();
|
|
||||||
logger.info("提交接口调用失败,响应失败信息:{}", errorReader);
|
|
||||||
return "提交接口 → 响应失败: " + errorContent;
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (IOException e) {
|
||||||
logger.info("请求失败,失败信息:{}", e);
|
logger.info("请求失败,失败信息:{}", e);
|
||||||
return "提交接口 → 请求失败," + e.getMessage();
|
return "提交接口 → 请求失败," + e.getMessage();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue