Commit 8d9cfeda by 郭倩芳

common 统一鉴权

parent 17582067
......@@ -210,7 +210,7 @@ public class SobotLoginTools {
* @param paramsMap 单独执行在线登录逻辑 参数
* @param resultBlock
*/
public void doLogin(final Object cancelTag, final Context mContext, final boolean isAppOrOnlineLogin, final String host, final String openApiHost, final String loginAcount, final String loginPwd,String factorVerifyCode, final Map<String, Object> paramsMap, final SobotResultBlock resultBlock) {
public void doLogin(final Object cancelTag, final Context mContext, final boolean isAppOrOnlineLogin, final String host, final String openApiHost, final String loginAcount, final String loginPwd, String factorVerifyCode, final Map<String, Object> paramsMap, final SobotResultBlock resultBlock) {
if (SobotStringUtils.isEmpty(host)) {
SobotLogUtils.i("host 域名不能为空");
if (resultBlock != null) {
......@@ -231,7 +231,7 @@ public class SobotLoginTools {
params.put("version", paramsMap.get("version"));
params.put("loginUser", loginAcount);
params.put("loginPwd", loginPwd);
if(SobotStringUtils.isNoEmpty(factorVerifyCode)) {
if (SobotStringUtils.isNoEmpty(factorVerifyCode)) {
params.put("factorVerifyCode", factorVerifyCode);
}
SobotHttpUtils.doPost(cancelTag, host + "/basic-login/serviceAppLogin/4", 8000, params, headerMap, new HttpBaseUtils.StringCallBack() {
......@@ -251,46 +251,7 @@ public class SobotLoginTools {
serviceInfoModel.setToken(token);
serviceInfoModel.setLoginAccount(loginAcount);
serviceInfoModel.setLoginPwd(loginPwd);
if ((serviceInfoModel.getCallV6Flag() == 1 || SobotPermissionManager.isHasNewPermission(SobotPermissionManager.SCC))) {
//如果是v6呼叫
String tempHost = openApiHost;
if (tempHost.contains("/text")) {
tempHost = tempHost.replace("/text", "");
}
final SobotServiceInfoModel tempServiceInfoModel = serviceInfoModel;
doAccessToken(cancelTag, tempHost, serviceInfoModel.getToken(), new SobotResultBlock() {
@Override
public void resultBolok(SobotResultCode code, String msg, Object obj) {
if (code == SobotResultCode.CODE_SUCCEEDED) {
SobotServiceInfoModel tempUserEntity = tempServiceInfoModel;
if (obj != null && obj instanceof String && SobotStringUtils.isNoEmpty((String) obj)) {
String accessToken = (String) obj;
tempUserEntity.setAccess_token(accessToken);
//判断是否有对话功能
if (SobotPermissionManager.checkPermission(SobotPermissionApi.USER_PERMISSION_TYPE_TALK) && isAppOrOnlineLogin) {
getAdminStatus(cancelTag, mContext, host, paramsMap, tempUserEntity, resultBlock);
} else {
setServiceInfo(tempUserEntity);
SobotSharedPreferencesUtil.getInstance(mContext).put(SobotLoginConstant.SOBOT_LOGIN_USER_INFO, tempUserEntity);
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity);
}
}
} else {
SobotLogUtils.i("accessToken获取失败");
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempServiceInfoModel);
}
}
} else {
SobotLogUtils.i("accessToken获取失败");
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempServiceInfoModel);
}
}
}
});
} else {
//判断是否有对话功能
if (SobotPermissionManager.checkPermission(SobotPermissionApi.USER_PERMISSION_TYPE_TALK) && isAppOrOnlineLogin) {
getAdminStatus(cancelTag, mContext, host, paramsMap, serviceInfoModel, resultBlock);
......@@ -301,7 +262,6 @@ public class SobotLoginTools {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", serviceInfoModel);
}
}
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
......@@ -402,46 +362,7 @@ public class SobotLoginTools {
serviceInfoModel.setLogin_time(login_time);
serviceInfoModel.setToken(token);
serviceInfoModel.setLoginAccount(loginAcount);
if ((serviceInfoModel.getCallV6Flag() == 1 || SobotPermissionManager.isHasNewPermission(SobotPermissionManager.SCC))) {
//如果是v6呼叫
String tempHost = openApiHost;
if (tempHost.contains("/text")) {
tempHost = tempHost.replace("/text", "");
}
final SobotServiceInfoModel tempServiceInfoModel = serviceInfoModel;
doAccessToken(cancelTag, tempHost, serviceInfoModel.getToken(), new SobotResultBlock() {
@Override
public void resultBolok(SobotResultCode code, String msg, Object obj) {
if (code == SobotResultCode.CODE_SUCCEEDED) {
SobotServiceInfoModel tempUserEntity = tempServiceInfoModel;
if (obj != null && obj instanceof String && SobotStringUtils.isNoEmpty((String) obj)) {
String accessToken = (String) obj;
tempUserEntity.setAccess_token(accessToken);
//判断是否有对话功能
if (SobotPermissionManager.checkPermission(SobotPermissionApi.USER_PERMISSION_TYPE_TALK) && isAppOrOnlineLogin) {
getAdminStatus(cancelTag, mContext, host, paramsMap, tempUserEntity, resultBlock);
} else {
setServiceInfo(tempUserEntity);
SobotSharedPreferencesUtil.getInstance(mContext).put(SobotLoginConstant.SOBOT_LOGIN_USER_INFO, tempUserEntity);
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity);
}
}
} else {
SobotLogUtils.i("accessToken获取失败");
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempServiceInfoModel);
}
}
} else {
SobotLogUtils.i("accessToken获取失败");
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempServiceInfoModel);
}
}
}
});
} else {
//判断是否有对话功能
if (SobotPermissionManager.checkPermission(SobotPermissionApi.USER_PERMISSION_TYPE_TALK) && isAppOrOnlineLogin) {
getAdminStatus(cancelTag, mContext, host, paramsMap, serviceInfoModel, resultBlock);
......@@ -452,7 +373,6 @@ public class SobotLoginTools {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", serviceInfoModel);
}
}
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
......@@ -557,46 +477,7 @@ public class SobotLoginTools {
serviceInfoModel.setLogin_time(login_time);
serviceInfoModel.setToken(token);
serviceInfoModel.setLoginAccount(loginAcount);
if ((serviceInfoModel.getCallV6Flag() == 1 || SobotPermissionManager.isHasNewPermission(SobotPermissionManager.SCC))) {
//如果是v6呼叫
String tempHost = openApiHost;
if (tempHost.contains("/text")) {
tempHost = tempHost.replace("/text", "");
}
final SobotServiceInfoModel tempServiceInfoModel = serviceInfoModel;
doAccessToken(cancelTag, tempHost, serviceInfoModel.getToken(), new SobotResultBlock() {
@Override
public void resultBolok(SobotResultCode code, String msg, Object obj) {
if (code == SobotResultCode.CODE_SUCCEEDED) {
SobotServiceInfoModel tempUserEntity = tempServiceInfoModel;
if (obj != null && obj instanceof String && SobotStringUtils.isNoEmpty((String) obj)) {
String accessToken = (String) obj;
tempUserEntity.setAccess_token(accessToken);
//判断是否有对话功能
if (SobotPermissionManager.checkPermission(SobotPermissionApi.USER_PERMISSION_TYPE_TALK) && isAppOrOnlineLogin) {
getAdminStatus(cancelTag, mContext, host, paramsMap, tempUserEntity, resultBlock);
} else {
setServiceInfo(tempUserEntity);
SobotSharedPreferencesUtil.getInstance(mContext).put(SobotLoginConstant.SOBOT_LOGIN_USER_INFO, tempUserEntity);
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity);
}
}
} else {
SobotLogUtils.i("accessToken获取失败");
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempServiceInfoModel);
}
}
} else {
SobotLogUtils.i("accessToken获取失败");
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempServiceInfoModel);
}
}
}
});
} else {
//判断是否有对话功能
if (SobotPermissionManager.checkPermission(SobotPermissionApi.USER_PERMISSION_TYPE_TALK) && isAppOrOnlineLogin) {
getAdminStatus(cancelTag, mContext, host, paramsMap, serviceInfoModel, resultBlock);
......@@ -607,7 +488,6 @@ public class SobotLoginTools {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", serviceInfoModel);
}
}
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
......@@ -653,7 +533,7 @@ public class SobotLoginTools {
}
if (!isLogin(loginAcount)) {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED ,"上次登录的保存信息为空,不用再次退出登录", null);
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "上次登录的保存信息为空,不用再次退出登录", null);
}
return;
}
......@@ -661,6 +541,7 @@ public class SobotLoginTools {
params.put("loginUser", loginAcount);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("temp-id", getToken());
headerParams.put("authorization","Bearer "+ getToken());
headerParams.put("from", "2");
SobotHttpUtils.doPost(cancelTag, host + "/basic-login/serviceLogOut/4", 8000, params, headerParams, new HttpBaseUtils.StringCallBack() {
@Override
......@@ -708,6 +589,7 @@ public class SobotLoginTools {
Map<String, String> headerMap = new HashMap<>();
if (!SobotStringUtils.isEmpty(token)) {
headerMap.put("temp-id", token);
headerMap.put("authorization","Bearer "+ token);
}
if (!SobotStringUtils.isEmpty(language)) {
headerMap.put("language", language);
......@@ -803,69 +685,17 @@ public class SobotLoginTools {
}
}
/**
* 获取accessToken
*/
public void doAccessToken(Object cancelTag, String host, String token,
final SobotResultBlock resultBlock) {
Map<String, String> headerMap = new HashMap<>();
if (!SobotStringUtils.isEmpty(token)) {
headerMap.put("temp-id", token);
}
if (SobotStringUtils.isEmpty(host)) {
//获取accessToken 默认用腾讯云域名
host = "https://api-c.soboten.com";
}
headerMap.put("from", "2");
SobotHttpUtils.doPost(cancelTag, host + "/tokens/getToken", null, headerMap, new HttpBaseUtils.StringCallBack() {
@Override
public void onResponse(String result) {
if (!SobotStringUtils.isEmpty(result)) {
Map map = SobotGsonUtil.jsonToMaps((String) result);
if (map != null && map.containsKey("accessToken")) {
String accessToken = (String) map.get("accessToken");
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "", accessToken);
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "", null);
}
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "", null);
}
}
}
@Override
public void onError(Exception e, String msg, int responseCode) {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, msg, null);
}
}
@Override
public void inProgress(int progress) {
}
});
}
/**
* 如果是智齿客服APP 或者客服SDK 并且有对话模块,获取在线状态
*/
public void getAdminStatus(Object cancelTag, final Context context, String host, Map<String, Object> params, final SobotServiceInfoModel infoModel, final SobotResultBlock resultBlock) {
if (infoModel != null) {
Map<String, String> headerMap = new HashMap<>();
headerMap.put("token", SobotStringUtils.checkStringIsNull(infoModel.getToken()));
headerMap.put("authorization", "Bearer " + SobotStringUtils.checkStringIsNull(infoModel.getToken()));
headerMap.put("temp-id", SobotStringUtils.checkStringIsNull(infoModel.getToken()));
headerMap.put("language", SobotStringUtils.checkStringIsNull(infoModel.getServiceLanguage()));
headerMap.put("from", "2");
SobotHttpUtils.doGet(cancelTag, host + "/chat-sdk/sdk/admin/v1/appEnter", 8000, params, headerMap, new HttpBaseUtils.StringCallBack() {
SobotHttpUtils.doGet(cancelTag, host + "/chat-sdk/sdk/admin/v2/appEnter", 8000, params, headerMap, new HttpBaseUtils.StringCallBack() {
@Override
public void onResponse(String result) {
if (!SobotStringUtils.isEmpty(result)) {
......@@ -884,9 +714,9 @@ public class SobotLoginTools {
tempServiceInfoModel.setKbVersion(SobotStringUtils.checkStringIsNull(userEntity.getKbVersion()));
tempServiceInfoModel.setRobotVersion(SobotStringUtils.checkStringIsNull(userEntity.getRobotVersion()));
tempServiceInfoModel.setOnlineVersion(SobotStringUtils.checkStringIsNull(userEntity.getOnlineVersion()));
if(userEntity.getStatus()==2){
if (userEntity.getStatus() == 2) {
tempServiceInfoModel.setStatus(userEntity.getStatusCode());
}else {
} else {
tempServiceInfoModel.setStatus(userEntity.getStatus());
}
tempServiceInfoModel.setFuseWork(userEntity.getFuseWork());
......
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