Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
3a676134
Commit
3a676134
authored
Jan 05, 2022
by
李健华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
联调调用金融网关
parent
4cbc8afb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
11 deletions
+36
-11
UserController.java
...n/quantgroup/xyqb/controller/external/UserController.java
+34
-11
TokenExchange.java
src/main/java/cn/quantgroup/xyqb/model/TokenExchange.java
+2
-0
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/UserController.java
View file @
3a676134
...
...
@@ -30,6 +30,7 @@ import cn.quantgroup.xyqb.util.TenantUtil;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.binary.Base64
;
...
...
@@ -445,6 +446,11 @@ public class UserController implements IBaseController {
String
tokenKey2
=
Constants
.
Session
.
USER_SESSION_CACHE
+
token
;
// 判断token是否存在
boolean
exist
=
stringRedisTemplate
.
hasKey
(
tokenKey
)
||
stringRedisTemplate
.
hasKey
(
tokenKey2
);
if
(!
token
.
contains
(
prefix
)
&&
!
exist
)
{
Integer
tenantId
=
TenantUtil
.
TENANT_DEFAULT
;
findTokenExchange
(
token
,
tenantId
);
exist
=
stringRedisTemplate
.
hasKey
(
tokenKey
)
||
stringRedisTemplate
.
hasKey
(
tokenKey2
);
}
return
JsonResult
.
buildSuccessResult
(
"token valid"
,
exist
);
}
...
...
@@ -466,7 +472,16 @@ public class UserController implements IBaseController {
}
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSessionFromRedis
(
token
);
if
(
sessionStruct
==
null
||
sessionStruct
.
getValues
()
==
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
result
);
// 使用token去电商查询信息, 如果token 不包含本系统token前缀
if
(!
token
.
contains
(
prefix
))
{
findTokenExchange
(
token
,
tenantId
);
sessionStruct
=
XyqbSessionContextHolder
.
getXSessionFromRedis
(
token
);
if
(
sessionStruct
==
null
||
sessionStruct
.
getValues
()
==
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
result
);
}
}
else
{
return
JsonResult
.
buildSuccessResult
(
null
,
result
);
}
}
User
user
=
sessionStruct
.
getValues
().
getUser
();
Integer
sessionTenantId
=
sessionStruct
.
getValues
().
getLoginProperties
().
getTenantId
();
...
...
@@ -498,23 +513,25 @@ public class UserController implements IBaseController {
*
*/
@RequestMapping
(
"/tokenExchange"
)
public
TokenExchange
tokenExchange
(
@RequestParam
String
token
,
@RequestParam
(
required
=
false
)
Integer
tenantId
)
{
public
JsonResult
tokenExchange
(
@RequestParam
String
token
,
@RequestParam
(
required
=
false
)
Integer
tenantId
)
{
TokenExchange
tokenExchange
=
new
TokenExchange
();
if
(
StringUtils
.
isEmpty
(
token
))
{
return
null
;
return
JsonResult
.
buildSuccessResult
(
null
,
tokenExchange
)
;
}
if
(
token
.
contains
(
Constants
.
TOKEN_MASTER
))
{
return
null
;
return
JsonResult
.
buildSuccessResult
(
null
,
tokenExchange
)
;
}
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSessionFromRedis
(
token
);
if
(
sessionStruct
==
null
||
sessionStruct
.
getValues
()
==
null
)
{
return
null
;
return
JsonResult
.
buildSuccessResult
(
null
,
tokenExchange
)
;
}
User
user
=
sessionStruct
.
getValues
().
getUser
();
tokenExchange
.
setLoginProperties
(
JSONObject
.
toJSONString
(
sessionStruct
.
getValues
().
getLoginProperties
()));
tokenExchange
.
setUserId
(
user
.
getId
());
return
tokenExchange
;
tokenExchange
.
setPhoneNo
(
user
.
getPhoneNo
());
tokenExchange
.
setUuid
(
user
.
getUuid
());
return
JsonResult
.
buildSuccessResult
(
null
,
tokenExchange
);
}
...
...
@@ -523,16 +540,22 @@ public class UserController implements IBaseController {
* @param token
* @return
*/
private
void
findTokenExchange
(
String
token
)
{
private
void
findTokenExchange
(
String
token
,
Integer
tenantId
)
{
if
(
tenantId
==
null
)
{
tenantId
=
TenantUtil
.
TENANT_DEFAULT
;
}
// 请求其他系统信息
HashMap
<
String
,
String
>
parameters
=
new
HashMap
<>();
HashMap
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"qg-tenant-id"
,
tenantId
.
toString
());
parameters
.
put
(
"token"
,
token
);
String
resultStr
=
httpService
.
post
(
userHost
+
"/user/tokenExchange"
,
parameters
);
String
resultStr
=
httpService
.
post
(
userHost
+
"/api/finance-gateway/finance-user/finance/tokenExchange"
,
headers
,
parameters
);
// 如果有返回值
if
(!
resultStr
.
isEmpty
())
{
TokenExchange
tokenExchange
=
JSONObject
.
parseObject
(
resultStr
,
TokenExchange
.
class
);
if
(
resultStr
!=
null
)
{
JsonResult
<
TokenExchange
>
tokenExchangeResult
=
JSONObject
.
parseObject
(
resultStr
,
new
TypeReference
<
JsonResult
<
TokenExchange
>>(){});
TokenExchange
tokenExchange
=
tokenExchangeResult
.
getData
();
SessionValue
sessionValue
=
new
SessionValue
();
tokenExchange
.
setUserId
(
65172086L
);
User
user
=
userService
.
findById
(
tokenExchange
.
getUserId
());
LoginProperties
loginProperties
=
JSONObject
.
parseObject
(
tokenExchange
.
getLoginProperties
(),
LoginProperties
.
class
);
...
...
src/main/java/cn/quantgroup/xyqb/model/TokenExchange.java
View file @
3a676134
...
...
@@ -22,6 +22,8 @@ public class TokenExchange implements Serializable {
private
String
uuid
;
private
String
phoneNo
;
private
String
loginProperties
;
}
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