绑定调整

debug
王绍全 2 months ago
parent 5389a69d9f
commit 7681486ac6
  1. 2
      src/main/java/com/ynxbd/common/action/AliAction.java
  2. 6
      src/main/java/com/ynxbd/common/action/HealthCodeAction.java
  3. 117
      src/main/java/com/ynxbd/common/service/HCodeService.java

@ -128,7 +128,7 @@ public class AliAction extends BaseAction {
if (ObjectUtils.isEmpty(areaCode)) { if (ObjectUtils.isEmpty(areaCode)) {
areaCode = county; 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);
} }

@ -382,7 +382,11 @@ public class HealthCodeAction extends BaseAction {
/** /**
* 实人认证生成orderId * 实人认证生成orderId
* * @param qrCodeText 二维码编码 *
* @param idCardNo idCardNo
* @param name name
* @param wechatCode wechatCode
* @return result
*/ */
@Action("registerUniformVerifyOrder") @Action("registerUniformVerifyOrder")
public Result registerUniformVerifyOrder(String idCardNo, String name, String wechatCode) { public Result registerUniformVerifyOrder(String idCardNo, String name, String wechatCode) {

@ -48,8 +48,7 @@ public class HCodeService {
static { static {
ProperHelper config = new ProperHelper().read("hcode.properties"); ProperHelper config = new ProperHelper().read("hcode.properties");
IS_ENABLE = config.getBoolean("is_enable", false); IS_ENABLE = config.getBoolean("is_enable", false);
config.setIsEnable(IS_ENABLE); // 不用对config设置开关,不开启时也需要用到参数
H_APP_ID = config.getString("h.app_id"); H_APP_ID = config.getString("h.app_id");
H_APP_SECRET = config.getString("h.app_secret"); H_APP_SECRET = config.getString("h.app_secret");
CARD_APP_ID = config.getString("h.card_app_id"); 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() { public static boolean isEnableHCode() {
if (!IS_ENABLE) { if (!IS_ENABLE) {
log.info("hcode.properties中禁用电子健康卡isEnable={}", IS_ENABLE); log.info("hcode.properties中禁用电子健康卡 isEnable={}", IS_ENABLE);
} }
return IS_ENABLE; return IS_ENABLE;
} }
public String getAppToken() {
return getAppToken(true);
}
/** /**
* 获取token * 获取token
* *
* @return token * @return token
*/ */
public String getAppToken() { public String getAppToken(boolean isEnTokenSwitch) {
if (!isEnableHCode()) { if (isEnTokenSwitch && !isEnableHCode()) {
return null; return null;
} }
@ -107,25 +115,19 @@ public class HCodeService {
} }
try { 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 = new HealthCardServerImpl(H_APP_SECRET, 5, 10)
.getAppToken(createCommonIn(""), H_APP_ID);
//调用接口
JSONObject resultObj = healthCard.getAppToken(commonIn, H_APP_ID);
JSONObject commonOut = resultObj.getJSONObject("commonOut"); JSONObject commonOut = resultObj.getJSONObject("commonOut");
if (!"0".equals(commonOut.getString("resultCode"))) { if (!"0".equals(commonOut.getString("resultCode"))) {
log.info("[电子健康卡]获取appToken失败: {}", resultObj); log.info("[电子健康卡]获取appToken失败: {}", resultObj);
return null; return null;
} }
JSONObject respJson = appTokenObj.getJSONObject("rsp"); JSONObject respJson = resultObj.getJSONObject("rsp");
appToken = respJson.getString("appToken"); appToken = respJson.getString("appToken");
if (CACHE != null && appToken != null && !"".equals(appToken)) { if (CACHE != null && !ObjectUtils.isEmpty(appToken)) {
CACHE.put("appToken", appToken); CACHE.put("appToken", appToken);
} }
@ -148,10 +150,9 @@ public class HCodeService {
if (appToken == null) { if (appToken == null) {
return null; return null;
} }
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); CommonIn commonIn = createCommonIn(appToken);
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0); JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).getHealthCardByHealthCode(commonIn, healthCode);
JSONObject resultObj = healthCard.getHealthCardByHealthCode(commonIn, healthCode);
JSONObject rspObj = resultObj.getJSONObject("rsp"); JSONObject rspObj = resultObj.getJSONObject("rsp");
JSONObject cardJson = rspObj.getJSONObject("card"); JSONObject cardJson = rspObj.getJSONObject("card");
Patient patient = new Patient(); Patient patient = new Patient();
@ -199,11 +200,8 @@ public class HCodeService {
areaAddress = ""; 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(); HealthCardInfo healthCardInfoReq = new HealthCardInfo();
healthCardInfoReq.setAddress(areaAddress + address); healthCardInfoReq.setAddress(areaAddress + address);
healthCardInfoReq.setBirthday(birthday); healthCardInfoReq.setBirthday(birthday);
@ -216,7 +214,7 @@ public class HCodeService {
healthCardInfoReq.setWechatCode(wechatCode); healthCardInfoReq.setWechatCode(wechatCode);
healthCardInfoReq.setPatid(patientId); healthCardInfoReq.setPatid(patientId);
//调用接口 //调用接口
JSONObject resultObj = healthCard.registerHealthCard(commonIn, healthCardInfoReq); JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).registerHealthCard(commonIn, healthCardInfoReq);
JSONObject commonOut = resultObj.getJSONObject("commonOut"); JSONObject commonOut = resultObj.getJSONObject("commonOut");
if (!"0".equals(commonOut.getString("resultCode"))) { if (!"0".equals(commonOut.getString("resultCode"))) {
log.info("[电子健康卡]注册失败: {}", resultObj); log.info("[电子健康卡]注册失败: {}", resultObj);
@ -237,15 +235,13 @@ public class HCodeService {
*/ */
public Patient getInfoByHealthCode(String healthCode) { public Patient getInfoByHealthCode(String healthCode) {
try { try {
String appToken = getAppToken(); String appToken = getAppToken(false);
if (appToken == null) { if (appToken == null) {
return null; return null;
} }
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); CommonIn commonIn = createCommonIn(appToken);
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0);
//调用接口 //调用接口
JSONObject resultObj = healthCard.getHealthCardByHealthCode(commonIn, healthCode); JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).getHealthCardByHealthCode(commonIn, healthCode);
JSONObject commonOut = resultObj.getJSONObject("commonOut"); JSONObject commonOut = resultObj.getJSONObject("commonOut");
JSONObject rspObj = resultObj.getJSONObject("rsp"); JSONObject rspObj = resultObj.getJSONObject("rsp");
if (!"0".equals(commonOut.getString("resultCode")) || rspObj == null) { if (!"0".equals(commonOut.getString("resultCode")) || rspObj == null) {
@ -298,11 +294,9 @@ public class HCodeService {
if (appToken == null) { if (appToken == null) {
return null; return null;
} }
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); CommonIn commonIn = createCommonIn(appToken);
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0);
//调用接口 //调用接口
JSONObject resultObj = healthCard.getHealthCardByQRCode(commonIn, qrCode); JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).getHealthCardByQRCode(commonIn, qrCode);
JSONObject commonOut = resultObj.getJSONObject("commonOut"); JSONObject commonOut = resultObj.getJSONObject("commonOut");
if (!"0".equals(commonOut.getString("resultCode"))) { if (!"0".equals(commonOut.getString("resultCode"))) {
log.info("[电子健康卡]二维码获取健康卡失败: {}", resultObj); log.info("[电子健康卡]二维码获取健康卡失败: {}", resultObj);
@ -348,11 +342,13 @@ public class HCodeService {
if (appToken == null) { if (appToken == null) {
return null; return null;
} }
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); CommonIn commonIn = createCommonIn(appToken);
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0);
//调用接口 //调用接口
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"); JSONObject commonOut = resultJson.getJSONObject("commonOut");
if (!"0".equals(commonOut.getString("resultCode"))) { if (!"0".equals(commonOut.getString("resultCode"))) {
log.info("[电子健康卡]实人认证生成orderId接口失败: {}", resultJson); log.info("[电子健康卡]实人认证生成orderId接口失败: {}", resultJson);
@ -383,11 +379,9 @@ public class HCodeService {
if (appToken == null) { if (appToken == null) {
return false; return false;
} }
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); CommonIn commonIn = createCommonIn(appToken);
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0);
//调用接口 //调用接口
JSONObject resultJson = healthCard.checkUniformVerifyResult(commonIn, verifyOrderId, registerOrderId); JSONObject resultJson = new HealthCardServerImpl(H_APP_SECRET).checkUniformVerifyResult(commonIn, verifyOrderId, registerOrderId);
JSONObject commonOut = resultJson.getJSONObject("commonOut"); JSONObject commonOut = resultJson.getJSONObject("commonOut");
if (!"0".equals(commonOut.getString("resultCode"))) { if (!"0".equals(commonOut.getString("resultCode"))) {
log.info("[电子健康卡]实人认证结果查询失败: {}", resultJson); log.info("[电子健康卡]实人认证结果查询失败: {}", resultJson);
@ -418,11 +412,9 @@ public class HCodeService {
return null; return null;
} }
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); CommonIn commonIn = createCommonIn(appToken);
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0);
//调用接口 //调用接口
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"); JSONObject commonOut = resultObj.getJSONObject("commonOut");
if (!"0".equals(commonOut.getString("resultCode"))) { if (!"0".equals(commonOut.getString("resultCode"))) {
log.info("[电子健康卡]获取卡包订单ID 失败: {}", resultObj); log.info("[电子健康卡]获取卡包订单ID 失败: {}", resultObj);
@ -458,8 +450,7 @@ public class HCodeService {
} }
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET);
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); CommonIn commonIn = createCommonIn(appToken);
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0);
//构造请求参数req //构造请求参数req
ReportHISData reportHISData = new ReportHISData(); ReportHISData reportHISData = new ReportHISData();
reportHISData.setQrCodeText(qrCodeText); reportHISData.setQrCodeText(qrCodeText);
@ -511,11 +502,9 @@ public class HCodeService {
return null; return null;
} }
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); CommonIn commonIn = createCommonIn(appToken);
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0);
//调用接口 //调用接口
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"); JSONObject commonOut = resultObj.getJSONObject("commonOut");
if (!"0".equals(commonOut.getString("resultCode"))) { if (!"0".equals(commonOut.getString("resultCode"))) {
log.info("获取健康卡二维码失败: {}", resultObj); log.info("获取健康卡二维码失败: {}", resultObj);
@ -546,12 +535,8 @@ public class HCodeService {
return null; return null;
} }
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); CommonIn commonIn = createCommonIn(appToken);
//构造公共输入参数commonIn JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).bindCardRelation(commonIn, patientId, qrCodeText);
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, 0);
JSONObject resultObj = healthCard.bindCardRelation(commonIn, patientId, qrCodeText);
JSONObject commonOut = resultObj.getJSONObject("commonOut"); JSONObject commonOut = resultObj.getJSONObject("commonOut");
if (!"0".equals(commonOut.getString("resultCode"))) { if (!"0".equals(commonOut.getString("resultCode"))) {
log.info("[电子健康卡]绑定健康卡和医院关系失败: {}", resultObj); log.info("[电子健康卡]绑定健康卡和医院关系失败: {}", resultObj);
@ -662,18 +647,14 @@ public class HCodeService {
return null; return null;
} }
String appToken = getAppToken(); String appToken = getAppToken(false); // 未开启功能时也能获取token
if (appToken == null) { if (appToken == null) {
return null; return null;
} }
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET); CommonIn commonIn = createCommonIn(appToken);
//构造公共输入参数commonIn
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
int channelNum = 0;
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, channelNum);
//调用接口 //调用接口
JSONObject resultObj = healthCard.ocrInfo(commonIn, imageContent); JSONObject resultObj = new HealthCardServerImpl(H_APP_SECRET).ocrInfo(commonIn, imageContent);
JSONObject commonOut = resultObj.getJSONObject("commonOut"); JSONObject commonOut = resultObj.getJSONObject("commonOut");
if (!"0".equals(commonOut.getString("resultCode"))) { if (!"0".equals(commonOut.getString("resultCode"))) {
log.info("[电子健康卡]身份证识别失败: {}", resultObj); log.info("[电子健康卡]身份证识别失败: {}", resultObj);
@ -759,12 +740,10 @@ public class HCodeService {
* @return json * @return json
*/ */
public JSONArray batchUpdate(List<Patient> lstPatient) { public JSONArray batchUpdate(List<Patient> lstPatient) {
HealthCardServerImpl healthCard = new HealthCardServerImpl(H_APP_SECRET);
//构造公共输入参数commonIn //构造公共输入参数commonIn
String appToken = getAppToken(); String appToken = getAppToken();
String requestId = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); CommonIn commonIn = createCommonIn(appToken);
int channelNum = 0;
CommonIn commonIn = new CommonIn(appToken, requestId, H_HOSPITAL_ID, channelNum);
List<HealthCardInfo> lstHealthCard = new ArrayList<>(); List<HealthCardInfo> lstHealthCard = new ArrayList<>();
for (Patient patient : lstPatient) { for (Patient patient : lstPatient) {
HealthCardInfo healthCardInfo = new HealthCardInfo(); HealthCardInfo healthCardInfo = new HealthCardInfo();
@ -783,7 +762,7 @@ public class HCodeService {
lstHealthCard.add(healthCardInfo); 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 commonOut = healthCardInfosRsp.getJSONObject("commonOut");
JSONObject rspObj = healthCardInfosRsp.getJSONObject("rsp"); JSONObject rspObj = healthCardInfosRsp.getJSONObject("rsp");
if (!"0".equals(commonOut.getString("resultCode")) || rspObj == null) { if (!"0".equals(commonOut.getString("resultCode")) || rspObj == null) {

Loading…
Cancel
Save