Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Sobot_module_Dev
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sobot_android
Sobot_module_Dev
Commits
b636afae
Commit
b636afae
authored
Jan 17, 2024
by
zhengnw@sobot.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common 1.5.4 token登录时,如果 账号和token一样 token未过期 就代表已经登录成功,不用重新登录
parent
838ba1c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
17 deletions
+41
-17
sobot-common-publish-mavencentral.gradle
sobot_common/sobot-common-publish-mavencentral.gradle
+1
-1
SobotLoginTools.java
...src/main/java/com/sobot/common/login/SobotLoginTools.java
+40
-16
No files found.
sobot_common/sobot-common-publish-mavencentral.gradle
View file @
b636afae
...
...
@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext
{
PUBLISH_GROUP_ID
=
"com.sobot.library"
//项目包名
PUBLISH_ARTIFACT_ID
=
'sobotcommon'
//项目名
PUBLISH_VERSION
=
'1.5.
4
'
//版本号
PUBLISH_VERSION
=
'1.5.
6
'
//版本号
}
...
...
sobot_common/src/main/java/com/sobot/common/login/SobotLoginTools.java
View file @
b636afae
...
...
@@ -166,7 +166,7 @@ public class SobotLoginTools {
//判断是否已经登录
public
boolean
isLogin
(
String
loginAccount
)
{
//登录对象,客户对象不为空,登录账号和登录对象里边账号一样,token 不为空,token 没过期 才判定已经登录成功,其它情况都是没登录
if
(
getLoginUser
()
!=
null
&&
getServiceInfo
()
!=
null
&&
!
Text
Utils
.
isEmpty
(
loginAccount
)
&&
loginAccount
.
equals
(
getLoginUser
().
getLoginAccount
())
&&
!
SobotStringUtils
.
isEmpty
(
getLoginUser
().
getToken
())
&&
checkExpiresToken
())
{
if
(
getLoginUser
()
!=
null
&&
getServiceInfo
()
!=
null
&&
!
SobotString
Utils
.
isEmpty
(
loginAccount
)
&&
loginAccount
.
equals
(
getLoginUser
().
getLoginAccount
())
&&
!
SobotStringUtils
.
isEmpty
(
getLoginUser
().
getToken
())
&&
checkExpiresToken
())
{
return
true
;
}
else
{
return
false
;
...
...
@@ -175,8 +175,9 @@ 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
,
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
))
{
SobotLogUtils
.
i
(
"已经登录成功,不用重新登录"
);
if
(
resultBlock
!=
null
)
{
resultBlock
.
resultBolok
(
SobotResultCode
.
CODE_SUCCEEDED
,
"已经登录成功"
,
getLoginUser
());
}
...
...
@@ -185,7 +186,7 @@ public class SobotLoginTools {
SobotHttpUtils
.
doPost
(
cancelTag
,
host
+
"/chat-sdk/sdk/admin/v1/login.action"
,
timeout
,
params
,
headers
,
new
HttpBaseUtils
.
StringCallBack
()
{
@Override
public
void
onResponse
(
String
result
)
{
if
(!
Text
Utils
.
isEmpty
(
result
))
{
if
(!
SobotString
Utils
.
isEmpty
(
result
))
{
final
SobotBaseCode
<
LoginUserEntity
>
baseModel
=
SobotGsonUtil
.
jsonToBeans
(
result
,
new
com
.
sobot
.
gson
.
reflect
.
TypeToken
<
SobotBaseCode
<
LoginUserEntity
>>()
{
}.
getType
());
if
(
baseModel
!=
null
)
{
...
...
@@ -211,9 +212,10 @@ 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
);
...
...
@@ -231,7 +233,11 @@ public class SobotLoginTools {
}
}
}
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
);
}
...
...
@@ -273,9 +279,10 @@ 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
());
}
...
...
@@ -288,7 +295,7 @@ public class SobotLoginTools {
@Override
public
void
onResponse
(
String
response
)
{
SobotCallBaseCode
result
=
SobotGsonUtil
.
jsonToBean
(
response
,
SobotCallBaseCode
.
class
);
if
(
result
!=
null
&&
!
Text
Utils
.
isEmpty
(
result
.
getRetCode
())
&&
"000000"
.
equals
(
result
.
getRetCode
())
&&
!
SobotStringUtils
.
isEmpty
(
result
.
getItem
()))
{
if
(
result
!=
null
&&
!
SobotString
Utils
.
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
());
...
...
@@ -311,9 +318,10 @@ 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
);
...
...
@@ -331,7 +339,11 @@ public class SobotLoginTools {
}
}
}
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
);
}
...
...
@@ -366,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
);
...
...
@@ -388,9 +407,10 @@ 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
);
...
...
@@ -408,7 +428,11 @@ public class SobotLoginTools {
}
}
}
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
);
}
...
...
@@ -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
)
{
final
String
url
=
host
+
"/basic-config-service/consoleAuth/queryAppAgentMenus"
;
Map
<
String
,
String
>
headerMap
=
new
HashMap
<>();
if
(!
Text
Utils
.
isEmpty
(
token
))
{
if
(!
SobotString
Utils
.
isEmpty
(
token
))
{
headerMap
.
put
(
"temp-id"
,
token
);
}
if
(!
Text
Utils
.
isEmpty
(
language
))
{
if
(!
SobotString
Utils
.
isEmpty
(
language
))
{
headerMap
.
put
(
"language"
,
language
);
}
SobotHttpUtils
.
doGet
(
cancelTag
,
url
,
null
,
headerMap
,
new
HttpBaseUtils
.
StringCallBack
()
{
@Override
public
void
onResponse
(
String
result
)
{
if
(!
Text
Utils
.
isEmpty
(
result
))
{
if
(!
SobotString
Utils
.
isEmpty
(
result
))
{
try
{
org
.
json
.
JSONObject
resonseObj
=
new
org
.
json
.
JSONObject
(
result
);
String
retCode
=
resonseObj
.
optString
(
"retCode"
);
...
...
@@ -535,13 +559,13 @@ public class SobotLoginTools {
public
void
doAccessToken
(
Object
cancelTag
,
String
host
,
String
token
,
final
SobotResultBlock
resultBlock
)
{
Map
<
String
,
String
>
headerMap
=
new
HashMap
<>();
if
(!
Text
Utils
.
isEmpty
(
token
))
{
if
(!
SobotString
Utils
.
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
(!
Text
Utils
.
isEmpty
(
result
))
{
if
(!
SobotString
Utils
.
isEmpty
(
result
))
{
Map
map
=
SobotGsonUtil
.
jsonToMaps
((
String
)
result
);
if
(
map
!=
null
&&
map
.
containsKey
(
"accessToken"
))
{
String
accessToken
=
(
String
)
map
.
get
(
"accessToken"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment