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
41055133
Commit
41055133
authored
Mar 17, 2017
by
lee_mingzhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change something
parent
3e4070e3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
2 deletions
+85
-2
WeChatController.java
...group/xyqb/controller/external/user/WeChatController.java
+85
-2
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/user/WeChatController.java
View file @
41055133
...
...
@@ -3,6 +3,7 @@ package cn.quantgroup.xyqb.controller.external.user;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.controller.IBaseController
;
import
cn.quantgroup.xyqb.entity.Merchant
;
import
cn.quantgroup.xyqb.entity.MerchantConfig
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.WechatUserInfo
;
import
cn.quantgroup.xyqb.model.AuthBean
;
...
...
@@ -283,6 +284,7 @@ public class WeChatController implements IBaseController {
String
code
,
@PathVariable
(
value
=
"key"
)
String
systemKey
,
@PathVariable
(
value
=
"extdata"
)
String
extData
,
HttpServletResponse
response
)
{
try
{
String
originExtData
=
extData
;
String
schema
=
getProtocol
();
extData
=
getExtData
(
extData
);
...
...
@@ -301,7 +303,7 @@ public class WeChatController implements IBaseController {
normalLogin
(
code
,
systemKey
,
response
,
schema
);
return
;
}
selfDefinedLogin
(
code
,
systemKey
,
response
,
schema
,
extDataObj
);
selfDefinedLogin
2
(
code
,
systemKey
,
response
,
extDataObj
,
originExtData
);
}
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"发生异常"
,
ex
);
...
...
@@ -371,6 +373,58 @@ public class WeChatController implements IBaseController {
return
false
;
}
private
boolean
selfDefinedLogin2
(
String
code
,
String
systemKey
,
HttpServletResponse
response
,
HashMap
<
String
,
Object
>
extDataObj
,
String
encodeExtData
)
{
Long
registerFrom
=
Long
.
valueOf
(
extDataObj
.
getOrDefault
(
"registerFrom"
,
"1"
).
toString
());
String
redirect
=
(
String
)
extDataObj
.
getOrDefault
(
"redirect"
,
"redirect"
);
LOGGER
.
info
(
"从微信登录,registerFrom:{}, redirect:{}"
,
registerFrom
,
redirect
);
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
);
return
true
;
}
WechatUserInfo
userInfo
=
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
token
.
getOpenId
());
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
);
return
true
;
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
// welcome 首次登录
if
(
userInfoInDb
==
null
)
{
// 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
if
(
StringUtils
.
isNotBlank
(
userInfo
.
getNickName
()))
{
String
nickName
=
EmojiUtil
.
filter
(
userInfo
.
getNickName
());
userInfo
.
setNickName
(
nickName
);
}
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
);
return
true
;
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
);
return
true
;
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
);
return
true
;
}
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
String
redirectUrl
=
createUserSession2
(
user
,
merchant
,
redirect
,
registerFrom
,
encodeExtData
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
return
false
;
}
private
boolean
normalLogin
(
String
code
,
String
systemKey
,
HttpServletResponse
response
,
String
schema
)
{
// 从code获取token
...
...
@@ -439,7 +493,6 @@ public class WeChatController implements IBaseController {
}
private
String
createUserSession
(
User
user
,
Merchant
merchant
,
String
redirect
,
String
schema
,
Long
registerFrom
)
{
//TODO 临时紧急上线修改的.下次上线的时候修复一下,不能这样写.
String
url
=
schema
+
"//passport.xyqb.com"
;
if
(
StringUtils
.
isEmpty
(
redirect
)
||
"redirect"
.
equals
(
redirect
))
{
LOGGER
.
info
(
"微信登录:redirect为null,走正常流程."
);
...
...
@@ -457,6 +510,36 @@ public class WeChatController implements IBaseController {
return
null
;
}
private
String
createUserSession2
(
User
user
,
Merchant
merchant
,
String
extData
,
Long
registerFrom
,
String
encodeExtData
)
{
if
(
StringUtils
.
isEmpty
(
encodeExtData
)
||
"{}"
.
equals
(
encodeExtData
))
{
LOGGER
.
info
(
"微信登录:redirect为null,走正常流程."
);
if
(
"baitiao"
.
equals
(
merchant
.
getName
()))
{
return
loginInWechatWithSessionCreated2
(
user
,
merchant
,
"cashTarget5"
,
Constants
.
Channel
.
BAITIAO
,
Constants
.
Channel
.
WECHAT
);
}
else
{
return
loginInWechatWithSessionCreated2
(
user
,
merchant
,
"cashTarget4"
,
1L
,
registerFrom
);
}
}
else
{
LOGGER
.
info
(
"微信登录:redirect{}"
,
extData
);
AuthBean
authBean
=
sessionService
.
createSession
(
Constants
.
Channel
.
WECHAT
,
Constants
.
Channel
.
WECHAT
,
""
,
user
,
merchant
);
String
protocol
=
getProtocol
();
LOGGER
.
info
(
"请求业务方receive_token方法,参数token:{}, protocol:{}, json:{}"
,
authBean
.
getToken
(),
protocol
,
extData
);
return
redirectReceiveToken
(
authBean
.
getToken
(),
encodeExtData
,
protocol
,
merchant
);
}
}
private
String
redirectReceiveToken
(
String
token
,
String
extData
,
String
protocol
,
Merchant
merchant
){
LOGGER
.
info
(
"redirectReceiveToken token:{}, extData:{}, protocol:{}, merchantId:{}"
,
token
,
extData
,
protocol
,
merchant
.
getId
());
//使用merchantId获取merchantConfig配置.id不同获取的url地址不同.不用判断是白条和现金贷了。
MerchantConfig
config
=
merchantService
.
findConfigByMerchantIdAndConfigName
(
merchant
.
getId
(),
"returnUrl"
);
LOGGER
.
info
(
"redirectReceiveToken config Url:{}"
,
config
.
getConfigValue
());
return
config
.
getConfigValue
()
+
"?token="
+
token
+
"&protocol="
+
protocol
+
"&extData="
+
extData
;
}
private
String
loginInWechatWithSessionCreated2
(
User
user
,
Merchant
merchant
,
String
target
,
Long
channelId
,
Long
registerFrom
)
{
AuthBean
authBean
=
sessionService
.
createSession
(
channelId
,
registerFrom
,
""
,
user
,
merchant
);
return
userUIAddr
+
"/landing?token="
+
authBean
.
getToken
()
+
"®isterFrom="
+
registerFrom
+
"&channelId="
+
channelId
+
"&key="
+
merchant
.
getName
()
+
"&target="
+
target
;
}
private
String
loginInWechatWithSessionCreated
(
User
user
,
Merchant
merchant
,
String
target
,
Long
channelId
,
String
url
,
Long
registerFrom
)
{
AuthBean
authBean
=
sessionService
.
createSession
(
channelId
,
registerFrom
,
""
,
user
,
merchant
);
return
url
+
"/landing?token="
+
authBean
.
getToken
()
+
"®isterFrom="
+
registerFrom
+
"&channelId="
+
channelId
+
"&key="
+
merchant
.
getName
()
+
"&target="
+
target
;
...
...
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