|
@@ -61,7 +61,7 @@ public class HuaduDocServiceImpl implements IHuaduDocService{
|
|
OrgPersonBean person = orgManager.findPersonByIdNoClone(userId);
|
|
OrgPersonBean person = orgManager.findPersonByIdNoClone(userId);
|
|
OrgPrincipal principal = principalService.getPrincipalByPersonId(person.getId());
|
|
OrgPrincipal principal = principalService.getPrincipalByPersonId(person.getId());
|
|
//获取全局通用的token()
|
|
//获取全局通用的token()
|
|
- String token = getToken(config, null);
|
|
|
|
|
|
+ String token = getToken(config);
|
|
if(StringUtils.isEmpty(token)){
|
|
if(StringUtils.isEmpty(token)){
|
|
log.error("获取通用token失败!");
|
|
log.error("获取通用token失败!");
|
|
return null;
|
|
return null;
|
|
@@ -76,11 +76,8 @@ public class HuaduDocServiceImpl implements IHuaduDocService{
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- String urlToken = getToken(config, principal.getUsername());
|
|
|
|
- if(StringUtils.isEmpty(urlToken)){
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- return MessageFormat.format("{0}/home?token={1}", config.getUrl(), urlToken);
|
|
|
|
|
|
+ return MessageFormat.format("{0}/home?token={1}&loginName={2}", config.getUrl(), token,
|
|
|
|
+ encrypt(principal.getUsername()));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -100,11 +97,11 @@ public class HuaduDocServiceImpl implements IHuaduDocService{
|
|
// 解析响应体
|
|
// 解析响应体
|
|
String body = execute.body();
|
|
String body = execute.body();
|
|
return "false".equals(body);
|
|
return "false".equals(body);
|
|
-// if(StringUtils.isNotEmpty(body)){
|
|
|
|
-// JSONObject entries = JSONUtil.parseObj(body);
|
|
|
|
-// // 检查响应是否有效,并返回用户存在状态
|
|
|
|
-// return entries != null && 200 == entries.getInt("code") && entries.getBool("data", false);
|
|
|
|
-// }
|
|
|
|
|
|
+ // if(StringUtils.isNotEmpty(body)){
|
|
|
|
+ // JSONObject entries = JSONUtil.parseObj(body);
|
|
|
|
+ // // 检查响应是否有效,并返回用户存在状态
|
|
|
|
+ // return entries != null && 200 == entries.getInt("code") && entries.getBool("data", false);
|
|
|
|
+ // }
|
|
}
|
|
}
|
|
// 如果请求失败或响应无效,返回false
|
|
// 如果请求失败或响应无效,返回false
|
|
//return false;
|
|
//return false;
|
|
@@ -157,21 +154,16 @@ public class HuaduDocServiceImpl implements IHuaduDocService{
|
|
/**
|
|
/**
|
|
* 获取用户令牌
|
|
* 获取用户令牌
|
|
*
|
|
*
|
|
- * @param config 配置信息,包含访问所需的URL等
|
|
|
|
- * @param username 用户名
|
|
|
|
|
|
+ * @param config 配置信息,包含访问所需的URL等
|
|
* @return 用户的令牌,如果获取失败返回null
|
|
* @return 用户的令牌,如果获取失败返回null
|
|
*/
|
|
*/
|
|
- private static String getToken(HuaduConfig config, String username){
|
|
|
|
|
|
+ private static String getToken(HuaduConfig config){
|
|
// 构造获取令牌的URL
|
|
// 构造获取令牌的URL
|
|
String url = MessageFormat.format("{0}/getToken", config.getApiUrl());
|
|
String url = MessageFormat.format("{0}/getToken", config.getApiUrl());
|
|
// 构造请求体
|
|
// 构造请求体
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("appName", config.getAppName());
|
|
map.put("appName", config.getAppName());
|
|
map.put("secret", config.getAppSecret());
|
|
map.put("secret", config.getAppSecret());
|
|
- // 如果提供了用户名,则添加到请求体中
|
|
|
|
- if(StringUtils.isNotEmpty(username)){
|
|
|
|
- map.put("loginName", encrypt(username));
|
|
|
|
- }
|
|
|
|
// 发送请求并获取响应
|
|
// 发送请求并获取响应
|
|
String token = null;
|
|
String token = null;
|
|
try(HttpResponse execute = HttpRequest.of(url).method(Method.POST).form(map)
|
|
try(HttpResponse execute = HttpRequest.of(url).method(Method.POST).form(map)
|
|
@@ -215,17 +207,13 @@ public class HuaduDocServiceImpl implements IHuaduDocService{
|
|
String encryptedStr = Base64.getEncoder().encodeToString(encryptedBytes);
|
|
String encryptedStr = Base64.getEncoder().encodeToString(encryptedBytes);
|
|
|
|
|
|
// 替换特殊字符以避免传输问题
|
|
// 替换特殊字符以避免传输问题
|
|
- //String val = encryptedStr.replace("#", "%23").replace("%", "%25").replace("&", "%26").replace("+", "%2B")
|
|
|
|
- // .replace("/", "%2F").replace("?", "%3F");
|
|
|
|
|
|
+ String val = encryptedStr.replace("#", "%23").replace("%", "%25").replace("&", "%26").replace("+", "%2B")
|
|
|
|
+ .replace("/", "%2F").replace("?", "%3F");
|
|
|
|
|
|
- return encryptedStr;
|
|
|
|
|
|
+ return val;
|
|
} catch(Exception e){
|
|
} catch(Exception e){
|
|
throw new BusinessException("加密出错!", e);
|
|
throw new BusinessException("加密出错!", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static void main(String[] args){
|
|
|
|
- System.out.println(encrypt("13911778917"));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|