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
dca45e7f
Commit
dca45e7f
authored
Feb 07, 2017
by
lee_mingzhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove phone_no column
parent
3f221ecc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
36 deletions
+66
-36
UserController.java
...ntgroup/xyqb/controller/internal/user/UserController.java
+57
-36
WechatUserInfo.java
src/main/java/cn/quantgroup/xyqb/entity/WechatUserInfo.java
+2
-0
IWeChatUserRepository.java
.../cn/quantgroup/xyqb/repository/IWeChatUserRepository.java
+1
-0
IWechatService.java
...ava/cn/quantgroup/xyqb/service/wechat/IWechatService.java
+1
-0
WechatServiceImpl.java
...uantgroup/xyqb/service/wechat/impl/WechatServiceImpl.java
+5
-0
No files found.
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserController.java
View file @
dca45e7f
...
...
@@ -77,15 +77,15 @@ public class UserController implements IBaseController {
public
JsonResult
login
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
channelId
,
String
appChannel
,
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
createdFrom
,
@RequestParam
(
required
=
false
,
defaultValue
=
""
)
String
userId
,
String
key
,
HttpServletRequest
request
)
{
@RequestParam
(
required
=
false
,
defaultValue
=
""
)
String
userId
,
String
key
,
HttpServletRequest
request
,
String
openId
)
{
Merchant
merchant
=
merchantService
.
findMerchantByName
(
key
);
if
(
merchant
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"未知的连接"
,
null
);
}
if
(!
StringUtils
.
isEmpty
(
userId
)
&&
userId
.
length
()
>
10
)
{
if
(!
StringUtils
.
isEmpty
(
userId
)
&&
userId
.
length
()
>
10
)
{
return
loginWithUserId
(
channelId
,
appChannel
,
createdFrom
,
userId
,
merchant
);
}
else
{
return
loginWithHttpBasic
(
channelId
,
appChannel
,
createdFrom
,
merchant
,
request
);
return
loginWithHttpBasic
(
channelId
,
appChannel
,
createdFrom
,
merchant
,
request
,
openId
);
}
}
...
...
@@ -97,9 +97,9 @@ public class UserController implements IBaseController {
@RequestMapping
(
"/login/fast"
)
public
JsonResult
loginFast
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
channelId
,
String
appChannel
,
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
createdFrom
,
String
key
,
HttpServletRequest
request
){
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
createdFrom
,
String
key
,
HttpServletRequest
request
)
{
Map
<
String
,
JsonResult
>
validMap
=
getHeaderParam
(
request
);
if
(
null
!=
validMap
.
get
(
"fail"
))
{
if
(
null
!=
validMap
.
get
(
"fail"
))
{
return
validMap
.
get
(
"fail"
);
}
Merchant
merchant
=
merchantService
.
findMerchantByName
(
key
);
...
...
@@ -109,7 +109,7 @@ public class UserController implements IBaseController {
JsonResult
successResult
=
validMap
.
get
(
"success"
);
String
phoneNo
=
successResult
.
getData
().
toString
();
User
user
=
userService
.
findByPhoneWithCache
(
phoneNo
);
if
(
user
==
null
)
{
if
(
user
==
null
)
{
user
=
registerFastWhenLogin
(
phoneNo
,
channelId
,
createdFrom
,
appChannel
);
if
(
user
==
null
)
{
throw
new
UserNotExistException
(
"用户未找到"
);
...
...
@@ -121,38 +121,39 @@ public class UserController implements IBaseController {
/**
* 快速登录验证
*
* @param request
* @return
*/
private
Map
<
String
,
JsonResult
>
getHeaderParam
(
HttpServletRequest
request
){
private
Map
<
String
,
JsonResult
>
getHeaderParam
(
HttpServletRequest
request
)
{
Map
<
String
,
JsonResult
>
result
=
new
HashMap
<>();
String
verificationHeader
=
"Verification "
;
String
credential
=
request
.
getHeader
(
"authorization"
);
if
(
StringUtils
.
isBlank
(
credential
))
{
if
(
StringUtils
.
isBlank
(
credential
))
{
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
));
}
if
(!
credential
.
startsWith
(
verificationHeader
))
{
if
(!
credential
.
startsWith
(
verificationHeader
))
{
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
));
}
credential
=
credential
.
substring
(
verificationHeader
.
length
(),
credential
.
length
());
byte
[]
buf
=
Base64
.
decodeBase64
(
credential
);
try
{
credential
=
new
String
(
buf
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
){
}
catch
(
UnsupportedEncodingException
e
)
{
LOGGER
.
error
(
"不支持的编码."
);
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
));
}
String
[]
credentialArr
=
credential
.
split
(
":"
);
if
(
credentialArr
.
length
!=
2
)
{
if
(
credentialArr
.
length
!=
2
)
{
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
));
}
String
phoneNo
=
credentialArr
[
0
];
String
verificationCode
=
credentialArr
[
1
];
LOGGER
.
info
(
"用户快速登录,phoneNo:{} , verificationCode:{}"
,
phoneNo
,
verificationCode
);
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
));
}
if
(!
smsService
.
validateFastLoginVerificationCode
(
phoneNo
,
verificationCode
))
{
if
(!
smsService
.
validateFastLoginVerificationCode
(
phoneNo
,
verificationCode
))
{
LOGGER
.
info
(
"用户快速登录,验证码校验失败,phoneNo:{} , verificationCode:{}"
,
phoneNo
,
verificationCode
);
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"验证码错误"
,
null
));
}
...
...
@@ -348,16 +349,16 @@ public class UserController implements IBaseController {
}
@RequestMapping
(
"/syncUserInfo"
)
@RequestMapping
(
"/syncUserInfo"
)
public
JsonResult
syncUserInfo
()
{
User
user
=
getCurrentUser
();
if
(
null
==
user
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
UserDetail
detail
=
userDetailService
.
findByUserId
(
user
.
getId
());
//UserDetail detail = userDetailRepository.findByUserId(user.getId());
UserModel
userModel
=
new
UserModel
(
user
,
detail
);
return
JsonResult
.
buildSuccessResult
(
"token校验成功"
,
userModel
);
User
user
=
getCurrentUser
();
if
(
null
==
user
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
UserDetail
detail
=
userDetailService
.
findByUserId
(
user
.
getId
());
//UserDetail detail = userDetailRepository.findByUserId(user.getId());
UserModel
userModel
=
new
UserModel
(
user
,
detail
);
return
JsonResult
.
buildSuccessResult
(
"token校验成功"
,
userModel
);
}
private
User
registerFastWhenLogin
(
String
phoneNo
,
Long
channelId
,
Long
registerFrom
,
String
appChannel
)
{
...
...
@@ -377,18 +378,22 @@ public class UserController implements IBaseController {
}
private
JsonResult
loginWithHttpBasic
(
Long
channelId
,
String
appChannel
,
Long
createdFrom
,
Merchant
merchant
,
HttpServletRequest
request
)
{
User
user
=
verificateUserNameAndPassword
(
request
);
private
JsonResult
loginWithHttpBasic
(
Long
channelId
,
String
appChannel
,
Long
createdFrom
,
Merchant
merchant
,
HttpServletRequest
request
,
String
openId
)
{
User
user
=
verificateUserNameAndPassword
(
request
,
openId
);
if
(
user
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"用户名或密码不正确"
,
null
);
}
else
{
//id为-1,微信重复绑定的标示.
if
(
user
.
getId
()
==
-
1L
)
{
return
JsonResult
.
buildErrorStateResult
(
"该手机号已绑定了其他微信账号."
,
null
);
}
return
new
JsonResult
(
sessionService
.
createSession
(
channelId
,
createdFrom
,
appChannel
,
user
,
merchant
));
}
}
private
User
verificateUserNameAndPassword
(
HttpServletRequest
request
)
{
private
User
verificateUserNameAndPassword
(
HttpServletRequest
request
,
String
openId
)
{
String
credential
=
request
.
getHeader
(
"authorization"
);
if
(!
credential
.
startsWith
(
"Basic "
))
{
if
(!
credential
.
startsWith
(
"Basic "
))
{
return
null
;
}
credential
=
credential
.
substring
(
"Basic "
.
length
(),
credential
.
length
());
...
...
@@ -396,17 +401,31 @@ public class UserController implements IBaseController {
String
bufStr
=
""
;
try
{
bufStr
=
new
String
(
buf
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
){
}
catch
(
UnsupportedEncodingException
e
)
{
LOGGER
.
error
(
"不支持的编码: "
,
e
);
}
String
[]
credentialArr
=
bufStr
.
split
(
":"
);
if
(
credentialArr
.
length
!=
2
)
{
if
(
credentialArr
.
length
!=
2
)
{
return
null
;
}
String
userName
=
credentialArr
[
0
];
String
pass
=
credentialArr
[
1
];
/*//判断是否微信登录(openId不为空,认为是微信登录)
if(StringUtils.isNotEmpty(openId)) {
WechatUserInfo wechatUserInfo = wechatService.findWechatUserInfoFromDb(openId);
//说明微信用户已经绑定过xyqb用户了
if(wechatUserInfo != null && wechatUserInfo.getUserId() != null && wechatUserInfo.getUserId() != 0L) {
//判断绑定的xyqb用户的手机号是否和本次登录的手机号一致
User xyqbUser = userService.findById(wechatUserInfo.getUserId());
if(!xyqbUser.getPhoneNo().equals(userName)) {
User user = new User();
user.setId(-1L);
return user;
}
}
}*/
User
user
=
userService
.
findByPhoneWithCache
(
userName
);
if
(
user
==
null
)
{
if
(
user
==
null
)
{
return
null
;
}
//验证密码
...
...
@@ -416,7 +435,7 @@ public class UserController implements IBaseController {
return
user
;
}
private
boolean
validatePassword
(
String
paramPass
,
String
targetPassword
){
private
boolean
validatePassword
(
String
paramPass
,
String
targetPassword
)
{
return
StringUtils
.
defaultString
(
targetPassword
,
""
).
equals
(
PasswordUtil
.
MD5
(
paramPass
.
toLowerCase
()
+
pwdSalt
));
}
...
...
@@ -424,7 +443,7 @@ public class UserController implements IBaseController {
//查询用户,存在则保存用户session信息,userId为uuid
User
user
=
userService
.
findByUuidInDb
(
userId
);
//用户信息存在,更新session中的最后访问时间,重新写入缓存.
if
(
null
!=
user
)
{
if
(
null
!=
user
)
{
return
new
JsonResult
(
sessionService
.
createSession
(
channelId
,
createdFrom
,
appChannel
,
user
,
merchant
));
}
else
{
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
...
...
@@ -432,20 +451,22 @@ public class UserController implements IBaseController {
}
@RequestMapping
(
"/associate_wechat"
)
public
JsonResult
associateWithWechat
(
String
openId
)
{
public
JsonResult
associateWithWechat
(
String
openId
,
String
phoneNo
)
{
LOGGER
.
info
(
"关联用户:start"
);
User
user
=
getCurrentUser
();
Long
userId
=
user
.
getId
();
LOGGER
.
info
(
"关联用户:当前登录用户id:"
+
userId
);
String
phoneNo
=
user
.
getPhoneNo
(
);
if
(
userService
.
findByPhoneInDb
(
phoneNo
)
!=
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"该手机号已
经关联了其他微信账号
."
,
null
);
WechatUserInfo
wechatUserInfo
=
wechatService
.
findWechatUserInfoByPhoneNo
(
phoneNo
);
if
(
wechatUserInfo
!=
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"该手机号已
绑定其他微信号码
."
,
null
);
}
WechatUserInfo
userInfo
=
wechatService
.
findWechatUserInfoFromDb
(
openId
);
//限制微信用户和xyqb用户为一对一的关系
LOGGER
.
info
(
"关联用户:查询微信用户信息:start"
);
if
(
userInfo
!=
null
&&
userInfo
.
getUserId
()
==
null
)
{
if
(
userInfo
!=
null
)
{
LOGGER
.
info
(
"关联用户:查询到了微信用户信息."
);
userInfo
.
setUserId
(
userId
);
userInfo
.
setPhoneNo
(
phoneNo
);
wechatService
.
saveWechatUserInfo
(
userInfo
);
LOGGER
.
info
(
"关联用户:关联xyqb用户成功."
);
}
...
...
src/main/java/cn/quantgroup/xyqb/entity/WechatUserInfo.java
View file @
dca45e7f
...
...
@@ -24,6 +24,8 @@ public class WechatUserInfo implements Serializable{
private
Long
userId
;
@Column
(
name
=
"open_id"
)
private
String
openId
;
@Column
(
name
=
"phone_no"
)
private
String
phoneNo
;
@Column
(
name
=
"nick_name"
)
private
String
nickName
;
@Column
(
name
=
"sex"
)
...
...
src/main/java/cn/quantgroup/xyqb/repository/IWeChatUserRepository.java
View file @
dca45e7f
...
...
@@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
*/
public
interface
IWeChatUserRepository
extends
JpaRepository
<
WechatUserInfo
,
Long
>
{
WechatUserInfo
findByOpenId
(
String
openId
);
WechatUserInfo
findByPhoneNo
(
String
phoneNo
);
}
src/main/java/cn/quantgroup/xyqb/service/wechat/IWechatService.java
View file @
dca45e7f
...
...
@@ -12,6 +12,7 @@ public interface IWechatService {
WechatUserInfo
findWechatUserInfoFromDb
(
String
openId
);
WechatUserInfo
findWechatUserInfoByPhoneNo
(
String
phoneNo
);
WechatUserInfo
saveWechatUserInfo
(
WechatUserInfo
userInfo
);
}
src/main/java/cn/quantgroup/xyqb/service/wechat/impl/WechatServiceImpl.java
View file @
dca45e7f
...
...
@@ -115,6 +115,11 @@ public class WechatServiceImpl implements IWechatService {
return
weChatUserRepository
.
save
(
userInfo
);
}
@Override
public
WechatUserInfo
findWechatUserInfoByPhoneNo
(
String
phoneNo
)
{
return
weChatUserRepository
.
findByPhoneNo
(
phoneNo
);
}
private
String
getTokenFromWechatServer
(
String
code
)
{
if
(
StringUtils
.
isEmpty
(
code
))
{
return
null
;
...
...
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