parent
8372e0d2b7
commit
f5933260b2
|
@ -10,16 +10,12 @@ 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 kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -30,7 +26,6 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description
|
* @Description
|
||||||
|
@ -47,97 +42,61 @@ public class ApiService {
|
||||||
public static String getBIPToken(String domainName) {
|
public static String getBIPToken(String domainName) {
|
||||||
String token = null;
|
String token = null;
|
||||||
try {
|
try {
|
||||||
// 自定义 TrustManager
|
String timestamp = Long.toString(System.currentTimeMillis());
|
||||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
String signature = generateSignature("appKey" + APP_KEY + "timestamp" + timestamp);
|
||||||
new X509TrustManager() {
|
|
||||||
public X509Certificate[] getAcceptedIssuers() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 安装所有信任的管理器
|
|
||||||
SSLContext sc = SSLContext.getInstance("SSL");
|
|
||||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
||||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
|
||||||
|
|
||||||
// 自定义 HostnameVerifier
|
|
||||||
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
|
|
||||||
@Override
|
|
||||||
public boolean verify(String hostname, SSLSession session) {
|
|
||||||
logger.info("Verifying hostname: " + hostname);
|
|
||||||
return true; // 始终返回 true,绕过验证
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 设置自定义 HostnameVerifier
|
|
||||||
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
|
|
||||||
|
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
|
||||||
String signature = generateSignature("appKey" + APP_KEY + "timestamp" + currentTimeMillis);
|
|
||||||
logger.info("getBIPToken → 签名: {}", signature);
|
logger.info("getBIPToken → 签名: {}", signature);
|
||||||
|
|
||||||
|
// URL with parameters
|
||||||
|
String urlString = String.format(
|
||||||
|
domainName + API_ENDPOINT + "?appKey=%s×tamp=%s&signature=%s",
|
||||||
|
APP_KEY, timestamp, signature
|
||||||
|
);
|
||||||
|
URL url = new URL(urlString);
|
||||||
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||||
// 禁用 SSL 证书验证
|
// 禁用 SSL 证书验证
|
||||||
disableSSLCertificateChecking();
|
disableSSLCertificateValidation();
|
||||||
// 构建URL
|
|
||||||
String urlString = domainName + API_ENDPOINT +
|
// 禁用 SSL 证书验证
|
||||||
"?appKey=" + APP_KEY +
|
// disableSSLCertificateChecking();
|
||||||
"×tamp=" + currentTimeMillis +
|
|
||||||
"&signature=" + signature;
|
|
||||||
// return urlString;
|
// return urlString;
|
||||||
|
|
||||||
logger.info("getBIPToken → 构建URL: {}", urlString);
|
// 设置自定义主机名
|
||||||
try {
|
connection.setHostnameVerifier((hostname, session) -> {
|
||||||
// 发送请求
|
logger.info("获取验证主机名: " + hostname);
|
||||||
Request request = buildRequest(urlString);
|
return true; // Always return true to bypass verification
|
||||||
Response response = client.newCall(request).execute();
|
});
|
||||||
logger.info("getBIPToken → 获取返回数据:{}", response);
|
|
||||||
token = handleResponse(response);
|
// 设置请求方法
|
||||||
} catch (Exception e) {
|
connection.setRequestMethod("GET");
|
||||||
logger.error("getBIPToken → 请求失败: ", e);
|
|
||||||
token = null;
|
// 发送请求并获取响应
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
logger.info("响应code: " + responseCode);
|
||||||
|
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
|
||||||
|
String inputLine;
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
response.append(inputLine);
|
||||||
}
|
}
|
||||||
// 处理响应
|
in.close();
|
||||||
logger.info("getBIPToken method completed successfully");
|
|
||||||
|
logger.info("响应结果: " + response);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.info("Error in getBIPToken", e);
|
logger.info("getBIPToken错误: " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Request buildRequest(String urlString) {
|
private static void disableSSLCertificateValidation() throws Exception {
|
||||||
return new Request.Builder()
|
// Create a trust manager that does not validate certificate chains
|
||||||
.url(urlString)
|
|
||||||
.get()
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String handleResponse(Response response) throws IOException {
|
|
||||||
if (response.isSuccessful()) {
|
|
||||||
String responseBody = response.body().string();
|
|
||||||
logger.info("handleResponse → 响应内容: {}", responseBody);
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(responseBody);
|
|
||||||
JSONObject data = jsonObject.getJSONObject("data");
|
|
||||||
return data.getString("access_token");
|
|
||||||
} else {
|
|
||||||
logger.error("handleResponse → 请求失败,响应码: {}", response.code());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SSLContext createInsecureSSLContext() throws Exception {
|
|
||||||
// 创建一个信任所有证书的 TrustManager
|
|
||||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||||
new X509TrustManager() {
|
new X509TrustManager() {
|
||||||
public X509Certificate[] getAcceptedIssuers() {
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
return new X509Certificate[0];
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
||||||
|
@ -148,28 +107,19 @@ public class ApiService {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 安装信任所有证书的 TrustManager
|
// Install the all-trusting trust manager
|
||||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
SSLContext sc = SSLContext.getInstance("SSL");
|
||||||
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||||
return sslContext;
|
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||||
}
|
|
||||||
|
|
||||||
public static void disableSSLCertificateChecking() {
|
// Create all-trusting host name verifier
|
||||||
try {
|
HostnameVerifier allHostsValid = (hostname, session) -> {
|
||||||
// 创建一个信任所有证书的 SSLContext
|
logger.info("HostnameVerifier called for: " + hostname);
|
||||||
SSLContext sslContext = createInsecureSSLContext();
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
// 设置 HttpsURLConnection 使用这个 SSLContext
|
// Install the all-trusting host verifier
|
||||||
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
|
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
|
||||||
|
|
||||||
// 创建一个 HostnameVerifier,信任所有主机名
|
|
||||||
HostnameVerifier allHostsValid = (hostname, session) -> true;
|
|
||||||
|
|
||||||
// 安装这个 HostnameVerifier
|
|
||||||
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generateSignature(String toSign) {
|
private static String generateSignature(String toSign) {
|
||||||
|
@ -261,6 +211,30 @@ public class ApiService {
|
||||||
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);
|
||||||
|
logger.info("收款处理 → BIP保存接口 → 返回结果:{}", saveResponseBody);
|
||||||
|
jsonObject = JSON.parseObject(saveResponseBody);
|
||||||
|
code = jsonObject.getString("code");
|
||||||
|
if ("200".equals(code)) {
|
||||||
|
logger.info("收款处理 → BIP保存接口 → 成功\n失败单据编号:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveResponseBody);
|
||||||
|
data = jsonObject.getJSONObject("data");
|
||||||
|
dynamic.set("shkd_businessnumber", data.getString("code"));
|
||||||
|
dynamic.set("shkd_businessid", data.getString("id"));
|
||||||
|
dynamic.set("shkd_businessname", "BIP");
|
||||||
|
dynamic.set("shkd_pushstatus", "已结算");
|
||||||
|
dynamicObjects.add(dynamic);
|
||||||
|
|
||||||
|
submitUrl = objects[0].getString("shkd_submiturl");
|
||||||
|
submitRequestBody = getSubmitRequestBody("cmp.fundcollection.FundCollection", "cmp_fundcollection", data.getString("id"));
|
||||||
|
// 提交
|
||||||
|
submitResponseBody = pushBill(objects[0], submitUrl, JSON.toJSONString(submitRequestBody));
|
||||||
|
logger.info("收款处理 → BIP提交接口 → 返回结果:{}", submitResponseBody);
|
||||||
|
result = "推送 → 收款处理 → 成功";
|
||||||
|
} else {
|
||||||
|
logger.info("收款处理 → BIP保存接口 → 成功\n失败单据编号:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveResponseBody);
|
||||||
|
result = "推送 → 收款处理 → 失败";
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
// 银行收付处理
|
// 银行收付处理
|
||||||
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/ctm/cmp/bankReconciliationBatchSave":
|
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/ctm/cmp/bankReconciliationBatchSave":
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package shkd.sys.sys.plugin.form;
|
package shkd.sys.sys.plugin.form;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import kd.bos.bill.AbstractBillPlugIn;
|
import kd.bos.bill.AbstractBillPlugIn;
|
||||||
import kd.bos.form.control.Toolbar;
|
import kd.bos.form.control.Toolbar;
|
||||||
import kd.bos.form.control.events.ItemClickEvent;
|
import kd.bos.form.control.events.ItemClickEvent;
|
||||||
|
@ -8,7 +7,6 @@ import kd.sdk.plugin.Plugin;
|
||||||
import shkd.sys.sys.mservice.ApiService;
|
import shkd.sys.sys.mservice.ApiService;
|
||||||
|
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单据界面插件
|
* 单据界面插件
|
||||||
|
|
|
@ -63,13 +63,10 @@ public class PushTaskPlugin extends AbstractTask implements Plugin {
|
||||||
"shkd_pushstatus,shkd_businessnumber,shkd_businessid,shkd_businessname,billstatus,bankpaystatus"
|
"shkd_pushstatus,shkd_businessnumber,shkd_businessid,shkd_businessname,billstatus,bankpaystatus"
|
||||||
, new QFilter("bizdate", QCP.large_equals, date)
|
, new QFilter("bizdate", QCP.large_equals, date)
|
||||||
.and("shkd_pushstatus", QCP.not_equals, "已结算")
|
.and("shkd_pushstatus", QCP.not_equals, "已结算")
|
||||||
.and("shkd_pushstatus", QCP.not_equals, "未结算")
|
|
||||||
.and("shkd_pushstatus", QCP.not_equals, "结算失败")
|
.and("shkd_pushstatus", QCP.not_equals, "结算失败")
|
||||||
.and("billstatus", QCP.equals, "D").toArray());
|
.and("billstatus", QCP.equals, "D").toArray());
|
||||||
dynamicObjects = Arrays.asList(objects1);
|
dynamicObjects = Arrays.asList(objects1);
|
||||||
dynamicObjects.forEach(dynamicObject -> {
|
dynamicObjects.forEach(dynamicObject -> ApiService.paymentSlipsJson(dynamicObject, "BIP", dynamicObjectList));
|
||||||
ApiService.paymentSlipsJson(dynamicObject, "BIP", dynamicObjectList);
|
|
||||||
});
|
|
||||||
SaveServiceHelper.save(dynamicObjectList.toArray(new DynamicObject[0]));
|
SaveServiceHelper.save(dynamicObjectList.toArray(new DynamicObject[0]));
|
||||||
break;
|
break;
|
||||||
// 收款处理
|
// 收款处理
|
||||||
|
@ -79,8 +76,10 @@ public class PushTaskPlugin extends AbstractTask implements Plugin {
|
||||||
"payertype,org,bizdate,accountbank,payernumber,actrecamt,txt_description,shkd_pushstatus," +
|
"payertype,org,bizdate,accountbank,payernumber,actrecamt,txt_description,shkd_pushstatus," +
|
||||||
"shkd_businessnumber,shkd_businessid,shkd_businessname,billstatus"
|
"shkd_businessnumber,shkd_businessid,shkd_businessname,billstatus"
|
||||||
, new QFilter("bizdate", QCP.large_equals, date)
|
, new QFilter("bizdate", QCP.large_equals, date)
|
||||||
.and("shkd_pushstatus", QCP.not_equals, "已推送").toArray());
|
.and("shkd_pushstatus", QCP.not_equals, "已结算")
|
||||||
|
.and("billstatus", QCP.equals, "D").toArray());
|
||||||
dynamicObjects = Arrays.asList(objects2);
|
dynamicObjects = Arrays.asList(objects2);
|
||||||
|
dynamicObjects.forEach(dynamicObject -> ApiService.paymentSlipsJson(dynamicObject, "BIP", dynamicObjectList));
|
||||||
billName = "收款处理";
|
billName = "收款处理";
|
||||||
break;
|
break;
|
||||||
// 银行收付处理
|
// 银行收付处理
|
||||||
|
|
Loading…
Reference in New Issue