Commit b636afae by zhengnw@sobot.com

common 1.5.4 token登录时,如果 账号和token一样 token未过期 就代表已经登录成功,不用重新登录

parent 838ba1c7
...@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) { ...@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext { ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名 PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'sobotcommon' //项目名 PUBLISH_ARTIFACT_ID = 'sobotcommon' //项目名
PUBLISH_VERSION = '1.5.4' //版本号 PUBLISH_VERSION = '1.5.6' //版本号
} }
......
...@@ -166,7 +166,7 @@ public class SobotLoginTools { ...@@ -166,7 +166,7 @@ public class SobotLoginTools {
//判断是否已经登录 //判断是否已经登录
public boolean isLogin(String loginAccount) { public boolean isLogin(String loginAccount) {
//登录对象,客户对象不为空,登录账号和登录对象里边账号一样,token 不为空,token 没过期 才判定已经登录成功,其它情况都是没登录 //登录对象,客户对象不为空,登录账号和登录对象里边账号一样,token 不为空,token 没过期 才判定已经登录成功,其它情况都是没登录
if (getLoginUser() != null && getServiceInfo() != null && !TextUtils.isEmpty(loginAccount) && loginAccount.equals(getLoginUser().getLoginAccount()) && !SobotStringUtils.isEmpty(getLoginUser().getToken()) && checkExpiresToken()) { if (getLoginUser() != null && getServiceInfo() != null && !SobotStringUtils.isEmpty(loginAccount) && loginAccount.equals(getLoginUser().getLoginAccount()) && !SobotStringUtils.isEmpty(getLoginUser().getToken()) && checkExpiresToken()) {
return true; return true;
} else { } else {
return false; return false;
...@@ -175,8 +175,9 @@ public class SobotLoginTools { ...@@ -175,8 +175,9 @@ public class SobotLoginTools {
// 执行APP登录接口 // 执行APP登录接口
public void doAppLogin(final Object cancelTag, final Context mContext, final String host, final String openApiHost, long timeout, Map<String, Object> params, Map<String, String> headers, String loginAccount, final SobotResultBlock resultBlock) { public void doAppLogin(final Object cancelTag, final Context mContext, final String host, final String openApiHost, long timeout, Map<String, Object> params, Map<String, String> headers, final String loginAccount, final String loginPwd, final SobotResultBlock resultBlock) {
if (isLogin(loginAccount)) { if (isLogin(loginAccount)) {
SobotLogUtils.i("已经登录成功,不用重新登录");
if (resultBlock != null) { if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "已经登录成功", getLoginUser()); resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "已经登录成功", getLoginUser());
} }
...@@ -185,7 +186,7 @@ public class SobotLoginTools { ...@@ -185,7 +186,7 @@ public class SobotLoginTools {
SobotHttpUtils.doPost(cancelTag, host + "/chat-sdk/sdk/admin/v1/login.action", timeout, params, headers, new HttpBaseUtils.StringCallBack() { SobotHttpUtils.doPost(cancelTag, host + "/chat-sdk/sdk/admin/v1/login.action", timeout, params, headers, new HttpBaseUtils.StringCallBack() {
@Override @Override
public void onResponse(String result) { public void onResponse(String result) {
if (!TextUtils.isEmpty(result)) { if (!SobotStringUtils.isEmpty(result)) {
final SobotBaseCode<LoginUserEntity> baseModel = SobotGsonUtil.jsonToBeans(result, new com.sobot.gson.reflect.TypeToken<SobotBaseCode<LoginUserEntity>>() { final SobotBaseCode<LoginUserEntity> baseModel = SobotGsonUtil.jsonToBeans(result, new com.sobot.gson.reflect.TypeToken<SobotBaseCode<LoginUserEntity>>() {
}.getType()); }.getType());
if (baseModel != null) { if (baseModel != null) {
...@@ -211,9 +212,10 @@ public class SobotLoginTools { ...@@ -211,9 +212,10 @@ public class SobotLoginTools {
if (code == SobotResultCode.CODE_SUCCEEDED) { if (code == SobotResultCode.CODE_SUCCEEDED) {
LoginUserEntity tempUserEntity = userEntity; LoginUserEntity tempUserEntity = userEntity;
String accessToken = (String) obj; String accessToken = (String) obj;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setAccess_token(accessToken); tempUserEntity.setAccess_token(accessToken);
tempUserEntity.setLogin_time(System.currentTimeMillis()); tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAccount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity); setLoginUser(tempUserEntity);
if (resultBlock != null) { if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity); resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity);
...@@ -231,7 +233,11 @@ public class SobotLoginTools { ...@@ -231,7 +233,11 @@ public class SobotLoginTools {
} }
} }
} else { } else {
setLoginUser(userEntity); LoginUserEntity tempUserEntity = userEntity;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAccount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity);
if (resultBlock != null) { if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", userEntity); resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", userEntity);
} }
...@@ -273,9 +279,10 @@ public class SobotLoginTools { ...@@ -273,9 +279,10 @@ public class SobotLoginTools {
} }
// sdk 执行登录接口 会获取accesstoken // sdk 执行登录接口 会获取accesstoken
public void doLogin(final Object cancelTag, final Context mContext, final String host, final String openApiHost, String loginAcount, String loginPwd, String logintoken, final SobotResultBlock resultBlock) { public void doLogin(final Object cancelTag, final Context mContext, final String host, final String openApiHost, final String loginAcount, final String loginPwd, String logintoken, final SobotResultBlock resultBlock) {
if (SobotStringUtils.isEmpty(logintoken)) { if (SobotStringUtils.isEmpty(logintoken)) {
if (isLogin(loginAcount)) { if (isLogin(loginAcount)) {
SobotLogUtils.i("已经登录成功,不用重新登录");
if (resultBlock != null) { if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "已经登录成功", getLoginUser()); resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "已经登录成功", getLoginUser());
} }
...@@ -288,7 +295,7 @@ public class SobotLoginTools { ...@@ -288,7 +295,7 @@ public class SobotLoginTools {
@Override @Override
public void onResponse(String response) { public void onResponse(String response) {
SobotCallBaseCode result = SobotGsonUtil.jsonToBean(response, SobotCallBaseCode.class); SobotCallBaseCode result = SobotGsonUtil.jsonToBean(response, SobotCallBaseCode.class);
if (result != null && !TextUtils.isEmpty(result.getRetCode()) && "000000".equals(result.getRetCode()) && !SobotStringUtils.isEmpty(result.getItem())) { if (result != null && !SobotStringUtils.isEmpty(result.getRetCode()) && "000000".equals(result.getRetCode()) && !SobotStringUtils.isEmpty(result.getItem())) {
final LoginUserEntity userEntity = new LoginUserEntity(); final LoginUserEntity userEntity = new LoginUserEntity();
userEntity.setLogin_time(System.currentTimeMillis()); userEntity.setLogin_time(System.currentTimeMillis());
userEntity.setToken((String) result.getItem()); userEntity.setToken((String) result.getItem());
...@@ -311,9 +318,10 @@ public class SobotLoginTools { ...@@ -311,9 +318,10 @@ public class SobotLoginTools {
if (code == SobotResultCode.CODE_SUCCEEDED) { if (code == SobotResultCode.CODE_SUCCEEDED) {
LoginUserEntity tempUserEntity = userEntity; LoginUserEntity tempUserEntity = userEntity;
String accessToken = (String) obj; String accessToken = (String) obj;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setAccess_token(accessToken); tempUserEntity.setAccess_token(accessToken);
tempUserEntity.setLogin_time(System.currentTimeMillis()); tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAcount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity); setLoginUser(tempUserEntity);
if (resultBlock != null) { if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity); resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity);
...@@ -331,7 +339,11 @@ public class SobotLoginTools { ...@@ -331,7 +339,11 @@ public class SobotLoginTools {
} }
} }
} else { } else {
setLoginUser(userEntity); LoginUserEntity tempUserEntity = userEntity;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAcount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity);
if (resultBlock != null) { if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", userEntity); resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", userEntity);
} }
...@@ -366,6 +378,13 @@ public class SobotLoginTools { ...@@ -366,6 +378,13 @@ public class SobotLoginTools {
}); });
} else { } else {
if (isLogin(loginAcount) && getToken().equals(logintoken)) {
SobotLogUtils.i("账号和token一样 token未过期 已经登录成功,不用重新登录");
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "已经登录成功", getLoginUser());
}
return;
}
final LoginUserEntity userEntity = new LoginUserEntity(); final LoginUserEntity userEntity = new LoginUserEntity();
userEntity.setLogin_time(System.currentTimeMillis()); userEntity.setLogin_time(System.currentTimeMillis());
userEntity.setToken(logintoken); userEntity.setToken(logintoken);
...@@ -388,9 +407,10 @@ public class SobotLoginTools { ...@@ -388,9 +407,10 @@ public class SobotLoginTools {
if (code == SobotResultCode.CODE_SUCCEEDED) { if (code == SobotResultCode.CODE_SUCCEEDED) {
LoginUserEntity tempUserEntity = userEntity; LoginUserEntity tempUserEntity = userEntity;
String accessToken = (String) obj; String accessToken = (String) obj;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setAccess_token(accessToken); tempUserEntity.setAccess_token(accessToken);
tempUserEntity.setLogin_time(System.currentTimeMillis()); tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAcount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity); setLoginUser(tempUserEntity);
if (resultBlock != null) { if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity); resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity);
...@@ -408,7 +428,11 @@ public class SobotLoginTools { ...@@ -408,7 +428,11 @@ public class SobotLoginTools {
} }
} }
} else { } else {
setLoginUser(userEntity); LoginUserEntity tempUserEntity = userEntity;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAcount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity);
if (resultBlock != null) { if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", userEntity); resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", userEntity);
} }
...@@ -438,16 +462,16 @@ public class SobotLoginTools { ...@@ -438,16 +462,16 @@ public class SobotLoginTools {
public void getLoginUserInfo(final Object cancelTag, final Context mContext, final String host, String token, String language, final SobotResultBlock resultBlock) { public void getLoginUserInfo(final Object cancelTag, final Context mContext, final String host, String token, String language, final SobotResultBlock resultBlock) {
final String url = host + "/basic-config-service/consoleAuth/queryAppAgentMenus"; final String url = host + "/basic-config-service/consoleAuth/queryAppAgentMenus";
Map<String, String> headerMap = new HashMap<>(); Map<String, String> headerMap = new HashMap<>();
if (!TextUtils.isEmpty(token)) { if (!SobotStringUtils.isEmpty(token)) {
headerMap.put("temp-id", token); headerMap.put("temp-id", token);
} }
if (!TextUtils.isEmpty(language)) { if (!SobotStringUtils.isEmpty(language)) {
headerMap.put("language", language); headerMap.put("language", language);
} }
SobotHttpUtils.doGet(cancelTag, url, null, headerMap, new HttpBaseUtils.StringCallBack() { SobotHttpUtils.doGet(cancelTag, url, null, headerMap, new HttpBaseUtils.StringCallBack() {
@Override @Override
public void onResponse(String result) { public void onResponse(String result) {
if (!TextUtils.isEmpty(result)) { if (!SobotStringUtils.isEmpty(result)) {
try { try {
org.json.JSONObject resonseObj = new org.json.JSONObject(result); org.json.JSONObject resonseObj = new org.json.JSONObject(result);
String retCode = resonseObj.optString("retCode"); String retCode = resonseObj.optString("retCode");
...@@ -535,13 +559,13 @@ public class SobotLoginTools { ...@@ -535,13 +559,13 @@ public class SobotLoginTools {
public void doAccessToken(Object cancelTag, String host, String token, final SobotResultBlock resultBlock) { public void doAccessToken(Object cancelTag, String host, String token, final SobotResultBlock resultBlock) {
Map<String, String> headerMap = new HashMap<>(); Map<String, String> headerMap = new HashMap<>();
if (!TextUtils.isEmpty(token)) { if (!SobotStringUtils.isEmpty(token)) {
headerMap.put("temp-id", token); headerMap.put("temp-id", token);
} }
SobotHttpUtils.doPost(cancelTag, host + "/tokens/getToken", null, headerMap, new HttpBaseUtils.StringCallBack() { SobotHttpUtils.doPost(cancelTag, host + "/tokens/getToken", null, headerMap, new HttpBaseUtils.StringCallBack() {
@Override @Override
public void onResponse(String result) { public void onResponse(String result) {
if (!TextUtils.isEmpty(result)) { if (!SobotStringUtils.isEmpty(result)) {
Map map = SobotGsonUtil.jsonToMaps((String) result); Map map = SobotGsonUtil.jsonToMaps((String) result);
if (map != null && map.containsKey("accessToken")) { if (map != null && map.containsKey("accessToken")) {
String accessToken = (String) map.get("accessToken"); String accessToken = (String) map.get("accessToken");
......
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