From 8c7c439c4e7cae3f36bb9a65beb976becf5ef786 Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Tue, 3 Dec 2024 16:27:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A=E9=82=B9?= =?UTF-8?q?=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85=E5=AE=B9?= =?UTF-8?q?=EF=BC=9AAPI=E6=98=A0=E5=B0=84=E5=85=AC=E5=85=B1=E5=8D=95?= =?UTF-8?q?=E6=8D=AE=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4=EF=BC=9A2024/1?= =?UTF-8?q?2/03?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shkd/sys/sys/mservice/ApiService.java | 31 ++++++++++--------- .../sys/plugin/form/ApiMappingBillPlugin.java | 2 +- .../sys/plugin/form/ApiTestBillPlugin.java | 4 +-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/ApiService.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/ApiService.java index e5ed3eb..49d8394 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/ApiService.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/ApiService.java @@ -39,29 +39,32 @@ public class ApiService { Map map = new HashMap<>(); String signature = generateSignature("appKey" + APP_KEY + "timestamp" + currentTimeMillis); logger.info("getBIPToken → 签名: {}", signature); - try { - // 禁用 SSL 证书验证 - disableSSLCertificateChecking(); - // 构建URL - String urlString = domainName + API_ENDPOINT + - "?appKey=" + APP_KEY + - "×tamp=" + currentTimeMillis + - "&signature=" + signature; - map.put("url", urlString); + + // 禁用 SSL 证书验证 + disableSSLCertificateChecking(); + // 构建URL + String urlString = domainName + API_ENDPOINT + + "?appKey=" + APP_KEY + + "×tamp=" + currentTimeMillis + + "&signature=" + signature; + map.put("url", urlString); // return urlString; + String token; + try { // 发送请求 Request request = buildRequest(urlString); logger.info("getBIPToken → 获取返回数据:{}", request); Response response = client.newCall(request).execute(); - String token = handleResponse(response); - map.put("token", token); - // 处理响应 - return map; + token = handleResponse(response); } catch (Exception e) { logger.error("getBIPToken → 请求失败: ", e); - return null; + token = null; } + map.put("token", token); + // 处理响应 + return map; + } private static Request buildRequest(String urlString) { diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java index 2bbf83b..8056840 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java @@ -173,7 +173,7 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin { apiEntity.setHeaders(headMap); Map paramsMap = new HashMap<>(); Map resultMap = ApiService.getBIPToken(domainName); - paramsMap.put("access_token", resultMap != null ? resultMap.get("token") : ""); + paramsMap.put("access_token", resultMap.get("token")); apiEntity.setQueryParams(paramsMap); apiEntity.setRequestBody(codeEdit.getText()); JSONObject responseBody = ApiEntity.getResponseBody(apiEntity); 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 index 6eeb973..decec33 100644 --- 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 @@ -36,13 +36,13 @@ public class ApiTestBillPlugin extends AbstractBillPlugIn implements Plugin { if ("shkd_token".equals(key)) { String url = this.getModel().getValue("shkd_url").toString(); Map resultMap = ApiService.getBIPToken(url); - this.getView().showTipNotification(resultMap != null ? resultMap.get("token").toString() : "数据为空"); + this.getView().showTipNotification(resultMap.get("token") == null ? "获取token为空" :resultMap.get("token").toString()); } if ("shkd_geturl".equals(key)) { String url = this.getModel().getValue("shkd_url").toString(); Map resultMap = ApiService.getBIPToken(url); - this.getView().showTipNotification(resultMap != null ? resultMap.get("url").toString() : "数据为空"); + this.getView().showTipNotification(resultMap.get("url").toString()); } if ("shkd_api".equals(key)) {