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
36975cc9
Commit
36975cc9
authored
Jun 13, 2017
by
技术部—现金贷—曾丽宾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加微信登录注册协议信息http或者https
parent
93c5aced
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
34 deletions
+57
-34
WeChatController.java
...group/xyqb/controller/external/user/WeChatController.java
+55
-34
xyqb.properties
src/main/resources/config/dev/xyqb.properties
+1
-0
xyqb.properties
src/main/resources/config/release01/xyqb.properties
+1
-0
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/user/WeChatController.java
View file @
36975cc9
...
...
@@ -64,6 +64,10 @@ public class WeChatController implements IBaseController {
@Value
(
"${xyqb.user.domain}"
)
private
String
userDomainStr
;
//加https地址
@Value
(
"${xyqb-user.ui-s}"
)
private
String
userUIAddrS
;
/**
* 开发者资质认证,有必要吗?
*
...
...
@@ -162,6 +166,8 @@ public class WeChatController implements IBaseController {
extData
=
""
;
}
String
protocol
=
"http"
;
LOGGER
.
info
(
"从微信extdata版本接口进入:{}, extData:{}"
,
schema
,
extData
);
if
(
StringUtils
.
isEmpty
(
extData
))
{
// 从code获取token
...
...
@@ -170,7 +176,7 @@ public class WeChatController implements IBaseController {
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
WechatUserInfo
userInfo
=
...
...
@@ -178,7 +184,7 @@ public class WeChatController implements IBaseController {
token
.
getOpenId
());
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
...
...
@@ -191,19 +197,19 @@ public class WeChatController implements IBaseController {
}
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
Constants
.
Channel
.
WECHAT
);
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
);
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
);
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
// 已经关联了用户
...
...
@@ -226,7 +232,7 @@ public class WeChatController implements IBaseController {
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
WechatUserInfo
userInfo
=
...
...
@@ -234,7 +240,7 @@ public class WeChatController implements IBaseController {
token
.
getOpenId
());
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
WechatUserInfo
userInfoInDb
=
...
...
@@ -248,19 +254,19 @@ public class WeChatController implements IBaseController {
}
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
Constants
.
Channel
.
WECHAT
);
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
);
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
);
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
// 已经关联了用户
...
...
@@ -271,6 +277,9 @@ public class WeChatController implements IBaseController {
response
.
setStatus
(
301
);
return
;
}
protocol
=
extDataObj
.
getOrDefault
(
"protocol"
,
"http"
).
toString
();
LOGGER
.
info
(
"从微信登录extData中获得协议信息,protocol:{}"
,
protocol
);
Long
registerFrom
=
Long
.
valueOf
(
extDataObj
.
getOrDefault
(
"registerFrom"
,
"1"
).
toString
());
String
redirect
=
(
String
)
extDataObj
.
getOrDefault
(
"redirect"
,
"redirect"
);
LOGGER
.
info
(
"从微信登录,registerFrom:{}, redirect:{}"
,
registerFrom
,
redirect
);
...
...
@@ -278,7 +287,7 @@ public class WeChatController implements IBaseController {
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
);
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
protocol
);
return
;
}
WechatUserInfo
userInfo
=
...
...
@@ -286,7 +295,7 @@ public class WeChatController implements IBaseController {
token
.
getOpenId
());
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
);
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
protocol
);
return
;
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
...
...
@@ -298,17 +307,17 @@ public class WeChatController implements IBaseController {
userInfo
.
setNickName
(
nickName
);
}
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
,
protocol
);
return
;
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
protocol
);
return
;
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
protocol
);
return
;
}
// 已经关联了用户
...
...
@@ -333,6 +342,7 @@ public class WeChatController implements IBaseController {
@RequestMapping
(
"/receiveCode/{key}"
)
public
void
receiveCodeNoRedirect
(
String
code
,
@PathVariable
(
value
=
"key"
)
String
systemKey
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
String
schema
=
request
.
getScheme
();
String
protocol
=
"http"
;
LOGGER
.
info
(
"HTTP协议no redirect:"
+
schema
);
// 从code获取token
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
...
...
@@ -340,13 +350,13 @@ public class WeChatController implements IBaseController {
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
WechatUserInfo
userInfo
=
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
token
.
getOpenId
());
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
...
...
@@ -358,17 +368,17 @@ public class WeChatController implements IBaseController {
userInfo
.
setNickName
(
nickName
);
}
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
Constants
.
Channel
.
WECHAT
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
,
protocol
);
return
;
}
// 已经关联了用户
...
...
@@ -413,47 +423,58 @@ public class WeChatController implements IBaseController {
return
url
+
"/landing?token="
+
authBean
.
getToken
()
+
"®isterFrom="
+
registerFrom
+
"&channelId="
+
channelId
+
"&key="
+
merchant
.
getName
()
+
"&target="
+
target
;
}
private
void
redirectWechatLoginUrlWithoutLogin
(
HttpServletResponse
response
,
Merchant
merchant
,
WechatUserInfo
userInfo
,
Long
registerFrom
)
{
String
redirectUrl
=
assembleWechatRedirectUrl
(
merchant
,
userInfo
,
registerFrom
);
private
void
redirectWechatLoginUrlWithoutLogin
(
HttpServletResponse
response
,
Merchant
merchant
,
WechatUserInfo
userInfo
,
Long
registerFrom
,
String
protocol
)
{
String
redirectUrl
=
assembleWechatRedirectUrl
(
merchant
,
userInfo
,
registerFrom
,
protocol
);
LOGGER
.
info
(
"redirectWechatLoginUrlWithoutLogin redirectUrl:[{}]"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
}
private
void
redirectNormalUrl
(
HttpServletResponse
response
,
Merchant
merchant
,
Long
registerFrom
)
{
String
redirectUrl
=
assembleNormalRedirectUrl
(
merchant
,
registerFrom
);
private
void
redirectNormalUrl
(
HttpServletResponse
response
,
Merchant
merchant
,
Long
registerFrom
,
String
protocol
)
{
String
redirectUrl
=
assembleNormalRedirectUrl
(
merchant
,
registerFrom
,
protocol
);
LOGGER
.
info
(
"redirectNormalUrl redirectUrl:[{}]"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
}
private
String
assembleNormalRedirectUrl
(
Merchant
merchant
,
Long
registerFrom
)
{
private
String
assembleNormalRedirectUrl
(
Merchant
merchant
,
Long
registerFrom
,
String
protocol
)
{
String
domains
=
userUIAddr
;
if
(
protocol
!=
null
&&
protocol
.
equals
(
"https"
)){
domains
=
userUIAddrS
;
}
if
(
"baitiao"
.
equals
(
merchant
.
getName
()))
{
if
(
registerFrom
==
58
l
||
registerFrom
==
198
l
){
return
userUIAddr
+
"/landing?key=baitiao&target=cashTarget5&channelId=222®isterFrom="
+
registerFrom
;
return
domains
+
"/landing?key=baitiao&target=cashTarget5&channelId=222®isterFrom="
+
registerFrom
;
}
else
{
return
userUIAddr
+
"/landing?key=baitiao&target=cashTarget5&channelId=222®isterFrom=198"
;
return
domains
+
"/landing?key=baitiao&target=cashTarget5&channelId=222®isterFrom=198"
;
}
}
else
if
(
"wechat-pay"
.
equals
(
merchant
.
getName
()))
{
return
userUIAddr
+
"/landing?key=wechat-pay&target=cashTarget5&channelId=1&page=landing/4®isterFrom"
+
registerFrom
;
return
domains
+
"/landing?key=wechat-pay&target=cashTarget5&channelId=1&page=landing/4®isterFrom"
+
registerFrom
;
}
else
{
return
userUIAddr
+
"/landing?key=xyqb&target=cashTarget4&channelId=1®isterFrom="
+
registerFrom
;
return
domains
+
"/landing?key=xyqb&target=cashTarget4&channelId=1®isterFrom="
+
registerFrom
;
}
}
private
String
assembleWechatRedirectUrl
(
Merchant
merchant
,
WechatUserInfo
userInfo
,
Long
registerFrom
)
{
private
String
assembleWechatRedirectUrl
(
Merchant
merchant
,
WechatUserInfo
userInfo
,
Long
registerFrom
,
String
protocol
)
{
String
domains
=
userUIAddr
;
if
(
protocol
!=
null
&&
protocol
.
equals
(
"https"
)){
domains
=
userUIAddrS
;
}
if
(
"baitiao"
.
equals
(
merchant
.
getName
()))
{
if
(
registerFrom
==
58
l
||
registerFrom
==
198
l
){
return
userUIAddr
+
"/landing?key=baitiao&target=cashTarget5®isterFrom="
+
registerFrom
+
"&channelId=222&isWechat=true&openId="
+
userInfo
.
getOpenId
();
return
domains
+
"/landing?key=baitiao&target=cashTarget5®isterFrom="
+
registerFrom
+
"&channelId=222&isWechat=true&openId="
+
userInfo
.
getOpenId
();
}
else
{
return
userUIAddr
+
"/landing?key=baitiao&target=cashTarget5®isterFrom=198&channelId=222&isWechat=true&openId="
+
userInfo
.
getOpenId
();
return
domains
+
"/landing?key=baitiao&target=cashTarget5®isterFrom=198&channelId=222&isWechat=true&openId="
+
userInfo
.
getOpenId
();
}
}
else
if
(
"wechat-pay"
.
equals
(
merchant
.
getName
()))
{
return
userUIAddr
+
"/landing?key=wechat-pay&target=cashTarget5&page=landing/4®isterFrom= "
+
registerFrom
+
"&channelId=1&isWechat=true&openId="
+
userInfo
.
getOpenId
();
return
domains
+
"/landing?key=wechat-pay&target=cashTarget5&page=landing/4®isterFrom= "
+
registerFrom
+
"&channelId=1&isWechat=true&openId="
+
userInfo
.
getOpenId
();
}
else
{
return
userUIAddr
+
"/landing?key=xyqb&target=cashTarget4®isterFrom= "
+
registerFrom
+
"&channelId=1&isWechat=true&openId="
+
userInfo
.
getOpenId
();
return
domains
+
"/landing?key=xyqb&target=cashTarget4®isterFrom= "
+
registerFrom
+
"&channelId=1&isWechat=true&openId="
+
userInfo
.
getOpenId
();
}
}
...
...
src/main/resources/config/dev/xyqb.properties
View file @
36975cc9
...
...
@@ -71,6 +71,7 @@ xyqb.auth.url=http://192.168.192.206:9001
usersys.url
=
http://localhost:9001
xyqb-user.ui
=
http://192.168.100.36:7043
xyqb-user.ui-s
=
https://192.168.100.36:7043
wechat.appid
=
wxcdf6077af8127559
wechat.secret
=
16eaec16084d0d9c52d4114f359cc72c
...
...
src/main/resources/config/release01/xyqb.properties
View file @
36975cc9
...
...
@@ -36,6 +36,7 @@ jr58.notify.userinfo=http://dk.58.com/customer/quantgroup_user_info
model.quantgroup.url
=
http://model.quantgroup.cn
xyqb.auth.url
=
http://auth.xyqb.com
xyqb-user.ui
=
http://passport.xyqb.com
xyqb-user.ui-s
=
https://passport.xyqb.com
#motan protocol
protocol.name
=
motan
protocol.contentLength
=
1048576
...
...
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