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
5072d893
Commit
5072d893
authored
Mar 23, 2017
by
lee_mingzhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
回滚代码到3月16日下午4.04分的代码
parent
cebf60ef
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
175 additions
and
224 deletions
+175
-224
WeChatController.java
...group/xyqb/controller/external/user/WeChatController.java
+175
-224
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/user/WeChatController.java
View file @
5072d893
...
@@ -3,9 +3,9 @@ package cn.quantgroup.xyqb.controller.external.user;
...
@@ -3,9 +3,9 @@ package cn.quantgroup.xyqb.controller.external.user;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.controller.IBaseController
;
import
cn.quantgroup.xyqb.controller.IBaseController
;
import
cn.quantgroup.xyqb.entity.Merchant
;
import
cn.quantgroup.xyqb.entity.Merchant
;
import
cn.quantgroup.xyqb.entity.MerchantConfig
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.WechatUserInfo
;
import
cn.quantgroup.xyqb.entity.WechatUserInfo
;
import
cn.quantgroup.xyqb.event.UserinfoChangedEvent
;
import
cn.quantgroup.xyqb.model.AuthBean
;
import
cn.quantgroup.xyqb.model.AuthBean
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.webchat.AccessTokenResponse
;
import
cn.quantgroup.xyqb.model.webchat.AccessTokenResponse
;
...
@@ -17,9 +17,7 @@ import cn.quantgroup.xyqb.service.wechat.IWechatService;
...
@@ -17,9 +17,7 @@ import cn.quantgroup.xyqb.service.wechat.IWechatService;
import
cn.quantgroup.xyqb.util.EmojiUtil
;
import
cn.quantgroup.xyqb.util.EmojiUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.TypeReference
;
import
com.alibaba.fastjson.TypeReference
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
...
@@ -206,7 +204,7 @@ public class WeChatController implements IBaseController {
...
@@ -206,7 +204,7 @@ public class WeChatController implements IBaseController {
// welcome 首次登录
// welcome 首次登录
if
(
userInfoInDb
==
null
)
{
if
(
userInfoInDb
==
null
)
{
// 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
// 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
if
(
StringUtils
.
isNotBlank
(
userInfo
.
getNickName
()))
{
if
(
StringUtils
.
isNotBlank
(
userInfo
.
getNickName
()))
{
String
nickName
=
EmojiUtil
.
filter
(
userInfo
.
getNickName
());
String
nickName
=
EmojiUtil
.
filter
(
userInfo
.
getNickName
());
userInfo
.
setNickName
(
nickName
);
userInfo
.
setNickName
(
nickName
);
}
}
...
@@ -232,6 +230,7 @@ public class WeChatController implements IBaseController {
...
@@ -232,6 +230,7 @@ public class WeChatController implements IBaseController {
}
}
/**
/**
* 前端微信跳转页面,通过extdata
* 前端微信跳转页面,通过extdata
*
*
...
@@ -245,52 +244,62 @@ public class WeChatController implements IBaseController {
...
@@ -245,52 +244,62 @@ public class WeChatController implements IBaseController {
)
{
)
{
try
{
try
{
String
schema
=
getProtocol
();
String
schema
=
getProtocol
();
extData
=
getExtData
(
extData
);
try
{
extData
=
new
String
(
Base64
.
decodeBase64
(
extData
),
"UTF-8"
);
}
catch
(
Exception
ex
)
{
extData
=
""
;
}
LOGGER
.
info
(
"从微信extdata版本接口进入:{}, extData:{}"
,
schema
,
extData
);
LOGGER
.
info
(
"从微信extdata版本接口进入:{}, extData:{}"
,
schema
,
extData
);
if
(
StringUtils
.
isEmpty
(
extData
))
{
if
(
StringUtils
.
isEmpty
(
extData
))
{
normalLogin
(
code
,
systemKey
,
response
,
schema
);
}
else
{
HashMap
<
String
,
Object
>
extDataObj
;
try
{
extDataObj
=
JSON
.
parseObject
(
extData
,
new
TypeReference
<
HashMap
<
String
,
Object
>>()
{
});
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"解析extData发生错误"
,
ex
);
// 从code获取token
// 从code获取token
normalLogin
(
code
,
systemKey
,
response
,
schema
);
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
return
;
return
;
}
}
selfDefinedLogin
(
code
,
systemKey
,
response
,
schema
,
extDataObj
);
WechatUserInfo
userInfo
=
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
token
.
getOpenId
());
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
return
;
}
}
}
catch
(
Exception
ex
)
{
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
LOGGER
.
error
(
"发生异常"
,
ex
);
// welcome 首次登录
throw
ex
;
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
,
Constants
.
Channel
.
WECHAT
);
return
;
}
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
/**
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
* 前端微信跳转页面,通过extdata
Constants
.
Channel
.
WECHAT
);
*
return
;
* @param response
}
* @return
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
*/
if
(
user
==
null
)
{
@RequestMapping
(
"/receiveCode/forward/{key}/{extdata}"
)
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
public
void
receiveCodeWithForward
(
Constants
.
Channel
.
WECHAT
);
String
code
,
@PathVariable
(
value
=
"key"
)
String
systemKey
,
@PathVariable
(
value
=
"extdata"
)
String
extData
,
HttpServletResponse
response
return
;
)
{
}
try
{
// 已经关联了用户
String
originExtData
=
extData
;
// create session, 登进去,该怎么玩怎么玩。
String
schema
=
getProtocol
();
String
redirectUrl
=
extData
=
getExtData
(
extData
);
createUserSession
(
user
,
merchant
,
""
,
schema
,
Constants
.
Channel
.
WECHAT
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
LOGGER
.
info
(
"从微信extdata版本接口进入:{}, extData:{}"
,
schema
,
extData
);
response
.
setStatus
(
301
);
if
(
StringUtils
.
isEmpty
(
extData
))
{
normalLogin
(
code
,
systemKey
,
response
,
schema
);
}
else
{
}
else
{
HashMap
<
String
,
Object
>
extDataObj
;
HashMap
<
String
,
Object
>
extDataObj
;
try
{
try
{
...
@@ -300,50 +309,24 @@ public class WeChatController implements IBaseController {
...
@@ -300,50 +309,24 @@ public class WeChatController implements IBaseController {
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"解析extData发生错误"
,
ex
);
LOGGER
.
error
(
"解析extData发生错误"
,
ex
);
// 从code获取token
// 从code获取token
normalLogin
(
code
,
systemKey
,
response
,
schema
);
return
;
}
selfDefinedLogin2
(
code
,
systemKey
,
response
,
extDataObj
,
originExtData
);
}
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"发生异常"
,
ex
);
throw
ex
;
}
}
private
String
getExtData
(
String
extData
)
{
try
{
extData
=
new
String
(
Base64
.
decodeBase64
(
extData
),
"UTF-8"
);
}
catch
(
Exception
ex
)
{
extData
=
""
;
}
return
extData
;
}
private
boolean
selfDefinedLogin
(
String
code
,
String
systemKey
,
HttpServletResponse
response
,
String
schema
,
HashMap
<
String
,
Object
>
extDataObj
)
{
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
);
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
if
(
token
==
null
)
{
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
);
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
return
true
;
return
;
}
}
WechatUserInfo
userInfo
=
WechatUserInfo
userInfo
=
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
token
.
getOpenId
());
token
.
getOpenId
());
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
);
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
return
true
;
return
;
}
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
// welcome 首次登录
// welcome 首次登录
if
(
userInfoInDb
==
null
)
{
if
(
userInfoInDb
==
null
)
{
// 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
// 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
...
@@ -352,30 +335,30 @@ public class WeChatController implements IBaseController {
...
@@ -352,30 +335,30 @@ public class WeChatController implements IBaseController {
userInfo
.
setNickName
(
nickName
);
userInfo
.
setNickName
(
nickName
);
}
}
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
return
true
;
Constants
.
Channel
.
WECHAT
);
return
;
}
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
return
true
;
Constants
.
Channel
.
WECHAT
);
return
;
}
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
if
(
user
==
null
)
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
return
true
;
Constants
.
Channel
.
WECHAT
);
return
;
}
}
// 已经关联了用户
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
// create session, 登进去,该怎么玩怎么玩。
String
redirectUrl
=
createUserSession
(
user
,
merchant
,
redirect
,
schema
,
registerFrom
);
String
redirectUrl
=
createUserSession
(
user
,
merchant
,
""
,
schema
,
Constants
.
Channel
.
WECHAT
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
response
.
setStatus
(
301
);
return
false
;
return
;
}
}
private
boolean
selfDefinedLogin2
(
String
code
,
String
systemKey
,
HttpServletResponse
response
,
HashMap
<
String
,
Object
>
extDataObj
,
String
encodeExtData
)
{
Long
registerFrom
=
Long
.
valueOf
(
extDataObj
.
getOrDefault
(
"registerFrom"
,
"1"
).
toString
());
Long
registerFrom
=
Long
.
valueOf
(
extDataObj
.
getOrDefault
(
"registerFrom"
,
"1"
).
toString
());
String
redirect
=
(
String
)
extDataObj
.
getOrDefault
(
"redirect"
,
"redirect"
);
String
redirect
=
(
String
)
extDataObj
.
getOrDefault
(
"redirect"
,
"redirect"
);
LOGGER
.
info
(
"从微信登录,registerFrom:{}, redirect:{}"
,
registerFrom
,
redirect
);
LOGGER
.
info
(
"从微信登录,registerFrom:{}, redirect:{}"
,
registerFrom
,
redirect
);
...
@@ -384,7 +367,7 @@ public class WeChatController implements IBaseController {
...
@@ -384,7 +367,7 @@ public class WeChatController implements IBaseController {
if
(
token
==
null
)
{
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
);
redirectNormalUrl
(
response
,
merchant
,
registerFrom
);
return
true
;
return
;
}
}
WechatUserInfo
userInfo
=
WechatUserInfo
userInfo
=
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
...
@@ -392,7 +375,7 @@ public class WeChatController implements IBaseController {
...
@@ -392,7 +375,7 @@ public class WeChatController implements IBaseController {
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
);
redirectNormalUrl
(
response
,
merchant
,
registerFrom
);
return
true
;
return
;
}
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
// welcome 首次登录
// welcome 首次登录
...
@@ -404,29 +387,44 @@ public class WeChatController implements IBaseController {
...
@@ -404,29 +387,44 @@ public class WeChatController implements IBaseController {
}
}
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
);
return
true
;
return
;
}
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
);
return
true
;
return
;
}
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
if
(
user
==
null
)
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
);
return
true
;
return
;
}
}
// 已经关联了用户
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
// create session, 登进去,该怎么玩怎么玩。
String
redirectUrl
=
createUserSession2
(
user
,
merchant
,
redirect
,
registerFrom
,
encodeExtData
);
String
redirectUrl
=
createUserSession
(
user
,
merchant
,
redirect
,
schema
,
registerFrom
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
response
.
setStatus
(
301
);
return
false
;
}
}
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"发生异常"
,
ex
);
throw
ex
;
}
private
boolean
normalLogin
(
String
code
,
String
systemKey
,
}
HttpServletResponse
response
,
String
schema
)
{
/**
* 通过redirect_url获取code
*
* @param response
* @return
*/
@RequestMapping
(
"/receiveCode/{key}"
)
public
void
receiveCodeNoRedirect
(
String
code
,
@PathVariable
(
value
=
"key"
)
String
systemKey
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
String
schema
=
request
.
getScheme
();
LOGGER
.
info
(
"HTTP协议no redirect:"
+
schema
);
// 从code获取token
// 从code获取token
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
...
@@ -434,74 +432,57 @@ public class WeChatController implements IBaseController {
...
@@ -434,74 +432,57 @@ public class WeChatController implements IBaseController {
if
(
token
==
null
)
{
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
return
true
;
return
;
}
}
WechatUserInfo
userInfo
=
WechatUserInfo
userInfo
=
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
token
.
getOpenId
());
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
token
.
getOpenId
());
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
redirectNormalUrl
(
response
,
merchant
,
Constants
.
Channel
.
WECHAT
);
return
true
;
return
;
}
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
// welcome 首次登录
// welcome 首次登录
if
(
userInfoInDb
==
null
)
{
if
(
userInfoInDb
==
null
)
{
// 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
// 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
if
(
StringUtils
.
isNotBlank
(
userInfo
.
getNickName
()))
{
if
(
StringUtils
.
isNotBlank
(
userInfo
.
getNickName
()))
{
String
nickName
=
EmojiUtil
.
filter
(
userInfo
.
getNickName
());
String
nickName
=
EmojiUtil
.
filter
(
userInfo
.
getNickName
());
userInfo
.
setNickName
(
nickName
);
userInfo
.
setNickName
(
nickName
);
}
}
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
Constants
.
Channel
.
WECHAT
);
Constants
.
Channel
.
WECHAT
);
return
;
return
true
;
}
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
);
Constants
.
Channel
.
WECHAT
);
return
;
return
true
;
}
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
if
(
user
==
null
)
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
);
Constants
.
Channel
.
WECHAT
);
return
;
return
true
;
}
}
// 已经关联了用户
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
// create session, 登进去,该怎么玩怎么玩。
String
redirectUrl
=
String
redirectUrl
=
createUserSession
(
user
,
merchant
,
""
,
schema
,
Constants
.
Channel
.
WECHAT
);
createUserSession
(
user
,
merchant
,
""
,
schema
,
Constants
.
Channel
.
WECHAT
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
response
.
setStatus
(
301
);
return
false
;
}
/**
* 通过redirect_url获取code
*
* @param response
* @return
*/
@RequestMapping
(
"/receiveCode/{key}"
)
public
void
receiveCodeNoRedirect
(
String
code
,
@PathVariable
(
value
=
"key"
)
String
systemKey
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
String
schema
=
request
.
getScheme
();
LOGGER
.
info
(
"HTTP协议no redirect:"
+
schema
);
// 从code获取token
normalLogin
(
code
,
systemKey
,
response
,
schema
);
}
}
private
String
createUserSession
(
User
user
,
Merchant
merchant
,
String
redirect
,
String
schema
,
Long
registerFrom
)
{
private
String
createUserSession
(
User
user
,
Merchant
merchant
,
String
redirect
,
String
schema
,
Long
registerFrom
)
{
String
url
=
schema
+
"//passport.xyqb.com"
;
//TODO 临时紧急上线修改的.下次上线的时候修复一下,不能这样写.
if
(
StringUtils
.
isEmpty
(
redirect
)
||
"redirect"
.
equals
(
redirect
))
{
String
url
=
"http://passport.xyqb.com"
;
if
(
"https"
.
equals
(
schema
))
{
url
=
"https://passport.xyqb.com"
;
}
if
(
StringUtils
.
isEmpty
(
redirect
)
||
"redirect"
.
equals
(
redirect
))
{
LOGGER
.
info
(
"微信登录:redirect为null,走正常流程."
);
LOGGER
.
info
(
"微信登录:redirect为null,走正常流程."
);
if
(
"baitiao"
.
equals
(
merchant
.
getName
()))
{
if
(
"baitiao"
.
equals
(
merchant
.
getName
()))
{
return
loginInWechatWithSessionCreated
(
user
,
merchant
,
"cashTarget5"
,
Constants
.
Channel
.
BAITIAO
,
url
,
Constants
.
Channel
.
WECHAT
);
return
loginInWechatWithSessionCreated
(
user
,
merchant
,
"cashTarget5"
,
Constants
.
Channel
.
BAITIAO
,
url
,
Constants
.
Channel
.
WECHAT
);
}
else
{
}
else
{
return
loginInWechatWithSessionCreated
(
user
,
merchant
,
"cashTarget4"
,
1L
,
url
,
registerFrom
);
return
loginInWechatWithSessionCreated
(
user
,
merchant
,
"cashTarget4"
,
1L
,
url
,
registerFrom
);
}
}
}
else
if
(
"local"
.
equals
(
redirect
))
{
}
else
if
(
"local"
.
equals
(
redirect
))
{
LOGGER
.
info
(
"微信登录:redirect不为null,创建session跳到指定前端页面."
);
LOGGER
.
info
(
"微信登录:redirect不为null,创建session跳到指定前端页面."
);
AuthBean
authBean
=
sessionService
.
createSession
(
Constants
.
Channel
.
WECHAT
,
Constants
.
Channel
.
WECHAT
,
""
,
user
,
merchant
);
AuthBean
authBean
=
sessionService
.
createSession
(
Constants
.
Channel
.
WECHAT
,
Constants
.
Channel
.
WECHAT
,
""
,
user
,
merchant
);
LOGGER
.
info
(
"微信登录:跳转地址{}"
,
url
+
"/weixin/callback?phoneNo="
+
user
.
getPhoneNo
()
+
"&token="
+
authBean
.
getToken
());
LOGGER
.
info
(
"微信登录:跳转地址{}"
,
url
+
"/weixin/callback?phoneNo="
+
user
.
getPhoneNo
()
+
"&token="
+
authBean
.
getToken
());
...
@@ -510,39 +491,9 @@ public class WeChatController implements IBaseController {
...
@@ -510,39 +491,9 @@ public class WeChatController implements IBaseController {
return
null
;
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
)
{
private
String
loginInWechatWithSessionCreated
(
User
user
,
Merchant
merchant
,
String
target
,
Long
channelId
,
String
url
,
Long
registerFrom
)
{
AuthBean
authBean
=
sessionService
.
createSession
(
channelId
,
registerFrom
,
""
,
user
,
merchant
);
AuthBean
authBean
=
sessionService
.
createSession
(
channelId
,
registerFrom
,
""
,
user
,
merchant
);
return
url
+
"/landing?token="
+
authBean
.
getToken
()
+
"®isterFrom="
+
registerFrom
+
"&channelId="
+
channelId
+
"&key="
+
merchant
.
getName
()
+
"&target="
+
target
;
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
)
{
private
void
redirectWechatLoginUrlWithoutLogin
(
HttpServletResponse
response
,
Merchant
merchant
,
WechatUserInfo
userInfo
,
Long
registerFrom
)
{
...
...
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