Commit 01c647f6 by zhengnw@sobot.com

common 1.5.7

parent b4372306
......@@ -11,7 +11,7 @@ android {
//这里就是打jar包
task makeJar(type: Copy) {
//删除旧的jar包
delete 'build/libs/sobot_common_1.5.3.jar'
delete 'build/libs/sobot_common_1.5.7.jar'
//原地址
from('build/intermediates/packaged-classes/release/')
//导出jar包的地址
......@@ -19,7 +19,7 @@ android {
//包含的jar包
include('classes.jar')
//重命名jar包为mysdk
rename ('classes.jar', 'sobot_common_1.5.3.jar')
rename ('classes.jar', 'sobot_common_1.5.7.jar')
}
makeJar.dependsOn(build)
}
......
......@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'sobotcommon_x' //项目名
PUBLISH_VERSION = '1.5.3' //版本号
PUBLISH_VERSION = '1.5.7' //版本号
}
......
......@@ -39,7 +39,7 @@ public class SobotLoginTools {
}
public static SobotLoginTools getInstance() {
return SobotLoginTools.SobotLoginToolsHolder.instance;
return SobotLoginToolsHolder.instance;
}
private static class SobotLoginToolsHolder {
......@@ -155,7 +155,18 @@ public class SobotLoginTools {
}
public boolean isLogin() {
if (getLoginUser() != null && !SobotStringUtils.isEmpty(getLoginUser().getToken()) && checkExpiresToken()) {
//登录对象,客户对象不为空,token 不为空,token 没过期 才判定已经登录成功,其它情况都是没登录
if (getLoginUser() != null && getServiceInfo() != null && !SobotStringUtils.isEmpty(getLoginUser().getToken()) && checkExpiresToken()) {
return true;
} else {
return false;
}
}
//判断是否已经登录
public boolean isLogin(String loginAccount) {
//登录对象,客户对象不为空,登录账号和登录对象里边账号一样,token 不为空,token 没过期 才判定已经登录成功,其它情况都是没登录
if (getLoginUser() != null && getServiceInfo() != null && !SobotStringUtils.isEmpty(loginAccount) && loginAccount.equals(getLoginUser().getLoginAccount()) && !SobotStringUtils.isEmpty(getLoginUser().getToken()) && checkExpiresToken()) {
return true;
} else {
return false;
......@@ -164,11 +175,18 @@ public class SobotLoginTools {
// 执行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, 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)) {
SobotLogUtils.i("已经登录成功,不用重新登录");
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "已经登录成功", getLoginUser());
}
return;
}
SobotHttpUtils.doPost(cancelTag, host + "/chat-sdk/sdk/admin/v1/login.action", timeout, params, headers, new HttpBaseUtils.StringCallBack() {
@Override
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>>() {
}.getType());
if (baseModel != null) {
......@@ -194,43 +212,64 @@ public class SobotLoginTools {
if (code == SobotResultCode.CODE_SUCCEEDED) {
LoginUserEntity tempUserEntity = userEntity;
String accessToken = (String) obj;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setAccess_token(accessToken);
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAccount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity);
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity);
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
}
}
});
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
}
} else {
setLoginUser(userEntity);
LoginUserEntity tempUserEntity = userEntity;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAccount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity);
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", userEntity);
}
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
}
}
}
});
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, baseModel.getMsg(), baseModel.getCode());
}
}
} 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) {
......@@ -240,8 +279,15 @@ public class SobotLoginTools {
}
// 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 (isLogin(loginAcount)) {
SobotLogUtils.i("已经登录成功,不用重新登录");
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "已经登录成功", getLoginUser());
}
return;
}
Map<String, Object> params = new HashMap<>();
params.put("loginUser", loginAcount);
params.put("loginPwd", loginPwd);
......@@ -249,7 +295,7 @@ public class SobotLoginTools {
@Override
public void onResponse(String response) {
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();
userEntity.setLogin_time(System.currentTimeMillis());
userEntity.setToken((String) result.getItem());
......@@ -272,39 +318,58 @@ public class SobotLoginTools {
if (code == SobotResultCode.CODE_SUCCEEDED) {
LoginUserEntity tempUserEntity = userEntity;
String accessToken = (String) obj;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setAccess_token(accessToken);
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAcount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity);
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity);
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
}
}
});
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
}
} else {
setLoginUser(userEntity);
LoginUserEntity tempUserEntity = userEntity;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAcount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity);
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", userEntity);
}
}
} 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) {
......@@ -313,6 +378,13 @@ public class SobotLoginTools {
});
} 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();
userEntity.setLogin_time(System.currentTimeMillis());
userEntity.setToken(logintoken);
......@@ -335,25 +407,40 @@ public class SobotLoginTools {
if (code == SobotResultCode.CODE_SUCCEEDED) {
LoginUserEntity tempUserEntity = userEntity;
String accessToken = (String) obj;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setAccess_token(accessToken);
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAcount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity);
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity);
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
}
}
});
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
}
} else {
setLoginUser(userEntity);
LoginUserEntity tempUserEntity = userEntity;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setLoginAccount(loginAcount);
tempUserEntity.setLoginPwd(loginPwd);
setLoginUser(tempUserEntity);
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", userEntity);
}
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
}
}
......@@ -375,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) {
final String url = host + "/basic-config-service/consoleAuth/queryAppAgentMenus";
Map<String, String> headerMap = new HashMap<>();
if (!TextUtils.isEmpty(token)) {
if (!SobotStringUtils.isEmpty(token)) {
headerMap.put("temp-id", token);
}
if (!TextUtils.isEmpty(language)) {
if (!SobotStringUtils.isEmpty(language)) {
headerMap.put("language", language);
}
SobotHttpUtils.doGet(cancelTag, url, null, headerMap, new HttpBaseUtils.StringCallBack() {
@Override
public void onResponse(String result) {
if (!TextUtils.isEmpty(result)) {
if (!SobotStringUtils.isEmpty(result)) {
try {
org.json.JSONObject resonseObj = new org.json.JSONObject(result);
String retCode = resonseObj.optString("retCode");
......@@ -410,21 +497,29 @@ public class SobotLoginTools {
//保存在数据库
setServiceInfo(serviceInfoModel);
SobotSharedPreferencesUtil.getInstance(mContext).put(SobotLoginConstant.SOBOT_LOGIN_USER_INFO, serviceInfoModel);
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "获取成功", serviceInfoModel);
}
}
} else {
if (resultBlock != null) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, retMsg == null ? "" : retMsg, null);
}
}
} catch (Exception e) {
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) {
......@@ -464,29 +559,37 @@ public class SobotLoginTools {
public void doAccessToken(Object cancelTag, String host, String token, final SobotResultBlock resultBlock) {
Map<String, String> headerMap = new HashMap<>();
if (!TextUtils.isEmpty(token)) {
if (!SobotStringUtils.isEmpty(token)) {
headerMap.put("temp-id", token);
}
SobotHttpUtils.doPost(cancelTag, host + "/tokens/getToken", null, headerMap, new HttpBaseUtils.StringCallBack() {
@Override
public void onResponse(String result) {
if (!TextUtils.isEmpty(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) {
......
......@@ -88,6 +88,8 @@ public class LoginUserManager extends SobotCommonDao<LoginUserEntity> {
model.setLanguage(cursor.getString(cursor.getColumnIndex("local_language")));
model.setAccess_token(cursor.getString(cursor.getColumnIndex(LoginUserEntity.ACCESS_TOKEN)));
model.setLogin_time(cursor.getLong(cursor.getColumnIndex(LoginUserEntity.LOGIN_TIME)));
model.setLoginAccount(cursor.getString(cursor.getColumnIndex("login_account")));
model.setLoginPwd(cursor.getString(cursor.getColumnIndex("login_pwd")));
return model;
}
......@@ -133,6 +135,8 @@ public class LoginUserManager extends SobotCommonDao<LoginUserEntity> {
contentValues.put("local_language", userAccount.getLanguage());
contentValues.put(LoginUserEntity.ACCESS_TOKEN, userAccount.getAccess_token());
contentValues.put(LoginUserEntity.LOGIN_TIME, userAccount.getLogin_time());
contentValues.put("login_account",userAccount.getLoginAccount());
contentValues.put("login_pwd",userAccount.getLoginPwd());
return contentValues;
}
......
......@@ -17,7 +17,7 @@ class SobotCommonDBHelper extends SQLiteOpenHelper {
private static final String DB_CACHE_NAME = "sobot_common.db";
// private static final int DB_CACHE_VERSION = 1;
private static final int DB_CACHE_VERSION = 3;
private static final int DB_CACHE_VERSION = 4;
static final String TABLE_LOGIN_USER = "login_user";
static final String TABLE_SOBOT_HOST = "sobot_host";
static final String TABLE_SERVICE_INFO = "sobot_service";
......@@ -131,10 +131,10 @@ class SobotCommonDBHelper extends SQLiteOpenHelper {
case 1:
String sql = "ALTER TABLE " + TABLE_LOGIN_USER
+ " ADD COLUMN " + LoginUserEntity.ACCESS_TOKEN + " VARCHAR(700)";
db.execSQL(sql); // 执行修改表,添加字段的逻辑。
db.execSQL(sql); // 登录表添加ACCESS_TOKEN
String sql1 = "ALTER TABLE " + TABLE_LOGIN_USER
+ " ADD COLUMN " + LoginUserEntity.LOGIN_TIME + " INTEGER";
db.execSQL(sql1); // 执行修改表,添加字段的逻辑。
db.execSQL(sql1); // 登录表添加登录时间
break;
case 2:
String sql2 = "ALTER TABLE " + TABLE_SERVICE_INFO
......@@ -144,6 +144,14 @@ class SobotCommonDBHelper extends SQLiteOpenHelper {
+ " ADD COLUMN " + SobotServiceInfoModel.TIMEZONEID + " VARCHAR(30)";
db.execSQL(sql3); // 执行修改表,添加字段的逻辑。
break;
case 3:
String sql4 = "ALTER TABLE " + TABLE_LOGIN_USER
+ " ADD COLUMN login_account VARCHAR(40)";
db.execSQL(sql4); // 登录表添加登录账号
String sql5 = "ALTER TABLE " + TABLE_LOGIN_USER
+ " ADD COLUMN login_pwd VARCHAR(40)";
db.execSQL(sql5); // 登录表添加登录密码
break;
default:
break;
}
......
......@@ -10,7 +10,8 @@ import java.util.Map;
public class LoginUserEntity implements Serializable {
private static final long serialVersionUID = 1L;
private String loginAccount; //登录账号
private String loginPwd; //登录密码
private String tempId; //客服temp-id
private String nickName; //客服昵称
private String staffName; //客服名称
......@@ -335,4 +336,20 @@ public class LoginUserEntity implements Serializable {
public void setLogin_time(long login_time) {
this.login_time = login_time;
}
public String getLoginAccount() {
return loginAccount;
}
public void setLoginAccount(String loginAccount) {
this.loginAccount = loginAccount;
}
public String getLoginPwd() {
return loginPwd;
}
public void setLoginPwd(String loginPwd) {
this.loginPwd = loginPwd;
}
}
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