parent
8d8b77d460
commit
f808cb2f81
18 changed files with 778 additions and 281 deletions
@ -0,0 +1,426 @@ |
|||||||
|
package com.ynxbd.common.helper; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.tencent.healthcard.model.CommonIn; |
||||||
|
import com.tencent.healthcard.model.HealthCardInfo; |
||||||
|
import com.ynxbd.common.bean.Patient; |
||||||
|
import com.ynxbd.common.bean.enums.HCardTypeEnum; |
||||||
|
import com.ynxbd.common.config.HealthCardConfig; |
||||||
|
import com.ynxbd.common.helper.common.ErrorHelper; |
||||||
|
import com.ynxbd.common.helper.common.JsonHelper; |
||||||
|
import com.ynxbd.common.helper.common.URLHelper; |
||||||
|
import com.ynxbd.common.result.ServiceException; |
||||||
|
import com.ynxbd.wx.config.WeChatConfig; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.lang3.ObjectUtils; |
||||||
|
|
||||||
|
import java.util.UUID; |
||||||
|
|
||||||
|
@Slf4j |
||||||
|
public class HealthCardHelper { |
||||||
|
|
||||||
|
/** |
||||||
|
* 绑卡验证授权 |
||||||
|
* |
||||||
|
* @param wechatCode 微信身份码 |
||||||
|
*/ |
||||||
|
public static JSONObject registerHealthCardPreAuth(Boolean isMiniApp, Boolean isHCBindUI, String wechatCode) { |
||||||
|
try { |
||||||
|
if (isMiniApp == null) { |
||||||
|
isMiniApp = false; |
||||||
|
} |
||||||
|
CommonIn commonIn = HealthCardConfig.createCommonIn(isMiniApp); |
||||||
|
if (commonIn == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
String domain = WeChatConfig.getDomain(false); |
||||||
|
String webURL = WeChatConfig.getWebReqURL(); |
||||||
|
|
||||||
|
// 授权成功回调页
|
||||||
|
String successRedirectUrl = isMiniApp ? "mini:/path/to/isvpage?healthCode=${healthCode}" : (webURL + "health-card-form.html?healthCode=${healthCode}"); |
||||||
|
// 授权失败回调
|
||||||
|
String failRedirectUrl = isMiniApp ? "/path/to/isvpage?regInfoCode=${regInfoCode}" : (webURL + "health-card-form.html?regInfoCode=${regInfoCode}"); |
||||||
|
/* |
||||||
|
* 用户手动填写信息建卡可选两种方式(二选一): |
||||||
|
* 一、服务商自行提供建卡页(可以是H5或小程序),需增加authCode占位符,示例如下: |
||||||
|
* H5: https://xxx.xxx.xx/path/to/isvpage?authCode=${authCode} |小程序: mini:/path/to/isvpage?authCode=${authCode}
|
||||||
|
* 二、使用开放平台的H5绑卡组件页,需增加authCode占位符,示例如下: |
||||||
|
* https://h5-health.tengmed.com/h5/tencent/open/card/regist?hospitalId=${hospitalId}&redirect_uri=${redirect_uri}&fail_redirect_uri=${fail_redirect_uri}&authCode=${authCode}小程序需修改该域名地址为已配置的业务域名
|
||||||
|
* ${hospitalId},必传,为开放平台分配的医院ID(hospitalId); |
||||||
|
* ${redirect_uri},必传,为建卡成功后的回跳服务商页面,必须要对该URL进行UrlEncode编码。 |
||||||
|
* ${fail_redirect_uri},必传,为建卡失败后的回跳服务商页面,必须要对该URL进行UrlEncode编码。 |
||||||
|
* 小程序内嵌,仍以 mini 协议开头,且需要UrlEncode编码。 |
||||||
|
*/ |
||||||
|
|
||||||
|
String hcBindUIUrl = String.format("%s/h5/tencent/open/card/regist?hospitalId=%s&redirect_uri=%s&fail_redirect_uri=%s&authCode=%s", |
||||||
|
(isMiniApp ? domain : "https://h5-health.tengmed.com"), |
||||||
|
HealthCardConfig.H_HOSPITAL_ID, |
||||||
|
URLHelper.encodeURL(successRedirectUrl), |
||||||
|
URLHelper.encodeURL(failRedirectUrl), |
||||||
|
wechatCode); |
||||||
|
|
||||||
|
String userFormPageUrl = isHCBindUI |
||||||
|
? hcBindUIUrl |
||||||
|
: (webURL + "health-card-form.html?authCode=${authCode}"); |
||||||
|
|
||||||
|
// 小程序内嵌必传(固定为小程序路径,不需要加“mini:”前缀)示例: /path/to/facePage
|
||||||
|
String faceUrl = isMiniApp ? "/path/to/facePage" : null; |
||||||
|
// 放弃验证回调页
|
||||||
|
String verifyFailRedirectUrl = isMiniApp ? "mini:/path/to/isvpage" : (webURL + "health-card-fail.html?code=-1"); |
||||||
|
|
||||||
|
int patientType = 0; // 0-新患者 1-老患者(针对就诊卡升级健康卡);不传默认为0
|
||||||
|
|
||||||
|
JSONObject resultJson = HealthCardConfig.createHealthCardService().registerHealthCardPreAuth(commonIn, |
||||||
|
wechatCode, |
||||||
|
patientType, |
||||||
|
successRedirectUrl, |
||||||
|
failRedirectUrl, |
||||||
|
userFormPageUrl, |
||||||
|
faceUrl, |
||||||
|
verifyFailRedirectUrl, |
||||||
|
HealthCardConfig.DOMAIN_CHANNEL); |
||||||
|
log.info("[电子健康卡]绑卡验证授权 resp={}", JsonHelper.toJsonString(resultJson)); |
||||||
|
HealthCardConfig.HCardResult result = new HealthCardConfig.HCardResult(resultJson); |
||||||
|
if (!result.isOk) { |
||||||
|
log.info("[电子健康卡]绑卡验证授权-失败: {}", result.getErrMsg()); |
||||||
|
return result.getCommonOut(); |
||||||
|
} |
||||||
|
return result.getRsp(); |
||||||
|
} catch (Exception e) { |
||||||
|
ErrorHelper.println(e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 验证注册/绑卡接口 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public static JSONObject registerHealthCardPreFill(Boolean isMiniApp, String authCode, String name, String gender, String nation, String birthday, |
||||||
|
String idNumber, HCardTypeEnum cardTypeEnum, String phone1) { |
||||||
|
try { |
||||||
|
if (isMiniApp == null) { |
||||||
|
isMiniApp = false; |
||||||
|
} |
||||||
|
CommonIn commonIn = HealthCardConfig.createCommonIn(isMiniApp); |
||||||
|
if (commonIn == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
String webURL = WeChatConfig.getWebReqURL(); |
||||||
|
|
||||||
|
// 授权成功回调页
|
||||||
|
String successRedirectUrl = isMiniApp ? "mini:/path/to/isvpage?healthCode=${healthCode}" : (webURL + "health-card-form.html?healthCode=${healthCode}"); |
||||||
|
// 授权失败回调
|
||||||
|
String failRedirectUrl = isMiniApp ? "/path/to/isvpage??regInfoCode=${regInfoCode}" : (webURL + "health-card-form.html?regInfoCode=${regInfoCode}"); |
||||||
|
|
||||||
|
// 小程序内嵌必传(固定为小程序路径,不需要加“mini:”前缀)示例: /path/to/facePage
|
||||||
|
String faceUrl = isMiniApp ? "/path/to/facePage" : null; |
||||||
|
// 放弃验证回调页
|
||||||
|
String verifyFailRedirectUrl = isMiniApp ? "mini:/path/to/isvpage" : (webURL + "health-card-fail.html?code=-2"); |
||||||
|
|
||||||
|
if (!nation.contains("族")) { |
||||||
|
nation = nation + "族"; |
||||||
|
} |
||||||
|
|
||||||
|
HealthCardInfo req = new HealthCardInfo(); |
||||||
|
req.setName(name); |
||||||
|
req.setGender(gender); |
||||||
|
req.setNation(nation); |
||||||
|
req.setBirthday(birthday); |
||||||
|
req.setIdNumber(idNumber); |
||||||
|
req.setIdType(cardTypeEnum.WX_CODE); |
||||||
|
req.setPhone1(phone1); |
||||||
|
|
||||||
|
JSONObject resultJson = HealthCardConfig.createHealthCardService().registerHealthCardPreFill(commonIn, |
||||||
|
req, |
||||||
|
authCode, |
||||||
|
successRedirectUrl, |
||||||
|
failRedirectUrl, |
||||||
|
faceUrl, |
||||||
|
verifyFailRedirectUrl, |
||||||
|
HealthCardConfig.DOMAIN_CHANNEL); |
||||||
|
HealthCardConfig.HCardResult result = new HealthCardConfig.HCardResult(resultJson); |
||||||
|
log.info("[电子健康卡]验证注册/绑卡接口 resp: {}", JsonHelper.toJsonString(resultJson)); |
||||||
|
if (!result.isOk) { |
||||||
|
log.info("[电子健康卡]验证注册/绑卡接口-失败: {}", result.getErrMsg()); |
||||||
|
return result.getCommonOut(); |
||||||
|
} |
||||||
|
return result.getRsp(); |
||||||
|
} catch (Exception e) { |
||||||
|
ErrorHelper.println(e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 健康卡授权码获取健康卡信息 |
||||||
|
* |
||||||
|
* @param healthCode 健康卡授权码 |
||||||
|
*/ |
||||||
|
public static Patient getHealthCardByHealthCode(Boolean isMiniApp, String healthCode) throws ServiceException { |
||||||
|
CommonIn commonIn = HealthCardConfig.createCommonIn(isMiniApp); |
||||||
|
if (commonIn == null) { |
||||||
|
throw new ServiceException("[电子健康卡]健康卡授权码获取健康卡信息-请求参数缺失"); |
||||||
|
} |
||||||
|
JSONObject resultJson = HealthCardConfig.createHealthCardService().getHealthCardByHealthCode(commonIn, healthCode); |
||||||
|
HealthCardConfig.HCardResult result = new HealthCardConfig.HCardResult(resultJson); |
||||||
|
JSONObject respJson = result.getRsp(); |
||||||
|
if (!result.isOk || respJson == null) { |
||||||
|
throw new ServiceException("[电子健康卡]健康卡授权码获取健康卡信息-失败:" + result.getJsonCommon()); |
||||||
|
} |
||||||
|
JSONObject card = respJson.getJSONObject("card"); |
||||||
|
if (card == null) { |
||||||
|
throw new ServiceException("[电子健康卡]健康卡授权码获取健康卡信息-数据解析失败"); |
||||||
|
} |
||||||
|
|
||||||
|
Patient patient = new Patient(); |
||||||
|
String phone1 = card.getString("phone1"); |
||||||
|
patient.setTel(ObjectUtils.isEmpty(phone1) ? card.getString("phone2") : phone1); |
||||||
|
|
||||||
|
patient.setHealthCardId(card.getString("healthCardId")); // 关键参数
|
||||||
|
patient.setName(card.getString("name")); |
||||||
|
patient.setSex(card.getString("gender")); |
||||||
|
patient.setCardType(card.getString("idType")); |
||||||
|
patient.setIdCardNo(card.getString("idNumber")); |
||||||
|
patient.setNation(card.getString("nation")); |
||||||
|
// 非必定返回参数
|
||||||
|
patient.setAddress(card.getString("address")); |
||||||
|
patient.setBirthday(card.getString("birthday")); |
||||||
|
patient.setIsMyself(card.getBoolean("isSelf")); |
||||||
|
|
||||||
|
log.info("[电子健康卡]健康卡授权码获取健康卡信息 info:{}", JsonHelper.toJsonString(patient)); |
||||||
|
return patient; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 身份证识别 |
||||||
|
* |
||||||
|
* @param imageContent 身份证正面照片的base64编码数据,头部信息需要删除,如image/png;base64、image/jpeg/png;base64等,并且数据量建议压缩到百K级别上传。 |
||||||
|
* @return 身份证信息 |
||||||
|
*/ |
||||||
|
public static Patient orcInfo(String imageContent) throws ServiceException { |
||||||
|
if (ObjectUtils.isEmpty(imageContent)) { |
||||||
|
throw new ServiceException("[电子健康卡]图片数据不能为空"); |
||||||
|
} |
||||||
|
|
||||||
|
int index = imageContent.indexOf(","); |
||||||
|
if (index != -1) { |
||||||
|
imageContent = imageContent.substring(index + 1); |
||||||
|
} |
||||||
|
|
||||||
|
Patient patient = new Patient(); |
||||||
|
if (!HealthCardConfig.isEnable()) { // 判断是否禁用电子健康卡
|
||||||
|
throw new ServiceException("[电子健康卡]功能未开启"); |
||||||
|
} |
||||||
|
CommonIn commonIn = new CommonIn(HealthCardConfig.getAppToken(false, false), UUID.randomUUID().toString().replaceAll("-", ""), HealthCardConfig.H_HOSPITAL_ID, 0, null, null); |
||||||
|
JSONObject resultJson = HealthCardConfig.createHealthCardService().ocrInfo(commonIn, imageContent); |
||||||
|
HealthCardConfig.HCardResult result = new HealthCardConfig.HCardResult(resultJson); |
||||||
|
if (!result.isOk) { |
||||||
|
throw new ServiceException("[电子健康卡]身份证识别-失败: " + JsonHelper.toJsonString(resultJson)); |
||||||
|
} |
||||||
|
JSONObject rsp = result.getRsp(); |
||||||
|
if (rsp == null) { |
||||||
|
throw new ServiceException("[电子健康卡]身份证识别-未查询到数据"); |
||||||
|
} |
||||||
|
JSONObject cardInfo = rsp.getJSONObject("cardInfo"); |
||||||
|
if (cardInfo == null) { |
||||||
|
throw new ServiceException("[电子健康卡]身份证识别-数据解析失败"); |
||||||
|
} |
||||||
|
// 读取信息
|
||||||
|
String idNumber = cardInfo.getString("id"); |
||||||
|
|
||||||
|
patient.setIdCardNo(idNumber == null ? null : idNumber.toUpperCase()); |
||||||
|
patient.setName(cardInfo.getString("name")); |
||||||
|
patient.setSex(cardInfo.getString("gender")); |
||||||
|
patient.setAddress(cardInfo.getString("address")); |
||||||
|
patient.setNation(cardInfo.getString("nation")); |
||||||
|
patient.setBirthday(cardInfo.getString("birth")); |
||||||
|
|
||||||
|
// if (!"".equals(idNumber)) {
|
||||||
|
// FileHelper.saveBase64Image("data:image/png;base64," + imageContent, "idCard", (idNumber + ".png"), true, false);
|
||||||
|
// }
|
||||||
|
return patient; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 注册健康卡 |
||||||
|
* |
||||||
|
* @param wechatCode 微信身份码 |
||||||
|
* @param birthday 出生年月日 |
||||||
|
* @param cardTypeEnum 证件类型(01-居民身份证,其他参考证件类型表) |
||||||
|
* @param areaAddress 区域地址 |
||||||
|
* @param address 地址 |
||||||
|
* @param sex 性别 |
||||||
|
* @param nation 民族 |
||||||
|
* @param name 姓名 |
||||||
|
* @param idCardNo 证件号码 |
||||||
|
* @param phone1 联系方式1 |
||||||
|
*/ |
||||||
|
public static JSONObject registerHealthCard(Boolean isMiniApp, String patientId, String wechatCode, |
||||||
|
String birthday, HCardTypeEnum cardTypeEnum, String address, String areaAddress, |
||||||
|
String sex, String nation, String name, String idCardNo, String phone1) { |
||||||
|
try { |
||||||
|
CommonIn commonIn = HealthCardConfig.createCommonIn(isMiniApp); |
||||||
|
if (commonIn == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
if (cardTypeEnum == null) { |
||||||
|
cardTypeEnum = HCardTypeEnum._01; // 居民身份证
|
||||||
|
} |
||||||
|
|
||||||
|
if (ObjectUtils.isEmpty(areaAddress)) { |
||||||
|
areaAddress = ""; |
||||||
|
} |
||||||
|
|
||||||
|
HealthCardInfo req = new HealthCardInfo(); |
||||||
|
req.setAddress(areaAddress + address); |
||||||
|
req.setBirthday(birthday); |
||||||
|
req.setGender(sex); |
||||||
|
req.setIdNumber(idCardNo); |
||||||
|
req.setIdType(cardTypeEnum.WX_CODE); |
||||||
|
req.setNation(nation); |
||||||
|
req.setName(name); |
||||||
|
req.setPhone1(phone1); |
||||||
|
req.setWechatCode(wechatCode); |
||||||
|
req.setPatid(patientId); |
||||||
|
|
||||||
|
JSONObject resultJson = HealthCardConfig.createHealthCardService().registerHealthCard(commonIn, req); |
||||||
|
HealthCardConfig.HCardResult result = new HealthCardConfig.HCardResult(resultJson); |
||||||
|
if (!result.isOk) { |
||||||
|
log.info("[电子健康卡]注册失败: {}", resultJson); |
||||||
|
return result.getCommonOut(); |
||||||
|
} |
||||||
|
return result.getRsp(); |
||||||
|
} catch (Exception e) { |
||||||
|
ErrorHelper.println(e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取建档信息 |
||||||
|
* |
||||||
|
* @param regInfoCode 建档授权码 |
||||||
|
*/ |
||||||
|
public static Patient getRegInfoByCode(Boolean isMiniApp, String regInfoCode) throws ServiceException { |
||||||
|
CommonIn commonIn = HealthCardConfig.createCommonIn(isMiniApp); |
||||||
|
if (commonIn == null) { |
||||||
|
throw new ServiceException("[电子健康卡]获取建档信息-请求参数缺失"); |
||||||
|
} |
||||||
|
JSONObject resultJson = HealthCardConfig.createHealthCardService().getRegInfoByCode(commonIn, regInfoCode); |
||||||
|
HealthCardConfig.HCardResult result = new HealthCardConfig.HCardResult(resultJson); |
||||||
|
JSONObject respJsonObj = result.getRsp(); |
||||||
|
if (!result.isOk || respJsonObj == null) { |
||||||
|
throw new ServiceException("[电子健康卡]获取建档信息-失败:" + result.getJsonCommon()); |
||||||
|
} |
||||||
|
JSONObject card = respJsonObj.getJSONObject("card"); |
||||||
|
if (card == null) { |
||||||
|
throw new ServiceException("[电子健康卡]获取建档信息-数据解析失败"); |
||||||
|
} |
||||||
|
|
||||||
|
Patient patient = new Patient(); |
||||||
|
String phone1 = card.getString("phone1"); |
||||||
|
patient.setTel(ObjectUtils.isEmpty(phone1) ? card.getString("phone2") : phone1); |
||||||
|
|
||||||
|
patient.setName(card.getString("name")); |
||||||
|
patient.setSex(card.getString("gender")); |
||||||
|
patient.setCardType(card.getString("idType")); |
||||||
|
patient.setIdCardNo(card.getString("idNumber")); |
||||||
|
// 非必定返回参数
|
||||||
|
patient.setNation(card.getString("nation")); |
||||||
|
patient.setAddress(card.getString("address")); |
||||||
|
patient.setBirthday(card.getString("birthday")); |
||||||
|
patient.setIsMyself(card.getBoolean("isSelf")); |
||||||
|
patient.setHealthCardId(card.getString("healthCardId")); |
||||||
|
|
||||||
|
log.info("[电子健康卡]获取建档信息 info:{}", JsonHelper.toJsonString(patient)); |
||||||
|
return patient; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取健康卡二维码 |
||||||
|
* |
||||||
|
* @param healthCardId 健康卡ID |
||||||
|
* @param idCardNo 证件号码 |
||||||
|
* @param codeType 传0或者1,0返回动态码,1返回静态码 |
||||||
|
*/ |
||||||
|
public static JSONObject getDynamicQRCode(Boolean isMiniApp, String healthCardId, String idCardNo, String codeType) { |
||||||
|
if (healthCardId == null || idCardNo == null || codeType == null) { |
||||||
|
log.info("[电子健康卡]获取健康卡二维码-参数缺失 healthCardId={}, idCardNo={}, codeType={}", healthCardId, idCardNo, codeType); |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
CommonIn commonIn = HealthCardConfig.createCommonIn(isMiniApp); |
||||||
|
if (commonIn == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
JSONObject resultJson = HealthCardConfig.createHealthCardService().getDynamicQRCode(commonIn, healthCardId, "01", idCardNo, codeType); |
||||||
|
HealthCardConfig.HCardResult result = new HealthCardConfig.HCardResult(resultJson); |
||||||
|
if (!result.isOk) { |
||||||
|
log.info("[电子健康卡]获取健康卡二维码失败: {}", resultJson); |
||||||
|
return null; |
||||||
|
} |
||||||
|
return result.getRsp(); |
||||||
|
} catch (Exception e) { |
||||||
|
ErrorHelper.println(e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据健康卡ID获取动态二维码 |
||||||
|
* |
||||||
|
* @param healthCardId 健康卡ID |
||||||
|
* @param idCardNo 身份证号 |
||||||
|
* @return 动态二维码 |
||||||
|
*/ |
||||||
|
public static String getQRCodeText(Boolean isMiniApp, String healthCardId, String idCardNo) { |
||||||
|
JSONObject QRResult = getDynamicQRCode(isMiniApp, healthCardId, idCardNo, "0"); |
||||||
|
if (QRResult == null) { |
||||||
|
log.info("[电子健康卡]用卡数据监测接口-获取二维码失败"); |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
String qrCodeText = QRResult.getString("qrCodeText"); |
||||||
|
if (ObjectUtils.isEmpty(qrCodeText)) { |
||||||
|
log.info("[电子健康卡]用卡数据监测接口-获取qrCodeText失败"); |
||||||
|
return null; |
||||||
|
} |
||||||
|
return qrCodeText; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取卡包订单ID |
||||||
|
* |
||||||
|
* @param qrCodeText 二维码编码 |
||||||
|
*/ |
||||||
|
public static JSONObject getOrderIdByOutAppId(Boolean isMiniApp, String qrCodeText) { |
||||||
|
try { |
||||||
|
CommonIn commonIn = HealthCardConfig.createCommonIn(isMiniApp); |
||||||
|
if (commonIn == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
//调用接口
|
||||||
|
JSONObject resultJson = HealthCardConfig.createHealthCardService().getOrderIdByOutAppId(commonIn, WeChatConfig.APP_ID, qrCodeText); |
||||||
|
HealthCardConfig.HCardResult result = new HealthCardConfig.HCardResult(resultJson); |
||||||
|
if (!result.isOk) { |
||||||
|
log.info("[电子健康卡]获取卡包订单ID 失败: {}", result.getJsonCommon()); |
||||||
|
return null; |
||||||
|
} |
||||||
|
return result.getRsp(); |
||||||
|
} catch (Exception e) { |
||||||
|
ErrorHelper.println(e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
@ -1,78 +0,0 @@ |
|||||||
package com.ynxbd.common.service; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject; |
|
||||||
import com.tencent.healthcard.model.CommonIn; |
|
||||||
import com.ynxbd.common.config.HealthCardConfig; |
|
||||||
import com.ynxbd.common.helper.common.ErrorHelper; |
|
||||||
import com.ynxbd.common.helper.common.JsonHelper; |
|
||||||
import com.ynxbd.common.helper.common.URLHelper; |
|
||||||
import lombok.extern.slf4j.Slf4j; |
|
||||||
|
|
||||||
@Slf4j |
|
||||||
public class HealthCardService { |
|
||||||
|
|
||||||
/** |
|
||||||
* 绑卡验证授权 |
|
||||||
* |
|
||||||
* @param wechatCode 微信身份码 |
|
||||||
* @param openId openId |
|
||||||
*/ |
|
||||||
public static JSONObject registerHealthCardPreAuth(Boolean isMiniApp, String domain, String wechatCode, String healthCode, String openId) { |
|
||||||
try { |
|
||||||
CommonIn commonIn = HealthCardConfig.createCommonIn(isMiniApp); |
|
||||||
if (commonIn == null) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
// 成功回调页
|
|
||||||
String successRedirectUrl = (isMiniApp ? "mini:/path/to/isvpage?healthCode=" : (domain + "/path/to/isvpage?healthCode=")) + wechatCode; |
|
||||||
// 失败回调页
|
|
||||||
String failRedirectUrl = (isMiniApp ? "/path/to/isvpage?regInfoCode=" : (domain + "/path/to/isvpage?regInfoCode=")) + wechatCode; |
|
||||||
/* |
|
||||||
* 用户手动填写信息建卡可选两种方式(二选一): |
|
||||||
* 一、服务商自行提供建卡页(可以是H5或小程序),需增加authCode占位符,示例如下: |
|
||||||
* H5: https://xxx.xxx.xx/path/to/isvpage?authCode=${authCode} |小程序: mini:/path/to/isvpage?authCode=${authCode}
|
|
||||||
* 二、使用开放平台的H5绑卡组件页,需增加authCode占位符,示例如下: |
|
||||||
* https://h5-health.tengmed.com/h5/tencent/open/card/regist?hospitalId=${hospitalId}&redirect_uri=${redirect_uri}&fail_redirect_uri=${fail_redirect_uri}&authCode=${authCode}小程序需修改该域名地址为已配置的业务域名
|
|
||||||
* ${hospitalId},必传,为开放平台分配的医院ID(hospitalId); |
|
||||||
* ${redirect_uri},必传,为建卡成功后的回跳服务商页面,必须要对该URL进行UrlEncode编码。 |
|
||||||
* ${fail_redirect_uri},必传,为建卡失败后的回跳服务商页面,必须要对该URL进行UrlEncode编码。 |
|
||||||
* 小程序内嵌,仍以 mini 协议开头,且需要UrlEncode编码。 |
|
||||||
*/ |
|
||||||
|
|
||||||
String userFormPageUrl = String.format("%s/h5/tencent/open/card/regist?hospitalId=%s&redirect_uri=%s&fail_redirect_uri=%s&authCode=%s", |
|
||||||
(isMiniApp ? domain : " https://h5-health.tengmed.com"), |
|
||||||
HealthCardConfig.H_HOSPITAL_ID, |
|
||||||
URLHelper.encodeURL(successRedirectUrl), |
|
||||||
URLHelper.encodeURL(failRedirectUrl), |
|
||||||
wechatCode); |
|
||||||
|
|
||||||
// 小程序内嵌必传(固定为小程序路径,不需要加“mini:”前缀)示例: /path/to/facePage
|
|
||||||
String faceUrl = isMiniApp ? "/path/to/facePage" : null; |
|
||||||
// 放弃验证回调页
|
|
||||||
String verifyFailRedirectUrl = isMiniApp ? "mini:/path/to/isvpage" : (domain + "/path/to/isvpage"); |
|
||||||
|
|
||||||
int patientType = 0; // 0-新患者 1-老患者(针对就诊卡升级健康卡);不传默认为0
|
|
||||||
|
|
||||||
JSONObject resultJson = HealthCardConfig.createHealthCardService().registerHealthCardPreAuth(commonIn, |
|
||||||
wechatCode, |
|
||||||
patientType, |
|
||||||
successRedirectUrl, |
|
||||||
failRedirectUrl, |
|
||||||
userFormPageUrl, |
|
||||||
faceUrl, |
|
||||||
verifyFailRedirectUrl, |
|
||||||
HealthCardConfig.domainChannel); |
|
||||||
log.info("[电子健康卡]绑卡验证授权 resp={}", JsonHelper.toJsonString(resultJson)); |
|
||||||
HealthCardConfig.HCardResult result = new HealthCardConfig.HCardResult(resultJson); |
|
||||||
if (!result.isOk) { |
|
||||||
log.info("[电子健康卡]绑卡验证授权-失败: {}", resultJson); |
|
||||||
return result.getCommonOut(); |
|
||||||
} |
|
||||||
return result.getRsp(); |
|
||||||
} catch (Exception e) { |
|
||||||
ErrorHelper.println(e); |
|
||||||
} |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue