提交 9e563c56 authored 作者: 李炎's avatar 李炎

微调指http请求

上级 9f29056a
...@@ -74,20 +74,20 @@ public class TokenUtils { ...@@ -74,20 +74,20 @@ public class TokenUtils {
* @return * @return
*/ */
private static boolean jwtTokenRefresh(String token, String userName, String passWord, RedisUtil redisUtil) { private static boolean jwtTokenRefresh(String token, String userName, String passWord, RedisUtil redisUtil) {
String cacheToken = String.valueOf(redisUtil.get(CommonConstant.PREFIX_USER_TOKEN + token)); String cacheToken = String.valueOf(RedisUtil.get(CommonConstant.PREFIX_USER_TOKEN + token));
if (oConvertUtils.isNotEmpty(cacheToken)) { if (oConvertUtils.isNotEmpty(cacheToken)) {
// 校验token有效性 // 校验token有效性
if (!JwtUtil.verify(cacheToken, userName, passWord)) { if (!JwtUtil.verify(cacheToken, userName, passWord)) {
String newAuthorization = JwtUtil.sign(userName, passWord); String newAuthorization = JwtUtil.sign(userName, passWord);
// 设置Toekn缓存有效时间 // 设置Toekn缓存有效时间
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, newAuthorization); RedisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, newAuthorization);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000); RedisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
} }
//update-begin--Author:scott Date:20191005 for:解决每次请求,都重写redis中 token缓存问题 //update-begin--Author:scott Date:20191005 for:解决每次请求,都重写redis中 token缓存问题
else { else {
//redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, cacheToken); //RedisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, cacheToken);
// 设置超时时间 // 设置超时时间
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000); RedisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000);
} }
//update-end--Author:scott Date:20191005 for:解决每次请求,都重写redis中 token缓存问题 //update-end--Author:scott Date:20191005 for:解决每次请求,都重写redis中 token缓存问题
return true; return true;
......
...@@ -144,21 +144,21 @@ public class ShiroRealm extends AuthorizingRealm { ...@@ -144,21 +144,21 @@ public class ShiroRealm extends AuthorizingRealm {
* @return * @return
*/ */
public boolean jwtTokenRefresh(String token, String userName, String passWord) { public boolean jwtTokenRefresh(String token, String userName, String passWord) {
String cacheToken = String.valueOf(redisUtil.get(CommonConstant.PREFIX_USER_TOKEN + token)); String cacheToken = String.valueOf(RedisUtil.get(CommonConstant.PREFIX_USER_TOKEN + token));
if (oConvertUtils.isNotEmpty(cacheToken)) { if (oConvertUtils.isNotEmpty(cacheToken)) {
// 校验token有效性 // 校验token有效性
if (!JwtUtil.verify(cacheToken, userName, passWord)) { if (!JwtUtil.verify(cacheToken, userName, passWord)) {
String newAuthorization = JwtUtil.sign(userName, passWord); String newAuthorization = JwtUtil.sign(userName, passWord);
// 设置超时时间 // 设置超时时间
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, newAuthorization); RedisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, newAuthorization);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME *2 / 1000); RedisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME *2 / 1000);
log.info("——————————用户在线操作,更新token保证不掉线—————————jwtTokenRefresh——————— "+ token); log.info("——————————用户在线操作,更新token保证不掉线—————————jwtTokenRefresh——————— "+ token);
} }
//update-begin--Author:scott Date:20191005 for:解决每次请求,都重写redis中 token缓存问题 //update-begin--Author:scott Date:20191005 for:解决每次请求,都重写redis中 token缓存问题
else { else {
// // 设置超时时间 // // 设置超时时间
// redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, cacheToken); // RedisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, cacheToken);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000); RedisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000);
} }
//update-end--Author:scott Date:20191005 for:解决每次请求,都重写redis中 token缓存问题 //update-end--Author:scott Date:20191005 for:解决每次请求,都重写redis中 token缓存问题
return true; return true;
......
...@@ -181,7 +181,7 @@ public class JeecgDemoController extends JeecgController<JeecgDemo, IJeecgDemoSe ...@@ -181,7 +181,7 @@ public class JeecgDemoController extends JeecgController<JeecgDemo, IJeecgDemoSe
*/ */
@GetMapping(value = "/redisSet") @GetMapping(value = "/redisSet")
public void redisSet() { public void redisSet() {
redisUtil.set("name", "张三" + DateUtils.now()); RedisUtil.set("name", "张三" + DateUtils.now());
} }
/** /**
...@@ -189,7 +189,7 @@ public class JeecgDemoController extends JeecgController<JeecgDemo, IJeecgDemoSe ...@@ -189,7 +189,7 @@ public class JeecgDemoController extends JeecgController<JeecgDemo, IJeecgDemoSe
*/ */
@GetMapping(value = "/redisGet") @GetMapping(value = "/redisGet")
public String redisGet() { public String redisGet() {
return (String) redisUtil.get("name"); return (String) RedisUtil.get("name");
} }
/** /**
...@@ -203,7 +203,7 @@ public class JeecgDemoController extends JeecgController<JeecgDemo, IJeecgDemoSe ...@@ -203,7 +203,7 @@ public class JeecgDemoController extends JeecgController<JeecgDemo, IJeecgDemoSe
p.setContent("hello"); p.setContent("hello");
p.setName("张三"); p.setName("张三");
p.setSex("男"); p.setSex("男");
redisUtil.set("user-zdh", p); RedisUtil.set("user-zdh", p);
} }
/** /**
...@@ -211,7 +211,7 @@ public class JeecgDemoController extends JeecgController<JeecgDemo, IJeecgDemoSe ...@@ -211,7 +211,7 @@ public class JeecgDemoController extends JeecgController<JeecgDemo, IJeecgDemoSe
*/ */
@GetMapping(value = "/redisGetObj") @GetMapping(value = "/redisGetObj")
public Object redisGetObj() { public Object redisGetObj() {
return redisUtil.get("user-zdh"); return RedisUtil.get("user-zdh");
} }
/** /**
......
...@@ -69,6 +69,18 @@ ...@@ -69,6 +69,18 @@
<version>1.0</version> <version>1.0</version>
<systemPath>${project.basedir}/src/main/resources/lib/gson-2.8.0.jar</systemPath> <systemPath>${project.basedir}/src/main/resources/lib/gson-2.8.0.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>Framework</groupId>
<artifactId>adapte-framework</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${project.basedir}/src/main/resources/lib/adapte-framework-0.0.1.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- pdf --> <!-- pdf -->
<dependency> <dependency>
<groupId>com.itextpdf</groupId> <groupId>com.itextpdf</groupId>
......
...@@ -84,8 +84,8 @@ public class CasClientController { ...@@ -84,8 +84,8 @@ public class CasClientController {
} }
String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword()); String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword());
// 设置超时时间 // 设置超时时间
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); RedisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000); RedisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
//获取用户部门信息 //获取用户部门信息
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
......
...@@ -40,42 +40,41 @@ public class SynTimed implements Job { ...@@ -40,42 +40,41 @@ public class SynTimed implements Job {
String uid = categoryDao.getUid(); String uid = categoryDao.getUid();
String pwd = categoryDao.getPwd(); String pwd = categoryDao.getPwd();
int lang = categoryDao.getLang(); int lang = categoryDao.getLang();
// String loginResult = new String(); String loginResult = new String();
// Object[] loginInfo = new Object[]{dbId, uid, pwd, lang}; Object[] loginInfo = new Object[]{dbId, uid, pwd, lang};
// try { try {
// loginResult = client2.execute("Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser", loginInfo, String.class); loginResult = client2.execute("Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser", loginInfo, String.class);
// } catch (Exception e) { } catch (Exception e) {
// log.error(KingDeeConstant.URL); log.error(KingDeeConstant.URL);
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.URL); categoryDao.setLoginResult(KingDeeConstant.URL);
// } }
// com.alibaba.fastjson.JSONObject jsonObject = new JSONObject(); com.alibaba.fastjson.JSONObject jsonObject = new JSONObject();
// try { try {
// jsonObject = JSON.parseObject(loginResult); jsonObject = JSON.parseObject(loginResult);
// } catch (Exception e) { } catch (Exception e) {
// log.error(KingDeeConstant.PORT); log.error(KingDeeConstant.PORT);
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.PORT); categoryDao.setLoginResult(KingDeeConstant.PORT);
// } }
// if (!ObjectUtils.isEmpty(jsonObject)) { if (!ObjectUtils.isEmpty(jsonObject)) {
// if (KingDeeConstant.LoginValue.equals(jsonObject.get("Message"))) { if (KingDeeConstant.LoginValue.equals(jsonObject.get("Message"))) {
// log.error(KingDeeConstant.LoginValue); log.error(KingDeeConstant.LoginValue);
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.LoginValue); categoryDao.setLoginResult(KingDeeConstant.LoginValue);
// } else if (KingDeeConstant.DBID.equals(jsonObject.get("Message"))) { } else if (KingDeeConstant.DBID.equals(jsonObject.get("Message"))) {
// log.error(KingDeeConstant.DBID); log.error(KingDeeConstant.DBID);
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.DBID); categoryDao.setLoginResult(KingDeeConstant.DBID);
// } else { } else {
// result = true; result = true;
// log.info("金蝶云登录成功"); log.info("金蝶云登录成功");
// } }
//
// } }
try { try {
result = client2.login(dbId, uid, pwd, lang); result = client2.login(dbId, uid, pwd, lang);
} catch (Exception e) { } catch (Exception e) {
categoryDao.setLoginResult(KingDeeConstant.URL + ":" + client2.checkAuthInfo());
e.printStackTrace(); e.printStackTrace();
} }
log.info("<==========任务设置result: " + result); log.info("<==========任务设置result: " + result);
...@@ -86,43 +85,42 @@ public class SynTimed implements Job { ...@@ -86,43 +85,42 @@ public class SynTimed implements Job {
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
// Object[] loginInfo2 = new Object[]{dbId, uid, pwd, lang}; Object[] loginInfo2 = new Object[]{dbId, uid, pwd, lang};
// String loginResult2 = new String(); String loginResult2 = new String();
// try { try {
// loginResult2 = client3.execute("Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser", loginInfo2, String.class); loginResult2 = client3.execute("Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser", loginInfo2, String.class);
// } catch (Exception e) { } catch (Exception e) {
// log.error(KingDeeConstant.URL); log.error(KingDeeConstant.URL);
// result2 = false; result2 = false;
// categoryDao.setLoginResult(KingDeeConstant.URL); categoryDao.setLoginResult(KingDeeConstant.URL);
// } }
// com.alibaba.fastjson.JSONObject jsonObject2 = new JSONObject(); com.alibaba.fastjson.JSONObject jsonObject2 = new JSONObject();
// try { try {
// jsonObject2 = JSON.parseObject(loginResult2); jsonObject2 = JSON.parseObject(loginResult2);
// } catch (Exception e) { } catch (Exception e) {
// log.error(KingDeeConstant.PORT); log.error(KingDeeConstant.PORT);
// result2 = false; result2 = false;
// categoryDao.setLoginResult(KingDeeConstant.PORT); categoryDao.setLoginResult(KingDeeConstant.PORT);
// } }
// if (!ObjectUtils.isEmpty(jsonObject)) { if (!ObjectUtils.isEmpty(jsonObject)) {
// if (KingDeeConstant.LoginValue.equals(jsonObject2.get("Message"))) { if (KingDeeConstant.LoginValue.equals(jsonObject2.get("Message"))) {
// log.error(KingDeeConstant.LoginValue); log.error(KingDeeConstant.LoginValue);
// result2 = false; result2 = false;
// categoryDao.setLoginResult(KingDeeConstant.LoginValue); categoryDao.setLoginResult(KingDeeConstant.LoginValue);
// } else if (KingDeeConstant.DBID.equals(jsonObject2.get("Message"))) { } else if (KingDeeConstant.DBID.equals(jsonObject2.get("Message"))) {
// log.error(KingDeeConstant.DBID); log.error(KingDeeConstant.DBID);
// result2 = false; result2 = false;
// categoryDao.setLoginResult(KingDeeConstant.DBID); categoryDao.setLoginResult(KingDeeConstant.DBID);
// } else { } else {
// result2 = true; result2 = true;
// log.info("金蝶云登录成功"); log.info("金蝶云登录成功");
// } }
// } }
try { try {
result2 = client3.login(dbId, uid, pwd, lang); result2 = client3.login(dbId, uid, pwd, lang);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
categoryDao.setLoginResult(KingDeeConstant.URL + "." + client2.checkAuthInfo());
} }
log.info("<==========任务设置result2: " + result2); log.info("<==========任务设置result2: " + result2);
categoryDao.setClient(client3); categoryDao.setClient(client3);
......
package org.jeecg.modules.iost.ims.Util;
import java.util.Collection;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 字符串工具类
*
* @author ruoyi
*/
public class StringUtil extends org.apache.commons.lang3.StringUtils {
/**
* 空字符串
*/
private static final String NULL_STRING = "";
/**
* 下划线
*/
private static final char SEPARATOR = '_';
/**
* 正则验证字符串是否是数字
*/
private static final Pattern NUM_PATTERN = Pattern.compile("^[0-9]*$");
/**
* 获取参数不为空值
*
* @param value defaultValue 要判断的value
* @return value 返回值
*/
public static <T> T nvl(T value, T defaultValue) {
return value != null ? value : defaultValue;
}
/**
* * 判断一个Collection是否为空, 包含List,Set,Queue
*
* @param coll 要判断的Collection
* @return true:为空 false:非空
*/
public static boolean isEmpty(Collection<?> coll) {
return isNull(coll) || coll.isEmpty();
}
/**
* * 判断一个Collection是否非空,包含List,Set,Queue
*
* @param coll 要判断的Collection
* @return true:非空 false:空
*/
public static boolean isNotEmpty(Collection<?> coll) {
return !isEmpty(coll);
}
/**
* * 判断一个对象数组是否为空
*
* @param objects 要判断的对象数组
* @return true:为空 false:非空
*/
public static boolean isEmpty(Object[] objects) {
return isNull(objects) || (objects.length == 0);
}
/**
* * 判断一个对象数组是否非空
*
* @param objects 要判断的对象数组
* @return true:非空 false:空
*/
public static boolean isNotEmpty(Object[] objects) {
return !isEmpty(objects);
}
/**
* * 判断一个Map是否为空
*
* @param map 要判断的Map
* @return true:为空 false:非空
*/
public static boolean isEmpty(Map<?, ?> map) {
return isNull(map) || map.isEmpty();
}
/**
* * 判断一个Map是否为空
*
* @param map 要判断的Map
* @return true:非空 false:空
*/
public static boolean isNotEmpty(Map<?, ?> map) {
return !isEmpty(map);
}
/**
* * 判断一个字符串是否为空串
*
* @param str String
* @return true:为空 false:非空
*/
public static boolean isEmpty(String str) {
return isNull(str) || NULL_STRING.equals(str.trim());
}
/**
* * 判断一个字符串是否为非空串
*
* @param str String
* @return true:非空串 false:空串
*/
public static boolean isNotEmpty(String str) {
return !isEmpty(str);
}
/**
* * 判断一个对象是否为空
*
* @param object Object
* @return true:为空 false:非空
*/
public static boolean isNull(Object object) {
return object == null;
}
/**
* * 判断一个对象是否非空
*
* @param object Object
* @return true:非空 false:空
*/
public static boolean isNotNull(Object object) {
return !isNull(object);
}
/**
* * 判断一个对象是否是数组类型(Java基本型别的数组)
*
* @param object 对象
* @return true:是数组 false:不是数组
*/
public static boolean isArray(Object object) {
return isNotNull(object) && object.getClass().isArray();
}
/**
* 去空格
*/
public static String trim(String str) {
return (str == null ? "" : str.trim());
}
/**
* 截取字符串
*
* @param str 字符串
* @param start 开始
* @return 结果
*/
public static String substring(final String str, int start) {
if (str == null) {
return NULL_STRING;
}
if (start < 0) {
start = str.length() + start;
}
if (start < 0) {
start = 0;
}
if (start > str.length()) {
return NULL_STRING;
}
return str.substring(start);
}
/**
* 截取字符串
*
* @param str 字符串
* @param start 开始
* @param end 结束
* @return 结果
*/
public static String substring(final String str, int start, int end) {
if (str == null) {
return NULL_STRING;
}
if (end < 0) {
end = str.length() + end;
}
if (start < 0) {
start = str.length() + start;
}
if (end > str.length()) {
end = str.length();
}
if (start > end) {
return NULL_STRING;
}
if (start < 0) {
start = 0;
}
if (end < 0) {
end = 0;
}
return str.substring(start, end);
}
/**
* 下划线转驼峰命名
*/
public static String toUnderScoreCase(String str) {
if (str == null) {
return null;
}
StringBuilder sb = new StringBuilder();
// 前置字符是否大写
boolean preCharIsUpperCase = true;
// 当前字符是否大写
boolean curreCharIsUpperCase = true;
// 下一字符是否大写
boolean nexteCharIsUpperCase = true;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (i > 0) {
preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
} else {
preCharIsUpperCase = false;
}
curreCharIsUpperCase = Character.isUpperCase(c);
if (i < (str.length() - 1)) {
nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
}
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
sb.append(SEPARATOR);
} else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) {
sb.append(SEPARATOR);
}
sb.append(Character.toLowerCase(c));
}
return sb.toString();
}
/**
* 是否包含字符串
*
* @param str 验证字符串
* @param strs 字符串组
* @return 包含返回true
*/
public static boolean inStringIgnoreCase(String str, String... strs) {
if (str != null && strs != null) {
for (String s : strs) {
if (str.equalsIgnoreCase(trim(s))) {
return true;
}
}
}
return false;
}
/**
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld
*
* @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串
*/
public static String convertToCamelCase(String name) {
StringBuilder result = new StringBuilder();
// 快速检查
if (name == null || name.isEmpty()) {
// 没必要转换
return "";
} else if (!name.contains("_")) {
// 不含下划线,仅将首字母大写
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
// 用下划线将原始字符串分割
String[] camels = name.split("_");
for (String camel : camels) {
// 跳过原始字符串中开头、结尾的下换线或双重下划线
if (camel.isEmpty()) {
continue;
}
// 首字母大写
result.append(camel.substring(0, 1).toUpperCase());
result.append(camel.substring(1).toLowerCase());
}
return result.toString();
}
/**
* 驼峰式命名法 例如:user_name->userName
*/
public static String toCamelCase(String s) {
if (s == null) {
return null;
}
s = s.toLowerCase();
StringBuilder sb = new StringBuilder(s.length());
boolean upperCase = false;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == SEPARATOR) {
upperCase = true;
} else if (upperCase) {
sb.append(Character.toUpperCase(c));
upperCase = false;
} else {
sb.append(c);
}
}
return sb.toString();
}
/**
* 判断字符串是否是数字
*/
public static boolean isStr2Num(String str) {
Matcher matcher = NUM_PATTERN.matcher(str);
return matcher.matches();
}
/**
* java去除字符串中的空格、回车、换行符、制表符
*/
public static String replaceBlank(String str) {
String dest = "";
if (str != null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}
return dest;
}
}
\ No newline at end of file
package org.jeecg.modules.iost.ims.client;
import com.lingqingkeji.integration.adapterframework.vo.IntegrateBaseOutVo;
import org.jeecg.modules.iost.ims.Util.JsonUtil;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* @author Inori
*/
@Deprecated
public class KingDeeK3CloudApi extends KingdeeApiClient {
public KingDeeK3CloudApi(String serverUrl) {
super(serverUrl);
}
public String excuteOperation(String formid, String opNumber, String data, IntegrateBaseOutVo integrateBaseOutVo) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExcuteOperation", new Object[]{formid, opNumber, data}, Object.class, integrateBaseOutVo);
return JsonUtil.toString(execute);
}
public String save(String formid, String data, IntegrateBaseOutVo integrateBaseOutVo) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save", new Object[]{formid, data}, Object.class, integrateBaseOutVo);
return JsonUtil.toString(execute);
}
public String batchSave(String formid, String data, IntegrateBaseOutVo integrateBaseOutVo) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.BatchSave", new Object[]{formid, data}, Object.class, integrateBaseOutVo);
return JsonUtil.toString(execute);
}
public String audit(String formid, HashMap data, IntegrateBaseOutVo integrateBaseOutVo) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit", new Object[]{formid, data}, Object.class, integrateBaseOutVo);
return JsonUtil.toString(execute);
}
public String delete(String formid, String data, IntegrateBaseOutVo integrateBaseOutVo) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Delete", new Object[]{formid, data}, Object.class, integrateBaseOutVo);
return JsonUtil.toString(execute);
}
public String unAudit(String formid, HashMap data, IntegrateBaseOutVo integrateBaseOutVo) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.UnAudit", new Object[]{formid, data}, Object.class, integrateBaseOutVo);
return JsonUtil.toString(execute);
}
public String submit(String formid, HashMap data, IntegrateBaseOutVo integrateBaseOutVo) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Submit", new Object[]{formid, data}, Object.class, integrateBaseOutVo);
return JsonUtil.toString(execute);
}
public String view(String formid, String data, IntegrateBaseOutVo integrateBaseOutVo) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.View", new Object[]{formid, data}, Object.class, integrateBaseOutVo);
return JsonUtil.toString(execute);
}
public List<List<Object>> executeBillQuery(String data, IntegrateBaseOutVo integrateBaseOutVo) throws Exception {
List execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery", new Object[]{data}, ArrayList.class, integrateBaseOutVo);
if (CollectionUtils.isEmpty(execute)) {
execute = new ArrayList<>();
}
return execute;
}
public String draft(String formid, String data, IntegrateBaseOutVo integrateBaseOutVo) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Draft", new Object[]{formid, data}, Object.class, integrateBaseOutVo);
return JsonUtil.toString(execute);
}
}
package org.jeecg.modules.iost.ims.client;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.kingdee.bos.webapi.entity.IdentifyInfo;
import com.kingdee.bos.webapi.entity.RepoResult;
import com.kingdee.bos.webapi.entity.RepoStatus;
import com.kingdee.bos.webapi.sdk.K3CloudApi;
import kingdee.bos.json.JSONObject;
import kingdee.bos.webapi.client.ApiHttpClient;
import kingdee.bos.webapi.client.ApiRequest;
import kingdee.bos.webapi.client.ApiServiceRequest;
import kingdee.bos.webapi.client.IAsyncActionCallBack;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.CookieStore;
import org.jeecg.common.util.ThreadLocalConfig;
import org.jeecg.modules.iost.ims.Util.JsonUtil;
import org.jeecg.modules.iost.ims.kingdeeapi.HttpUtil;
import org.springframework.http.ResponseEntity;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class KingdeeApiClientSDK {
private String _serverUrl;
private K3CloudApi api;
public KingdeeApiClientSDK(String serverUrl) {
this._serverUrl = serverUrl;
}
public <T> T execute(String servicename, Object[] parameters, Class<T> returnType) throws Exception {
execute(servicename, parameters);
long startTime = System.currentTimeMillis();
T execute = api.execute(servicename, parameters, returnType);
long duration = System.currentTimeMillis() - startTime;
log.info("<======sdk请求耗时:" + duration + "毫秒");
return execute;
}
public void execute(String serviceName, Object[] parameters) throws Exception {
String cookie = HttpUtil.login(this._serverUrl);
log.info("cookie:" + cookie);
Map<String, Object> header = new HashMap<>(1);
header.put("cookie", cookie);
Map<String, Object> request = new HashMap<>(1);
request.put("parameters", parameters);
String url = this._serverUrl + serviceName + ".common.kdsvc";
String requestStr = JsonUtil.toString(request);
long start = System.currentTimeMillis();
ResponseEntity<String> responseEntity = HttpUtil.httpPost(url, header, requestStr);
long costTime = System.currentTimeMillis() - start;
log.info("<======模拟http耗时:" + String.valueOf(costTime));
log.info("Body_" + responseEntity.getBody());
}
public String checkAuthInfo() {
try {
String s = api.CheckAuthInfo().getResult().toString();
System.out.println("<=====检测登录状态: " + s);
return s;
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
public static void main(String[] args) throws Exception {
IdentifyInfo identifyInfo = new IdentifyInfo() {
};
identifyInfo.setAppId("232190_5d4pQbjpRvp86VypX3TD1dXJUKXc4ppo");
identifyInfo.setAppSecret("7e4a4779a554403eb2189bf3841552e3");
identifyInfo.setServerUrl("http://10.10.1.212/k3cloud");
identifyInfo.setdCID("62f50a9ea1ece4");
identifyInfo.setlCID(2052);
identifyInfo.setUserName("MES");
System.out.println("开始");
K3CloudApi api = new K3CloudApi(identifyInfo);
RepoResult repoResult = api.CheckAuthInfo();
RepoStatus responseStatus = repoResult.getResponseStatus();
System.out.println(":" + repoResult.getResult());
System.out.println("is" + responseStatus.isIsSuccess());
}
public Boolean login(String dbId, String userName, String password, int lcid) throws Exception {
try {
IdentifyInfo iden = new IdentifyInfo();
iden.setUserName("admin");
iden.setAppId("267026_TedP2+lJznBfWUXEX4SB78+L4J07QsKo");
iden.setAppSecret("0ea786a865ef4413923b1367de5408aa");
iden.setdCID("6476c5b6077e71");
iden.setlCID(2052);
iden.setServerUrl(_serverUrl);
api = new K3CloudApi(iden);
// String data = "{\"CreateOrgId\": 0,\"Number\": \"111\",\"Id\": \"\",\"IsSortBySeq\": \"false\"}";
// String result = api.view("BD_Material", data);
// System.out.println("<=====test:" + result);
RepoResult repoResult = api.CheckAuthInfo();
RepoStatus responseStatus = repoResult.getResponseStatus();
boolean isSuccess = responseStatus.isIsSuccess();
System.out.println("<=====登录状态:" + isSuccess);
System.out.println("<=====登录返回:" + repoResult.getResult());
System.out.println("<=====登录返回:" + repoResult.getResponseStatus().getErrorCode());
System.out.println("<=====登录返回:" + repoResult.getResponseStatus().getSuccessEntitys());
System.out.println("<=====登录返回:" + repoResult.getResponseStatus().getErrors());
return isSuccess;
} catch (Exception var10) {
var10.printStackTrace();
return false;
}
}
public Boolean login(String dbId, String userName, String appId, String appSec, int lcid) throws Exception {
try {
// IdentifyInfo iden = new IdentifyInfo();
// iden.setUserName(userName);
// iden.setAppId(appId);
// iden.setAppSecret(appSec);
// iden.setdCID(dbId);
// iden.setlCID(lcid);
// iden.setServerUrl(_serverUrl);
IdentifyInfo iden = new IdentifyInfo();
iden.setUserName(userName);
iden.setAppId("267026_TedP2+IJznBfWUXEX4SB78+L4J07QsKo");
iden.setAppSecret("4db4e81eeb65ada35ff203b181552de87c2c1c99");
iden.setdCID(dbId);
iden.setlCID(lcid);
iden.setServerUrl(_serverUrl);
api = new K3CloudApi(iden);
RepoResult repoResult = api.CheckAuthInfo();
RepoStatus responseStatus = repoResult.getResponseStatus();
boolean isSuccess = responseStatus.isIsSuccess();
return isSuccess;
} catch (Exception var10) {
var10.printStackTrace();
return false;
}
}
}
package org.jeecg.modules.iost.ims.client;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
public class SerializerProxy {
public SerializerProxy() {
}
public Object deserialize(String content, Class<?> type) {
if (content != null && content.length() != 0) {
return "java.lang.string".equalsIgnoreCase(type.getName()) ? content : this.toDeserialize(content, type);
} else if (!type.isPrimitive()) {
return type;
} else {
return "java.lang.String".equalsIgnoreCase(type.getName()) ? content : null;
}
}
public Object toDeserialize(String content, Class<?> type) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readValue(content, type);
} catch (IOException var5) {
var5.printStackTrace();
return null;
}
}
}
\ No newline at end of file
...@@ -565,38 +565,38 @@ public class WebApi { ...@@ -565,38 +565,38 @@ public class WebApi {
String uid = categoryDao.getUid(); String uid = categoryDao.getUid();
String pwd = categoryDao.getPwd(); String pwd = categoryDao.getPwd();
int lang = categoryDao.getLang(); int lang = categoryDao.getLang();
// String loginResult = new String(); String loginResult = new String();
// Object[] loginInfo = new Object[]{dbId, uid, pwd, lang}; Object[] loginInfo = new Object[]{dbId, uid, pwd, lang};
// try { try {
// loginResult = client.execute("Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser", loginInfo, String.class); loginResult = client.execute("Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser", loginInfo, String.class);
// } catch (Exception e) { } catch (Exception e) {
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.URL); categoryDao.setLoginResult(KingDeeConstant.URL);
// throw new KingdeeConnectException(KingDeeConstant.URL); throw new KingdeeConnectException(KingDeeConstant.URL);
// } }
// com.alibaba.fastjson.JSONObject jsonObject = new JSONObject(); com.alibaba.fastjson.JSONObject jsonObject = new JSONObject();
// try { try {
// jsonObject = JSON.parseObject(loginResult); jsonObject = JSON.parseObject(loginResult);
// } catch (Exception e) { } catch (Exception e) {
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.PORT); categoryDao.setLoginResult(KingDeeConstant.PORT);
// throw new KingdeeConnectException(KingDeeConstant.PORT); throw new KingdeeConnectException(KingDeeConstant.PORT);
// } }
// if (!ObjectUtils.isEmpty(jsonObject)) { if (!ObjectUtils.isEmpty(jsonObject)) {
// if (KingDeeConstant.LoginValue.equals(jsonObject.get("Message"))) { if (KingDeeConstant.LoginValue.equals(jsonObject.get("Message"))) {
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.LoginValue); categoryDao.setLoginResult(KingDeeConstant.LoginValue);
// throw new KingdeeConnectException(KingDeeConstant.LoginValue); throw new KingdeeConnectException(KingDeeConstant.LoginValue);
// } else if (KingDeeConstant.DBID.equals(jsonObject.get("Message"))) { } else if (KingDeeConstant.DBID.equals(jsonObject.get("Message"))) {
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.DBID); categoryDao.setLoginResult(KingDeeConstant.DBID);
// //throw new KingdeeConnectException(KingDeeConstant.DBID); //throw new KingdeeConnectException(KingDeeConstant.DBID);
// } else { } else {
// result = true; result = true;
// } }
//
// } }
try { try {
result = client.login(dbId, uid, pwd, lang); result = client.login(dbId, uid, pwd, lang);
} catch (Exception e) { } catch (Exception e) {
...@@ -615,38 +615,38 @@ public class WebApi { ...@@ -615,38 +615,38 @@ public class WebApi {
String uid = categoryDao.getUid(); String uid = categoryDao.getUid();
String pwd = categoryDao.getPwd(); String pwd = categoryDao.getPwd();
int lang = categoryDao.getLang(); int lang = categoryDao.getLang();
// String loginResult = new String(); String loginResult = new String();
// Object[] loginInfo = new Object[]{dbId, uid, pwd, lang}; Object[] loginInfo = new Object[]{dbId, uid, pwd, lang};
// try { try {
// loginResult = client.execute("Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser", loginInfo, String.class); loginResult = client.execute("Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser", loginInfo, String.class);
// } catch (Exception e) { } catch (Exception e) {
// log.error(KingDeeConstant.URL); log.error(KingDeeConstant.URL);
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.URL); categoryDao.setLoginResult(KingDeeConstant.URL);
// } }
//
// com.alibaba.fastjson.JSONObject jsonObject = new JSONObject(); com.alibaba.fastjson.JSONObject jsonObject = new JSONObject();
// try { try {
// jsonObject = JSON.parseObject(loginResult); jsonObject = JSON.parseObject(loginResult);
// } catch (Exception e) { } catch (Exception e) {
// log.error(KingDeeConstant.PORT); log.error(KingDeeConstant.PORT);
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.PORT); categoryDao.setLoginResult(KingDeeConstant.PORT);
// } }
// if (!ObjectUtils.isEmpty(jsonObject)) { if (!ObjectUtils.isEmpty(jsonObject)) {
// if (KingDeeConstant.LoginValue.equals(jsonObject.get("Message"))) { if (KingDeeConstant.LoginValue.equals(jsonObject.get("Message"))) {
// log.error(KingDeeConstant.LoginValue); log.error(KingDeeConstant.LoginValue);
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.LoginValue); categoryDao.setLoginResult(KingDeeConstant.LoginValue);
// } else if (KingDeeConstant.DBID.equals(jsonObject.get("Message"))) { } else if (KingDeeConstant.DBID.equals(jsonObject.get("Message"))) {
// log.error(KingDeeConstant.DBID); log.error(KingDeeConstant.DBID);
// result = false; result = false;
// categoryDao.setLoginResult(KingDeeConstant.DBID); categoryDao.setLoginResult(KingDeeConstant.DBID);
// } else { } else {
// result = true; result = true;
// } }
//
// } }
try { try {
result = client.login(dbId, uid, pwd, lang); result = client.login(dbId, uid, pwd, lang);
} catch (Exception e) { } catch (Exception e) {
......
package org.jeecg.modules.iost.ims.kingdeeadapter;
import com.lingqingkeji.integration.adapterframework.utils.JsonUtil;
import org.jeecg.modules.iost.ims.Util.StringUtil;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author Inori
*/
public class KingDeeUtil {
private static final String kingdeeCookieKeyPrefix = "kingdee:token:cookie:";
private static final long kingdeeCookieKeyOutTime = 60 * 19;
public static String createCookieKey(String dbId, String userName, String password, int lcid) {
return kingdeeCookieKeyPrefix + dbId + ":" + userName + ":" + password + ":" + lcid;
}
public static long getCookieKeyOutTime() {
return kingdeeCookieKeyOutTime;
}
public static boolean isError(String json) {
Map<String, Object> map = JsonUtil.toMap(json, String.class, Object.class);
Map<String, Object> tempMap = JsonUtil.toMap(JsonUtil.toString(map.get("Result")), String.class, Object.class);
Map<String, Object> responseMap = JsonUtil.toMap(JsonUtil.toString(tempMap.get("ResponseStatus")), String.class, Object.class);
List<Object> errorList = JsonUtil.toList(JsonUtil.toString(responseMap.get("Errors")), Object.class);
return !CollectionUtils.isEmpty(errorList);
}
public static String getMessage(Object object) {
Map<String, Object> map = JsonUtil.toMap(JsonUtil.toString(object), String.class, Object.class);
String result = JsonUtil.toString(map.get("Result"));
Map<String, Object> toMap = JsonUtil.toMap(result, String.class, Object.class);
String responseStatus = JsonUtil.toString(toMap.get("ResponseStatus"));
Map<String, Object> objectMap = JsonUtil.toMap(responseStatus, String.class, Object.class);
List<Object> errorList = JsonUtil.toList(JsonUtil.toString(objectMap.get("Errors")), Object.class);
String message = "";
for (Object obj : errorList) {
Map<String, Object> messageMap = JsonUtil.toMap(JsonUtil.toString(obj), String.class, Object.class);
if (StringUtil.isEmpty(message)) {
message += messageMap.get("Message").toString();
} else {
message += "," + messageMap.get("Message").toString();
}
}
return message.toString();
}
public static List<Map<String, Object>> getSuccessEntity(String json) {
Map<String, Object> map = JsonUtil.toMap(json, String.class, Object.class);
Map<String, Object> tempMap = JsonUtil.toMap(JsonUtil.toString(map.get("Result")), String.class, Object.class);
String responseStatus = JsonUtil.toString(tempMap.get("ResponseStatus"));
Map<String, Object> responseMap = JsonUtil.toMap(responseStatus, String.class, Object.class);
List<Object> successEntityList = JsonUtil.toList(JsonUtil.toString(responseMap.get("SuccessEntitys")), Object.class);
return successEntityList.stream().map(m -> JsonUtil.toMap(JsonUtil.toString(m), String.class, Object.class)).collect(Collectors.toList());
}
public static List<List<Map<String, Object>>> getPushResultMap(List<Map<String, Object>> temps) {
List<List<Map<String, Object>>> numberLists = new ArrayList<>();
for (Map<String, Object> temp : temps) {
if (temp.containsKey("resultData")) {
List<Object> addSuccessEntityList = JsonUtil.toList(JsonUtil.toString(temp.get("resultData")), Object.class);
List<Map<String, Object>> numberList = addSuccessEntityList.stream()
.map(m -> JsonUtil.toMap(JsonUtil.toString(m), String.class, Object.class))
.collect(Collectors.toList());
numberLists.add(numberList);
}
}
return numberLists;
}
}
package org.jeecg.modules.iost.ims.kingdeeadapter.constants;
/**
* @author Inori
*/
public interface Constants {
Integer ZERO = 0;
Integer ONE = 1;
Integer TWO = 2;
Integer THREE = 3;
String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
String FILE_FORMAT = "lic.tmp";
String EFFECTIVE_TIME = "effectiveTime";
String VERIFICATION_INTERVAL = "verificationInterval";
String CODE_NAME = "code";
String DATA_NAME = "data";
String NAME = "name";
}
package org.jeecg.modules.iost.ims.kingdeeadapter.constants;
/**
* @author Inori
*/
public interface KingDeeConstants {
String KING_DEE_COOKIE_NAME = "Set-Cookie";
String KING_DEE_SESSION_NAME = "kdservice-sessionid";
String LOGIN_RESULT_TYPE = "LoginResultType";
String KINGDEE_RESPONSE_NAME = "ResponseStatus";
String KINGDEE_CODE_NAME = "IsSuccess";
String KINGDEE_ERROR_NAME = "Errors";
String KINGDEE_ERROR_MESSAGE_NAME = "Message";
String CODE_NAME = "resultCode";
String CODE_NAME_2 = "code";
String DATA_NAME = "resultData";
String MSG_NAME = "resultMsg";
String SUCCESS_CODE = "0000";
String SUCCESS_CODE_2 = "200";
String ERROR_CODE = "0002";
String OVERTIME_CODE = "0101";
String NOT_LOGGED_IN_CODE = "0010";
String DATA = "data";
}
package org.jeecg.modules.iost.ims.kingdeeadapter.constants;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* 静态获取spring容器中的bean
*
* @author Inori
*/
public class SpringContextHolder implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringContextHolder.applicationContext = applicationContext;
}
public static ApplicationContext getApplicationContext() {
assertApplicationContext();
return applicationContext;
}
@SuppressWarnings("unchecked")
public static <T> T getBean(String beanName) {
assertApplicationContext();
return (T) applicationContext.getBean(beanName);
}
public static <T> T getBean(Class<T> requiredType) {
assertApplicationContext();
return applicationContext.getBean(requiredType);
}
private static void assertApplicationContext() {
if (SpringContextHolder.applicationContext == null) {
throw new RuntimeException("applicationContext属性为null,请检查是否注入了SpringContextHolder!");
}
}
}
package org.jeecg.modules.iost.ims.kingdeeadapter.model;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
/**
* @author Inori
*/
public class DelayedElement implements Delayed {
private long mills;
public DelayedElement(Integer min) {
this.mills = System.currentTimeMillis() / 1000 + (60 * min);
}
/**
* 当方法返回小于或等于0的数值时, 元素将会被消耗
*/
@Override
public long getDelay(TimeUnit unit) {
return mills - (System.currentTimeMillis() / 1000);
}
/**
* DelayQueue底层是优先队列,需要实现compareTo方法,
* 用于在入列的时候与容器中的数据进行比较,以便确定元素位置。
*/
@Override
public int compareTo(Delayed o) {
return (int) (mills - ((DelayedElement) o).getMills());
}
public long getMills() {
return mills;
}
public void setMills(long mills) {
this.mills = mills;
}
public static void main(String[] args) {
System.out.println("{\"parameters\":[{\"http\":{\"encode\":\"YHHD000775\",\"formId\":\"LQKJ_Bankslip\",\"name\":\"SZ000352CMB02U755915671510703715B000048730_1.pdf\",\"url\":\"http://s3gw.cmburl.cn:8081/s/L2xmNDJfMDFfY2JzZmlsZXMuMTAvU1owMDAzNTJDTUIwMlU3NTU5MTU2NzE1MTA3MDM3MTVCMDAwMDQ4NzMwXzEucGRmP0FXU0FjY2Vzc0tleUlkPWxmNDJfdXNlcjcmRXhwaXJlcz0xNzAyMzY1OTIxJlNpZ25hdHVyZT1ZVGFqczEzNGgydkRQUWRSWVZ3OTk0cDV6RkUlM0QmcmVzcG9uc2UtY29udGVudC1kaXNwb3NpdGlvbj1hdHRhY2htZW50JTNCZmlsZW5hbWUlM0RTWjAwMDM1MkNNQjAyVTc1NTkxNTY3MTUxMDcwMzcxNUIwMDAwNDg3MzBfMS5wZGY=/VmkS-iQueXzTFC6KmSKTQuo1OCw=/lf42-user7-dmz/0\"}}]}");
}
}
...@@ -84,7 +84,7 @@ public class LoginController { ...@@ -84,7 +84,7 @@ public class LoginController {
} }
String lowerCaseCaptcha = captcha.toLowerCase(); String lowerCaseCaptcha = captcha.toLowerCase();
String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + sysLoginModel.getCheckKey(), "utf-8"); String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + sysLoginModel.getCheckKey(), "utf-8");
Object checkCode = redisUtil.get(realKey); Object checkCode = RedisUtil.get(realKey);
//当进入登录页时,有一定几率出现验证码错误 #1714 //当进入登录页时,有一定几率出现验证码错误 #1714
if (checkCode == null || !checkCode.toString().equals(lowerCaseCaptcha)) { if (checkCode == null || !checkCode.toString().equals(lowerCaseCaptcha)) {
result.error500("验证码错误"); result.error500("验证码错误");
...@@ -143,11 +143,11 @@ public class LoginController { ...@@ -143,11 +143,11 @@ public class LoginController {
//update-end--Author:wangshuai Date:20200714 for:登出日志没有记录人员 //update-end--Author:wangshuai Date:20200714 for:登出日志没有记录人员
log.info(" 用户名: " + sysUser.getRealname() + ",退出成功! "); log.info(" 用户名: " + sysUser.getRealname() + ",退出成功! ");
//清空用户登录Token缓存 //清空用户登录Token缓存
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token); RedisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
//清空用户登录Shiro权限缓存 //清空用户登录Shiro权限缓存
redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId()); RedisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
//清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username> //清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username>
redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername())); RedisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
//调用shiro的logout //调用shiro的logout
SecurityUtils.getSubject().logout(); SecurityUtils.getSubject().logout();
return Result.ok("退出登录成功!"); return Result.ok("退出登录成功!");
...@@ -252,7 +252,7 @@ public class LoginController { ...@@ -252,7 +252,7 @@ public class LoginController {
result.setSuccess(false); result.setSuccess(false);
return result; return result;
} }
Object object = redisUtil.get(mobile); Object object = RedisUtil.get(mobile);
if (object != null) { if (object != null) {
result.setMessage("验证码10分钟内,仍然有效!"); result.setMessage("验证码10分钟内,仍然有效!");
result.setSuccess(false); result.setSuccess(false);
...@@ -304,7 +304,7 @@ public class LoginController { ...@@ -304,7 +304,7 @@ public class LoginController {
return result; return result;
} }
//验证码10分钟内有效 //验证码10分钟内有效
redisUtil.set(mobile, captcha, 600); RedisUtil.set(mobile, captcha, 600);
//update-begin--Author:scott Date:20190812 for:issues#391 //update-begin--Author:scott Date:20190812 for:issues#391
//result.setResult(captcha); //result.setResult(captcha);
//update-end--Author:scott Date:20190812 for:issues#391 //update-end--Author:scott Date:20190812 for:issues#391
...@@ -339,7 +339,7 @@ public class LoginController { ...@@ -339,7 +339,7 @@ public class LoginController {
} }
String smscode = jsonObject.getString("captcha"); String smscode = jsonObject.getString("captcha");
Object code = redisUtil.get(phone); Object code = RedisUtil.get(phone);
if (!smscode.equals(code)) { if (!smscode.equals(code)) {
result.setMessage("手机验证码错误"); result.setMessage("手机验证码错误");
return result; return result;
...@@ -379,8 +379,8 @@ public class LoginController { ...@@ -379,8 +379,8 @@ public class LoginController {
// 生成token // 生成token
String token = JwtUtil.sign(username, syspassword); String token = JwtUtil.sign(username, syspassword);
// 设置token缓存有效时间 // 设置token缓存有效时间
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); RedisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000); RedisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
// 获取用户部门信息 // 获取用户部门信息
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
...@@ -438,7 +438,7 @@ public class LoginController { ...@@ -438,7 +438,7 @@ public class LoginController {
String code = RandomUtil.randomString(BASE_CHECK_CODES, 4); String code = RandomUtil.randomString(BASE_CHECK_CODES, 4);
String lowerCaseCode = code.toLowerCase(); String lowerCaseCode = code.toLowerCase();
String realKey = MD5Util.MD5Encode(lowerCaseCode + key, "utf-8"); String realKey = MD5Util.MD5Encode(lowerCaseCode + key, "utf-8");
redisUtil.set(realKey, lowerCaseCode, 60); RedisUtil.set(realKey, lowerCaseCode, 60);
String base64 = RandImageUtil.generate(code); String base64 = RandImageUtil.generate(code);
res.setSuccess(true); res.setSuccess(true);
res.setResult(base64); res.setResult(base64);
...@@ -496,8 +496,8 @@ public class LoginController { ...@@ -496,8 +496,8 @@ public class LoginController {
// 生成token // 生成token
String token = JwtUtil.sign(username, syspassword); String token = JwtUtil.sign(username, syspassword);
// 设置超时时间 // 设置超时时间
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); RedisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000); RedisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
//token 信息 //token 信息
obj.put("token", token); obj.put("token", token);
...@@ -523,7 +523,7 @@ public class LoginController { ...@@ -523,7 +523,7 @@ public class LoginController {
} }
String lowerCaseCaptcha = captcha.toLowerCase(); String lowerCaseCaptcha = captcha.toLowerCase();
String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + checkKey, "utf-8"); String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + checkKey, "utf-8");
Object checkCode = redisUtil.get(realKey); Object checkCode = RedisUtil.get(realKey);
if (checkCode == null || !checkCode.equals(lowerCaseCaptcha)) { if (checkCode == null || !checkCode.equals(lowerCaseCaptcha)) {
return Result.error("验证码错误"); return Result.error("验证码错误");
} }
......
...@@ -856,7 +856,7 @@ public class SysUserController { ...@@ -856,7 +856,7 @@ public class SysUserController {
Result<JSONObject> result = new Result<JSONObject>(); Result<JSONObject> result = new Result<JSONObject>();
String phone = jsonObject.getString("phone"); String phone = jsonObject.getString("phone");
String smscode = jsonObject.getString("smscode"); String smscode = jsonObject.getString("smscode");
Object code = redisUtil.get(phone); Object code = RedisUtil.get(phone);
String username = jsonObject.getString("username"); String username = jsonObject.getString("username");
//未设置用户名,则用手机号作为用户名 //未设置用户名,则用手机号作为用户名
if(oConvertUtils.isEmpty(username)){ if(oConvertUtils.isEmpty(username)){
...@@ -961,14 +961,14 @@ public class SysUserController { ...@@ -961,14 +961,14 @@ public class SysUserController {
Result<Map<String,String>> result = new Result<Map<String,String>>(); Result<Map<String,String>> result = new Result<Map<String,String>>();
String phone = jsonObject.getString("phone"); String phone = jsonObject.getString("phone");
String smscode = jsonObject.getString("smscode"); String smscode = jsonObject.getString("smscode");
Object code = redisUtil.get(phone); Object code = RedisUtil.get(phone);
if (!smscode.equals(code)) { if (!smscode.equals(code)) {
result.setMessage("手机验证码错误"); result.setMessage("手机验证码错误");
result.setSuccess(false); result.setSuccess(false);
return result; return result;
} }
//设置有效时间 //设置有效时间
redisUtil.set(phone, smscode,600); RedisUtil.set(phone, smscode,600);
//新增查询用户名 //新增查询用户名
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>();
query.eq(SysUser::getPhone,phone); query.eq(SysUser::getPhone,phone);
...@@ -997,7 +997,7 @@ public class SysUserController { ...@@ -997,7 +997,7 @@ public class SysUserController {
} }
SysUser sysUser=new SysUser(); SysUser sysUser=new SysUser();
Object object= redisUtil.get(phone); Object object= RedisUtil.get(phone);
if(null==object) { if(null==object) {
result.setMessage("短信验证码失效!"); result.setMessage("短信验证码失效!");
result.setSuccess(false); result.setSuccess(false);
...@@ -1313,7 +1313,7 @@ public class SysUserController { ...@@ -1313,7 +1313,7 @@ public class SysUserController {
result.setSuccess(false); result.setSuccess(false);
return result; return result;
} }
Object object= redisUtil.get(phone); Object object= RedisUtil.get(phone);
if(null==object) { if(null==object) {
result.setMessage("短信验证码失效!"); result.setMessage("短信验证码失效!");
result.setSuccess(false); result.setSuccess(false);
......
...@@ -105,9 +105,9 @@ public class ThirdLoginController { ...@@ -105,9 +105,9 @@ public class ThirdLoginController {
} }
// 生成token // 生成token
String token = JwtUtil.sign(user.getUsername(), user.getPassword()); String token = JwtUtil.sign(user.getUsername(), user.getPassword());
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); RedisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
// 设置超时时间 // 设置超时时间
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000); RedisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000);
modelMap.addAttribute("token", token); modelMap.addAttribute("token", token);
//update-begin--Author:wangshuai Date:20200729 for:接口在签名校验失败时返回失败的标识码 issues#1441-------------------- //update-begin--Author:wangshuai Date:20200729 for:接口在签名校验失败时返回失败的标识码 issues#1441--------------------
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论