微信后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.0 KiB

package com.ynxbd.common.service;
import com.ynxbd.common.result.ResultEnum;
import com.ynxbd.common.result.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.ObjectUtils;
@Slf4j
public class XBDService {
public String getCloudToken(String treatNum) {
treatNum = treatNum + "huiyou69";
String key = DigestUtils.md5Hex(treatNum).toUpperCase();
if (ObjectUtils.isEmpty(key) || key.length() < 12) {
return null;
}
return key.substring(3, 12);
}
/**
* 获取云胶片的授权地址
*
* @param treatNum 门诊号|住院号
* @param treatType 类型[1:门诊;2:住院]
*/
public String getPacsAuthUrl(Integer version, String patientId, String treatNum, String treatType) throws ServiceException {
if (version == null) {
version = 1;
}
if (version == 1) {
return getPacsAuthUrlByPatientId(version, patientId);
}
if (version == 2) {
return getPacsAuthUrlByTreatNum(version, treatNum, treatType);
}
throw new ServiceException("[云胶片]授权version未匹配");
}
/**
* 获取云胶片的授权地址[版本2]
*
* @param treatNum 门诊号|住院号
* @param treatType 类型[1:门诊;2:住院]
*/
public String getPacsAuthUrlByTreatNum(Integer version, String treatNum, String treatType) throws ServiceException {
log.info("[云胶片]授权 version={}, treatType={}, treatNum={}", version, treatType, treatNum);
if (treatType == null || treatNum == null) {
throw new ServiceException(ResultEnum.PARAM_IS_INVALID);
}
String token = DigestUtils.md5Hex(treatNum + "huiyou69");
if (ObjectUtils.isEmpty(token)) {
throw new ServiceException("token转化失败");
}
if (token.length() < 12) {
throw new ServiceException("token长度错误");
}
token = token.substring(3, 12).toUpperCase();
String url = "/smsPacs?token=" + token + ("1".equals(treatType) ? "&opsNum=" : "&inHosNum=") + treatNum;
log.info("[云胶片]授权 url={}", url);
return url;
}
/**
* 获取云胶片的授权地址[版本1]
*
* @param patientId 患者id
*/
public String getPacsAuthUrlByPatientId(Integer version, String patientId) throws ServiceException {
log.info("[云胶片]授权 version={}, patientId={}", version, patientId);
if (ObjectUtils.isEmpty(patientId)) {
throw new ServiceException(ResultEnum.PARAM_IS_INVALID);
}
String token = DigestUtils.md5Hex(patientId + "huiyou69");
if (ObjectUtils.isEmpty(token)) {
throw new ServiceException("token转化失败");
}
String url = "/smsPacs?token=" + token.toUpperCase() + "&patID=" + patientId;
log.info("[云胶片]授权 url={}", url);
return url;
}
}