From 7681486ac6720462380e5549933f29e83b0d35dd Mon Sep 17 00:00:00 2001 From: wangsq Date: Tue, 18 Nov 2025 14:43:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ynxbd/common/action/AliAction.java | 2 +- .../ynxbd/common/action/HealthCodeAction.java | 6 +- .../ynxbd/common/service/HCodeService.java | 117 +++++++----------- 3 files changed, 54 insertions(+), 71 deletions(-) diff --git a/src/main/java/com/ynxbd/common/action/AliAction.java b/src/main/java/com/ynxbd/common/action/AliAction.java index 89afa4e..c3b8b3e 100644 --- a/src/main/java/com/ynxbd/common/action/AliAction.java +++ b/src/main/java/com/ynxbd/common/action/AliAction.java @@ -128,7 +128,7 @@ public class AliAction extends BaseAction { if (ObjectUtils.isEmpty(areaCode)) { areaCode = county; } - return new PatientService().bindMyself(trueName, idCardNo, cardTypeEnum, areaCode, areaAddress, address, openid, gender, nation, birthday, isVerifyCode, tel, smsCode); + return new PatientService().bindMyself(trueName, idCardNo, cardTypeEnum, address, areaCode, areaAddress, openid, gender, nation, birthday, isVerifyCode, tel, smsCode); } diff --git a/src/main/java/com/ynxbd/common/action/HealthCodeAction.java b/src/main/java/com/ynxbd/common/action/HealthCodeAction.java index 4ab1701..1e39f76 100644 --- a/src/main/java/com/ynxbd/common/action/HealthCodeAction.java +++ b/src/main/java/com/ynxbd/common/action/HealthCodeAction.java @@ -382,7 +382,11 @@ public class HealthCodeAction extends BaseAction { /** * 实人认证生成orderId - * * @param qrCodeText 二维码编码 + * + * @param idCardNo idCardNo + * @param name name + * @param wechatCode wechatCode + * @return result */ @Action("registerUniformVerifyOrder") public Result registerUniformVerifyOrder(String idCardNo, String name, String wechatCode) { diff --git a/src/main/java/com/ynxbd/common/service/HCodeService.java b/src/main/java/com/ynxbd/common/service/HCodeService.java index 2a517ce..36e9cef 100644 --- a/src/main/java/com/ynxbd/common/service/HCodeService.java +++ b/src/main/java/com/ynxbd/common/service/HCodeService.java @@ -48,8 +48,7 @@ public class HCodeService { static { ProperHelper config = new ProperHelper().read("hcode.properties"); IS_ENABLE = config.getBoolean("is_enable", false); - config.setIsEnable(IS_ENABLE); - + // 不用对config设置开关,不开启时也需要用到参数 H_APP_ID = config.getString("h.app_id"); H_APP_SECRET = config.getString("h.app_secret"); CARD_APP_ID = config.getString("h.card_app_id"); @@ -72,6 +71,12 @@ public class HCodeService { } + private CommonIn createCommonIn(String appToken) { + String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); + int channelNum = 0; + return new CommonIn(appToken, requestId, H_HOSPITAL_ID, channelNum); + } + /** * 判断是否使用电子健康卡 * @@ -79,19 +84,22 @@ public class HCodeService { */ public static boolean isEnableHCode() { if (!IS_ENABLE) { - log.info("hcode.properties中禁用电子健康卡isEnable={}", IS_ENABLE); + log.info("hcode.properties中禁用电子健康卡 isEnable={}", IS_ENABLE); } return IS_ENABLE; } + public String getAppToken() { + return getAppToken(true); + } /** * 获取token * * @return token */ - public String getAppToken() { - if (!isEnableHCode()) { + public String getAppToken(boolean isEnTokenSwitch) { + if (isEnTokenSwitch && !isEnableHCode()) { return null; } @@ -107,25 +115,19 @@ public class HCodeService { } try { - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET, 5, 10); - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - int channelNum = 0; - CommonIn commonIn = new CommonIn("", requestId, H_HOSPITAL_ID, channelNum); //调用接口 - JSONObject appTokenObj = healthCard.getAppToken(commonIn, H_APP_ID); - - //调用接口 - JSONObject resultObj = healthCard.getAppToken(commonIn, H_APP_ID); + JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET, 5, 10) + .getAppToken(createCommonIn(""), H_APP_ID); JSONObject commonOut = resultObj.getJSONObject("commonOut"); if (!"0".equals(commonOut.getString("resultCode"))) { log.info("[电子健康卡]获取appToken失败: {}", resultObj); return null; } - JSONObject respJson = appTokenObj.getJSONObject("rsp"); + JSONObject respJson = resultObj.getJSONObject("rsp"); appToken = respJson.getString("appToken"); - if (CACHE != null && appToken != null && !"".equals(appToken)) { + if (CACHE != null && !ObjectUtils.isEmpty(appToken)) { CACHE.put("appToken", appToken); } @@ -148,10 +150,9 @@ public class HCodeService { if (appToken == null) { return null; } - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); - JSONObject resultObj = healthCard.getHealthCardByHealthCode(commonIn, healthCode); + CommonIn commonIn = createCommonIn(appToken); + + JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).getHealthCardByHealthCode(commonIn, healthCode); JSONObject rspObj = resultObj.getJSONObject("rsp"); JSONObject cardJson = rspObj.getJSONObject("card"); Patient patient = new Patient(); @@ -199,11 +200,8 @@ public class HCodeService { areaAddress = ""; } - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); + CommonIn commonIn = createCommonIn(appToken); - // 构造公共输入参数commonIn - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); HealthCardInfo healthCardInfoReq = new HealthCardInfo(); healthCardInfoReq.setAddress(areaAddress + address); healthCardInfoReq.setBirthday(birthday); @@ -216,7 +214,7 @@ public class HCodeService { healthCardInfoReq.setWechatCode(wechatCode); healthCardInfoReq.setPatid(patientId); //调用接口 - JSONObject resultObj = healthCard.registerHealthCard(commonIn, healthCardInfoReq); + JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).registerHealthCard(commonIn, healthCardInfoReq); JSONObject commonOut = resultObj.getJSONObject("commonOut"); if (!"0".equals(commonOut.getString("resultCode"))) { log.info("[电子健康卡]注册失败: {}", resultObj); @@ -237,15 +235,13 @@ public class HCodeService { */ public Patient getInfoByHealthCode(String healthCode) { try { - String appToken = getAppToken(); + String appToken = getAppToken(false); if (appToken == null) { return null; } - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); + CommonIn commonIn = createCommonIn(appToken); //调用接口 - JSONObject resultObj = healthCard.getHealthCardByHealthCode(commonIn, healthCode); + JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).getHealthCardByHealthCode(commonIn, healthCode); JSONObject commonOut = resultObj.getJSONObject("commonOut"); JSONObject rspObj = resultObj.getJSONObject("rsp"); if (!"0".equals(commonOut.getString("resultCode")) || rspObj == null) { @@ -298,11 +294,9 @@ public class HCodeService { if (appToken == null) { return null; } - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); + CommonIn commonIn = createCommonIn(appToken); //调用接口 - JSONObject resultObj = healthCard.getHealthCardByQRCode(commonIn, qrCode); + JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).getHealthCardByQRCode(commonIn, qrCode); JSONObject commonOut = resultObj.getJSONObject("commonOut"); if (!"0".equals(commonOut.getString("resultCode"))) { log.info("[电子健康卡]二维码获取健康卡失败: {}", resultObj); @@ -348,11 +342,13 @@ public class HCodeService { if (appToken == null) { return null; } - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); + CommonIn commonIn = createCommonIn(appToken); //调用接口 - JSONObject resultJson = healthCard.registerUniformVerifyOrder(commonIn, idCardNo, "01", name, wechatCode); + + + String okURL = WeChatConfig.getWebUrl() + "/health-card-bind.html"; + + JSONObject resultJson = new HealthCardServerImpl(H_APP_SECRET).registerUniformVerifyOrder(commonIn, idCardNo, "01", name, wechatCode); JSONObject commonOut = resultJson.getJSONObject("commonOut"); if (!"0".equals(commonOut.getString("resultCode"))) { log.info("[电子健康卡]实人认证生成orderId接口失败: {}", resultJson); @@ -383,11 +379,9 @@ public class HCodeService { if (appToken == null) { return false; } - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); + CommonIn commonIn = createCommonIn(appToken); //调用接口 - JSONObject resultJson = healthCard.checkUniformVerifyResult(commonIn, verifyOrderId, registerOrderId); + JSONObject resultJson = new HealthCardServerImpl(H_APP_SECRET).checkUniformVerifyResult(commonIn, verifyOrderId, registerOrderId); JSONObject commonOut = resultJson.getJSONObject("commonOut"); if (!"0".equals(commonOut.getString("resultCode"))) { log.info("[电子健康卡]实人认证结果查询失败: {}", resultJson); @@ -418,11 +412,9 @@ public class HCodeService { return null; } - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); + CommonIn commonIn = createCommonIn(appToken); //调用接口 - JSONObject resultObj = healthCard.getOrderIdByOutAppId(commonIn, WeChatConfig.APP_ID, qrCodeText); + JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).getOrderIdByOutAppId(commonIn, WeChatConfig.APP_ID, qrCodeText); JSONObject commonOut = resultObj.getJSONObject("commonOut"); if (!"0".equals(commonOut.getString("resultCode"))) { log.info("[电子健康卡]获取卡包订单ID 失败: {}", resultObj); @@ -458,8 +450,7 @@ public class HCodeService { } HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); + CommonIn commonIn = createCommonIn(appToken); //构造请求参数req ReportHISData reportHISData = new ReportHISData(); reportHISData.setQrCodeText(qrCodeText); @@ -511,11 +502,9 @@ public class HCodeService { return null; } - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); + CommonIn commonIn = createCommonIn(appToken); //调用接口 - JSONObject resultObj = healthCard.getDynamicQRCode(commonIn, healthCardId, "01", idCardNo, codeType); + JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).getDynamicQRCode(commonIn, healthCardId, "01", idCardNo, codeType); JSONObject commonOut = resultObj.getJSONObject("commonOut"); if (!"0".equals(commonOut.getString("resultCode"))) { log.info("获取健康卡二维码失败: {}", resultObj); @@ -546,12 +535,8 @@ public class HCodeService { return null; } - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); - //构造公共输入参数commonIn - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); - JSONObject resultObj = healthCard.bindCardRelation(commonIn, patientId, qrCodeText); + CommonIn commonIn = createCommonIn(appToken); + JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).bindCardRelation(commonIn, patientId, qrCodeText); JSONObject commonOut = resultObj.getJSONObject("commonOut"); if (!"0".equals(commonOut.getString("resultCode"))) { log.info("[电子健康卡]绑定健康卡和医院关系失败: {}", resultObj); @@ -662,18 +647,14 @@ public class HCodeService { return null; } - String appToken = getAppToken(); + String appToken = getAppToken(false); // 未开启功能时也能获取token if (appToken == null) { return null; } - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); - //构造公共输入参数commonIn - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - int channelNum = 0; - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, channelNum); + CommonIn commonIn = createCommonIn(appToken); //调用接口 - JSONObject resultObj = healthCard.ocrInfo(commonIn, imageContent); + JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).ocrInfo(commonIn, imageContent); JSONObject commonOut = resultObj.getJSONObject("commonOut"); if (!"0".equals(commonOut.getString("resultCode"))) { log.info("[电子健康卡]身份证识别失败: {}", resultObj); @@ -759,12 +740,10 @@ public class HCodeService { * @return json */ public JSONArray batchUpdate(List lstPatient) { - HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); //构造公共输入参数commonIn String appToken = getAppToken(); - String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); - int channelNum = 0; - CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, channelNum); + CommonIn commonIn = createCommonIn(appToken); + List lstHealthCard = new ArrayList<>(); for (Patient patient : lstPatient) { HealthCardInfo healthCardInfo = new HealthCardInfo(); @@ -783,7 +762,7 @@ public class HCodeService { lstHealthCard.add(healthCardInfo); } - JSONObject healthCardInfosRsp = healthCard.registerBatchHealthCard(commonIn, lstHealthCard); + JSONObject healthCardInfosRsp = new HealthCardServerImpl(H_APP_SECRET).registerBatchHealthCard(commonIn, lstHealthCard); JSONObject commonOut = healthCardInfosRsp.getJSONObject("commonOut"); JSONObject rspObj = healthCardInfosRsp.getJSONObject("rsp"); if (!"0".equals(commonOut.getString("resultCode")) || rspObj == null) {