|
|
|
@ -1,17 +1,12 @@
|
|
|
|
|
package com.dsideal.Sso.Util;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileReader;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.dsideal.Sso.Model.Login;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
|
|
|
|
|
public class CommonUtil {
|
|
|
|
|
/**
|
|
|
|
@ -29,71 +24,6 @@ public class CommonUtil {
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Map<String, Object> returnMessageJson(boolean result, JSONObject jo) {
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("success", result);
|
|
|
|
|
map.put("result", jo);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Map<String, Object> returnMessageJson(boolean result, List<Record> list) {
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("success", result);
|
|
|
|
|
map.put("result", list);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 将字符串参数转为Map
|
|
|
|
|
*
|
|
|
|
|
* @param strUrlParam
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static Map<String, String> urlSplit(String strUrlParam) {
|
|
|
|
|
Map<String, String> mapRequest = new HashMap<>();
|
|
|
|
|
String[] arrSplit = null;
|
|
|
|
|
arrSplit = strUrlParam.split("[&]");
|
|
|
|
|
for (String strSplit : arrSplit) {
|
|
|
|
|
String[] arrSplitEqual = null;
|
|
|
|
|
arrSplitEqual = strSplit.split("[=]");
|
|
|
|
|
if (arrSplitEqual.length > 1) {
|
|
|
|
|
mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);
|
|
|
|
|
} else {
|
|
|
|
|
if (arrSplitEqual[0] != "") {
|
|
|
|
|
mapRequest.put(arrSplitEqual[0], "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return mapRequest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将一个Map<String, Object>转为Map<String, String>
|
|
|
|
|
*
|
|
|
|
|
* @param mapValueStr
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static Map<String, Object> MapValueStringToObject(Map<String, String> mapValueStr) {
|
|
|
|
|
Map<String, Object> mapValueObj = new HashMap<>();
|
|
|
|
|
for (Map.Entry<String, String> entry : mapValueStr.entrySet()) {
|
|
|
|
|
mapValueObj.put(entry.getKey(), entry.getValue());
|
|
|
|
|
}
|
|
|
|
|
return mapValueObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将一个Map<String, String>转为Map<String, Object>
|
|
|
|
|
*
|
|
|
|
|
* @param mapValueObj
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static Map<String, String> MapValueObjectToString(Map<String, Object> mapValueObj) {
|
|
|
|
|
Map<String, String> mapValueStr = new HashMap<>();
|
|
|
|
|
for (Map.Entry<String, Object> entry : mapValueObj.entrySet()) {
|
|
|
|
|
mapValueStr.put(entry.getKey(), entry.getValue().toString());
|
|
|
|
|
}
|
|
|
|
|
return mapValueStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取6位随机数
|
|
|
|
|
*
|
|
|
|
@ -102,11 +32,10 @@ public class CommonUtil {
|
|
|
|
|
public static String getRandom() {
|
|
|
|
|
String sources = "0123456789";
|
|
|
|
|
Random rand = new Random();
|
|
|
|
|
StringBuffer flag = new StringBuffer();
|
|
|
|
|
StringBuilder flag = new StringBuilder();
|
|
|
|
|
for (int j = 0; j < 6; j++) {
|
|
|
|
|
flag.append(sources.charAt(rand.nextInt(9)) + "");
|
|
|
|
|
flag.append(sources.charAt(rand.nextInt(9)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flag.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -132,29 +61,6 @@ public class CommonUtil {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:将文本文件的内容读到字符串里
|
|
|
|
|
* 作者:黄海
|
|
|
|
|
* 时间:2018-11-22
|
|
|
|
|
*
|
|
|
|
|
* @param file
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String txt2String(File file) {
|
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
|
|
try {
|
|
|
|
|
BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件
|
|
|
|
|
String s = null;
|
|
|
|
|
while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行
|
|
|
|
|
result.append(System.lineSeparator() + s);
|
|
|
|
|
}
|
|
|
|
|
br.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return result.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证是否为邮箱
|
|
|
|
|
*
|
|
|
|
@ -162,7 +68,6 @@ public class CommonUtil {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static boolean getIsEmailLegal(String eMail) {
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
try {
|
|
|
|
|
String regExp = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
|
|
|
|
|
Pattern p = Pattern.compile(regExp);
|
|
|
|
@ -182,7 +87,6 @@ public class CommonUtil {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static boolean getPwdLegal(String pwd) {
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
try {
|
|
|
|
|
String regExp = "[a-z0-9A-Z]+";
|
|
|
|
|
Pattern p = Pattern.compile(regExp);
|
|
|
|
@ -258,49 +162,32 @@ public class CommonUtil {
|
|
|
|
|
return nowTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取6位随机数
|
|
|
|
|
* 作者:吴缤
|
|
|
|
|
* 日期:2018-11-27
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String getSixRandom() {
|
|
|
|
|
String sources = "0123456789";
|
|
|
|
|
Random rand = new Random();
|
|
|
|
|
StringBuffer flag = new StringBuffer();
|
|
|
|
|
for (int j = 0; j < 6; j++) {
|
|
|
|
|
flag.append(sources.charAt(rand.nextInt(9)) + "");
|
|
|
|
|
}
|
|
|
|
|
return flag.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String handleRedirectUrlParas(String redirect_url) {
|
|
|
|
|
String redirectUrl = redirect_url;
|
|
|
|
|
String[] paras = redirect_url.split("\\?");
|
|
|
|
|
if (paras.length > 1) {
|
|
|
|
|
String uri = paras[0];
|
|
|
|
|
StringBuilder uri = new StringBuilder(paras[0]);
|
|
|
|
|
Map<String, String> parasMap = URLRequest(redirect_url);
|
|
|
|
|
for (Map.Entry<String, String> entry : parasMap.entrySet()) {
|
|
|
|
|
if (!entry.getKey().equals(PropKit.get("sso.sessionid"))) {
|
|
|
|
|
if (uri.indexOf("?") == -1) {
|
|
|
|
|
uri += "?"+entry.getKey()+"="+entry.getValue();
|
|
|
|
|
if (!uri.toString().contains("?")) {
|
|
|
|
|
uri.append("?").append(entry.getKey()).append("=").append(entry.getValue());
|
|
|
|
|
}else{
|
|
|
|
|
uri += "&"+entry.getKey()+"="+entry.getValue();
|
|
|
|
|
uri.append("&").append(entry.getKey()).append("=").append(entry.getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
redirectUrl = uri;
|
|
|
|
|
redirectUrl = uri.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return redirectUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Map<String, String> URLRequest(String URL) {
|
|
|
|
|
Map<String, String> mapRequest = new HashMap<String, String>();
|
|
|
|
|
Map<String, String> mapRequest = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
String[] arrSplit = null;
|
|
|
|
|
String[] arrSplit;
|
|
|
|
|
|
|
|
|
|
String strUrlParam = TruncateUrlPage(URL);
|
|
|
|
|
if (strUrlParam == null) {
|
|
|
|
@ -329,7 +216,7 @@ public class CommonUtil {
|
|
|
|
|
|
|
|
|
|
private static String TruncateUrlPage(String strURL) {
|
|
|
|
|
String strAllParam = null;
|
|
|
|
|
String[] arrSplit = null;
|
|
|
|
|
String[] arrSplit;
|
|
|
|
|
|
|
|
|
|
strURL = strURL.trim();
|
|
|
|
|
|
|
|
|
@ -341,9 +228,6 @@ public class CommonUtil {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return strAllParam;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|