LAPTOP-5NTQJPUS\LT 1 tahun lalu
induk
melakukan
cb32cee4d4
1 mengubah file dengan 143 tambahan dan 29 penghapusan
  1. 143 29
      DataFusion/src/com/zskk/service/DataService.java

+ 143 - 29
DataFusion/src/com/zskk/service/DataService.java

@@ -1,10 +1,15 @@
 package com.zskk.service;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.math.BigInteger;
 import java.net.URLEncoder;
 import java.security.InvalidKeyException;
+import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
 import java.util.Date;
 import java.util.Formatter;
 import java.util.HashMap;
@@ -20,7 +25,9 @@ import com.alibaba.fastjson.JSONObject;
 import com.jfinal.kit.PropKit;
 
 import okhttp3.FormBody;
+import okhttp3.Headers;
 import okhttp3.MediaType;
+import okhttp3.MultipartBody;
 import okhttp3.OkHttpClient;
 import okhttp3.Request;
 import okhttp3.RequestBody;
@@ -94,11 +101,60 @@ public class DataService {
     	for (Map.Entry<String, String> entry : map.entrySet()) {
     		formbody.add(entry.getKey(), entry.getValue());
 		}
-		RequestBody requestBody = formbody.build();
+		RequestBody fBody = formbody.build();
+		
+		// 文件数据
+        File file = new File("C:\\Users\\LT\\Desktop\\2a9.jpg");
+        RequestBody fileBody = RequestBody.create(MediaType.parse("image/jpg"), file);
+ 
+		String jsstrString = "{\r\n"
+    			+ "  \"deviceSn\": \"GT1000-0102-1410-0018\",\r\n"
+    			+ "  \"deviceProviderCode\": \"GR\",\r\n"
+    			+ "  \"patientIdcard\": \"11010119900307475X\",\r\n"
+    			+ "  \"patientName\": \"某患者\",\r\n"
+    			+ "  \"reportDoctor\": \"诊断医生大名\",\r\n"
+    			+ "  \"reportTime\": 1603778400000,\r\n"
+    			+ "  \"detectTime\": 1603779436000,\r\n"
+    			+ "  \"detectPoint\": \"全身\",\r\n"
+    			+ "  \"detectDep\": \"外科\",\r\n"
+    			+ "  \"reportType\": \"BP\",\r\n"
+    			+ "  \"reportCode\": \"58f9c056f6c64cb8b0589791b37d53d8\",\r\n"
+    			+ "  \"reportResult\": \"正常\",\r\n"
+    			+ "  \"orgCode\": \"G00010001\",\r\n"
+    			+ "  \"orgName\": \"久安县\",\r\n"
+    			+ "  \"applyTime\":\"\",\r\n"
+    			+ "  \"reportRequestType\": 1,\r\n"
+    			+ "  \"reportOrgCode\": \"G00010001\",\r\n"
+    			+ "  \"reportOrgName\": \"久安县\",\r\n"
+    			+ "  \"reportCrc\": \"d868b9360e2ba7a1819f5ed2d8cf87b9\",\r\n"
+    			+ "  \"dataFileNum\": \"1\"\r\n"
+    			+ "}";
+		RequestBody requestBody2 = RequestBody.create(JSON_TYPE, jsstrString);
+
+//        // 构建 MultipartBody
+//        RequestBody requestBody = new MultipartBody.Builder()
+//                .setType(MultipartBody.FORM)
+//                .addFormDataPart("reportFile", "2a9.jpg", fileBody)
+//                .addPart("reportFile", "2a9.jpg", fileBody)
+//                .addPart(requestBody2)
+//                .build();
+		
+		// 构建MultipartBody请求体
+        MultipartBody multipartBody = new MultipartBody.Builder()
+                .setType(MultipartBody.FORM)
+                .addFormDataPart("accessKeyId", "pxmy93cman2zsmmq")
+                .addFormDataPart("signature", "MzhlZWY3MzQ4NWNmMzM1N2I0ZWJmNmIxY2ViOTg2NTU2MDA5Yjg0ZA==")
+                .addFormDataPart("interfaceCode", "I301008")
+                .addFormDataPart("seq", "7a70949970a64ec89886d02319ac75bd")
+                .addFormDataPart("timestamp", "1703242603337")
+
+                .addPart(Headers.of("Content-Disposition", "form-data; name=\"data\""), requestBody2)
+                .addPart(Headers.of("Content-Disposition", "form-data; name=\"reportFile\"; filename=\"" + file.getName() + "\""), fileBody)
+                .build();
 		
 		Request request = new Request.Builder()
 		        .url(url)
-		        .post(requestBody)
+		        .post(multipartBody)
 		        .build();
 
 		    try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
@@ -188,6 +244,60 @@ public class DataService {
             return null;
         }
     }
