Explorar el Código

解决包名错误导致报错、删除重复类,将base64改为apache-codec实现,兼容高版本jdk

aa51513 hace 4 años
padre
commit
c95ef73563

+ 5 - 3
java110-core/src/main/java/com/java110/core/factory/ValidateCodeFactory.java

@@ -1,6 +1,5 @@
 package com.java110.core.factory;
 
-import sun.misc.BASE64Encoder;
 
 import java.awt.Color;
 import java.awt.Font;
@@ -14,6 +13,8 @@ import java.util.Arrays;
 import java.util.Random;
 
 import javax.imageio.ImageIO;
+
+import org.apache.commons.codec.binary.Base64;
 /**
  * <p><b>ValidateCodeFactory Description:</b> (验证码生成)</p>
  * <b>DATE:</b> 2016年6月2日 下午3:53:34
@@ -23,7 +24,8 @@ public class ValidateCodeFactory{
     //使用到Algerian字体,系统里没有的话需要安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字符
     public static final String VERIFY_CODES = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
     private static Random random = new Random();
-    static BASE64Encoder encoder = new sun.misc.BASE64Encoder();
+    
+    private static Base64 base64 = new Base64();
 
 
     /**
@@ -180,7 +182,7 @@ public class ValidateCodeFactory{
         ImageIO.write(image, "jpg", baos);
         byte[] bytes = baos.toByteArray();
 
-        return "data:image/jpeg;base64,"+encoder.encodeBuffer(bytes).trim();
+        return "data:image/jpeg;base64,"+base64.encodeToString(bytes).trim();
     }
 
     private static Color getRandColor(int fc, int bc) {

+ 6 - 6
java110-core/src/main/java/com/java110/core/factory/WechatFactory.java

@@ -6,11 +6,11 @@ import com.java110.utils.cache.JWTCache;
 import com.java110.utils.constant.WechatConstant;
 import com.java110.utils.factory.ApplicationContextFactory;
 import com.java110.utils.util.StringUtil;
+
+import org.apache.commons.codec.binary.Base64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.client.RestTemplate;
-import sun.misc.BASE64Decoder;
-
 import javax.crypto.Cipher;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
@@ -117,13 +117,13 @@ public class WechatFactory {
 
     public static String decryptS5(String sSrc, String encodingFormat, String sKey, String ivParameter) {
         try {
-            BASE64Decoder decoder = new BASE64Decoder();
-            byte[] raw = decoder.decodeBuffer(sKey);
+        	Base64 base64 = new Base64();
+            byte[] raw = base64.decode(sKey);
             SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
-            IvParameterSpec iv = new IvParameterSpec(decoder.decodeBuffer(ivParameter));
+            IvParameterSpec iv = new IvParameterSpec(base64.decode(ivParameter));
             Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
             cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
-            byte[] myendicod = decoder.decodeBuffer(sSrc);
+            byte[] myendicod = base64.decode(sSrc);
             byte[] original = cipher.doFinal(myendicod);
             String originalString = new String(original, encodingFormat);
             return originalString;

+ 0 - 22
java110-core/src/test/java/com/java110/core/proxy/ITestService.java

@@ -1,22 +0,0 @@
-package com.java110.core.proxy;
-
-/**
- * @ClassName ITestService
- * @Description TODO
- * @Author wuxw
- * @Date 2019/5/15 15:53
- * @Version 1.0
- * add by wuxw 2019/5/15
- **/
-public interface ITestService {
-
-    /**
-     * 获取
-     *
-     * @param param 参数
-     * @return 返回
-     */
-    String get(String param);
-
-    void set(String param);
-}

+ 0 - 34
java110-core/src/test/java/com/java110/core/proxy/ServiceInvocationHandler.java

