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
be88ece7
Commit
be88ece7
authored
Dec 28, 2021
by
李健华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信公众号优化需求
parent
738586df
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
8 deletions
+31
-8
Constants.java
src/main/java/cn/quantgroup/xyqb/Constants.java
+1
-0
WeChatController.java
...quantgroup/xyqb/controller/external/WeChatController.java
+30
-8
No files found.
src/main/java/cn/quantgroup/xyqb/Constants.java
View file @
be88ece7
...
...
@@ -77,6 +77,7 @@ public interface Constants {
String
PROTOCOL_HEAD_HTTPS
=
"https:"
;
String
PROTOCOL_HEAD_HTTP
=
"http:"
;
String
REDIRECT
=
"redirect"
;
String
CUSTOMREDIRECT
=
"customredirect"
;
String
LOCAL
=
"local"
;
String
REDIRECT_ORDER
=
"orders"
;
String
DOCKER_DOMAIN
=
"liangkebang"
;
...
...
src/main/java/cn/quantgroup/xyqb/controller/external/WeChatController.java
View file @
be88ece7
...
...
@@ -178,13 +178,14 @@ public class WeChatController implements IBaseController {
Long
registerFrom
=
null
;
String
redirect
=
null
;
String
schema
=
null
;
String
customRedirect
=
null
;
try
{
extData
=
new
String
(
Base64
.
decodeBase64
(
extData
),
"UTF-8"
);
}
catch
(
Exception
ex
)
{
extData
=
""
;
}
if
(
StringUtils
.
isBlank
(
extData
))
{
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
response
);
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
customRedirect
,
response
);
return
;
}
log
.
info
(
"从微信extdata版本接口进入:{}, extData:{}"
,
schema
,
extData
);
...
...
@@ -194,15 +195,16 @@ public class WeChatController implements IBaseController {
});
}
catch
(
Exception
ex
)
{
log
.
error
(
"解析extData发生错误"
,
ex
);
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
response
);
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
customRedirect
,
response
);
return
;
}
schema
=
extDataObj
.
getOrDefault
(
"protocol"
,
Constants
.
PROTOCOL_HEAD_HTTP
).
toString
();
log
.
info
(
"从微信登录extData中获得协议信息,protocol:{}"
,
schema
);
registerFrom
=
Long
.
valueOf
(
extDataObj
.
getOrDefault
(
"registerFrom"
,
"1"
).
toString
());
redirect
=
(
String
)
extDataObj
.
getOrDefault
(
Constants
.
REDIRECT
,
Constants
.
REDIRECT
);
customRedirect
=
(
String
)
extDataObj
.
getOrDefault
(
Constants
.
CUSTOMREDIRECT
,
null
);
log
.
info
(
"从微信登录,registerFrom:{}, redirect:{}"
,
registerFrom
,
redirect
);
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
response
);
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
customRedirect
,
response
);
}
/**
...
...
@@ -215,7 +217,7 @@ public class WeChatController implements IBaseController {
* @param redirect
* @param response
*/
private
void
receiveCodeWithDefault
(
String
code
,
String
systemKey
,
String
schema
,
Long
registerFrom
,
String
redirect
,
HttpServletResponse
response
)
{
private
void
receiveCodeWithDefault
(
String
code
,
String
systemKey
,
String
schema
,
Long
registerFrom
,
String
redirect
,
String
customRedirect
,
HttpServletResponse
response
)
{
// 微信跳转请求入参监控
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
log
.
info
(
"[WeChatController][receiveCodeWithDefault]微信授权及跳转:code:{},systemKey:{},schema:{},registerFrom:{},redirect:{},request:{}"
,
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
JSON
.
toJSONString
(
getRequestHeaderMap
(
request
)));
...
...
@@ -247,6 +249,7 @@ public class WeChatController implements IBaseController {
log
.
info
(
"[WeChatController][receiveCodeWithDefault]微信授权及跳转:WechatUserInfo - from wechat api:{}"
,
userInfo
);
if
(
Objects
.
isNull
(
userInfo
)
||
StringUtils
.
isBlank
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
// 如果有自定义跳转链接
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
domain
);
return
;
}
...
...
@@ -257,19 +260,31 @@ public class WeChatController implements IBaseController {
userInfo
.
setNickName
(
EmojiUtil
.
BYTE_4_REPLACE_TEMPLATE
);
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
}
if
(
customRedirect
!=
null
)
{
customRedirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
,
customRedirect
);
}
else
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
,
domain
);
}
return
;
}
if
(
Objects
.
isNull
(
userInfoInDb
.
getUserId
()))
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
if
(
customRedirect
!=
null
)
{
customRedirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
customRedirect
);
}
else
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
domain
);
}
return
;
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
// 用户不存在或已注销
if
(
Objects
.
isNull
(
user
)
||
!
user
.
getEnable
())
{
// 用户已经微信登录了,但是关联信用钱包用户信息无效,跳转到注册页面
if
(
customRedirect
!=
null
)
{
customRedirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
customRedirect
);
}
else
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
domain
);
}
return
;
}
// 已经关联了用户
...
...
@@ -329,7 +344,7 @@ public class WeChatController implements IBaseController {
if
(
Objects
.
equals
(
Constants
.
PROTOCOL_HEAD_HTTPS
,
request
.
getScheme
()))
{
schema
=
Constants
.
PROTOCOL_HEAD_HTTPS
;
}
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
response
);
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
re
direct
,
re
sponse
);
}
private
String
createUserSession
(
User
user
,
Merchant
merchant
,
String
redirect
,
String
domain
,
Long
registerFrom
)
{
...
...
@@ -382,6 +397,13 @@ public class WeChatController implements IBaseController {
response
.
setStatus
(
HttpStatus
.
SC_MOVED_PERMANENTLY
);
}
private
void
customRedirectWechatLoginUrlWithoutLogin
(
HttpServletResponse
response
,
Merchant
merchant
,
WechatUserInfo
userInfo
,
Long
registerFrom
,
String
customRedirect
)
{
String
redirectUrl
=
customRedirect
+
"?registerFrom= "
+
registerFrom
+
"&channelId=1&isWechat=true&openId="
+
userInfo
.
getOpenId
();
log
.
info
(
"[WeChatController][redirectWechatLoginUrlWithoutLogin]微信授权及自定义跳转:redirectUrl:[{}]"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
HttpStatus
.
SC_MOVED_PERMANENTLY
);
}
private
String
assembleNormalRedirectUrl
(
Merchant
merchant
,
Long
registerFrom
,
String
domain
)
{
if
(
Constants
.
MERCHANT_BAITIAO
.
equals
(
merchant
.
getName
()))
{
if
(
registerFrom
==
Constants
.
Channel
.
HENGCHANG
||
registerFrom
==
Constants
.
Channel
.
WECHAT
)
{
...
...
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