From 9b9c96cb7976e58e558f5f7341de1fb835c934ce Mon Sep 17 00:00:00 2001 From: quyixiao <2621048238@qq.com> Date: Wed, 8 Oct 2025 17:24:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/heyu/api/data/utils/AesUtil.java | 105 ++++++++++++++++++ .../java/com/heyu/api/aop/ZhenZhenLogAop.java | 86 ++++++++++++-- 2 files changed, 184 insertions(+), 7 deletions(-) create mode 100644 api-mapper/src/main/java/com/heyu/api/data/utils/AesUtil.java diff --git a/api-mapper/src/main/java/com/heyu/api/data/utils/AesUtil.java b/api-mapper/src/main/java/com/heyu/api/data/utils/AesUtil.java new file mode 100644 index 0000000..2140799 --- /dev/null +++ b/api-mapper/src/main/java/com/heyu/api/data/utils/AesUtil.java @@ -0,0 +1,105 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package com.heyu.api.data.utils; + +import org.apache.commons.codec.binary.Base64; + +import javax.crypto.*; +import javax.crypto.spec.SecretKeySpec; +import java.io.UnsupportedEncodingException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +public class AesUtil { + + + private static byte[] doEncrypt(String content, String password) { + try { + KeyGenerator kgen = KeyGenerator.getInstance("AES"); + SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); + secureRandom.setSeed(password.getBytes()); + kgen.init(128, secureRandom); + SecretKey secretKey = kgen.generateKey(); + byte[] enCodeFormat = secretKey.getEncoded(); + SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES"); + Cipher cipher = Cipher.getInstance("AES"); + byte[] byteContent = content.getBytes("UTF-8"); + cipher.init(1, key); + byte[] result = cipher.doFinal(byteContent); + return result; + } catch (NoSuchAlgorithmException var10) { + System.out.println("encrypt NoSuchAlgorithmException"); + } catch (NoSuchPaddingException var11) { + System.out.println("encrypt NoSuchPaddingException"); + } catch (InvalidKeyException var12) { + System.out.println("encrypt InvalidKeyException"); + } catch (UnsupportedEncodingException var13) { + System.out.println("encrypt UnsupportedEncodingException"); + } catch (IllegalBlockSizeException var14) { + System.out.println("encrypt IllegalBlockSizeException"); + } catch (BadPaddingException var15) { + System.out.println("encrypt BadPaddingException"); + } + + return null; + } + + private static String decrypt(String contentStr, String password) { + try { + byte[] content = Base64.decodeBase64(contentStr.getBytes()); + KeyGenerator kgen = KeyGenerator.getInstance("AES"); + SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); + secureRandom.setSeed(password.getBytes()); + kgen.init(128, secureRandom); + SecretKey secretKey = kgen.generateKey(); + byte[] enCodeFormat = secretKey.getEncoded(); + SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES"); + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(2, key); + byte[] result = cipher.doFinal(content); + return new String(result); + } catch (NoSuchAlgorithmException var10) { + System.out.println("decrypt NoSuchAlgorithmException"); + } catch (NoSuchPaddingException var11) { + System.out.println("decrypt NoSuchPaddingException"); + } catch (InvalidKeyException var12) { + System.out.println("decrypt InvalidKeyException"); + } catch (IllegalBlockSizeException var13) { + System.out.println("decrypt IllegalBlockSizeException"); + } catch (BadPaddingException var14) { + System.out.println("decrypt BadPaddingException"); + } + + return contentStr; + } + + private static String encrypt(String value, String encrypt_password) { + return new String(Base64.encodeBase64(doEncrypt(value, encrypt_password))); + } + + public static String decrypt(String value) { + return decrypt(value, getPassword()); + } + + + private static String getPassword() { + String password = "123456"; + return password; + } + + public static String encrypt(String value) { + return new String(Base64.encodeBase64(doEncrypt(value, getPassword()))); + } + + public static void main(String[] args) { + String encode = encrypt("xxxxxx493983333333333339438943", getPassword()); + + + System.out.println(encode); + System.out.println(decrypt(encode, getPassword())); + } +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/aop/ZhenZhenLogAop.java b/api-web/api-interface/src/main/java/com/heyu/api/aop/ZhenZhenLogAop.java index 44818e1..483350e 100644 --- a/api-web/api-interface/src/main/java/com/heyu/api/aop/ZhenZhenLogAop.java +++ b/api-web/api-interface/src/main/java/com/heyu/api/aop/ZhenZhenLogAop.java @@ -4,10 +4,9 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.heyu.api.common.LogAspect; import com.heyu.api.data.dto.BuyerDTO; +import com.heyu.api.data.entity.vv.VvReverseOrderEntity; import com.heyu.api.data.service.bussiness.RedisSettingService; -import com.heyu.api.data.utils.OrderUtil; -import com.heyu.api.data.utils.RedisUtils; -import com.heyu.api.data.utils.StringUtils; +import com.heyu.api.data.utils.*; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.Signature; @@ -26,7 +25,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 日志aop @@ -105,6 +106,7 @@ public class ZhenZhenLogAop { for (Object argArr : argArrs) { argArr.getClass().getDeclaredMethods(); List methods = new ArrayList<>(); + getClassDeclaredMethods(argArr.getClass(),methods); for (Method m : methods) { @@ -129,6 +131,13 @@ public class ZhenZhenLogAop { } } result = point.proceed(); + + if(result instanceof R){ + R r = (R) result; + Object object = r.getData(); + convertImage(object); + } + } catch (Exception e) { log.error("LogAop set error " + sb.toString(), e); } finally { @@ -140,20 +149,83 @@ public class ZhenZhenLogAop { } + public static void convertImage(Object object){ + if(object == null){ + return ; + } + if(object instanceof List){ + List list = (List) object; + for (Object o : list) { + convertImage(o); + } + }else if (object instanceof Map) { + Map map = (Map) object; + for (Object key : map.keySet()) { + Object value = map.get(key); + convertImage(value); + } + }else if (object.getClass().isArray()) { + Object[] array = (Object[]) object; + for (Object o : array) { + convertImage(o); + } + } else if (SanUtils.isBasicDataTypes(object.getClass())) { + return; + } else { + List methods = new ArrayList<>(); + getClassDeclaredMethods(object.getClass(), methods); + Map methodMap = new HashMap<>(); + for (Method method : methods) { + methodMap.put(method.getName(), method); + } + for (Method method : methods) { + try { + method.setAccessible(true); + if (method.getName().startsWith("get")) { + Object image = method.invoke(object); + // 如果是基本数据类型 + if (SanUtils.isBasicDataTypes(method.getReturnType())) { + if (method.getReturnType() == String.class) { + String str = (String)image; + if (str!=null + && str.startsWith("http://heyuimage.ihzhy.com")) { + String setMethodName = "set" + method.getName().substring(3); + Method setMethod = methodMap.get(setMethodName); + String newImage = image + "?key=xxxxxxx"; + setMethod.invoke(object, new Object[]{newImage}); + } + } + } else { + convertImage(image); + } + } + } catch (Exception e) { + log.error("LogAop convertImage error " + method.getName() + ",Object:{}" + JSON.toJSONString(object), e); + } + } + } + } + + + public static void main(String[] args) { + + VvReverseOrderEntity vvReverseOrderEntity = new VvReverseOrderEntity(); + vvReverseOrderEntity.setStatus("http://heyuimage.ihzhy.com/48a458c49f5e0b9c74eeb163b577a49d.mp4"); + + convertImage(vvReverseOrderEntity); + System.out.println(JSON.toJSONString(vvReverseOrderEntity)); + } public static void getClassDeclaredMethods( Class entityType, List methods){ - if(entityType == Object.class){ return ; } - Method method [] = entityType.getDeclaredMethods(); - for (Method method1 : method) { methods.add(method1); } - + getClassDeclaredMethods(entityType.getSuperclass(), methods); }