@@ -1,34 +0,0 @@
-package com.java110.core.proxy;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-
-/**
- * @ClassName ServiceInvocationHandler
- * @Description TODO
- * @Author wuxw
- * @Date 2019/5/15 15:54
- * @Version 1.0
- * add by wuxw 2019/5/15
- **/
-public class ServiceInvocationHandler implements InvocationHandler {
-    private Class<?> interfaceType;
-
-    public ServiceInvocationHandler(Class<?> intefaceType) {
-        this.interfaceType = interfaceType;
-    }
-
-    @Override
-    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-        if (Object.class.equals(method.getDeclaringClass())) {
-            System.out.println("if调用前");
-            return method.invoke(this, args);
-        }
-        System.out.println("调用前,参数:{}" + args);
-        Object result = Arrays.asList(args);
-        System.out.println("调用后,结果:{}" + result);
-        return result;
-    }
-
-}

+ 0 - 39
java110-core/src/test/java/com/java110/core/proxy/ServiceProxyFactory.java

@@ -1,39 +0,0 @@
-package com.java110.core.proxy;
-
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.stereotype.Component;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-
-
-/**
- * @ClassName ServiceProxyFactory
- * @Description TODO
- * @Author wuxw
- * @Date 2019/5/15 15:56
- * @Version 1.0
- * add by wuxw 2019/5/15
- **/
-@Component
-public class ServiceProxyFactory implements FactoryBean<ITestService> {
-
-    @Override
-    public ITestService getObject() throws Exception {
-        Class<?> interfaceType = ITestService.class;
-        InvocationHandler handler = new ServiceInvocationHandler(interfaceType);
-        return (ITestService) Proxy.newProxyInstance(interfaceType.getClassLoader(),
-                new Class[]{interfaceType}, handler);
-    }
-
-    @Override
-    public Class<?> getObjectType() {
-        return ITestService.class;
-    }
-
-    @Override
-    public boolean isSingleton() {
-        return true;
-    }
-
-}

+ 1 - 1
java110-utils/src/main/java/com/java110/utils/App.java

@@ -1,4 +1,4 @@
-package com.java110.entity;
+package com.java110.utils;
 
 /**
  * Hello world!

+ 7 - 6
java110-utils/src/main/java/com/java110/utils/util/Base64Convert.java

@@ -1,12 +1,13 @@
 package com.java110.utils.util;
 
-import sun.misc.BASE64Decoder;
-import sun.misc.BASE64Encoder;
-
 import java.io.*;
 
+import org.apache.commons.codec.binary.Base64;
+
 public class Base64Convert {
 
+	private static final Base64 base64 = new Base64();
+	
     private void Base64Convert() {
 
     }
@@ -25,7 +26,7 @@ public class Base64Convert {
             byte[] bytes = new byte[in.available()];
             // 将文件中的内容读入到数组中
             in.read(bytes);
-            strBase64 = new BASE64Encoder().encode(bytes);      //将字节流数组转换为字符串
+            strBase64 = base64.encodeToString(bytes);      //将字节流数组转换为字符串
         } finally {
             if (in != null) {
                 in.close();
@@ -45,7 +46,7 @@ public class Base64Convert {
     public static String byteToBase64(byte[] bytes)  {
         String strBase64 = null;
             // in.available()返回文件的字节长度
-            strBase64 = new BASE64Encoder().encode(bytes);      //将字节流数组转换为字符串
+            strBase64 = base64.encodeToString(bytes);      //将字节流数组转换为字符串
         return strBase64;
     }
 
@@ -61,7 +62,7 @@ public class Base64Convert {
      */
     public static byte[] base64ToByte(String strBase64) throws IOException {
         // 解码,然后将字节转换为文件
-        byte[] bytes = new BASE64Decoder().decodeBuffer(strBase64);   //将字符串转换为byte数组
+        byte[] bytes = base64.decode(strBase64);   //将字符串转换为byte数组
         return bytes;
     }
 }

+ 0 - 3
pom.xml

@@ -498,7 +498,6 @@
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>3.8.1</version>
             <scope>test</scope>
         </dependency>
         <dependency>
@@ -529,7 +528,6 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-javadoc-plugin</artifactId>
-                <version>2.10.4</version>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -540,7 +538,6 @@
             </plugin>
             <plugin>
                 <artifactId>maven-source-plugin</artifactId>
-                <version>3.0.1</version>
                 <configuration>
                     <attach>true</attach>
                 </configuration>