LAPTOP-5NTQJPUS\LT 1 年之前
父節點
當前提交
17450460c6
共有 1 個文件被更改,包括 112 次插入3 次删除
  1. 112 3
      DataFusion/src/com/zskk/service/DataService.java

+ 112 - 3
DataFusion/src/com/zskk/service/DataService.java

@@ -1,8 +1,18 @@
 package com.zskk.service;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Date;
+import java.util.Formatter;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.UUID;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -94,6 +104,7 @@ public class DataService {
 		    try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
 		      if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
 		      String content = response.body().string();
+		      System.out.println(content);
 		      return content;
 		    } catch (IOException e) {
 				// TODO Auto-generated catch block
@@ -121,11 +132,109 @@ public class DataService {
 		}
 	}
     
+    public static String URLEncode(String string) {
+		try {
+			return URLEncoder.encode(string, "utf-8");
+		} catch (UnsupportedEncodingException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			return null;
+		}
+	}
+    
+    /**
+     * HMAC_SHA1 签名
+     * @param content 待签名内容
+     * @param key 签名Key
+     * @return
+     */
+    public static String hmacsha1(String content, String key) {
+        return getHmacSign(content, "UTF-8", key, "HmacSHA1");
+    }
+ 
+    /**
+     * MAC签名
+     * @param content 待签名内容
+     * @param charset 编码
+     * @param key 签名Key
+     * @param hamaAlgorithm Mac算法
+     * @return
+     */
+    public static String getHmacSign(String content, String charset, String key, String hamaAlgorithm) {
+        String result = null;
+        try {
+            //根据给定的字节数组构造一个密钥,第二参数指定一个密钥算法的名称
+            SecretKeySpec signinKey = new SecretKeySpec(key.getBytes(charset), hamaAlgorithm);
+            //生成一个指定 Mac 算法 的 Mac 对象
+            Mac mac = Mac.getInstance(hamaAlgorithm);
+            //用给定密钥初始化 Mac 对象
+            mac.init(signinKey);
+            //完成 Mac 操作
+            byte[] rawHmac = mac.doFinal(content.getBytes(charset));
+            result = toHexString(rawHmac);
+ 
+        } catch (NoSuchAlgorithmException e) {
+            System.err.println(e.getMessage());
+        } catch (InvalidKeyException e) {
+            System.err.println(e.getMessage());
+        } catch (IllegalStateException e) {
+            System.err.println(e.getMessage());
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        if (null != result) {
+            return result;
+        } else {
+            return null;
+        }
+    }
+ 
+    private static String toHexString(byte[] bytes) {
+        Formatter formatter = new Formatter();
+        for (byte b : bytes) {
+            formatter.format("%02x", b);
+        }
+        return formatter.toString();
+    }
+
+
     public static void main(String[] args) {
     	Map <String,String> map = new HashMap<String,String>();
-    	map.put("institution_id", "47600001");
-    	map.put("num", "10");
-		postWithParameters(GET_EXAM_URL, map);
+    	map.put("accessKeyId", "pvhtcj15wq7emolc");
+    	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 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);
 	}
 
 }