+    
+    public static String buildBase64(String str) {
+        if (str != null && str.length() != 0) {
+            byte[] byteArray = null;
+            try {
+                byteArray = str.getBytes("UTF-8");
+            } catch (UnsupportedEncodingException var3) {
+                var3.printStackTrace();
+            }
+
+            String data = Base64.getEncoder().encodeToString(byteArray);
+            data = removeNextLine(data);
+            return data;
+        } else {
+            return str;
+        }
+    }
+
+    public static String removeNextLine(String data) {
+        StringBuffer sb = new StringBuffer(data.length());
+
+        for (int i = 0; i < data.length(); ++i) {
+            char ch = data.charAt(i);
+            if (ch != '\r' && ch != '\n') {
+                sb.append(ch);
+            }
+        }
+
+        return sb.toString();
+    }
+
+    public static String getMD5Three(String path) {
+        BigInteger bi = null;
+        try {
+            byte[] buffer = new byte[8192];
+            int len = 0;
+            MessageDigest md = MessageDigest.getInstance("MD5");
+            File f = new File(path);
+            FileInputStream fis = new FileInputStream(f);
+            while ((len = fis.read(buffer)) != -1) {
+                md.update(buffer, 0, len);
+            }
+            fis.close();
+            byte[] b = md.digest();
+            bi = new BigInteger(1, b);
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return bi.toString(16);
+    }
+
+
  
     private static String toHexString(byte[] bytes) {
         Formatter formatter = new Formatter();
@@ -200,41 +310,45 @@ public class DataService {
 
     public static void main(String[] args) {
     	Map <String,String> map = new HashMap<String,String>();
-    	map.put("accessKeyId", "pvhtcj15wq7emolc");
+    	map.put("accessKeyId", "pxmy93cman2zsmmq");
     	map.put("interfaceCode", "I301008");
     	String seqString = UUID.randomUUID().toString().replace("-", "");
     	map.put("seq", seqString);
     	String timeString = Long.toString(new Date().getTime());
     	map.put("timestamp", timeString);
-    	String signatureString = "accessKeyId=pvhtcj15wq7emolc&interfaceCode=I301008&seq="+seqString+"&timestamp="+timeString;
+    	String signatureString = "accessKeyId=pxmy93cman2zsmmq&interfaceCode=I301008&seq="+seqString+"&timestamp="+timeString;
     	
 		String StringToSign= URLEncode("POST")+URLEncode("&") +URLEncode("/") + URLEncode("&") + URLEncode(signatureString);
 	
-		String signature = hmacsha1(StringToSign,"bctxik05ytdhkksrpvw96uo9n95jgi3q");
-    	map.put("signature", signature);
-    	map.put("data", "{\r\n"
-    			+ "  \"deviceSn\": \"GT1000-0102-1410-0018\",\r\n"
-    			+ "  \"deviceProviderCode\": \"GR\",\r\n"
-    			+ "  \"patientIdcard\": \"11010119900307475X\",\r\n"
-    			+ "  \"patientName\": \"某患者\",\r\n"
-    			+ "  \"reportDoctor\": \"诊断医生大名\",\r\n"
-    			+ "  \"reportTime\": 1603778400000,\r\n"
-    			+ "  \"detectTime\": 1603779436000,\r\n"
-    			+ "  \"detectPoint\": \"全身\",\r\n"
-    			+ "  \"detectDep\": \"外科\",\r\n"
-    			+ "  \"reportType\": \"BP\",\r\n"
-    			+ "  \"reportCode\": \"58f9c056f6c64cb8b0589791b37d53d8\",\r\n"
-    			+ "  \"reportResult\": \"正常\",\r\n"
-    			+ "  \"orgCode\": \"G00010001\",\r\n"
-    			+ "  \"orgName\": \"久安县\",\r\n"
-    			+ "  \"applyTime\":\"\",\r\n"
-    			+ "  \"reportRequestType\": 1,\r\n"
-    			+ "  \"reportOrgCode\": \"G00010001\",\r\n"
-    			+ "  \"reportOrgName\": \"久安县\",\r\n"
-    			+ "  \"reportCrc\": \"b10bfa870d76ecf39b0fe20fd89203be\",\r\n"
-    			+ "  \"dataFileNum\": \"0\"\r\n"
-    			+ "}");
-		postWithParameters("http://test.gareatech.com/ghc-das-server/api/imageDiagnosis/create", map);
+		
+		String hamcsha1 = hmacsha1(StringToSign,"u98q67foeh59zf19gifsjo5nqpweidnv");
+		String signature = buildBase64(hamcsha1);
+		map.put("signature", signature);
+//    	map.put("data", "{\r\n"
+//    			+ "  \"deviceSn\": \"GT1000-0102-1410-0018\",\r\n"
+//    			+ "  \"deviceProviderCode\": \"GR\",\r\n"
+//    			+ "  \"patientIdcard\": \"11010119900307475X\",\r\n"
+//    			+ "  \"patientName\": \"某患者\",\r\n"
+//    			+ "  \"reportDoctor\": \"诊断医生大名\",\r\n"
+//    			+ "  \"reportTime\": 1603778400000,\r\n"
+//    			+ "  \"detectTime\": 1603779436000,\r\n"
+//    			+ "  \"detectPoint\": \"全身\",\r\n"
+//    			+ "  \"detectDep\": \"外科\",\r\n"
+//    			+ "  \"reportType\": \"BP\",\r\n"
+//    			+ "  \"reportCode\": \"58f9c056f6c64cb8b0589791b37d53d8\",\r\n"
+//    			+ "  \"reportResult\": \"正常\",\r\n"
+//    			+ "  \"orgCode\": \"G00010001\",\r\n"
+//    			+ "  \"orgName\": \"久安县\",\r\n"
+//    			+ "  \"applyTime\":\"\",\r\n"
+//    			+ "  \"reportRequestType\": 1,\r\n"
+//    			+ "  \"reportOrgCode\": \"G00010001\",\r\n"
+//    			+ "  \"reportOrgName\": \"久安县\",\r\n"
+//    			+ "  \"reportCrc\": \"270ad2d79c28b50b209d59b54cfb3275033f2145\",\r\n"
+//    			+ "  \"dataFileNum\": \"1\"\r\n"
+//    			+ "}");
+    	System.out.print(getMD5Three("C:\\\\Users\\\\LT\\\\Desktop\\\\2a9.jpg"));
+    	getMD5Three("C:\\\\Users\\\\LT\\\\Desktop\\\\2a9.jpg");
+		postWithParameters("https://ylt.tsgryy.cn/ghc-das-server/api/imageDiagnosis/create", map);
 	}
 
 }