DESKTOP-G6NQ3SI\dante 7 лет назад
Родитель
Сommit
9994ef5173

+ 4 - 12
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/ZysoftApi.java

@ -23,26 +23,18 @@ public class ZysoftApi extends AbstractApiExecuter {
    private static byte[]  publicKey;
    private static byte[]  zkzlPublicKey;
    private static byte[]  zkzlPrivateKey;
    private static byte[]  immPublicKey;
    private static String  immPublicKey;
    
    /**
     * 获取计免预约加密公钥
     */
    private static byte[] getImmPublicKey() throws Exception {
    public static String getImmPublicKey() throws Exception {
        if(immPublicKey == null)
        {
            immPublicKey =  sehrCrypto.sehrCrypto.ReadFileBytes(ZysoftApi.class.getClassLoader().getResource(SystemConfig.getInstance().getImmPublicKey()).toURI().getPath());
            immPublicKey =  ZysoftApi.class.getClassLoader().getResource(SystemConfig.getInstance().getImmPublicKey()).toURI().getPath();
        }
        return immPublicKey;
    }
    
    
    public String getConditionRSA(String source) throws Exception
    {
        CryptoKey key = buildCryptoKey(getImmPublicKey());
        String restult = cryptoParameter(key,source);
        return restult;
    }
    
    /**
@ -181,7 +173,7 @@ public class ZysoftApi extends AbstractApiExecuter {
    {
        if(apiCryptoParameter == null)
        {
            apiCryptoParameter =  buildApiCryptoParameter(getPublicKey(), "<root><org code=\"jtqy\" /><visitor type=\"0\" code=\"jtqy\" key=\"jtqy\" /></root>");
            apiCryptoParameter =  buildApiCryptoParameter(getPublicKey(), "<root><org code=\"jkzl\" /><visitor type=\"0\" code=\"jkzl\" key=\"jkzl\" /></root>");
        }
        return  apiCryptoParameter;

+ 44 - 9
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/guahao/GuahaoService.java

@ -52,6 +52,16 @@ public class GuahaoService {
    private String ORDER_INFO = "GetReservationRecord";//预约信息
    private String REG_LIST = "GetRegList";//获取市民预约挂号信息
    /** *//**
     * RSA最大加密明文大小
     */
    private static final int MAX_ENCRYPT_BLOCK = 117;
    /** *//**
     * RSA最大解密密文大小
     */
    private static final int MAX_DECRYPT_BLOCK = 128;
    @Autowired
    private PatientDao patientDao;
@ -1286,7 +1296,7 @@ public class GuahaoService {
        
        return result;
    }
    
    /**
     * 获取免疫接种机构列表
     * @return
@ -1295,18 +1305,43 @@ public class GuahaoService {
        String result = "";
        Map<String,String> params = new HashMap<>();
        String condition = "<root><zone>350203</zone><zone>350206</zone><zone>350205</zone><zone>350211</zone><zone>350212</zone><zone>350213</zone></root>";
    
        ZysoftApi api = ZysoftApi.getSingleton();
    
        condition = api.getConditionRSA(condition);
        
        //加密后的东西
        System.out.println("Condition: " + condition);
    
        PublicKey publicKey=immPublicKeyget(api.getImmPublicKey());
        byte[] encryptedBytes = this.encrypt(condition.getBytes(),publicKey);
        condition = new String(encryptedBytes,"utf-8");
        System.out.println(condition);
        params.put("Condition", condition);
        return immPostSecond("GetOrgImmuneList","计免预约-获取免疫接种机构列表",params);
    }
    
    public static byte[] encrypt(byte[] data, PublicKey publicKey) throws Exception{
        Cipher cipher=Cipher.getInstance("RSA");//java默认"RSA"="RSA/ECB/PKCS1Padding"
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        int inputLen = data.length;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int offSet = 0;
        byte[] cache;
        int i = 0;
        // 对数据分段加密
        while (inputLen - offSet > 0) {
            if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
                cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK);
            } else {
                cache = cipher.doFinal(data, offSet, inputLen - offSet);
            }
            out.write(cache, 0, cache.length);
            i++;
            offSet = i * MAX_ENCRYPT_BLOCK;
        }
        byte[] encryptedData = out.toByteArray();
        out.close();
        return encryptedData;
    }
    public PublicKey immPublicKeyget(String filename) throws Exception {
        File f = new File(filename);
        FileInputStream fis = new FileInputStream(f);