刘韬 2 vuotta sitten
vanhempi
commit
436a59cf26

+ 5 - 22
DataFusion/src/com/zskk/control/ViewController.java

@@ -57,15 +57,8 @@ public class ViewController extends Controller {
 		try {
 	        String IV = "0000000000000000";
 			DataService dService = ServiceFactory.getService(DataService.class);
-			String aesEncryptStr = this.getPara("data");
-	        String aesDecodeStr = AESUtils.aesDecodeStr("Q1R3PhZX3/h9Mue5L5kmupSKW24KiGag5yst5k0a0YtVSC5mnenePI5LLZ4GigdpH2RUv/NHX1Kjhnzt1eQpYBgGS5t9Ki63Vc5E/R3T6TnrXfPyeIv1K+HgaCai3sc0", "2c1db8e7eee65eeeebacb0afbec37096" ,IV);
-	        String aesEncryptStr2 = AESUtils.aesEncryptStr(aesDecodeStr, "27c78f49ba635c90a4a44af98a76e313",IV);
-	        String aesEncryptStr3 = dService.getExamList(aesEncryptStr2);
-			JSONObject jsonObject = JSON.parseObject(aesEncryptStr3);
-			
-	        String aesDecodeSt4 = AESUtils.aesDecodeStr(jsonObject.getString("data"), "27c78f49ba635c90a4a44af98a76e313" ,IV);
-	        String aesDecodeSt5 = AESUtils.aesEncryptStr(aesDecodeSt4, PropKit.get("nw_key"),IV);
-			this.renderText(aesDecodeSt5);
+	        String aesEncryptStr3 = dService.getExamList(this.getPara("data"));
+			this.renderText(aesEncryptStr3);
 		} catch (Exception e) {
 			// TODO: handle exception
 			this.renderText(e.toString());
@@ -89,19 +82,9 @@ public class ViewController extends Controller {
 	}
 	
 	public void testConn3() {
-		File file = new File("./123-测试记录.txt");
-		try {
-		    // 使用FileWriter不需要考虑原文件不存在的情况
-		    // 当该文件不存在时,new FileWriter(file)会自动创建一个真实存在的空文件
-		    FileWriter fileWriter = new FileWriter(file);
-		    // 往文件重写内容
-		    fileWriter.write("");// 清空
-		    fileWriter.flush();
-		    fileWriter.close();
-		    renderNull();
-		} catch (IOException e) {
-		    e.printStackTrace();
-		}
+		DataService dService = ServiceFactory.getService(DataService.class);
+		dService.updateCloudKey();
+		renderNull();
 	}
 	
 	public static DruidPlugin createConnectedDruidPlugin() {

+ 95 - 27
DataFusion/src/com/zskk/service/DataService.java

@@ -12,6 +12,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.jfinal.kit.PropKit;
+import com.zskk.tools.AESUtils;
 
 import okhttp3.FormBody;
 import okhttp3.MediaType;
@@ -37,21 +38,96 @@ public class DataService {
     
 	private static final MediaType JSON_TYPE = MediaType.parse("application/json; charset=utf-8");
 
+	 /**
+     * 获取云端密钥
+     */
+    public String getCloudKey() {
+		String key = "";
+		try {
+			key = fileToString("./key.txt");
+			JSONObject jsonObject = JSON.parseObject(key);
+			key = jsonObject.getJSONObject("data").getString("key");
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			return key;
+		}
+		return key;
+		
+	}
+    
+    /**
+     * 更新云端密钥
+     */
+    public void updateCloudKey() {
+    	Map <String,String> map = new HashMap<String,String>();
+    	map.put("institution_id", PropKit.get("institution_id"));
+		String content = postWithParameters(GET_KEY_URL, map);
+		File file = new File("./key.txt");
+		try {
+			// 使用FileWriter不需要考虑原文件不存在的情况
+			// 当该文件不存在时,new FileWriter(file)会自动创建一个真实存在的空文件
+			FileWriter fileWriter = new FileWriter(file);
+			// 往文件重写内容
+			fileWriter.write(content);// 清空
+			fileWriter.flush();
+			fileWriter.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
     
     /**
      * 获取未出报告的检查列表
      * @param instutionId
      * @param number
      */
-    public String getExamList(String str) {
+    public String getExamList(String jmstr) {
+    	String cloudjmStr = localjm2cloudjm(jmstr);
     	Map <String,String> map = new HashMap<String,String>();
     	map.put("institution_id", "06300009");
-    	map.put("params", str);
+    	map.put("params", cloudjmStr);
 		String content = postWithParameters(GET_EXAM_URL, map);
-		return content;
+		String examlistStr = cloudjm2localjm(content);
+		return examlistStr;
+		
+	}
+    
+    public String localjm2cloudjm(String jmstr) {
+        String IV = "0000000000000000";
+    	//解密内网数据
+		String aesDecodeStr = "";
+		try {
+			aesDecodeStr = AESUtils.aesDecodeStr(jmstr,PropKit.get("nw_key"), IV);
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		//加密为云数据
+		String aesEncryptStr = AESUtils.aesEncryptStr(aesDecodeStr, getCloudKey(), IV);
+		return aesEncryptStr;
 		
 	}
     
+    public String cloudjm2localjm(String content) {
+        String IV = "0000000000000000";
+        //解密云端数据
+        JSONObject jsonObject = JSON.parseObject(content);
+        String aesDecodeSt = "";
+		try {
+			aesDecodeSt = AESUtils.aesDecodeStr(jsonObject.getString("data"), getCloudKey() ,IV);
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		//加密为内网密文
+        String aesEncryptStr = AESUtils.aesEncryptStr(aesDecodeSt, PropKit.get("nw_key"),IV);
+		return aesEncryptStr;
+
+	}
+    
+    
+    
     /**
      * 写入报告
      * @param instutionId
@@ -59,7 +135,6 @@ public class DataService {
      */
     public void saveReport(Map <String,String> map) {
 		postWithParameters(SAVE_REPORT_URL, map);
-		
 	}
     
     /**
@@ -125,7 +200,7 @@ public class DataService {
 		}
 	}
     
-    public static String fileToString(String path) throws IOException {
+    public String fileToString(String path) throws IOException {
         return Files.readString(Path.of(path));
     }
     
@@ -140,30 +215,23 @@ public class DataService {
 //		postWithParameters(SAVE_REPORT_URL, map);
 		String content = postWithParameters(GET_KEY_URL, map);
     	
+		File file = new File("./key.txt");
+		try {
+			// 使用FileWriter不需要考虑原文件不存在的情况
+			// 当该文件不存在时,new FileWriter(file)会自动创建一个真实存在的空文件
+			FileWriter fileWriter = new FileWriter(file);
+			// 往文件重写内容
+			fileWriter.write(content);// 清空
+			fileWriter.flush();
+			fileWriter.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+//    	String content = getCloudKey();
+//		System.out.println(content);
 
-    		File file = new File("./123-测试记录.txt");
-    		try {
-    		    // 使用FileWriter不需要考虑原文件不存在的情况
-    		    // 当该文件不存在时,new FileWriter(file)会自动创建一个真实存在的空文件
-    		    FileWriter fileWriter = new FileWriter(file);
-    		    // 往文件重写内容
-    		    fileWriter.write(content);// 清空
-    		    fileWriter.flush();
-    		    fileWriter.close();
-    		} catch (IOException e) {
-    		    e.printStackTrace();
-    		}
-    	    try {
-    	    	String content2= fileToString("./123-测试记录.txt");
-				
-				System.out.println("44"+content2);
-
-			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
 
-    	}
+	}