فهرست منبع

sup 批量同步

he2802 3 سال پیش
والد
کامیت
1e52533d99

+ 104 - 11
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/wisdom/SignatureUtil.java

@@ -60,8 +60,9 @@ public class SignatureUtil {
     public static String createSignature(Map<String, Object> paramMap, String key) throws SignatureException {
         String data = getParamString(paramMap);
         try {
-            SecretKeySpec signingKey = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA512");
-            Mac mac = Mac.getInstance("HmacSHA512");
+            String hmac = "HmacSHA512";
+            SecretKeySpec signingKey = new SecretKeySpec(key.getBytes("UTF-8"), hmac);
+            Mac mac = Mac.getInstance(hmac);
             mac.init(signingKey);
             byte[] rawHmac = mac.doFinal(data.getBytes("UTF-8"));
             return DatatypeConverter.printBase64Binary(rawHmac);
@@ -94,23 +95,85 @@ public class SignatureUtil {
             return null;
         }
         StringBuilder buffer = new StringBuilder();
+        buffer.append("me=my");
+//        List<String> keys = new ArrayList<String>(paramMap.keySet());
+//        Collections.sort(keys);
+//        for (String key : keys) {
+//            if (paramMap.get(key) != null){
+//                Object obj = paramMap.get(key);
+//                String value = obj.toString();
+//                if (StringUtils.isNotBlank(value)) {
+//                    try {
+//                        value = URLEncoder.encode(value, "UTF-8");
+//                    } catch (UnsupportedEncodingException e) {
+//                        value = null;
+//                    }
+//                }
+//                buffer.append("&").append(key).append("=").append(value);
+//            }
+//
+//        }
+
+        getParams(paramMap, buffer);
+
+        String result = buffer.toString();
+
+        System.out.println("签名串:" + result);
+
+        return result;
+    }
+
+    private static void getParams(Map<String, Object> paramMap, StringBuilder buffer) {
         List<String> keys = new ArrayList<String>(paramMap.keySet());
         Collections.sort(keys);
+
         for (String key : keys) {
-            if (paramMap.get(key) != null){
-                String value = paramMap.get(key).toString();
-                if (StringUtils.isNotBlank(value)) {
+            if (paramMap.get(key) != null && notfiler(key)){
+                Object obj = paramMap.get(key);
+
+                if (obj instanceof List<?>) {
                     try {
-                        value = URLEncoder.encode(value, "UTF-8");
-                    } catch (UnsupportedEncodingException e) {
-                        value = null;
+                        List<Map<String, Object>> list = (List<Map<String, Object>>) obj;
+
+                        for (Map<String, Object> map : list) {
+                            getParams(map , buffer);
+                        }
+                    }catch (Exception e){
+                        System.out.println("list 转map出错 :" + e.getMessage());
+                    }
+
+                }else if (obj instanceof Map<?,?>){
+                    Map<String, Object> map = (Map<String, Object>) obj;
+                    getParams(map , buffer);
+                }else if (obj instanceof String) {
+                    String value = obj.toString();
+                    if (StringUtils.isNotBlank(value)) {
+                        try {
+                            value = URLEncoder.encode(value, "UTF-8");
+                        } catch (UnsupportedEncodingException e) {
+                            value = null;
+                        }
                     }
+                    buffer.append("&").append(key).append("=").append(value);
                 }
-                buffer.append("&").append(key).append("=").append(value);
+
             }
 
         }
-        return buffer.substring(1);
+
+    }
+
+    private static boolean notfiler(String key){
+        boolean flag = true;
+        Map<String, Integer> map = new HashMap<>();
+
+        map.put("examineeZipFiles", 0);
+
+        if (map.containsKey(key)){
+            flag = false;
+        }
+
+        return flag;
     }
 
     private static Map<String, Object> getMap(List<Map<String, Object>> paramMapList, String key){
@@ -124,7 +187,7 @@ public class SignatureUtil {
         //参数
 //        Map<String, Object> paramMap = new HashMap<>();
 //
-//        String key = "ZZ-YXT-GZ-20220820-0001";
+        String key = "ZZ-YXT-GZ-20220820-0001";
 //
 //        paramMap.put("appid", key);
 //        paramMap.put("appname", "中正云学堂");
@@ -153,5 +216,35 @@ public class SignatureUtil {
 //        String res = s.substring(index1 + 1, index2);
 //
 //        System.out.println(res);
+
+        List<Map<String, Object>> map = new ArrayList<>();
+
+        Map<String, Object> param = new LinkedHashMap<>();
+
+        param.put("centerId", 245404160);
+        param.put("examCode", "DD6614110143");
+        param.put("zipFileName", "111考生证件照");
+
+        List<Map<String, Object>> map1 = new ArrayList<>();
+
+        Map<String, Object> param1 = new LinkedHashMap<>();
+
+        param1.put("examineeCode", "ZS123456");
+        param1.put("examineeName", "ddsfs");
+        param1.put("idCardImg1", "oss/images/avatar/53/1651809521815_1361907024");
+        param1.put("idCardImg2", "oss/images/avatar/53/1651807661764_861745654");
+        param1.put("idNumber", "fsdfdsfs");
+        param1.put("phone_num", "18565397890");
+        param1.put("reportStatus", "未签署");
+
+        map1.add(param1);
+
+        param.put("examinees",map1);
+
+        map.add(param);
+
+        String signature = createSignature(map, key);
+
+        System.out.println(signature);
     }
 }

+ 3 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/wisdom/service/impl/WisdomServiceImpl.java

@@ -291,6 +291,7 @@ public class WisdomServiceImpl  implements IWisdomService {
                 outStream.close();
                 byte[] dataByte = ToolsUtils.getBytesByFile(zipFile);
                 vo.setExamineeZipFiles(dataByte);
+                FileUtils.deleteFile(zipFile);
             } catch (IOException e) {
             }
             cList.add(vo);
@@ -312,8 +313,8 @@ public class WisdomServiceImpl  implements IWisdomService {
                 map.put("roomStatus",0);
                 map.put("examStatus",0);
                 map.put("examineeSum",0);
-    //            map.put("examineeZipFiles",vo.getExamineeZipFiles());
-                map.put("examineeZipFiles","2");
+                map.put("examineeZipFiles",vo.getExamineeZipFiles());
+    //            map.put("examineeZipFiles","2");
                 paramMapList.add(map);
             }
             String signature = SignatureUtil.createSignature(paramMapList, appid);