From 844833179145af896e2e45acacaf350a0408860f Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Thu, 14 Nov 2024 14:42:38 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E9=82=B9=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9A=E5=B0=9D=E8=AF=95=E8=B0=83=E7=94=A8=E4=BB=98?= =?UTF-8?q?=E6=AC=BE=E5=A4=84=E7=90=86=E6=8E=A5=E5=8F=A31.0=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=97=B6=E9=97=B4=EF=BC=9A2024/11/14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/shkd/sys/sys/common/ApiEntity.java | 105 ++++++++++++ .../shkd/sys/sys/mservice/BIPService.java | 156 ++++++++++++++++++ .../sys/plugin/api/PayBillApiSavePlugin.java | 2 + 3 files changed, 263 insertions(+) create mode 100644 sys/shkd-sys-sys/src/main/java/shkd/sys/sys/common/ApiEntity.java create mode 100644 sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/common/ApiEntity.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/common/ApiEntity.java new file mode 100644 index 0000000..6c07a27 --- /dev/null +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/common/ApiEntity.java @@ -0,0 +1,105 @@ +package shkd.sys.sys.common; + +import com.alibaba.fastjson.JSONObject; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +import java.util.ArrayList; +import java.util.Map; + +/** + * @Description + * @Author Tao + * @Date 2024/11/14 + */ +public class ApiEntity { + private String URL;//链接 + private String method;//请求方式 + private Map queryParams;//请求参数 + private Map headers;//请求头参数 + private JSONObject requestBody;//请求体 + + public String getURL() { + return URL; + } + + public void setURL(String URL) { + this.URL = URL; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public Map getQueryParams() { + return queryParams; + } + + public void setQueryParams(Map queryParams) { + this.queryParams = queryParams; + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + + public JSONObject getRequestBody() { + return requestBody; + } + + public void setRequestBody(JSONObject requestBody) { + this.requestBody = requestBody; + } + + public ApiEntity(String URL, String method, Map queryParams, Map headers, JSONObject requestBody) { + this.URL = URL; + this.method = method; + this.queryParams = queryParams; + this.headers = headers; + this.requestBody = requestBody; + } + + public ApiEntity() { + } + + public static JSONObject getResponseBody(ApiEntity apiEntity) { + RestTemplate restTemplate = new RestTemplate(); + HttpHeaders httpHeaders = new HttpHeaders(); + Map heads = apiEntity.getHeaders(); + if (heads != null) { + for (String key : heads.keySet()) { + httpHeaders.add(key, heads.get(key).toString()); + } + } + + HttpEntity objectHttpEntity = new HttpEntity<>(httpHeaders); + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(apiEntity.getURL()); + Map params = apiEntity.getQueryParams(); + if (params != null) { + for (String key : params.keySet()) { + uriComponentsBuilder.queryParam(key, params.get(key)); + } + } + + HttpMethod method; + if (apiEntity.getMethod().equals("POST")) { + method = HttpMethod.POST; + } else { + method = HttpMethod.GET; + } + ResponseEntity exchange = restTemplate.exchange(uriComponentsBuilder.build().toString(), method, objectHttpEntity, String.class); + return JSONObject.parseObject(exchange.getBody()); + } +} diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java new file mode 100644 index 0000000..1bf02ff --- /dev/null +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java @@ -0,0 +1,156 @@ +package shkd.sys.sys.mservice; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.logging.Log; +import kd.bos.logging.LogFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContextBuilder; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import shkd.sys.sys.common.ApiEntity; + +import javax.net.ssl.SSLContext; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; + +/** + * @Description + * @Author Tao + * @Date 2024/11/11 + */ +public class BIPService { + private static final Log logger = LogFactory.getLog(BIPService.class); + + public static String getBIPToken() { + String access_token = null; + long currentTimeMillis = System.currentTimeMillis(); + try { + RestTemplate restTemplate = new RestTemplate(); + HttpHeaders httpHeaders = new HttpHeaders(); + HttpEntity objectHttpEntity = new HttpEntity<>(httpHeaders); + UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://biptest.ctny.com.cn/iuap-api-auth/open-auth/selfAppAuth/getAccessToken") + .queryParam("appKey", "22564a240d3140d0b15582aca71a748c") + .queryParam("timestamp", currentTimeMillis) + .queryParam("signature", generateSignature("appKey22564a240d3140d0b15582aca71a748ctimestamp" + currentTimeMillis)); + ResponseEntity exchange = restTemplate.exchange(builder.build().toString(), HttpMethod.GET, objectHttpEntity, String.class); + JSONObject jsonObject = JSON.parseObject(exchange.getBody()); + if ("00000".equals(jsonObject.getString("code"))){ + JSONObject data = jsonObject.getJSONObject("data"); + access_token = data.getString("access_token"); + logger.info("getBIPToken → access_token:{}", access_token); + return access_token; + } + } catch (Exception e) { + e.printStackTrace(); + } + return access_token; + } + + private static RestTemplate createRestTemplateIgnoringSsl() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + SSLContext sslContext = new SSLContextBuilder() + .loadTrustMaterial(null, (chain, authType) -> true) + .build(); + + SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); + CloseableHttpClient httpClient = HttpClients.custom() + .setSSLSocketFactory(socketFactory) + .build(); + + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient); + return new RestTemplate(factory); + } + + private static String generateSignature(String toSign) throws Exception { + // 计算 HmacSHA256 签名 + byte[] hmacData = computeHmacSha256(toSign); + + // Base64 编码 + String base64Encoded = Base64.getEncoder().encodeToString(hmacData); + + // URL 编码 + return URLEncoder.encode(base64Encoded, StandardCharsets.UTF_8.toString()); + } + + private static byte[] computeHmacSha256(String data) throws Exception { + SecretKeySpec secretKey = new SecretKeySpec("79f0b7daa428c1abd9272565dbc65486ab565c80".getBytes(StandardCharsets.UTF_8), "HmacSHA256"); + Mac mac = Mac.getInstance("HmacSHA256"); + mac.init(secretKey); + return mac.doFinal(data.getBytes(StandardCharsets.UTF_8)); + } + + /** + * 组装推送BIP付款单JSON + * + * @return + */ + public static JSONObject paymentSlipsJson() { + ApiEntity apiEntity = new ApiEntity(); + + JSONObject root = new JSONObject(); + + // 创建"data"节点 + JSONObject data = new JSONObject(); + + // 设置"data"节点的属性 + data.put("accentity_code", "SIG1040100"); + data.put("vouchdate", "2022-04-20"); + data.put("tradetype_code", "cmp_fund_payment_other"); + data.put("exchangeRateType_code", "01"); + data.put("exchRate", 1); + data.put("currency_code", "CNY"); + data.put("_status", "Insert"); + + // 创建"FundPayment_b"列表 + JSONArray fundPaymentList = new JSONArray(); + + // 创建"FundPayment_b"列表中的第一个对象 + JSONObject fundPayment = new JSONObject(); + fundPayment.put("quickType_code", "6"); + fundPayment.put("settlestatus", "1"); + fundPayment.put("oriSum", 5000); + fundPayment.put("caobject", 2); + fundPayment.put("oppositeobjectname", "11510107MB1526717D"); + fundPayment.put("_status", "Insert"); + + // 将"FundPayment_b"对象添加到列表中 + fundPaymentList.add(fundPayment); + // 将"FundPayment_b"列表添加到"data"节点中 + data.put("FundPayment_b", fundPaymentList); + // 将"data"节点添加到根JSON对象中 + root.put("data", data); + + apiEntity.setURL(""); + apiEntity.setRequestBody(root); + apiEntity.setMethod("POST"); + + Map queryParams = new HashMap<>(); + queryParams.put("access_token", getBIPToken()); + apiEntity.setQueryParams(queryParams); + + Map headers = new HashMap<>(); + headers.put("Content-Type", "application/json"); + apiEntity.setHeaders(headers); + + return ApiEntity.getResponseBody(apiEntity); + } +} diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java index c73829c..10b2399 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java @@ -65,7 +65,9 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin Object payeebankObj = map.get("payeebank"); + logger.info("payeebankObj:{}", payeebankObj); Map payeebankMap = (Map) payeebankObj; + logger.info("payeebankMap:{}", payeebankMap); bankNumber = (String) payeebankMap.get("number"); From cfb429d6999d054ac91b6ec7b972a30b7726af16 Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Thu, 14 Nov 2024 14:48:55 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E9=82=B9=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9A=E6=B5=8B=E8=AF=95=E8=A1=A8=E5=8D=95=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4=EF=BC=9A2024/1?= =?UTF-8?q?1/14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sys/plugin/form/ApiTestBillPlugin.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiTestBillPlugin.java diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiTestBillPlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiTestBillPlugin.java new file mode 100644 index 0000000..b0be6fd --- /dev/null +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiTestBillPlugin.java @@ -0,0 +1,46 @@ +package shkd.sys.sys.plugin.form; + +import com.alibaba.fastjson.JSONObject; +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.form.control.Toolbar; +import kd.bos.form.control.events.ItemClickEvent; +import kd.sdk.plugin.Plugin; +import shkd.sys.sys.mservice.BIPService; + +import java.util.EventObject; + +/** + * 单据界面插件 + */ +public class ApiTestBillPlugin extends AbstractBillPlugIn implements Plugin { + @Override + public void registerListener(EventObject e) { +// super.registerListener(e); + + // 获取工具栏,监听整个工具栏 + Toolbar save = this.getView().getControl("tbmain"); + // 监听工具栏这个按钮的点击事件 + save.addItemClickListener(this); + + // 获取除了工具栏上的其他按钮 + // Button save = this.getView().getControl("qwz5_baritemap"); + // save.addClickListener(this); // 添加出菜单栏点击事件监听 + } + @Override + public void itemClick(ItemClickEvent evt) { + super.itemClick(evt); + // 获取键 + String key = evt.getItemKey(); + + if ("shkd_token".equals(key)) { + String bipToken = BIPService.getBIPToken(); + this.getView().showTipNotification(bipToken); + } + + if ("shkd_api".equals(key)) { + JSONObject jsonObject = BIPService.paymentSlipsJson(); + this.getView().showTipNotification(jsonObject.toJSONString()); + } + } + +} \ No newline at end of file From 268063abab947a984c5b37cb93a56f755f1b39ff Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Thu, 14 Nov 2024 15:07:48 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E9=82=B9=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9A=E6=B5=8B=E8=AF=95=E8=A1=A8=E5=8D=95=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4=EF=BC=9A2024/1?= =?UTF-8?q?1/14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/shkd/sys/sys/mservice/BIPService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java index 1bf02ff..5c34b8b 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java @@ -48,10 +48,12 @@ public class BIPService { RestTemplate restTemplate = new RestTemplate(); HttpHeaders httpHeaders = new HttpHeaders(); HttpEntity objectHttpEntity = new HttpEntity<>(httpHeaders); + String signature = generateSignature("appKey22564a240d3140d0b15582aca71a748ctimestamp" + currentTimeMillis); + logger.info("getBIPToken\ntimestamp:{}\nsignature:{}", currentTimeMillis, signature); UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://biptest.ctny.com.cn/iuap-api-auth/open-auth/selfAppAuth/getAccessToken") .queryParam("appKey", "22564a240d3140d0b15582aca71a748c") .queryParam("timestamp", currentTimeMillis) - .queryParam("signature", generateSignature("appKey22564a240d3140d0b15582aca71a748ctimestamp" + currentTimeMillis)); + .queryParam("signature", signature); ResponseEntity exchange = restTemplate.exchange(builder.build().toString(), HttpMethod.GET, objectHttpEntity, String.class); JSONObject jsonObject = JSON.parseObject(exchange.getBody()); if ("00000".equals(jsonObject.getString("code"))){ @@ -61,7 +63,7 @@ public class BIPService { return access_token; } } catch (Exception e) { - e.printStackTrace(); + logger.info("报错信息 error:" + e); } return access_token; } From be0769c0648ec960be008806e65ace82914b35c7 Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Thu, 14 Nov 2024 16:26:08 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E9=82=B9=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9A=E5=B0=9D=E8=AF=95=E8=B0=83=E7=94=A8=E4=BB=98?= =?UTF-8?q?=E6=AC=BE=E5=A4=84=E7=90=86=E6=8E=A5=E5=8F=A31.1=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=97=B6=E9=97=B4=EF=BC=9A2024/11/14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shkd/sys/sys/mservice/BIPService.java | 122 ++++++++++++------ 1 file changed, 79 insertions(+), 43 deletions(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java index 5c34b8b..15249d3 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java @@ -3,32 +3,20 @@ package shkd.sys.sys.mservice; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import kd.bos.dataentity.entity.DynamicObject; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContextBuilder; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import shkd.sys.sys.common.ApiEntity; -import javax.net.ssl.SSLContext; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; - import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import javax.net.ssl.*; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.security.cert.X509Certificate; import java.util.Base64; import java.util.HashMap; import java.util.Map; @@ -45,41 +33,89 @@ public class BIPService { String access_token = null; long currentTimeMillis = System.currentTimeMillis(); try { - RestTemplate restTemplate = new RestTemplate(); - HttpHeaders httpHeaders = new HttpHeaders(); - HttpEntity objectHttpEntity = new HttpEntity<>(httpHeaders); - String signature = generateSignature("appKey22564a240d3140d0b15582aca71a748ctimestamp" + currentTimeMillis); - logger.info("getBIPToken\ntimestamp:{}\nsignature:{}", currentTimeMillis, signature); - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://biptest.ctny.com.cn/iuap-api-auth/open-auth/selfAppAuth/getAccessToken") - .queryParam("appKey", "22564a240d3140d0b15582aca71a748c") - .queryParam("timestamp", currentTimeMillis) - .queryParam("signature", signature); - ResponseEntity exchange = restTemplate.exchange(builder.build().toString(), HttpMethod.GET, objectHttpEntity, String.class); - JSONObject jsonObject = JSON.parseObject(exchange.getBody()); - if ("00000".equals(jsonObject.getString("code"))){ + // 禁用 SSL 证书验证 + disableSSLCertificateChecking(); +// RestTemplate restTemplate = new RestTemplate(); + String appKey = "22564a240d3140d0b15582aca71a748c"; + String timestamp = String.valueOf(currentTimeMillis); + String signature = generateSignature("appKey" + appKey + "timestamp" + timestamp); + + // 构建URL + String urlString = "https://biptest.ctny.com.cn/iuap-api-auth/open-auth/selfAppAuth/getAccessToken" + + "?appKey=22564a240d3140d0b15582aca71a748c" + + "×tamp=" + currentTimeMillis + + "&signature=" + signature; + + URL url = new URL(urlString); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Accept", "application/json"); + + int responseCode = connection.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + // 读取响应 + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String inputLine; + StringBuilder response = new StringBuilder(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + // 解析响应 + JSONObject jsonObject = JSON.parseObject(response.toString()); JSONObject data = jsonObject.getJSONObject("data"); access_token = data.getString("access_token"); - logger.info("getBIPToken → access_token:{}", access_token); - return access_token; + logger.info("getBIPToken → 接口调用成功,access_token: {}", access_token); + } else { + logger.error("getBIPToken → 接口调用失败,状态码: {}", responseCode); } } catch (Exception e) { - logger.info("报错信息 error:" + e); + logger.error("getBIPToken → 调用接口报错: {}", e.getMessage()); } return access_token; } - private static RestTemplate createRestTemplateIgnoringSsl() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { - SSLContext sslContext = new SSLContextBuilder() - .loadTrustMaterial(null, (chain, authType) -> true) - .build(); + public static SSLContext createInsecureSSLContext() throws Exception { + // 创建一个信任所有证书的 TrustManager + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } - SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); - CloseableHttpClient httpClient = HttpClients.custom() - .setSSLSocketFactory(socketFactory) - .build(); + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } - HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient); - return new RestTemplate(factory); + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } + }; + + // 安装信任所有证书的 TrustManager + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); + return sslContext; + } + + public static void disableSSLCertificateChecking() { + try { + // 创建一个信任所有证书的 SSLContext + SSLContext sslContext = createInsecureSSLContext(); + + // 设置 HttpsURLConnection 使用这个 SSLContext + HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); + + // 创建一个 HostnameVerifier,信任所有主机名 + HostnameVerifier allHostsValid = (hostname, session) -> true; + + // 安装这个 HostnameVerifier + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + } catch (Exception e) { + e.printStackTrace(); + } } private static String generateSignature(String toSign) throws Exception { From c8809f56299603f3d46dbdd5661b7736fe4e4cc1 Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Thu, 14 Nov 2024 16:41:35 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E9=82=B9=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9A=E5=B0=9D=E8=AF=95=E8=B0=83=E7=94=A8=E4=BB=98?= =?UTF-8?q?=E6=AC=BE=E5=A4=84=E7=90=86=E6=8E=A5=E5=8F=A31.1=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=97=B6=E9=97=B4=EF=BC=9A2024/11/14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/shkd/sys/sys/mservice/BIPService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java index 15249d3..dc933e7 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/BIPService.java @@ -73,7 +73,7 @@ public class BIPService { logger.error("getBIPToken → 接口调用失败,状态码: {}", responseCode); } } catch (Exception e) { - logger.error("getBIPToken → 调用接口报错: {}", e.getMessage()); + logger.error("getBIPToken → 调用接口报错: {}", e); } return access_token; } From 53e242657929d7aeb04dc609226a81b7834b5b20 Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Thu, 14 Nov 2024 17:03:30 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E9=82=B9=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9AAPI=E5=85=A5=E5=8F=82=E5=87=BA=E5=8F=82?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=EF=BC=9A2024/11/14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sys/plugin/api/PayBillApiSavePlugin.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java index 10b2399..cdbe5e6 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java @@ -63,17 +63,13 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin //收款人ID fieldName1 = "payee"; - - Object payeebankObj = map.get("payeebank"); - logger.info("payeebankObj:{}", payeebankObj); - Map payeebankMap = (Map) payeebankObj; - logger.info("payeebankMap:{}", payeebankMap); - bankNumber = (String) payeebankMap.get("number"); - + Map payeebankObj = (Map) map.get("payeebank"); + bankNumber = (String) payeebankObj.get("number"); + logger.info("付款处理 → \nobjectType:{}\nobjectNumber:{}\nbankNumber:{}", objectType, objectNumber, bankNumber); fieldName2 = "payerbank"; - DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); - logger.info("objectType:{},objectNumber:{}", objectType, objectNumber); + DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id,billno", new QFilter("billno", QCP.equals, objectNumber).toArray()); + logger.info("objectNumber:{}", objectNumber); DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); logger.info("amAccountbank:{}", amAccountbank); map.put(fieldName1, dynamicObject.getString("id")); @@ -90,10 +86,9 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin fieldName1 = "payer"; - Object accountbank = map.get("accountbank"); - Map accountbankMap = (Map) accountbank; - bankNumber = (String) accountbankMap.get("number"); - + Map accountbank = (Map) map.get("accountbank"); + bankNumber = (String) accountbank.get("number"); + logger.info("收款处理 → \nobjectType:{}\nobjectNumber:{}\nbankNumber:{}", objectType, objectNumber, bankNumber); fieldName2 = "payeebank"; DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); logger.info("objectType:{},objectNumber:{}", objectType, objectNumber); From df62a13ac3417f4f9d82fdf84fe0afd60b9fb12f Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Thu, 14 Nov 2024 17:32:49 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E9=82=B9=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9AAPI=E5=85=A5=E5=8F=82=E5=87=BA=E5=8F=82?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=EF=BC=9A2024/11/14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sys/plugin/api/PayBillApiSavePlugin.java | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java index cdbe5e6..6c92e57 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java @@ -68,15 +68,21 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin logger.info("付款处理 → \nobjectType:{}\nobjectNumber:{}\nbankNumber:{}", objectType, objectNumber, bankNumber); fieldName2 = "payerbank"; - DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id,billno", new QFilter("billno", QCP.equals, objectNumber).toArray()); - logger.info("objectNumber:{}", objectNumber); - DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); - logger.info("amAccountbank:{}", amAccountbank); - map.put(fieldName1, dynamicObject.getString("id")); - + DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load(objectType, "id,billno", new QFilter("billno", QCP.equals, objectNumber).toArray()); + logger.info("dynamicObjects.length:{}", dynamicObjects.length); + if (dynamicObjects.length > 0) { + map.put(fieldName1, dynamicObjects[0].getPkValue()); + logger.info("dynamicObjects[0]:{}", dynamicObjects[0]); + } + DynamicObject[] amAccountbanks = BusinessDataServiceHelper.load("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); + logger.info("amAccountbanks.length:{}", amAccountbanks.length); Map payerbank = new HashMap<>(); - payerbank.put("number", amAccountbank.getDynamicObject("bank").getString("number")); + if (amAccountbanks.length > 0) { + payerbank.put("number", amAccountbanks[0].getDynamicObject("bank").getString("number")); + logger.info("amAccountbanks[0]:{}", amAccountbanks[0]); + } + logger.info("payerbank:{}", payerbank); map.put(fieldName2, payerbank); } @@ -90,14 +96,20 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin bankNumber = (String) accountbank.get("number"); logger.info("收款处理 → \nobjectType:{}\nobjectNumber:{}\nbankNumber:{}", objectType, objectNumber, bankNumber); fieldName2 = "payeebank"; - DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); - logger.info("objectType:{},objectNumber:{}", objectType, objectNumber); - DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); - logger.info("amAccountbank:{}", amAccountbank); - map.put(fieldName1, dynamicObject.getString("id")); + DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); + logger.info("dynamicObjects.length:{}", dynamicObjects.length); + if (dynamicObjects.length > 0) { + map.put(fieldName1, dynamicObjects[0].getPkValue()); + logger.info("dynamicObjects[0]:{}", dynamicObjects[0]); + } + DynamicObject[] amAccountbanks = BusinessDataServiceHelper.load("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); + logger.info("amAccountbanks.length:{}", amAccountbanks.length); Map payeebank = new HashMap<>(); - payeebank.put("number", amAccountbank.getDynamicObject("bank").getString("number")); + if (amAccountbanks.length > 0) { + payeebank.put("number", amAccountbanks[0].getDynamicObject("bank").getString("number")); + } + logger.info("payerbank:{}", payeebank); map.put(fieldName2, payeebank); } shkd_businessid = map.get("shkd_businessid").toString(); From 8d75042642dd5289ca410298e43e21201b3c6fde Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Thu, 14 Nov 2024 18:04:53 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E9=82=B9=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9AAPI=E5=85=A5=E5=8F=82=E5=87=BA=E5=8F=82?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=EF=BC=9A2024/11/14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java index 6c92e57..326519d 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java @@ -68,7 +68,7 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin logger.info("付款处理 → \nobjectType:{}\nobjectNumber:{}\nbankNumber:{}", objectType, objectNumber, bankNumber); fieldName2 = "payerbank"; - DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load(objectType, "id,billno", new QFilter("billno", QCP.equals, objectNumber).toArray()); + DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load(objectType, "id,number", new QFilter("number", QCP.equals, objectNumber).toArray()); logger.info("dynamicObjects.length:{}", dynamicObjects.length); if (dynamicObjects.length > 0) { map.put(fieldName1, dynamicObjects[0].getPkValue()); @@ -96,7 +96,7 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin bankNumber = (String) accountbank.get("number"); logger.info("收款处理 → \nobjectType:{}\nobjectNumber:{}\nbankNumber:{}", objectType, objectNumber, bankNumber); fieldName2 = "payeebank"; - DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); + DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load(objectType, "id,number", new QFilter("number", QCP.equals, objectNumber).toArray()); logger.info("dynamicObjects.length:{}", dynamicObjects.length); if (dynamicObjects.length > 0) { map.put(fieldName1, dynamicObjects[0].getPkValue()); From e71bb9a76cca8f675de3c16a807603aeb2036128 Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Fri, 15 Nov 2024 15:50:16 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E9=82=B9=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9AAPI=E5=85=A5=E5=8F=82=E5=87=BA=E5=8F=82?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=EF=BC=9A2024/11/15?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java index 326519d..0ca45a9 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java @@ -142,7 +142,9 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin } else { logger.info("进入else"); //其他类型的出参序列化 - return null; + String responseStr = new ObjectMapper().writeValueAsString(response); + JSONObject jsonObject = JSON.parseObject(responseStr); + return new SerializerResult(MediaType.TEXT_PLAIN, jsonObject.toJSONString()); } } catch (JsonProcessingException e) { logger.info("catch");