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
d450557c
Commit
d450557c
authored
Dec 01, 2017
by
Java—KA—李 青
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改随机密码获取方式
parent
6e6d8c7f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
67 deletions
+53
-67
UserController.java
...ntgroup/xyqb/controller/internal/user/UserController.java
+6
-46
PasswordUtil.java
src/main/java/cn/quantgroup/xyqb/util/PasswordUtil.java
+47
-21
No files found.
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserController.java
View file @
d450557c
...
@@ -14,7 +14,6 @@ import cn.quantgroup.xyqb.exception.UserNotExistException;
...
@@ -14,7 +14,6 @@ import cn.quantgroup.xyqb.exception.UserNotExistException;
import
cn.quantgroup.xyqb.exception.VerificationCodeErrorException
;
import
cn.quantgroup.xyqb.exception.VerificationCodeErrorException
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.UserModel
;
import
cn.quantgroup.xyqb.model.UserModel
;
import
cn.quantgroup.xyqb.model.UserRegisterMqMessage
;
import
cn.quantgroup.xyqb.model.UserStatistics
;
import
cn.quantgroup.xyqb.model.UserStatistics
;
import
cn.quantgroup.xyqb.service.merchant.IMerchantService
;
import
cn.quantgroup.xyqb.service.merchant.IMerchantService
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
...
@@ -23,7 +22,6 @@ import cn.quantgroup.xyqb.service.user.IUserDetailService;
...
@@ -23,7 +22,6 @@ import cn.quantgroup.xyqb.service.user.IUserDetailService;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.service.wechat.IWechatService
;
import
cn.quantgroup.xyqb.service.wechat.IWechatService
;
import
cn.quantgroup.xyqb.util.*
;
import
cn.quantgroup.xyqb.util.*
;
import
cn.quantgroup.xyqb.util.encrypt.MD5Util
;
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
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -38,7 +36,10 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -38,7 +36,10 @@ import org.springframework.web.bind.annotation.RestController;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
java.util.*
;
import
java.util.Calendar
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -73,12 +74,6 @@ public class UserController implements IBaseController {
...
@@ -73,12 +74,6 @@ public class UserController implements IBaseController {
@Autowired
@Autowired
private
IWechatService
wechatService
;
private
IWechatService
wechatService
;
private
static
final
char
[]
PWD_BASE
=
{
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
,
'j'
,
'k'
,
'l'
,
'm'
,
'n'
,
'o'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
'u'
,
'v'
,
'w'
,
'x'
,
'y'
,
'z'
,
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
};
@RequestMapping
(
"/test"
)
@RequestMapping
(
"/test"
)
public
JsonResult
test
()
{
public
JsonResult
test
()
{
HttpServletRequest
request
=
getRequest
();
HttpServletRequest
request
=
getRequest
();
...
@@ -250,7 +245,7 @@ public class UserController implements IBaseController {
...
@@ -250,7 +245,7 @@ public class UserController implements IBaseController {
}
}
private
User
registerFastWhenLogin
(
String
phoneNo
,
Long
channelId
,
Long
registerFrom
,
String
appChannel
,
Long
btRegisterChannelId
,
String
dimension
)
{
private
User
registerFastWhenLogin
(
String
phoneNo
,
Long
channelId
,
Long
registerFrom
,
String
appChannel
,
Long
btRegisterChannelId
,
String
dimension
)
{
String
password
=
gen
RandomPwd
();
String
password
=
PasswordUtil
.
generate
RandomPwd
();
LOGGER
.
info
(
"用户快速注册, phoneNo:{}, channelId:{}, registerFrom:{},appChannel:{},btRegisterChannelId"
,
phoneNo
,
channelId
,
registerFrom
,
appChannel
,
btRegisterChannelId
);
LOGGER
.
info
(
"用户快速注册, phoneNo:{}, channelId:{}, registerFrom:{},appChannel:{},btRegisterChannelId"
,
phoneNo
,
channelId
,
registerFrom
,
appChannel
,
btRegisterChannelId
);
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
LOGGER
.
info
(
"用户快速注册失败,手机号错误, registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
LOGGER
.
info
(
"用户快速注册失败,手机号错误, registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
...
@@ -318,7 +313,7 @@ public class UserController implements IBaseController {
...
@@ -318,7 +313,7 @@ public class UserController implements IBaseController {
public
JsonResult
registerFast
(
@RequestParam
String
phoneNo
,
@RequestParam
String
verificationCode
,
@RequestParam
(
required
=
false
)
Long
channelId
,
public
JsonResult
registerFast
(
@RequestParam
String
phoneNo
,
@RequestParam
String
verificationCode
,
@RequestParam
(
required
=
false
)
Long
channelId
,
@RequestParam
(
required
=
false
)
Long
registerFrom
,
@RequestParam
(
required
=
false
,
defaultValue
=
""
)
String
appChannel
,
@RequestParam
(
required
=
false
)
Long
registerFrom
,
@RequestParam
(
required
=
false
,
defaultValue
=
""
)
String
appChannel
,
@RequestParam
(
required
=
false
)
Long
btRegisterChannelId
,
@RequestParam
(
required
=
false
)
String
dimension
)
{
@RequestParam
(
required
=
false
)
Long
btRegisterChannelId
,
@RequestParam
(
required
=
false
)
String
dimension
)
{
String
password
=
gen
RandomPwd
();
String
password
=
PasswordUtil
.
generate
RandomPwd
();
LOGGER
.
info
(
"用户快速注册, phoneNo:{}, verificationCode:{}, channelId:{}, registerFrom:{},appChannel:{},btRegisterChannelId:{},dimension:{}"
,
phoneNo
,
verificationCode
,
channelId
,
registerFrom
,
appChannel
,
btRegisterChannelId
,
dimension
);
LOGGER
.
info
(
"用户快速注册, phoneNo:{}, verificationCode:{}, channelId:{}, registerFrom:{},appChannel:{},btRegisterChannelId:{},dimension:{}"
,
phoneNo
,
verificationCode
,
channelId
,
registerFrom
,
appChannel
,
btRegisterChannelId
,
dimension
);
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
LOGGER
.
info
(
"用户快速注册失败,手机号错误, registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
LOGGER
.
info
(
"用户快速注册失败,手机号错误, registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
...
@@ -477,24 +472,6 @@ public class UserController implements IBaseController {
...
@@ -477,24 +472,6 @@ public class UserController implements IBaseController {
return
JsonResult
.
buildSuccessResult
(
null
,
stringRedisTemplate
.
hasKey
(
tokenKey
)||
stringRedisTemplate
.
hasKey
(
tokenKey2
));
return
JsonResult
.
buildSuccessResult
(
null
,
stringRedisTemplate
.
hasKey
(
tokenKey
)||
stringRedisTemplate
.
hasKey
(
tokenKey2
));
}
}
private
String
genRandomPwd
()
{
int
pwdMax
=
PWD_BASE
.
length
;
int
i
;
// 生成的随机数
int
count
=
0
;
// 生成的密码的长度
StringBuffer
pwd
=
new
StringBuffer
();
Random
r
=
new
Random
();
while
(
count
<
15
)
{
i
=
Math
.
abs
(
r
.
nextInt
(
pwdMax
));
// 生成的数最大为36-1
if
(
i
>=
0
&&
i
<
PWD_BASE
.
length
)
{
pwd
.
append
(
PWD_BASE
[
i
]);
count
++;
}
}
return
pwd
.
toString
();
}
@RequestMapping
(
"/syncUserInfo"
)
@RequestMapping
(
"/syncUserInfo"
)
public
JsonResult
syncUserInfo
()
{
public
JsonResult
syncUserInfo
()
{
User
user
=
getCurrentUserFromRedis
();
User
user
=
getCurrentUserFromRedis
();
...
@@ -507,23 +484,6 @@ public class UserController implements IBaseController {
...
@@ -507,23 +484,6 @@ public class UserController implements IBaseController {
return
JsonResult
.
buildSuccessResult
(
"token校验成功"
,
userModel
);
return
JsonResult
.
buildSuccessResult
(
"token校验成功"
,
userModel
);
}
}
private
User
registerFastWhenLogin
(
String
phoneNo
,
Long
channelId
,
Long
registerFrom
,
String
appChannel
)
{
String
password
=
genRandomPwd
();
LOGGER
.
info
(
"用户快速注册, phoneNo:{}, verificationCode:{}, channelId:{}, registerFrom:{},appChannel:{}"
,
phoneNo
,
channelId
,
registerFrom
,
appChannel
);
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
LOGGER
.
info
(
"用户快速注册失败,手机号错误, registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
throw
new
UserNotExistException
(
"手机号错误"
);
}
if
(
null
==
registerFrom
)
{
registerFrom
=
1L
;
}
User
newUser
=
userService
.
registerAndReturn
(
phoneNo
,
password
,
registerFrom
);
if
(
newUser
!=
null
&&
newUser
.
getId
()
!=
null
&&
newUser
.
getId
()
>
0
){
LOGGER
.
info
(
"用户快速注册成功, registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
}
return
newUser
;
}
private
JsonResult
loginWithHttpBasic
(
Long
channelId
,
String
appChannel
,
Long
createdFrom
,
Merchant
merchant
,
HttpServletRequest
request
,
String
openId
,
String
dimension
)
{
private
JsonResult
loginWithHttpBasic
(
Long
channelId
,
String
appChannel
,
Long
createdFrom
,
Merchant
merchant
,
HttpServletRequest
request
,
String
openId
,
String
dimension
)
{
User
user
=
verificateUserNameAndPassword
(
request
,
openId
);
User
user
=
verificateUserNameAndPassword
(
request
,
openId
);
if
(
user
==
null
)
{
if
(
user
==
null
)
{
...
...
src/main/java/cn/quantgroup/xyqb/util/PasswordUtil.java
View file @
d450557c
package
cn
.
quantgroup
.
xyqb
.
util
;
package
cn
.
quantgroup
.
xyqb
.
util
;
import
java.security.MessageDigest
;
import
java.security.MessageDigest
;
import
java.util.concurrent.ThreadLocalRandom
;
/**
/**
* Created by Miraculous on 15/7/5.
* Created by Miraculous on 15/7/5.
*/
*/
public
class
PasswordUtil
{
public
class
PasswordUtil
{
private
static
final
char
[]
HEX_DIGITS
=
{
private
static
final
char
[]
HEX_DIGITS
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
};
public
final
static
String
MD5
(
String
s
)
{
private
static
final
char
[]
PWD_BASE
=
{
try
{
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
,
'j'
,
'k'
,
byte
[]
strTemp
=
s
.
getBytes
(
"utf-8"
);
'l'
,
'm'
,
'n'
,
'o'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
'u'
,
'v'
,
'w'
,
MessageDigest
mdTemp
=
MessageDigest
.
getInstance
(
"MD5"
);
'x'
,
'y'
,
'z'
,
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
mdTemp
.
update
(
strTemp
);
};
byte
[]
md
=
mdTemp
.
digest
();
int
j
=
md
.
length
;
public
final
static
String
MD5
(
String
s
)
{
char
[]
str
=
new
char
[
j
<<
1
];
try
{
int
k
=
0
;
byte
[]
strTemp
=
s
.
getBytes
(
"utf-8"
);
for
(
int
i
=
0
;
i
<
j
;
i
++)
{
MessageDigest
mdTemp
=
MessageDigest
.
getInstance
(
"MD5"
);
byte
byte0
=
md
[
i
];
mdTemp
.
update
(
strTemp
);
str
[
k
++]
=
HEX_DIGITS
[
byte0
>>>
4
&
0xf
];
byte
[]
md
=
mdTemp
.
digest
();
str
[
k
++]
=
HEX_DIGITS
[
byte0
&
0xf
];
int
j
=
md
.
length
;
}
char
[]
str
=
new
char
[
j
<<
1
];
return
new
String
(
str
);
int
k
=
0
;
}
catch
(
Exception
e
)
{
for
(
int
i
=
0
;
i
<
j
;
i
++)
{
return
null
;
byte
byte0
=
md
[
i
];
str
[
k
++]
=
HEX_DIGITS
[
byte0
>>>
4
&
0xf
];
str
[
k
++]
=
HEX_DIGITS
[
byte0
&
0xf
];
}
return
new
String
(
str
);
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 生成随机密码
* @return
*/
public
static
String
generateRandomPwd
()
{
int
pwdMax
=
PWD_BASE
.
length
;
int
i
;
// 生成的随机数
int
count
=
0
;
// 生成的密码的长度
StringBuffer
pwd
=
new
StringBuffer
();
while
(
count
<
15
)
{
i
=
Math
.
abs
(
ThreadLocalRandom
.
current
().
nextInt
(
pwdMax
));
// 生成的数最大为36-1
if
(
i
>=
0
&&
i
<
PWD_BASE
.
length
)
{
pwd
.
append
(
PWD_BASE
[
i
]);
count
++;
}
}
return
pwd
.
toString
();
}
}
}
}
}
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