parent
679067d51e
commit
3eeae9cdd9
13 changed files with 516 additions and 226 deletions
@ -0,0 +1,60 @@ |
|||||||
|
package com.ynxbd.common.action.healthcard; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.ynxbd.common.action.base.BaseAction; |
||||||
|
import com.ynxbd.common.config.HealthCardConfig; |
||||||
|
import com.ynxbd.common.config.healthcard.HCReportConfig; |
||||||
|
import com.ynxbd.common.config.healthcard.HCSignHelper; |
||||||
|
import com.ynxbd.common.config.interceptor.AesDecode; |
||||||
|
import com.ynxbd.common.helper.http.OkHttpHelper; |
||||||
|
import com.ynxbd.common.result.Result; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.struts2.convention.annotation.Action; |
||||||
|
import org.apache.struts2.convention.annotation.Namespace; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@Slf4j |
||||||
|
@Namespace("/hc_report") |
||||||
|
public class HCReportAction extends BaseAction { |
||||||
|
|
||||||
|
|
||||||
|
@Action("pushUserReport") |
||||||
|
public Result pushUserReport(@AesDecode String patientId, String reportId, String healthCardId, String msgId, String reportContent) { |
||||||
|
log.info("[报告解读] msgId={}, patientId={}, reportId={}", msgId, patientId, reportId); |
||||||
|
String url = HCReportConfig.IS_DEV |
||||||
|
? "https://med-biz-pre.wecity.qq.com/api/report/PushUserReport/" |
||||||
|
: "https://med-biz.wecity.qq.com/api/report/PushUserReport/"; |
||||||
|
|
||||||
|
HCSignHelper config = HCReportConfig.createSign(); |
||||||
|
String requestId = config.getRequestId(); |
||||||
|
|
||||||
|
Map<String, Object> reqHead = new HashMap<>(); |
||||||
|
reqHead.put("requestId", requestId); |
||||||
|
|
||||||
|
// Map<String, Object> textReportInfo = new HashMap<>();
|
||||||
|
// Map<String, Object> patientInfo = new HashMap<>();
|
||||||
|
// Map<String, Object> reportInfo = new HashMap<>();
|
||||||
|
|
||||||
|
// partnerId:合作方ID 腾讯健康提供
|
||||||
|
// JSONObject jsonObject = OkHttpHelper.postJson(url + "合作方ID 腾讯健康提供", params -> {
|
||||||
|
// params.put("reqHead", reqHead);
|
||||||
|
// params.put("hospitalId", HealthCardConfig.H_HOSPITAL_ID);
|
||||||
|
// params.put("outerId", reportId);
|
||||||
|
// params.put("healthCardId", healthCardId);
|
||||||
|
// params.put("patientId", patientId);
|
||||||
|
// params.put("msgId", msgId);
|
||||||
|
// params.put("reportFileType", 2); // [ 1:pdf;2:图片;3:文本]
|
||||||
|
// params.put("reportContent", reportContent); // 报告内容:报告文件base64编码、体积需要在30MB以内 当reportFileType 取值为 1, 2时,将报告文件base64编码放在该字段
|
||||||
|
// params.put("textReportInfo", ""); // 当reportFileType 取值为 3 时,将文本报告内容放下该字段。
|
||||||
|
// }, headers -> {
|
||||||
|
// headers.add("Content-Type", "application/json");
|
||||||
|
// headers.add("god-portal-signature", config.getSign());
|
||||||
|
// headers.add("god-portal-timestamp", config.getTimestamp());
|
||||||
|
// headers.add("god-portal-request-id", requestId);
|
||||||
|
// });
|
||||||
|
// log.info("[报告解读] resp={}", jsonObject);
|
||||||
|
return Result.success(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,81 @@ |
|||||||
|
package com.ynxbd.common.config.healthcard; |
||||||
|
|
||||||
|
import com.ynxbd.common.helper.common.HMACHelper; |
||||||
|
import com.ynxbd.common.helper.common.XmlConfigHelper; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.lang3.ObjectUtils; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
|
||||||
|
@Slf4j |
||||||
|
public class HCAIGuidanceConfig { |
||||||
|
public final static boolean IS_ENABLE; |
||||||
|
// 是否为测试环境
|
||||||
|
public final static boolean IS_DEV; |
||||||
|
// 是否为调试
|
||||||
|
public final static boolean IS_DEBUG; |
||||||
|
// 是否为分时段挂号
|
||||||
|
public final static boolean IS_SPLIT_TIME_REG; |
||||||
|
//配置文件读取项
|
||||||
|
public final static String HOSP_ID; |
||||||
|
// 密钥token
|
||||||
|
public final static String TOKEN; |
||||||
|
|
||||||
|
public final static String PARTNER_ID; |
||||||
|
|
||||||
|
public final static String HOSP_NAME; |
||||||
|
|
||||||
|
public final static String HOSP_ADDRESS; |
||||||
|
|
||||||
|
public final static String HOSP_INTRO; |
||||||
|
|
||||||
|
public final static String HOSP_LEVEL; |
||||||
|
|
||||||
|
public final static String HOSP_TEL; |
||||||
|
|
||||||
|
static { |
||||||
|
XmlConfigHelper config = new XmlConfigHelper().read("hc-config.xml", "ai_guidance"); |
||||||
|
IS_ENABLE = config.getBoolean("is_enable", false); |
||||||
|
config.setIsEnable(IS_ENABLE); |
||||||
|
|
||||||
|
IS_DEV = config.getBoolean("is_dev", false); |
||||||
|
IS_DEBUG = config.getBoolean("is_debug", false); |
||||||
|
IS_SPLIT_TIME_REG = config.getBoolean("is_split_time_reg", true); |
||||||
|
|
||||||
|
TOKEN = IS_DEV ? config.getString("dev_token") : config.getString("token"); |
||||||
|
|
||||||
|
PARTNER_ID = config.getString("partner_id"); |
||||||
|
HOSP_ID = config.getString("hosp_id"); |
||||||
|
HOSP_NAME = config.getString("hosp_name"); |
||||||
|
HOSP_ADDRESS = config.getString("hosp_address", ""); |
||||||
|
HOSP_INTRO = config.getString("hosp_intro", ""); |
||||||
|
HOSP_LEVEL = config.getString("hosp_level", ""); |
||||||
|
HOSP_TEL = config.getString("hosp_tel", ""); |
||||||
|
|
||||||
|
if (PARTNER_ID == null) { |
||||||
|
log.error("[智能导诊]读取配置文件失败|功能未开启"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 验签 |
||||||
|
* |
||||||
|
* @param request 请求 |
||||||
|
* @return 是否通过 |
||||||
|
*/ |
||||||
|
public static boolean isVerifySign(HttpServletRequest request) { |
||||||
|
if (!IS_ENABLE) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
String signature = request.getHeader("god-portal-signature"); // 签名
|
||||||
|
if (ObjectUtils.isEmpty(signature)) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
String timestamp = request.getHeader("god-portal-timestamp"); // 时间戳
|
||||||
|
|
||||||
|
log.info("[智能导诊]验签 timestamp={}, signature={}", timestamp, signature); |
||||||
|
String str = PARTNER_ID + timestamp; |
||||||
|
String cacheSign = HMACHelper.sha256(str, TOKEN); |
||||||
|
return signature.equals(cacheSign); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
package com.ynxbd.common.config.healthcard; |
||||||
|
|
||||||
|
import com.ynxbd.common.helper.common.XmlConfigHelper; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
@Slf4j |
||||||
|
public class HCReportConfig { |
||||||
|
|
||||||
|
public static final boolean IS_DEV; |
||||||
|
|
||||||
|
public static final String TOKEN; |
||||||
|
|
||||||
|
public static final String PARTNER_ID; // 医院ID(每家医院不一样)
|
||||||
|
|
||||||
|
static { |
||||||
|
XmlConfigHelper config = new XmlConfigHelper().read("hc-config.xml", "report"); |
||||||
|
|
||||||
|
IS_DEV = config.getBoolean("is_dev", false); |
||||||
|
TOKEN = config.getString("token"); |
||||||
|
PARTNER_ID = config.getString("partner_id"); |
||||||
|
} |
||||||
|
|
||||||
|
// 生成签名
|
||||||
|
public static HCSignHelper createSign() { |
||||||
|
return new HCSignHelper().createSign(PARTNER_ID, TOKEN); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
package com.ynxbd.common.config.healthcard; |
||||||
|
|
||||||
|
import cn.hutool.crypto.digest.DigestUtil; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
import java.util.UUID; |
||||||
|
|
||||||
|
@Slf4j |
||||||
|
@Getter |
||||||
|
public class HCSignHelper { |
||||||
|
private String sign; |
||||||
|
private String timestamp; |
||||||
|
private String requestId; |
||||||
|
|
||||||
|
// 生成签名
|
||||||
|
public HCSignHelper createSign(String partnerId, String token) { |
||||||
|
// 1. 当前毫秒时间戳
|
||||||
|
this.timestamp = String.valueOf(System.currentTimeMillis()); |
||||||
|
// 2. 拼接 signStr = partnerId + timestamp + token
|
||||||
|
String signStr = partnerId + this.timestamp + token; |
||||||
|
// 3. MD5 32位小写
|
||||||
|
this.sign = DigestUtil.md5Hex(signStr); |
||||||
|
this.requestId = String.valueOf(UUID.randomUUID()); |
||||||
|
return this; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,148 @@ |
|||||||
|
package com.ynxbd.common.helper.common; |
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.dom4j.Document; |
||||||
|
import org.dom4j.Element; |
||||||
|
import org.dom4j.io.SAXReader; |
||||||
|
|
||||||
|
import java.io.InputStream; |
||||||
|
|
||||||
|
|
||||||
|
@Slf4j |
||||||
|
public class XmlConfigHelper { |
||||||
|
private org.dom4j.Element root; |
||||||
|
|
||||||
|
private boolean isEnable = true; |
||||||
|
|
||||||
|
/** |
||||||
|
* 读取配置文件 |
||||||
|
* |
||||||
|
* @param filePath 文件路径 |
||||||
|
* @param rootName 根节点名 |
||||||
|
*/ |
||||||
|
public XmlConfigHelper read(String filePath, String rootName) { |
||||||
|
try (InputStream is = XmlConfigHelper.class.getClassLoader().getResourceAsStream(filePath)) { // 从classpath读取resources文件
|
||||||
|
SAXReader reader = new SAXReader(); |
||||||
|
Document document = reader.read(is); |
||||||
|
Element rootElement = document.getRootElement(); |
||||||
|
if (rootName == null) { |
||||||
|
root = rootElement; |
||||||
|
} else { |
||||||
|
root = rootElement.element(rootName); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
ErrorHelper.println(e); |
||||||
|
} |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public XmlConfigHelper read(String filePath) { |
||||||
|
return read(filePath, null); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public synchronized void setIsEnable(String rootName) { |
||||||
|
this.isEnable = getBoolean(rootName, false); |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized void setIsEnable(boolean isEnable) { |
||||||
|
this.isEnable = isEnable; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取配置文件Boolean值,可设默认值 |
||||||
|
* |
||||||
|
* @param rootNode 节点名 |
||||||
|
* @return Boolean |
||||||
|
*/ |
||||||
|
public boolean getBoolean(String rootNode, boolean defaultVal) { |
||||||
|
try { |
||||||
|
if (root == null) { |
||||||
|
return defaultVal; |
||||||
|
} |
||||||
|
|
||||||
|
String val = root.elementTextTrim(rootNode); |
||||||
|
return val == null ? defaultVal : Boolean.parseBoolean(val); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
return defaultVal; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取配置文件String值 |
||||||
|
* |
||||||
|
* @param rootNode 节点名 |
||||||
|
* @return String |
||||||
|
*/ |
||||||
|
public String getString(String rootNode) { |
||||||
|
return getString(rootNode, null); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取配置文件String值 |
||||||
|
* |
||||||
|
* @param rootNode 节点名 |
||||||
|
* @return String |
||||||
|
*/ |
||||||
|
public String getString(String rootNode, String defaultVal) { |
||||||
|
try { |
||||||
|
if (root == null) { |
||||||
|
return defaultVal; |
||||||
|
} |
||||||
|
|
||||||
|
if (!isEnable) { |
||||||
|
return defaultVal; |
||||||
|
} |
||||||
|
|
||||||
|
String val = root.elementTextTrim(rootNode); |
||||||
|
return val == null ? defaultVal : val; |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取配置文件Integer值 |
||||||
|
* |
||||||
|
* @param rootNode 节点名 |
||||||
|
* @return Integer |
||||||
|
*/ |
||||||
|
public Integer getInteger(String rootNode) { |
||||||
|
try { |
||||||
|
String val = getString(rootNode, null); |
||||||
|
return val == null ? null : Integer.parseInt(val.trim()); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// public static Element readXmlConfig(String filePath, String nodeName) {
|
||||||
|
// Element root = readXmlConfig(filePath);
|
||||||
|
// if (root == null) {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// return root.element(nodeName);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public static void main(String[] args) {
|
||||||
|
// Element report = readXmlConfig("hc-config.xml", "report");
|
||||||
|
// String s = report.elementText("is_dev");
|
||||||
|
// System.out.println(s);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// private static void readXmlData(Element root) {
|
||||||
|
// Element dbNode = root.element("db");
|
||||||
|
// System.out.println("密码:" + dbNode.elementText("password"));
|
||||||
|
// Element appNode = root.element("app");
|
||||||
|
// System.out.println("端口号:" + appNode.attributeValue("port"));
|
||||||
|
// }
|
||||||
|
|
||||||
|
} |
||||||
@ -1,83 +0,0 @@ |
|||||||
package com.ynxbd.wx.config; |
|
||||||
|
|
||||||
import com.ynxbd.common.helper.ProperHelper; |
|
||||||
import com.ynxbd.common.helper.common.HMACHelper; |
|
||||||
import lombok.extern.slf4j.Slf4j; |
|
||||||
import org.apache.commons.lang3.ObjectUtils; |
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import java.util.Date; |
|
||||||
|
|
||||||
/** |
|
||||||
* 智能导诊配置 |
|
||||||
*/ |
|
||||||
@Slf4j |
|
||||||
public class AIGuidanceConfig { |
|
||||||
private AIGuidanceConfig() { |
|
||||||
} |
|
||||||
|
|
||||||
public final static boolean IS_ENABLE; |
|
||||||
// 是否为测试环境
|
|
||||||
public final static boolean IS_DEV; |
|
||||||
// 是否为调试
|
|
||||||
public final static boolean IS_DEBUG; |
|
||||||
// 是否为分时段挂号
|
|
||||||
public final static boolean IS_SPLIT_TIME_REG; |
|
||||||
//配置文件读取项
|
|
||||||
public final static String HOS_ID; |
|
||||||
// 密钥
|
|
||||||
public final static String KEY; |
|
||||||
public final static String PARTNER_ID; |
|
||||||
public final static String HOS_NAME; |
|
||||||
public final static String HOS_ADDRESS; |
|
||||||
public final static String HOS_INTRO; |
|
||||||
public final static String HOS_LEVEL; |
|
||||||
public final static String HOS_TELEPHONE; |
|
||||||
|
|
||||||
static { |
|
||||||
ProperHelper config = new ProperHelper().read("ai-guidance.properties"); |
|
||||||
IS_ENABLE = config.getBoolean("ai.is_enable", false); |
|
||||||
config.setIsEnable(IS_ENABLE); |
|
||||||
|
|
||||||
IS_DEV = config.getBoolean("ai.is_dev", false); |
|
||||||
IS_DEBUG = config.getBoolean("ai.is_debug", false); |
|
||||||
IS_SPLIT_TIME_REG = config.getBoolean("ai.is_split_time_reg", true); |
|
||||||
|
|
||||||
KEY = IS_DEV ? config.getString("ai.dev_key") : config.getString("ai.key"); |
|
||||||
|
|
||||||
PARTNER_ID = config.getString("ai.partner_id"); |
|
||||||
HOS_ID = config.getString("ai.hos_id"); |
|
||||||
HOS_NAME = config.getString("ai.hos_name"); |
|
||||||
HOS_ADDRESS = config.getString("ai.hos_address", ""); |
|
||||||
HOS_INTRO = config.getString("ai.hos_intro", ""); |
|
||||||
HOS_LEVEL = config.getString("ai.hos_level", ""); |
|
||||||
HOS_TELEPHONE = config.getString("ai.hos_telephone", ""); |
|
||||||
|
|
||||||
if (PARTNER_ID == null) { |
|
||||||
log.error("[智能导诊]读取配置文件失败|功能未开启"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 验签 |
|
||||||
* |
|
||||||
* @param request 请求 |
|
||||||
* @return 是否通过 |
|
||||||
*/ |
|
||||||
public static boolean isVerifySign(HttpServletRequest request) { |
|
||||||
if (!IS_ENABLE) { |
|
||||||
return false; |
|
||||||
} |
|
||||||
String signature = request.getHeader("god-portal-signature"); // 签名
|
|
||||||
if (ObjectUtils.isEmpty(signature)) { |
|
||||||
return false; |
|
||||||
} |
|
||||||
String timestamp = request.getHeader("god-portal-timestamp"); // 时间戳
|
|
||||||
|
|
||||||
log.info("[智能导诊]验签 timestamp={}, signature={}", timestamp, signature); |
|
||||||
String str = PARTNER_ID + timestamp; |
|
||||||
String cacheSign = HMACHelper.sha256(str, KEY); |
|
||||||
return signature.equals(cacheSign); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,34 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<config> |
||||||
|
<!-- 报告解读 --> |
||||||
|
<report> |
||||||
|
<is_dev>true</is_dev> |
||||||
|
<partner_id>20009250</partner_id> |
||||||
|
<token>3bee9edc0a2f41ac911b9b714c854cad</token> |
||||||
|
</report> |
||||||
|
|
||||||
|
<!-- 智能导诊 --> |
||||||
|
<ai_guidance> |
||||||
|
<!-- 是否开启 --> |
||||||
|
<is_enable>true</is_enable> |
||||||
|
<!-- 是否开启调试 --> |
||||||
|
<is_debug>true</is_debug> |
||||||
|
<!-- 是否为测试环境 --> |
||||||
|
<is_dev>true</is_dev> |
||||||
|
<!-- 是否为分时段挂号(默认true) --> |
||||||
|
<is_split_time_reg>true</is_split_time_reg> |
||||||
|
<!-- 合作方ID --> |
||||||
|
<partner_id>100000317</partner_id> |
||||||
|
<!-- 密钥token --> |
||||||
|
<token>795b207e12572839976d9310bdde32be</token> |
||||||
|
<!-- 测试密钥token --> |
||||||
|
<dev_token>2a49b1566c3c2e42a1ff9e483abb57da</dev_token> |
||||||
|
|
||||||
|
<hosp_id name="医院ID">20002953</hosp_id> |
||||||
|
<hosp_name name="医院名称">德宏州中医医院</hosp_name> |
||||||
|
<hosp_intro name="医院介绍"></hosp_intro> |
||||||
|
<hosp_level name="医院等级"></hosp_level> |
||||||
|
<hosp_address name="医院地址"></hosp_address> |
||||||
|
<hosp_tel name="联系方式"></hosp_tel> |
||||||
|
</ai_guidance> |
||||||
|
</config> |
||||||
Loading…
Reference in new issue