parent
74c07044eb
commit
d089d552e5
|
@ -19,6 +19,7 @@ import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -162,6 +163,12 @@ public class ApiService {
|
||||||
new QFilter("shkd_sourcebill", QCP.equals, billMark).and(
|
new QFilter("shkd_sourcebill", QCP.equals, billMark).and(
|
||||||
new QFilter("shkd_targetsystem", QCP.equals, systemName)).toArray());
|
new QFilter("shkd_targetsystem", QCP.equals, systemName)).toArray());
|
||||||
|
|
||||||
|
|
||||||
|
// 获取token
|
||||||
|
String domainName = objects[0].getString("shkd_domainname");
|
||||||
|
String token = ApiService.getBIPToken(domainName);
|
||||||
|
logger.info("获取token:{}", token);
|
||||||
|
|
||||||
String saveUrl = objects[0].getString("shkd_url");
|
String saveUrl = objects[0].getString("shkd_url");
|
||||||
|
|
||||||
// 组装请求体数据
|
// 组装请求体数据
|
||||||
|
@ -181,7 +188,7 @@ public class ApiService {
|
||||||
// 付款处理
|
// 付款处理
|
||||||
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/fi/fundpayment/save":
|
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/fi/fundpayment/save":
|
||||||
// 保存
|
// 保存
|
||||||
saveResponseBody = pushBill(objects[0], saveUrl, saveRequestBody);
|
saveResponseBody = pushBill(token, saveUrl, saveRequestBody);
|
||||||
logger.info("付款处理 → BIP保存接口 → 返回结果:{}", saveResponseBody);
|
logger.info("付款处理 → BIP保存接口 → 返回结果:{}", saveResponseBody);
|
||||||
jsonObject = JSON.parseObject(saveResponseBody);
|
jsonObject = JSON.parseObject(saveResponseBody);
|
||||||
code = jsonObject.getString("code");
|
code = jsonObject.getString("code");
|
||||||
|
@ -196,19 +203,20 @@ public class ApiService {
|
||||||
|
|
||||||
submitUrl = objects[0].getString("shkd_submiturl");
|
submitUrl = objects[0].getString("shkd_submiturl");
|
||||||
submitRequestBody = getSubmitRequestBody("cmp.fundpayment.FundPayment", "cmp_fundpayment", data.getString("id"));
|
submitRequestBody = getSubmitRequestBody("cmp.fundpayment.FundPayment", "cmp_fundpayment", data.getString("id"));
|
||||||
|
logger.info("付款处理 →\n提交URL为:{}\n提交请求body:{}", submitUrl, JSON.toJSONString(submitRequestBody));
|
||||||
// 提交
|
// 提交
|
||||||
submitResponseBody = pushBill(objects[0], submitUrl, JSON.toJSONString(submitRequestBody));
|
submitResponseBody = submitBill(token, submitUrl, JSON.toJSONString(submitRequestBody));
|
||||||
logger.info("付款处理 → BIP提交接口 → 返回结果:{}", submitResponseBody);
|
logger.info("付款处理 → BIP提交接口 → 返回结果:{}", submitResponseBody);
|
||||||
result = "推送 → 付款处理单 → 成功";
|
result = "推送 → 付款处理单 → 成功";
|
||||||
} else {
|
} else {
|
||||||
logger.info("付款处理 → BIP保存接口 → 成功\n失败单据编号:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveResponseBody);
|
logger.info("付款处理 → BIP保存接口 → 失败\n失败单据编号:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveResponseBody);
|
||||||
result = "推送 → 付款处理单 → 失败";
|
result = "推送 → 付款处理单 → 失败";
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
// 收款处理
|
// 收款处理
|
||||||
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/fi/fundcollection/save":
|
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/fi/fundcollection/save":
|
||||||
saveResponseBody = pushBill(objects[0], saveUrl, saveRequestBody);
|
saveResponseBody = pushBill(token, saveUrl, saveRequestBody);
|
||||||
logger.info("收款处理 → BIP保存接口 → 返回结果:{}", saveResponseBody);
|
logger.info("收款处理 → BIP保存接口 → 返回结果:{}", saveResponseBody);
|
||||||
jsonObject = JSON.parseObject(saveResponseBody);
|
jsonObject = JSON.parseObject(saveResponseBody);
|
||||||
code = jsonObject.getString("code");
|
code = jsonObject.getString("code");
|
||||||
|
@ -224,7 +232,7 @@ public class ApiService {
|
||||||
submitUrl = objects[0].getString("shkd_submiturl");
|
submitUrl = objects[0].getString("shkd_submiturl");
|
||||||
submitRequestBody = getSubmitRequestBody("cmp.fundcollection.FundCollection", "cmp_fundcollection", data.getString("id"));
|
submitRequestBody = getSubmitRequestBody("cmp.fundcollection.FundCollection", "cmp_fundcollection", data.getString("id"));
|
||||||
// 提交
|
// 提交
|
||||||
submitResponseBody = pushBill(objects[0], submitUrl, JSON.toJSONString(submitRequestBody));
|
submitResponseBody = submitBill(token, submitUrl, JSON.toJSONString(submitRequestBody));
|
||||||
logger.info("收款处理 → BIP提交接口 → 返回结果:{}", submitResponseBody);
|
logger.info("收款处理 → BIP提交接口 → 返回结果:{}", submitResponseBody);
|
||||||
result = "推送 → 收款处理 → 成功";
|
result = "推送 → 收款处理 → 成功";
|
||||||
} else {
|
} else {
|
||||||
|
@ -238,7 +246,7 @@ public class ApiService {
|
||||||
break;
|
break;
|
||||||
// 支付结果
|
// 支付结果
|
||||||
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/ctm/api/settlement/feedback":
|
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/ctm/api/settlement/feedback":
|
||||||
saveResponseBody = pushBill(objects[0], saveUrl, saveRequestBody);
|
saveResponseBody = pushBill(token, saveUrl, saveRequestBody);
|
||||||
jsonObject = JSON.parseObject(saveResponseBody);
|
jsonObject = JSON.parseObject(saveResponseBody);
|
||||||
code = jsonObject.getString("code");
|
code = jsonObject.getString("code");
|
||||||
if ("200".equals(code)) {
|
if ("200".equals(code)) {
|
||||||
|
@ -511,19 +519,15 @@ public class ApiService {
|
||||||
/**
|
/**
|
||||||
* 推送单条数据
|
* 推送单条数据
|
||||||
*
|
*
|
||||||
* @param dataEntity API映射数据对象
|
* @param token token
|
||||||
* @param linkUrl 请求URL
|
* @param linkUrl 请求URL
|
||||||
* @param requestBody 请求体数据
|
* @param requestBody 请求体数据
|
||||||
* @return 推送结果
|
* @return 推送结果
|
||||||
*/
|
*/
|
||||||
private static String pushBill(DynamicObject dataEntity, String linkUrl, String requestBody) {
|
private static String pushBill(String token, String linkUrl, String requestBody) {
|
||||||
// 响应数据
|
// 响应数据
|
||||||
String formattedContent;
|
String formattedContent;
|
||||||
try {
|
try {
|
||||||
// 域名
|
|
||||||
String domainName = dataEntity.getString("shkd_domainname");
|
|
||||||
String token = ApiService.getBIPToken(domainName);
|
|
||||||
logger.info("获取token:{}", token);
|
|
||||||
// 请求URL
|
// 请求URL
|
||||||
URL url = new URL(linkUrl + "?access_token=" + token);
|
URL url = new URL(linkUrl + "?access_token=" + token);
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
@ -574,6 +578,69 @@ public class ApiService {
|
||||||
return formattedContent;
|
return formattedContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交接口调试
|
||||||
|
*
|
||||||
|
* @param token token
|
||||||
|
* @param linkUrl 提交接口url
|
||||||
|
* @param requestBody 请求体数据
|
||||||
|
* @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();
|
||||||
|
|
||||||
|
// 设置请求方法为POST
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
|
||||||
|
// 设置请求头
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
|
||||||
|
// 允许输出
|
||||||
|
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();
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.info("请求失败,失败信息:{}", e);
|
||||||
|
return "提交接口 → 请求失败," + e.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Map<String, Object> getSubmitRequestBody(String fullname, String billnum, String id) {
|
public static Map<String, Object> getSubmitRequestBody(String fullname, String billnum, String id) {
|
||||||
Map<String, Object> data = new HashMap<>();
|
Map<String, Object> data = new HashMap<>();
|
||||||
Map<String, String> innerData = new HashMap<>();
|
Map<String, String> innerData = new HashMap<>();
|
||||||
|
|
Loading…
Reference in New Issue