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