Commit dbc87957 by 罗胜

2022-07-25 罗胜

1.登录加密
parent 8426466b
......@@ -110,6 +110,7 @@ public class BasicVerifyFilter implements Filter {
// 基本参数不为NULL
if (content != null) {
message = "无效请求";
System.out.println(content);
BaseUserBean baseUserBean = JSON.parseObject(content, BaseUserBean.class);
// BaseUserBean baseUserBean = JSON.parseObject("{\"userSign\":\"1000849147\"}", BaseUserBean.class); //测试使用
String userSign = baseUserBean.getUserSign();
......
......@@ -212,4 +212,6 @@ public class OilAnalysisService extends BaseService<OilAnalysisDao> {
}
return oilAnalysisDao.getOilReasons(startTime,endTime);
}
}
......@@ -430,6 +430,7 @@ public class HuaweiUCSyncService {
return resultStr.toString();
}
/**
* 同步席位信息
*
......
......@@ -25,6 +25,8 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
......@@ -139,6 +141,14 @@ public class ShortMessageService extends BaseService<ShortMessageDao> {
return false;
}
public static void main(String[] args) throws UnsupportedEncodingException {
String url= "http://usertest.jdair.net/ussinterface/uss/json/mobile/messSend.json?ai.cp=10.68.26.52&ai.cc=5&mobile=15995791570&msg=95375";
HCFetcher fetcher = HCFetcher.getInstance();
FetchEntity entity = fetcher.post(url, null);
System.out.println(111);
}
/**
* 添加发送短信记录
*
......
......@@ -20,7 +20,9 @@ import com.ejweb.modules.role.service.UserRolesService;
import com.ejweb.modules.user.bean.*;
import com.ejweb.modules.user.entity.*;
import com.ejweb.modules.user.service.UserService;
import com.ejweb.modules.user.utils.DtoaUtils;
import com.jdair.util.http.client.HTTPClientUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.*;
......@@ -31,7 +33,11 @@ import org.springframework.util.CollectionUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.misc.BASE64Decoder;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
......@@ -162,6 +168,9 @@ public class UserController {
System.out.println("[UserController login][STATUS_CODE_4102]总共用时:" + Util.getDurationTime(duration));
return responseBean;
}
//用户名密码解密
loginBean.setLoginName(DtoaUtils.decrypt(loginBean.getLoginName()));
loginBean.setPassword(DtoaUtils.decrypt(loginBean.getPassword()));
String blackUsername = redisUtils.get("black_username:" + loginBean.getLoginName(), indexDb);
boolean sealup = false;
if (null != redisUsername && Integer.parseInt(redisUsername) >= usernameLimitTimes && StringUtils.isEmpty(blackUsername)) {
......@@ -1127,4 +1136,7 @@ public class UserController {
}
}
}
package com.ejweb.modules.user.utils;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DtoaUtils {
private static String base64hash = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
public static boolean isMatcher(String inStr, String reg) {
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(inStr);
if (matcher.matches()) {
return true;
}
return false;
}
/**
* btoa method
* @param inStr
* @return
*/
public static String btoa(String inStr) {
if (inStr == null || isMatcher(inStr, "([^\\u0000-\\u00ff])")) {
return null;
}
StringBuilder result = new StringBuilder();
int i = 0;
int mod = 0;
int ascii;
int prev = 0;
while (i < inStr.length()) {
ascii = inStr.charAt(i);
mod = i % 3;
switch (mod) {
case 0:
result.append(String.valueOf(base64hash.charAt(ascii >> 2)));
break;
case 1:
result.append(String.valueOf(base64hash.charAt((prev & 3) << 4 | (ascii >> 4))));
break;
case 2:
result.append(String.valueOf(base64hash.charAt((prev & 0x0f) << 2 | (ascii >> 6))));
result.append(String.valueOf(base64hash.charAt(ascii & 0x3f)));
break;
}
prev = ascii;
i++;
}
if (mod == 0) {
result.append(String.valueOf(base64hash.charAt((prev & 3) << 4)));
result.append("==");
} else if (mod == 1) {
result.append(String.valueOf(base64hash.charAt((prev & 0x0f) << 2)));
result.append("=");
}
return result.toString();
}
/**
* atob method 逆转encode的思路即可
* @param inStr
* @return
*/
public static String atob(String inStr) {
if (inStr == null)
return null;
inStr = inStr.replaceAll("\\s|=", "");
StringBuilder result = new StringBuilder();
int cur;
int prev = -1;
int mod;
int i = 0;
while (i < inStr.length()) {
cur = base64hash.indexOf(inStr.charAt(i));
mod = i % 4;
switch (mod) {
case 0:
break;
case 1:
result.append(String.valueOf((char) (prev << 2 | cur >> 4)));
break;
case 2:
result.append(String.valueOf((char) ((prev & 0x0f) << 4 | cur >> 2)));
break;
case 3:
result.append(String.valueOf((char) ((prev & 3) << 6 | cur)));
break;
}
prev = cur;
i++;
}
return result.toString();
}
/**
* 加密字符串
* @return
*/
public static String encryption(String str) {
String encode;
try {
encode = URLEncoder.encode(str,"utf-8");
encode=encode.replaceAll("\\+", "%20");//URLEncoder.encode 会将空格解释为+号
String btoa = DtoaUtils.btoa(encode);
return btoa;
} catch (UnsupportedEncodingException e) {
System.out.println("加密失败!");
}
return str;
}
/**
* 解密字符串
* @return
*/
public static String decrypt(String str) {
String atob = DtoaUtils.atob(str);
try {
String decode = URLDecoder.decode(atob, "utf-8");
return decode;
} catch (UnsupportedEncodingException e) {
System.out.println("atob加密函数出现错误。");
}
return str;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment