浏览代码

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

huangwenjie 8 年之前
父节点
当前提交
16e9dd60a9

+ 7 - 7
patient-co/patient-co-statistics/pom.xml

@ -12,7 +12,7 @@
    <version>1.0.0</version>
    <version>1.0.0</version>
    <modelVersion>4.0.0</modelVersion>
    <modelVersion>4.0.0</modelVersion>
    <!--打成war包需要的配置-->
    <!--打成war包需要的配置-->
    <packaging>jar</packaging>
    <packaging>war</packaging>
    <!--<packaging>jar</packaging>-->
    <!--<packaging>jar</packaging>-->
    <name>patient-co-statistics</name>
    <name>patient-co-statistics</name>
@ -418,12 +418,12 @@
                <groupId>org.springframework.boot</groupId>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            </plugin>
            <!--<plugin>-->
                <!--<artifactId>maven-war-plugin</artifactId>-->
                <!--<configuration>-->
                    <!--<failOnMissingWebXml>false</failOnMissingWebXml>-->
                <!--</configuration>-->
            <!--</plugin>-->
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <artifactId>maven-compiler-plugin</artifactId>

+ 1 - 1
patient-co/patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/CurrentDayAllQuotaJob.java

@ -1702,7 +1702,7 @@ public class CurrentDayAllQuotaJob implements Job {
                    "  t.admin_team_code, " +
                    "  t.admin_team_code, " +
                    "  LEFT (d.hospital, 8) " +
                    "  LEFT (d.hospital, 8) " +
                    " ) ss ON ss.admin_team_code = tm.id " +
                    " ) ss ON ss.admin_team_code = tm.id " +
                    " ORDER BY " +
                    " where tm.available=1 ORDER BY " +
                    " avgCount DESC";
                    " avgCount DESC";
            return team_SQL;
            return team_SQL;
        } else if ("All_hos_SQL".equals(code)) {
        } else if ("All_hos_SQL".equals(code)) {

+ 5 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/DoctorInterceptor.java

@ -59,11 +59,11 @@ public class DoctorInterceptor extends BaseInterceptor {
            String imei = json.has("imei") ? json.getString("imei") : "";
            String imei = json.has("imei") ? json.getString("imei") : "";
            String observer = json.has("observer") ? json.getString("observer") : "";
            String observer = json.has("observer") ? json.getString("observer") : "";
            Integer platform = json.has("platform") ? json.getInt("platform") : 2;
            Integer platform = json.has("platform") ? json.getInt("platform") : 2;
            logger.info("tokenStr:"+tokenStr);
            logger.info("uid:"+uid);
            logger.info("imei:"+imei);
            logger.info("observer:"+observer);
            logger.info("platform:"+platform);
            logger.debug("tokenStr:"+tokenStr);
            logger.debug("uid:"+uid);
            logger.debug("imei:"+imei);
            logger.debug("observer:"+observer);
            logger.debug("platform:"+platform);
            //如果是观察者直接返回true
            //如果是观察者直接返回true
            if (!org.springframework.util.StringUtils.isEmpty(observer) && observer.equals("1")) {
            if (!org.springframework.util.StringUtils.isEmpty(observer) && observer.equals("1")) {

+ 6 - 6
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/PatientInterceptor.java

@ -39,7 +39,7 @@ public class PatientInterceptor extends BaseInterceptor {
			}
			}
			response.setCharacterEncoding("UTF-8");
			response.setCharacterEncoding("UTF-8");
			JSONObject json = getAgent(request);
			JSONObject json = getAgent(request);
			logger.info("userAgent:"+json);
			logger.debug("userAgent:"+json);
			if (json == null) {
			if (json == null) {
				// 未登录
				// 未登录
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
@ -50,11 +50,11 @@ public class PatientInterceptor extends BaseInterceptor {
			String imei = json.has("imei") ? json.getString("imei") : "";
			String imei = json.has("imei") ? json.getString("imei") : "";
			String openid = json.has("openid") ? json.getString("openid") : "";
			String openid = json.has("openid") ? json.getString("openid") : "";
			int platform = json.has("platform") ? json.getInt("platform") : 1;
			int platform = json.has("platform") ? json.getInt("platform") : 1;
			logger.info("tokenStr:"+tokenStr);
			logger.info("uid:"+user);
			logger.info("imei:"+imei);
			logger.info("openid:"+openid);
			logger.info("platform:"+platform);
			logger.debug("tokenStr:"+tokenStr);
			logger.debug("uid:"+user);
			logger.debug("imei:"+imei);
			logger.debug("openid:"+openid);
			logger.debug("platform:"+platform);
			if (StringUtils.isEmpty(imei)) {
			if (StringUtils.isEmpty(imei)) {
				imei = openid;
				imei = openid;
			}
			}

+ 3 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -35,6 +35,9 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    @Query("select a from SignFamily a where a.patient = ?1 and status = ?2 and a.type = 2")
    @Query("select a from SignFamily a where a.patient = ?1 and status = ?2 and a.type = 2")
    SignFamily findByPatientCodeStatus(String patient, int status);
    SignFamily findByPatientCodeStatus(String patient, int status);
    @Query("select a from SignFamily a where a.patient = ?1 and status >= ?2 and a.type = 2")
    SignFamily findByPatientCodeStatus2(String patient, int status);
    @Query("select a from SignFamily a where a.patient = ?1 and a.type = ?2 and a.status >= 1")
    @Query("select a from SignFamily a where a.patient = ?1 and a.type = ?2 and a.status >= 1")
    SignFamily findByPatientAndType(String patient, int type);
    SignFamily findByPatientAndType(String patient, int type);

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java

@ -2459,7 +2459,7 @@ public class SignWebService extends BaseService {
        patient.setSickVillage(countryCode);
        patient.setSickVillage(countryCode);
        patient.setSickVillageName(country.getName());
        patient.setSickVillageName(country.getName());
        patientService.save(patient);
        patientService.save(patient);
        SignFamily signFamily = signFamilyDao.findByPatientCodeStatus(patientCode,0);
        SignFamily signFamily = signFamilyDao.findByPatientCodeStatus2(patientCode,0);
        if(signFamily!=null){
        if(signFamily!=null){
            signFamily.setSickVillage(countryCode);
            signFamily.setSickVillage(countryCode);
            signFamily.setSickVillageName(country.getName());
            signFamily.setSickVillageName(country.getName());

+ 3 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java

@ -1568,6 +1568,9 @@ public class StatisticsService extends BaseService {
            JSONObject relyRs = (JSONObject) relyMap.get(key);
            JSONObject relyRs = (JSONObject) relyMap.get(key);
            JSONObject totalRs = (JSONObject) totalMap.get(key);
            JSONObject totalRs = (JSONObject) totalMap.get(key);
            JSONObject onRelyRs = (JSONObject) onRelyMap.get(key);
            JSONObject onRelyRs = (JSONObject) onRelyMap.get(key);
            if(relyRs==null||totalRs==null||onRelyRs==null){
                continue;
            }
            //合并结果集
            //合并结果集
            Long totalNm = totalRs.getLong("num");
            Long totalNm = totalRs.getLong("num");
            Long relyNm = relyRs.getLong("num");
            Long relyNm = relyRs.getLong("num");

+ 334 - 312
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/RSAUtils.java

@ -20,8 +20,10 @@ import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.util.Date;
import java.util.Date;
import javax.annotation.PostConstruct;
import javax.crypto.Cipher;
import javax.crypto.Cipher;
import com.yihu.wlyy.repository.security.RSADao;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
@ -36,322 +38,342 @@ import org.springframework.stereotype.Component;
/**
/**
 * RSA算法加密/解密工具类。
 * RSA算法加密/解密工具类。
 * 
 *
 * @author fuchun
 * @author fuchun
 * @version 1.0.0, 2010-05-05
 * @version 1.0.0, 2010-05-05
 */
 */
@Component
@Component
public class RSAUtils {
public class RSAUtils {
	@Autowired
	private CommonUtil CommonUtil;
	private BaseService baseService;
	private static final Logger LOGGER = LoggerFactory.getLogger(RSAUtils.class);
	/** 算法名称 */
	private static final String ALGORITHOM = "RSA";
	/** 密钥大小 */
	private static final int KEY_SIZE = 1024;
	/** 默认的安全服务提供者 */
	private static final Provider DEFAULT_PROVIDER = new BouncyCastleProvider();
	private static KeyPairGenerator keyPairGen = null;
	private static KeyFactory keyFactory = null;
	/** 缓存的密钥对。 */
	private KeyPair oneKeyPair = null;
	private static RSAUtils rsaUtils = null;
	static {
		try {
			keyPairGen = KeyPairGenerator.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
			keyFactory = KeyFactory.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
		} catch (NoSuchAlgorithmException ex) {
			LOGGER.error(ex.getMessage());
		}
	}
	public synchronized static RSAUtils getInstance(BaseService baseService) {
		if (rsaUtils == null) {
			rsaUtils = new RSAUtils();
			rsaUtils.baseService = baseService;
		}
		return rsaUtils;
	}
	public KeyPair getKeyPair() {
		if (oneKeyPair == null) {
			// 从数据库加载
			RSA rsa = baseService.loadRSA();
			if (rsa == null) {
				// 生成密钥
				generateKeyPair();
			} else {
				// 由数据库取出来
				Object obj = CommonUtil.toObject(rsa.getData());
				oneKeyPair = (KeyPair) obj;
			}
		}
		return oneKeyPair;
	}
	/**
	 * 生成并返回RSA密钥对。
	 */
	private synchronized KeyPair generateKeyPair() {
		try {
			keyPairGen.initialize(KEY_SIZE, new SecureRandom(DateFormatUtils.format(new Date(), DateUtil.YYYYMMDD).getBytes()));
			oneKeyPair = keyPairGen.generateKeyPair();
			// 保存到数据库
			baseService.saveRSA(oneKeyPair);
			return oneKeyPair;
		} catch (InvalidParameterException ex) {
			LOGGER.error("KeyPairGenerator does not support a key length of " + KEY_SIZE + ".", ex);
		} catch (NullPointerException ex) {
			LOGGER.error("RSAUtils#KEY_PAIR_GEN is null, can not generate KeyPairGenerator instance.", ex);
		}
		return null;
	}
	/**
	 * 根据给定的系数和专用指数构造一个RSA专用的公钥对象。
	 * 
	 * @param modulus 系数。
	 * @param publicExponent 专用指数。
	 * @return RSA专用公钥对象。
	 */
	public RSAPublicKey generateRSAPublicKey(byte[] modulus, byte[] publicExponent) {
		RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(new BigInteger(modulus), new BigInteger(publicExponent));
		try {
			return (RSAPublicKey) keyFactory.generatePublic(publicKeySpec);
		} catch (InvalidKeySpecException ex) {
			LOGGER.error("RSAPublicKeySpec is unavailable.", ex);
		} catch (NullPointerException ex) {
			LOGGER.error("RSAUtils#KEY_FACTORY is null, can not generate KeyFactory instance.", ex);
		}
		return null;
	}
	/**
	 * 根据给定的系数和专用指数构造一个RSA专用的私钥对象。
	 * 
	 * @param modulus 系数。
	 * @param privateExponent 专用指数。
	 * @return RSA专用私钥对象。
	 */
	public RSAPrivateKey generateRSAPrivateKey(byte[] modulus, byte[] privateExponent) {
		RSAPrivateKeySpec privateKeySpec = new RSAPrivateKeySpec(new BigInteger(modulus), new BigInteger(privateExponent));
		try {
			return (RSAPrivateKey) keyFactory.generatePrivate(privateKeySpec);
		} catch (InvalidKeySpecException ex) {
			LOGGER.error("RSAPrivateKeySpec is unavailable.", ex);
		} catch (NullPointerException ex) {
			LOGGER.error("RSAUtils#KEY_FACTORY is null, can not generate KeyFactory instance.", ex);
		}
		return null;
	}
	/**
	 * 使用指定的公钥加密数据。
	 * 
	 * @param publicKey 给定的公钥。
	 * @param data 要加密的数据。
	 * @return 加密后的数据。
	 */
	public byte[] encrypt(PublicKey publicKey, byte[] data) throws Exception {
		Cipher ci = Cipher.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
		ci.init(Cipher.ENCRYPT_MODE, publicKey);
		return ci.doFinal(data);
	}
	/**
	 * 使用指定的私钥解密数据。
	 * 
	 * @param privateKey 给定的私钥。
	 * @param data 要解密的数据。
	 * @return 原数据。
	 */
	public byte[] decrypt(PrivateKey privateKey, byte[] data) throws Exception {
		Cipher ci = Cipher.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
		ci.init(Cipher.DECRYPT_MODE, privateKey);
		return ci.doFinal(data);
	}
	/**
	 * 使用给定的公钥加密给定的字符串。
	 * <p />
	 * 若 {@code publicKey} 为 {@code null},或者 {@code plaintext} 为 {@code null} 则返回 {@code
	 * null}。
	 * 
	 * @param publicKey 给定的公钥。
	 * @param plaintext 字符串。
	 * @return 给定字符串的密文。
	 */
	public String encryptString(PublicKey publicKey, String plaintext) {
		if (publicKey == null || plaintext == null) {
			return null;
		}
		byte[] data = plaintext.getBytes();
		try {
			byte[] en_data = encrypt(publicKey, data);
			return new String(Hex.encodeHex(en_data));
		} catch (Exception ex) {
			LOGGER.error(ex.getCause().getMessage());
		}
		return null;
	}
	/**
	 * 使用默认的公钥加密给定的字符串。
	 * <p />
	 * 若{@code plaintext} 为 {@code null} 则返回 {@code null}。
	 * 
	 * @param plaintext 字符串。
	 * @return 给定字符串的密文。
	 */
	public String encryptString(String plaintext) {
		if (plaintext == null) {
			return null;
		}
		byte[] data = plaintext.getBytes();
		try {
			byte[] en_data = encrypt((RSAPublicKey) getKeyPair().getPublic(), data);
			return new String(Hex.encodeHex(en_data));
		} catch (NullPointerException ex) {
			LOGGER.error("keyPair cannot be null.");
		} catch (Exception ex) {
			LOGGER.error(ex.getCause().getMessage());
		}
		return null;
	}
	/**
	 * 使用给定的私钥解密给定的字符串。
	 * <p />
	 * 若私钥为 {@code null},或者 {@code encrypttext} 为 {@code null}或空字符串则返回 {@code null}。
	 * 私钥不匹配时,返回 {@code null}。
	 * 
	 * @param privateKey 给定的私钥。
	 * @param encrypttext 密文。
	 * @return 原文字符串。
	 */
	public String decryptString(PrivateKey privateKey, String encrypttext) {
		if (privateKey == null || StringUtils.isBlank(encrypttext)) {
			return null;
		}
		try {
			byte[] en_data = Hex.decodeHex(encrypttext.toCharArray());
			byte[] data = decrypt(privateKey, en_data);
			return new String(data);
		} catch (Exception ex) {
			LOGGER.error(String.format("\"%s\" Decryption failed. Cause: %s", encrypttext, ex.getCause().getMessage()));
		}
		return null;
	}
	/**
	 * 使用默认的私钥解密给定的字符串。
	 * <p />
	 * 若{@code encrypttext} 为 {@code null}或空字符串则返回 {@code null}。
	 * 私钥不匹配时,返回 {@code null}。
	 * 
	 * @param encrypttext 密文。
	 * @return 原文字符串。
	 */
	public String decryptString(String encrypttext) {
		if (StringUtils.isBlank(encrypttext)) {
			return null;
		}
		try {
			byte[] en_data = Hex.decodeHex(encrypttext.toCharArray());
			byte[] data = decrypt((RSAPrivateKey) getKeyPair().getPrivate(), en_data);
			return new String(data) ;
		} catch (NullPointerException ex) {
			LOGGER.error("keyPair cannot be null.");
		} catch (Exception ex) {
			LOGGER.error(String.format("\"%s\" Decryption failed. Cause: %s", encrypttext, ex.getMessage()));
		}
		return null;
	}
	/**
	 * 使用默认的私钥解密由JS加密(使用此类提供的公钥加密)的字符串。
	 * 
	 * @param encrypttext 密文。
	 * @return {@code encrypttext} 的原文字符串。
	 */
	public String decryptStringByJs(String encrypttext) {
		String text = decryptString(encrypttext);
		if (text == null) {
			return null;
		}
		return StringUtils.reverse(text);
	}
	/** 返回已初始化的默认的公钥。*/
	public RSAPublicKey getDefaultPublicKey() {
		KeyPair keyPair = getKeyPair();
		if (keyPair != null) {
			return (RSAPublicKey) keyPair.getPublic();
		}
		return null;
	}
	/** 返回已初始化的默认的私钥。*/
	public RSAPrivateKey getDefaultPrivateKey() {
		KeyPair keyPair = getKeyPair();
		if (keyPair != null) {
			return (RSAPrivateKey) keyPair.getPrivate();
		}
		return null;
	}
	public String getModulus() {
		return new String(Hex.encodeHex(getDefaultPublicKey().getModulus().toByteArray()));
	}
	public String getExponent() {
		return new String(Hex.encodeHex(getDefaultPublicKey().getPublicExponent().toByteArray()));
	}
	public static byte[] getPublicGovKey2() throws IOException {
		byte[] buffer = null;
		InputStream fis = null;
		ByteArrayOutputStream bos = null;
		try {
			fis = RSAUtils.class.getClassLoader().getResourceAsStream("PublicGov.key");
			bos = new ByteArrayOutputStream(1000);
			byte[] b = new byte[1000];
			int n;
			while ((n = fis.read(b)) != -1) {
				bos.write(b, 0, n);
			}
			buffer = bos.toByteArray();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (fis != null)
				fis.close();
			if (bos != null)
				bos.close();
		}
		return buffer;
	}
	public static byte[] getPublicGovKey() {
		return sehrCrypto.sehrCrypto.ReadFileBytes(RSAUtils.class.getClassLoader().getResource("PublicGov.key").getPath());
	}
	public static void main(String[] args) {
		try {
			byte[] t1 = getPublicGovKey2();
			byte[] t2 = getPublicGovKey();
			System.out.println(t1);
			System.out.println(t2);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
    @Autowired
    private CommonUtil CommonUtil;
    @Autowired
    private RSADao rsaDao;
    private BaseService baseService;
    @PostConstruct
    public void cleanRSA() {
        // 情况缓存表
        rsaDao.deleteAll();
    }
    private static final Logger LOGGER = LoggerFactory.getLogger(RSAUtils.class);
    /**
     * 算法名称
     */
    private static final String ALGORITHOM = "RSA";
    /**
     * 密钥大小
     */
    private static final int KEY_SIZE = 1024;
    /**
     * 默认的安全服务提供者
     */
    private static final Provider DEFAULT_PROVIDER = new BouncyCastleProvider();
    private static KeyPairGenerator keyPairGen = null;
    private static KeyFactory keyFactory = null;
    /**
     * 缓存的密钥对。
     */
    private KeyPair oneKeyPair = null;
    private static RSAUtils rsaUtils = null;
    static {
        try {
            keyPairGen = KeyPairGenerator.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
            keyFactory = KeyFactory.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
        } catch (NoSuchAlgorithmException ex) {
            LOGGER.error(ex.getMessage());
        }
    }
    public synchronized static RSAUtils getInstance(BaseService baseService) {
        if (rsaUtils == null) {
            rsaUtils = new RSAUtils();
            rsaUtils.baseService = baseService;
        }
        return rsaUtils;
    }
    public KeyPair getKeyPair() {
        if (oneKeyPair == null) {
            // 从数据库加载
            RSA rsa = baseService.loadRSA();
            if (rsa == null) {
                // 生成密钥
                generateKeyPair();
            } else {
                // 由数据库取出来
                Object obj = CommonUtil.toObject(rsa.getData());
                oneKeyPair = (KeyPair) obj;
            }
        }
        return oneKeyPair;
    }
    /**
     * 生成并返回RSA密钥对。
     */
    private synchronized KeyPair generateKeyPair() {
        try {
            keyPairGen.initialize(KEY_SIZE, new SecureRandom(DateFormatUtils.format(new Date(), DateUtil.YYYYMMDD).getBytes()));
            oneKeyPair = keyPairGen.generateKeyPair();
            // 保存到数据库
            baseService.saveRSA(oneKeyPair);
            return oneKeyPair;
        } catch (InvalidParameterException ex) {
            LOGGER.error("KeyPairGenerator does not support a key length of " + KEY_SIZE + ".", ex);
        } catch (NullPointerException ex) {
            LOGGER.error("RSAUtils#KEY_PAIR_GEN is null, can not generate KeyPairGenerator instance.", ex);
        }
        return null;
    }
    /**
     * 根据给定的系数和专用指数构造一个RSA专用的公钥对象。
     *
     * @param modulus        系数。
     * @param publicExponent 专用指数。
     * @return RSA专用公钥对象。
     */
    public RSAPublicKey generateRSAPublicKey(byte[] modulus, byte[] publicExponent) {
        RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(new BigInteger(modulus), new BigInteger(publicExponent));
        try {
            return (RSAPublicKey) keyFactory.generatePublic(publicKeySpec);
        } catch (InvalidKeySpecException ex) {
            LOGGER.error("RSAPublicKeySpec is unavailable.", ex);
        } catch (NullPointerException ex) {
            LOGGER.error("RSAUtils#KEY_FACTORY is null, can not generate KeyFactory instance.", ex);
        }
        return null;
    }
    /**
     * 根据给定的系数和专用指数构造一个RSA专用的私钥对象。
     *
     * @param modulus         系数。
     * @param privateExponent 专用指数。
     * @return RSA专用私钥对象。
     */
    public RSAPrivateKey generateRSAPrivateKey(byte[] modulus, byte[] privateExponent) {
        RSAPrivateKeySpec privateKeySpec = new RSAPrivateKeySpec(new BigInteger(modulus), new BigInteger(privateExponent));
        try {
            return (RSAPrivateKey) keyFactory.generatePrivate(privateKeySpec);
        } catch (InvalidKeySpecException ex) {
            LOGGER.error("RSAPrivateKeySpec is unavailable.", ex);
        } catch (NullPointerException ex) {
            LOGGER.error("RSAUtils#KEY_FACTORY is null, can not generate KeyFactory instance.", ex);
        }
        return null;
    }
    /**
     * 使用指定的公钥加密数据。
     *
     * @param publicKey 给定的公钥。
     * @param data      要加密的数据。
     * @return 加密后的数据。
     */
    public byte[] encrypt(PublicKey publicKey, byte[] data) throws Exception {
        Cipher ci = Cipher.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
        ci.init(Cipher.ENCRYPT_MODE, publicKey);
        return ci.doFinal(data);
    }
    /**
     * 使用指定的私钥解密数据。
     *
     * @param privateKey 给定的私钥。
     * @param data       要解密的数据。
     * @return 原数据。
     */
    public byte[] decrypt(PrivateKey privateKey, byte[] data) throws Exception {
        Cipher ci = Cipher.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
        ci.init(Cipher.DECRYPT_MODE, privateKey);
        return ci.doFinal(data);
    }
    /**
     * 使用给定的公钥加密给定的字符串。
     * <p>
     * 若 {@code publicKey} 为 {@code null},或者 {@code plaintext} 为 {@code null} 则返回 {@code
     * null}。
     *
     * @param publicKey 给定的公钥。
     * @param plaintext 字符串。
     * @return 给定字符串的密文。
     */
    public String encryptString(PublicKey publicKey, String plaintext) {
        if (publicKey == null || plaintext == null) {
            return null;
        }
        byte[] data = plaintext.getBytes();
        try {
            byte[] en_data = encrypt(publicKey, data);
            return new String(Hex.encodeHex(en_data));
        } catch (Exception ex) {
            LOGGER.error(ex.getCause().getMessage());
        }
        return null;
    }
    /**
     * 使用默认的公钥加密给定的字符串。
     * <p>
     * 若{@code plaintext} 为 {@code null} 则返回 {@code null}。
     *
     * @param plaintext 字符串。
     * @return 给定字符串的密文。
     */
    public String encryptString(String plaintext) {
        if (plaintext == null) {
            return null;
        }
        byte[] data = plaintext.getBytes();
        try {
            byte[] en_data = encrypt((RSAPublicKey) getKeyPair().getPublic(), data);
            return new String(Hex.encodeHex(en_data));
        } catch (NullPointerException ex) {
            LOGGER.error("keyPair cannot be null.");
        } catch (Exception ex) {
            LOGGER.error(ex.getCause().getMessage());
        }
        return null;
    }
    /**
     * 使用给定的私钥解密给定的字符串。
     * <p>
     * 若私钥为 {@code null},或者 {@code encrypttext} 为 {@code null}或空字符串则返回 {@code null}。
     * 私钥不匹配时,返回 {@code null}。
     *
     * @param privateKey  给定的私钥。
     * @param encrypttext 密文。
     * @return 原文字符串。
     */
    public String decryptString(PrivateKey privateKey, String encrypttext) {
        if (privateKey == null || StringUtils.isBlank(encrypttext)) {
            return null;
        }
        try {
            byte[] en_data = Hex.decodeHex(encrypttext.toCharArray());
            byte[] data = decrypt(privateKey, en_data);
            return new String(data);
        } catch (Exception ex) {
            LOGGER.error(String.format("\"%s\" Decryption failed. Cause: %s", encrypttext, ex.getCause().getMessage()));
        }
        return null;
    }
    /**
     * 使用默认的私钥解密给定的字符串。
     * <p>
     * 若{@code encrypttext} 为 {@code null}或空字符串则返回 {@code null}。
     * 私钥不匹配时,返回 {@code null}。
     *
     * @param encrypttext 密文。
     * @return 原文字符串。
     */
    public String decryptString(String encrypttext) {
        if (StringUtils.isBlank(encrypttext)) {
            return null;
        }
        try {
            byte[] en_data = Hex.decodeHex(encrypttext.toCharArray());
            byte[] data = decrypt((RSAPrivateKey) getKeyPair().getPrivate(), en_data);
            return new String(data);
        } catch (NullPointerException ex) {
            LOGGER.error("keyPair cannot be null.");
        } catch (Exception ex) {
            LOGGER.error(String.format("\"%s\" Decryption failed. Cause: %s", encrypttext, ex.getMessage()));
        }
        return null;
    }
    /**
     * 使用默认的私钥解密由JS加密(使用此类提供的公钥加密)的字符串。
     *
     * @param encrypttext 密文。
     * @return {@code encrypttext} 的原文字符串。
     */
    public String decryptStringByJs(String encrypttext) {
        String text = decryptString(encrypttext);
        if (text == null) {
            return null;
        }
        return StringUtils.reverse(text);
    }
    /**
     * 返回已初始化的默认的公钥。
     */
    public RSAPublicKey getDefaultPublicKey() {
        KeyPair keyPair = getKeyPair();
        if (keyPair != null) {
            return (RSAPublicKey) keyPair.getPublic();
        }
        return null;
    }
    /**
     * 返回已初始化的默认的私钥。
     */
    public RSAPrivateKey getDefaultPrivateKey() {
        KeyPair keyPair = getKeyPair();
        if (keyPair != null) {
            return (RSAPrivateKey) keyPair.getPrivate();
        }
        return null;
    }
    public String getModulus() {
        return new String(Hex.encodeHex(getDefaultPublicKey().getModulus().toByteArray()));
    }
    public String getExponent() {
        return new String(Hex.encodeHex(getDefaultPublicKey().getPublicExponent().toByteArray()));
    }
    public static byte[] getPublicGovKey2() throws IOException {
        byte[] buffer = null;
        InputStream fis = null;
        ByteArrayOutputStream bos = null;
        try {
            fis = RSAUtils.class.getClassLoader().getResourceAsStream("PublicGov.key");
            bos = new ByteArrayOutputStream(1000);
            byte[] b = new byte[1000];
            int n;
            while ((n = fis.read(b)) != -1) {
                bos.write(b, 0, n);
            }
            buffer = bos.toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fis != null)
                fis.close();
            if (bos != null)
                bos.close();
        }
        return buffer;
    }
    public static byte[] getPublicGovKey() {
        return sehrCrypto.sehrCrypto.ReadFileBytes(RSAUtils.class.getClassLoader().getResource("PublicGov.key").getPath());
    }
    public static void main(String[] args) {
        try {
            byte[] t1 = getPublicGovKey2();
            byte[] t2 = getPublicGovKey();
            System.out.println(t1);
            System.out.println(t2);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
}

+ 6 - 6
patient-co/patient-co-wlyy/src/main/resources/application.yml

@ -166,17 +166,17 @@ spring:
  datasource:
  datasource:
    wlyy:
    wlyy:
      url: jdbc:mysql:/59.61.92.94:3306/wlyy?useUnicode:true&amp;characterEncoding=utf-8&amp;autoReconnect=true
      username: wlyy
      password: jkzlehr@123
      url: jdbc:mysql://59.61.92.94:3306/wlyy?useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true
      username: jkzl_root
      password: jkzlehr@321465
    health:
    health:
      url: jdbc:mysql://59.61.92.94:3306/device?useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true
      url: jdbc:mysql://59.61.92.94:3306/device?useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true
      username: wlyy
      username: wlyy
      password: jkzlehr@123
      password: jkzlehr@321465
  redis:
  redis:
    host: 120.41.253.95 # Redis server host.
    host: 120.41.253.95 # Redis server host.
    port: 6379 # Redis server port.
    port: 6380 # Redis server port.
    password: jkzl_ehr
    password: jkzl_ehr
server:
server:
@ -187,7 +187,7 @@ im:
  im_list_get: http://120.41.253.95:3000/
  im_list_get: http://120.41.253.95:3000/
  group_server: http://120.41.253.95:3000/api/v1/chats/gm
  group_server: http://120.41.253.95:3000/api/v1/chats/gm
  msg_push_server: http://120.41.253.95:3000/api/v1/chats/sm
  msg_push_server: http://120.41.253.95:3000/api/v1/chats/sm
  data_base_name: ichat
  data_base_name: im
wechat:
wechat:
  appId: wxad04e9c4c5255acf
  appId: wxad04e9c4c5255acf

+ 2 - 2
patient-co/patient-co-wlyy/src/main/resources/config/fdfs_client.conf

@ -9,7 +9,7 @@ http.secret_key = FastDFS1234567890
#tracker_server = 172.19.103.54:22122
#tracker_server = 172.19.103.54:22122
#-------------测试环境---------------#
#-------------测试环境---------------#
tracker_server = 172.19.103.54:22122
#tracker_server = 172.19.103.54:22122
#-------------正式环境---------------#
#-------------正式环境---------------#
#tracker_server = 192.168.0.239:22122
tracker_server = 192.168.0.239:22122