third commit by ailanyin

This commit is contained in:
2022-03-29 11:04:01 +08:00
parent e340066b15
commit 8a1288dee0
63 changed files with 1632 additions and 323 deletions

View File

@ -0,0 +1,27 @@
package com.ailanyin.common.utils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* @author ailanyin
* @version 1.0
* @since 2022/3/2 0002 下午 15:31
*/
public class Base64Util {
/**
* BASE64解密
* @throws Exception
*/
public static byte[] decrypt(String key) throws Exception {
return (new BASE64Decoder()).decodeBuffer(key);
}
/**
* BASE64加密
*/
public static String encrypt(byte[] key) throws Exception {
return (new BASE64Encoder()).encodeBuffer(key);
}
}

View File

@ -331,13 +331,22 @@ public class DateUtil extends org.apache.commons.lang3.time.DateUtils {
return getDayEndTime(cal.getTime());
}
public static int test() {
Calendar instance = Calendar.getInstance();
instance.set(Calendar.DAY_OF_MONTH,4);
return instance.get(Calendar.WEEK_OF_MONTH);
/**
* 得到几天前的时间
* @param d
* @param day
* @return
*/
public static Date getDateBefore(Date d,int day){
Calendar now =Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE,now.get(Calendar.DATE)-day);
return now.getTime();
}
public static void main(String[] args) {
System.out.println(test());
Date date = getDateBefore(new Date(), 3);
System.out.println(date);
}
}

View File

@ -5,7 +5,10 @@ import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -109,4 +112,76 @@ public class IpUtil {
Matcher matcher = pattern.matcher(ipStr);
return matcher.matches();
}
/**
* 获取本地IP地址
*
* @throws SocketException
*/
public static String getLocalIp() throws UnknownHostException {
try {
if (isWindowsOS()) {
return InetAddress.getLocalHost().getHostAddress();
} else {
return getLinuxLocalIp();
}
} catch (SocketException e) {
e.printStackTrace();
}
return null;
}
/**
* 判断操作系统是否是Windows
*
* @return
*/
public static boolean isWindowsOS() {
boolean isWindowsOS = false;
String osName = System.getProperty("os.name");
if (osName.toLowerCase().indexOf("windows") > -1) {
isWindowsOS = true;
}
return isWindowsOS;
}
/**
* 获取本地Host名称
*/
public static String getLocalHostName() throws UnknownHostException {
return InetAddress.getLocalHost().getHostName();
}
/**
* 获取Linux下的IP地址
*
* @return IP地址
* @throws SocketException
*/
private static String getLinuxLocalIp() throws SocketException {
String ip = "";
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
String name = intf.getName();
if (!name.contains("docker") && !name.contains("lo")) {
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String ipaddress = inetAddress.getHostAddress().toString();
if (!ipaddress.contains("::") && !ipaddress.contains("0:0:") && !ipaddress.contains("fe80")) {
ip = ipaddress;
}
}
}
}
}
} catch (SocketException ex) {
System.out.println("获取ip地址异常");
ip = "127.0.0.1";
ex.printStackTrace();
}
return ip;
}
}