|
@@ -5,7 +5,9 @@ import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.auth0.jwt.JWTCreator;
|
|
import com.auth0.jwt.JWTCreator;
|
|
|
import com.auth0.jwt.algorithms.Algorithm;
|
|
import com.auth0.jwt.algorithms.Algorithm;
|
|
|
|
|
+import com.takai.common.enums.UserTypeEnum;
|
|
|
import com.takai.common.utils.DateUtils;
|
|
import com.takai.common.utils.DateUtils;
|
|
|
|
|
+import com.takai.common.utils.SecurityUtils;
|
|
|
import com.takai.common.utils.StringUtils;
|
|
import com.takai.common.utils.StringUtils;
|
|
|
import com.takai.system.service.IJkApiService;
|
|
import com.takai.system.service.IJkApiService;
|
|
|
import com.takai.common.annotation.DataSource;
|
|
import com.takai.common.annotation.DataSource;
|
|
@@ -75,6 +77,8 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
|
|
|
|
|
public static final String PARAM_CODE = "code";
|
|
public static final String PARAM_CODE = "code";
|
|
|
|
|
|
|
|
|
|
+ public static final String PARAM_REDIRECT_URI = "redirect_uri";
|
|
|
|
|
+
|
|
|
public static final String PARAM_ACCESS_TOKEN = "access_token";
|
|
public static final String PARAM_ACCESS_TOKEN = "access_token";
|
|
|
|
|
|
|
|
public static final String PARAM_IDS = "ids";
|
|
public static final String PARAM_IDS = "ids";
|
|
@@ -95,6 +99,8 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
|
|
|
|
|
public static final String GRANT_TYPE_AC = "authorization_code";
|
|
public static final String GRANT_TYPE_AC = "authorization_code";
|
|
|
|
|
|
|
|
|
|
+ public static final int BEFORE_DAYS = 1000;
|
|
|
|
|
+
|
|
|
private static final MediaType JSON_UTF8 = MediaType.get("application/json; charset=utf-8");
|
|
private static final MediaType JSON_UTF8 = MediaType.get("application/json; charset=utf-8");
|
|
|
|
|
|
|
|
private static final OkHttpClient client = new OkHttpClient();
|
|
private static final OkHttpClient client = new OkHttpClient();
|
|
@@ -128,11 +134,12 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
//建科用户状态,启用:1,停用:0,删除:-1
|
|
//建科用户状态,启用:1,停用:0,删除:-1
|
|
|
String status = json.getString("app_account__status");
|
|
String status = json.getString("app_account__status");
|
|
|
status = status.equals("1") ? "0" : "1";
|
|
status = status.equals("1") ? "0" : "1";
|
|
|
- sysUser.setStatus("1");
|
|
|
|
|
|
|
+ sysUser.setStatus(status);
|
|
|
sysUser.setPhonenumber(json.getString("idt_user__mobile"));
|
|
sysUser.setPhonenumber(json.getString("idt_user__mobile"));
|
|
|
sysUser.setWorkNo(json.getString("idt_user__work_no"));
|
|
sysUser.setWorkNo(json.getString("idt_user__work_no"));
|
|
|
sysUser.setEmail(json.getString("idt_user__email"));
|
|
sysUser.setEmail(json.getString("idt_user__email"));
|
|
|
- sysUser.setUserType("01");//建科用户
|
|
|
|
|
|
|
+ sysUser.setUserType(UserTypeEnum.JK_USER.getCode());//建科用户
|
|
|
|
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(jkConfig.getJkPsw()));
|
|
|
JSONArray orgs = json.getJSONArray("orgs");
|
|
JSONArray orgs = json.getJSONArray("orgs");
|
|
|
if(orgs.size() > 0) {
|
|
if(orgs.size() > 0) {
|
|
|
sysUser.setDeptId(orgs.getJSONObject(0).getLong("idt_org__id"));
|
|
sysUser.setDeptId(orgs.getJSONObject(0).getLong("idt_org__id"));
|
|
@@ -164,7 +171,7 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
SysDept sysDept = new SysDept();
|
|
SysDept sysDept = new SysDept();
|
|
|
JSONObject json = jsonArray.getJSONObject(i);
|
|
JSONObject json = jsonArray.getJSONObject(i);
|
|
|
sysDept.setDeptId(json.getLong("idt_org__id"));
|
|
sysDept.setDeptId(json.getLong("idt_org__id"));
|
|
|
- sysDept.setDeptName(json.getString("idt_org__org_name"));
|
|
|
|
|
|
|
+ sysDept.setDeptName(json.getString("idt_org__name"));
|
|
|
sysDept.setParentId(json.getLong("idt_org__parent_id"));
|
|
sysDept.setParentId(json.getLong("idt_org__parent_id"));
|
|
|
sysDept.setAncestors(json.getString("idt_org__org_path").substring(1).replaceAll("/",","));
|
|
sysDept.setAncestors(json.getString("idt_org__org_path").substring(1).replaceAll("/",","));
|
|
|
//部门状态,启用:1,停用:0
|
|
//部门状态,启用:1,停用:0
|
|
@@ -287,11 +294,11 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Map<String, Object> getJkToken(String code) throws IOException {
|
|
|
|
|
|
|
+ public Map<String, Object> getJkToken(String code, String redirectUrl) throws IOException {
|
|
|
String token = "";
|
|
String token = "";
|
|
|
JSONObject userJson = null;
|
|
JSONObject userJson = null;
|
|
|
try {
|
|
try {
|
|
|
- Request request = buildTokenRequest(code);
|
|
|
|
|
|
|
+ Request request = buildTokenRequest(code, redirectUrl);
|
|
|
Response response = client.newCall(request).execute();
|
|
Response response = client.newCall(request).execute();
|
|
|
String responseBody = response.body().string();
|
|
String responseBody = response.body().string();
|
|
|
logger.info("获取建科token返回信息:" + responseBody);
|
|
logger.info("获取建科token返回信息:" + responseBody);
|
|
@@ -304,7 +311,7 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
if(!StringUtils.isEmpty(token)) {
|
|
if(!StringUtils.isEmpty(token)) {
|
|
|
//token 换取用户信息
|
|
//token 换取用户信息
|
|
|
Request pReq = buildProfileRequest(token);
|
|
Request pReq = buildProfileRequest(token);
|
|
|
- Response pResp = client.newCall(request).execute();
|
|
|
|
|
|
|
+ Response pResp = client.newCall(pReq).execute();
|
|
|
String pRespBody = pResp.body().string();
|
|
String pRespBody = pResp.body().string();
|
|
|
if (!pResp.isSuccessful()) {
|
|
if (!pResp.isSuccessful()) {
|
|
|
throw new IOException("token换取建科用户信息失败 " + pRespBody);
|
|
throw new IOException("token换取建科用户信息失败 " + pRespBody);
|
|
@@ -321,8 +328,8 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
}
|
|
}
|
|
|
JSONObject attrs = userJson.getJSONObject("attributes");
|
|
JSONObject attrs = userJson.getJSONObject("attributes");
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("userId", attrs.getString("sysadmintest"));
|
|
|
|
|
- map.put("nickName", attrs.getString("sysadmintest"));
|
|
|
|
|
|
|
+ map.put("userId", attrs.getString("account_no"));
|
|
|
|
|
+ map.put("nickName", attrs.getString("account_no"));
|
|
|
map.put("token", token);
|
|
map.put("token", token);
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
@@ -336,7 +343,7 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
|
|
|
|
|
private Request buildRequest(String url,int page) {
|
|
private Request buildRequest(String url,int page) {
|
|
|
Map<String, Object> requestBodyMap = new HashMap<>();
|
|
Map<String, Object> requestBodyMap = new HashMap<>();
|
|
|
- requestBodyMap.put(PARAM_ST, getStartTime());
|
|
|
|
|
|
|
+ requestBodyMap.put(PARAM_ST, getStartTimeBeforeDays(BEFORE_DAYS));
|
|
|
requestBodyMap.put(PARAM_PAGE, page);
|
|
requestBodyMap.put(PARAM_PAGE, page);
|
|
|
requestBodyMap.put(PARAM_SIZE, DEFAULT_SIZE);
|
|
requestBodyMap.put(PARAM_SIZE, DEFAULT_SIZE);
|
|
|
// 将 Map 转换为 JSON 字符串
|
|
// 将 Map 转换为 JSON 字符串
|
|
@@ -355,24 +362,22 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
return request;
|
|
return request;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Request buildTokenRequest(String code) {
|
|
|
|
|
- Map<String, Object> requestBodyMap = new HashMap<>();
|
|
|
|
|
- requestBodyMap.put(PARAM_GRANT_TYPE, GRANT_TYPE_AC);
|
|
|
|
|
- requestBodyMap.put(PARAM_CLIENT_ID, jkConfig.getIamClientID());
|
|
|
|
|
- requestBodyMap.put(PARAM_CLIENT_SECRET, jkConfig.getIamClientSecret());
|
|
|
|
|
- requestBodyMap.put(PARAM_CODE, code);
|
|
|
|
|
- // 将 Map 转换为 JSON 字符串
|
|
|
|
|
- String requestBodyJson = JSON.toJSONString(requestBodyMap);
|
|
|
|
|
|
|
+ private Request buildTokenRequest(String code, String redirectUrl) {
|
|
|
|
|
+ String completeUrl = jkConfig.getIamTokenUrl() + "?" +PARAM_GRANT_TYPE + "=" + GRANT_TYPE_AC
|
|
|
|
|
+ + "&" +PARAM_CLIENT_ID + "=" + jkConfig.getIamClientID()
|
|
|
|
|
+ + "&" +PARAM_CLIENT_SECRET + "=" + jkConfig.getIamClientSecret()
|
|
|
|
|
+ + "&" +PARAM_CODE + "=" + code
|
|
|
|
|
+ + "&" +PARAM_REDIRECT_URI + "=" + redirectUrl;
|
|
|
|
|
|
|
|
// 构建请求体
|
|
// 构建请求体
|
|
|
- RequestBody body = RequestBody.create(JSON_UTF8,requestBodyJson);
|
|
|
|
|
|
|
+ RequestBody body = RequestBody.create(JSON_UTF8,"");
|
|
|
Request request = new Request.Builder()
|
|
Request request = new Request.Builder()
|
|
|
.addHeader("accept", "*/*")
|
|
.addHeader("accept", "*/*")
|
|
|
.addHeader("Content-Type", "application/json")
|
|
.addHeader("Content-Type", "application/json")
|
|
|
.post(body)
|
|
.post(body)
|
|
|
- .url(jkConfig.getIamTokenUrl()).get().build();
|
|
|
|
|
|
|
+ .url(completeUrl).build();
|
|
|
logger.info("code换取token接口请求head:{}", request.headers().toString());
|
|
logger.info("code换取token接口请求head:{}", request.headers().toString());
|
|
|
- logger.info("code换取token接口请求body:{}", request.body().toString());
|
|
|
|
|
|
|
+ logger.info("code换取token接口请求url:{}", completeUrl);
|
|
|
return request;
|
|
return request;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -392,7 +397,7 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
.post(body)
|
|
.post(body)
|
|
|
.url(jkConfig.getIamCallbackUrl()).build();
|
|
.url(jkConfig.getIamCallbackUrl()).build();
|
|
|
logger.info("回调接口请求head:{}", request.headers().toString());
|
|
logger.info("回调接口请求head:{}", request.headers().toString());
|
|
|
- logger.info("回调接口请求body:{}", request.body().toString());
|
|
|
|
|
|
|
+ logger.info("回调接口请求body:{}", requestBodyJson);
|
|
|
return request;
|
|
return request;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -403,15 +408,16 @@ public class JkApiServiceImpl implements IJkApiService {
|
|
|
String url = urlBuilder.build().toString();
|
|
String url = urlBuilder.build().toString();
|
|
|
Request request = new Request.Builder()
|
|
Request request = new Request.Builder()
|
|
|
.url(url)
|
|
.url(url)
|
|
|
|
|
+ .get()
|
|
|
.build();
|
|
.build();
|
|
|
|
|
|
|
|
logger.info("token获取用户信息请求url", url);
|
|
logger.info("token获取用户信息请求url", url);
|
|
|
return request;
|
|
return request;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private String getStartTime() {
|
|
|
|
|
|
|
+ private String getStartTimeBeforeDays(int days) {
|
|
|
//7天内数据
|
|
//7天内数据
|
|
|
- return String.valueOf(DateUtils.getTimeBeforeDays(7));
|
|
|
|
|
|
|
+ return String.valueOf(DateUtils.getTimeBeforeDays(days));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private boolean isJsonObject(String data) {
|
|
private boolean isJsonObject(String data) {
|