parent
3aea7d84a0
commit
d9fe632590
|
@ -10,13 +10,16 @@ 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 org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -37,7 +40,7 @@ public class ApiService {
|
||||||
private static final Log logger = LogFactory.getLog(ApiService.class);
|
private static final Log logger = LogFactory.getLog(ApiService.class);
|
||||||
private static final String APP_KEY = "22564a240d3140d0b15582aca71a748c";
|
private static final String APP_KEY = "22564a240d3140d0b15582aca71a748c";
|
||||||
private static final String API_ENDPOINT = "/iuap-api-auth/open-auth/selfAppAuth/getAccessToken";
|
private static final String API_ENDPOINT = "/iuap-api-auth/open-auth/selfAppAuth/getAccessToken";
|
||||||
|
private static final RestTemplate restTemplate = new RestTemplate();
|
||||||
public static String getBIPToken(String domainName) {
|
public static String getBIPToken(String domainName) {
|
||||||
String token = "获取失败";
|
String token = "获取失败";
|
||||||
try {
|
try {
|
||||||
|
@ -589,29 +592,24 @@ 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) {
|
||||||
OkHttpClient client = new OkHttpClient();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
MediaType mediaType = MediaType.parse("application/json");
|
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
|
||||||
RequestBody body = RequestBody.create(mediaType, requestBody);
|
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
try {
|
||||||
.url(linkUrl + "?access_token=" + token)
|
ResponseEntity<String> response = restTemplate.postForEntity(linkUrl + "?access_token=" + token, requestEntity, String.class);
|
||||||
.post(body)
|
if (response.getStatusCode().is2xxSuccessful()) {
|
||||||
.addHeader("Content-Type", "application/json")
|
String responseBody = response.getBody() != null ? response.getBody() : "请求成功 → 无响应内容";
|
||||||
.build();
|
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
|
||||||
if (response.isSuccessful()) {
|
|
||||||
String responseBody = response.body() != null?response.body().string():"请求成功 → 无响应内容";
|
|
||||||
logger.info("提交接口调用成功,响应成功信息:{}", responseBody);
|
logger.info("提交接口调用成功,响应成功信息:{}", responseBody);
|
||||||
return "提交接口 → 响应成功: " + responseBody;
|
return "提交接口 → 响应成功: " + responseBody;
|
||||||
} else {
|
} else {
|
||||||
String errorBody = response.body() != null ? response.body().string() : "请求失败 → 无响应内容";
|
String errorBody = response.getBody() != null ? response.getBody() : "请求失败 → 无响应内容";
|
||||||
logger.info("提交接口调用失败,响应失败信息:{}", errorBody);
|
logger.info("提交接口调用失败,响应失败信息:{}", errorBody);
|
||||||
return "提交接口 → 响应失败: " + errorBody;
|
return "提交接口 → 响应失败: " + errorBody;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
logger.info("请求失败,失败信息:{}", e);
|
logger.info("请求失败,失败信息:{}", e.getMessage());
|
||||||
return "提交接口 → 请求失败," + e.getMessage();
|
return "提交接口 → 请求失败," + e.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue