Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
youjj
cloud-platform
Commits
4bd29ffb
Commit
4bd29ffb
authored
May 21, 2019
by
hezhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加微信qq登录接口,手机验证接口
parent
23a37a19
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
621 additions
and
19 deletions
+621
-19
pom.xml
ace-auth/ace-auth-server/pom.xml
+6
-0
SwaggerConfig.java
...ub/wxiaoqi/security/auth/configuration/SwaggerConfig.java
+56
-0
AuthController.java
...thub/wxiaoqi/security/auth/controller/AuthController.java
+53
-2
IUserService.java
.../com/github/wxiaoqi/security/auth/feign/IUserService.java
+14
-0
AuthService.java
...com/github/wxiaoqi/security/auth/service/AuthService.java
+4
-0
AppAuthServiceImpl.java
...xiaoqi/security/auth/service/impl/AppAuthServiceImpl.java
+20
-0
AuthServiceImpl.java
...b/wxiaoqi/security/auth/service/impl/AuthServiceImpl.java
+19
-0
EmojiFilter.java
.../com/github/wxiaoqi/security/common/util/EmojiFilter.java
+87
-0
SystemConfig.java
...ub/wxiaoqi/security/common/util/process/SystemConfig.java
+4
-0
resultcod.properties
...common/src/main/resources/properties/resultcod.properties
+1
-1
systemconfig.properties
...mon/src/main/resources/properties/systemconfig.properties
+5
-1
AppUserDetailBiz.java
...m/github/wxiaoqi/security/admin/biz/AppUserDetailBiz.java
+19
-1
AppUserLoginBiz.java
...om/github/wxiaoqi/security/admin/biz/AppUserLoginBiz.java
+20
-0
RedisKey.java
.../com/github/wxiaoqi/security/admin/constant/RedisKey.java
+10
-0
AppUserRest.java
...va/com/github/wxiaoqi/security/admin/rpc/AppUserRest.java
+77
-0
AppPermissionService.java
...aoqi/security/admin/rpc/service/AppPermissionService.java
+190
-14
JwtAuthenticationRequest.java
...wxiaoqi/security/admin/util/JwtAuthenticationRequest.java
+36
-0
No files found.
ace-auth/ace-auth-server/pom.xml
View file @
4bd29ffb
...
...
@@ -12,6 +12,12 @@
<artifactId>
ace-auth-server
</artifactId>
<dependencies>
<!-- swagger -->
<dependency>
<groupId>
com.spring4all
</groupId>
<artifactId>
swagger-spring-boot-starter
</artifactId>
<version>
1.6.0.RELEASE
</version>
</dependency>
<!--使用undertow 替换 Tomcat-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/configuration/SwaggerConfig.java
0 → 100644
View file @
4bd29ffb
package
com
.
github
.
wxiaoqi
.
security
.
auth
.
configuration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.ParameterBuilder
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.schema.ModelRef
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.service.Parameter
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @Description : swagger配置配置
* @Author : Mars
* @Date : 2017年9月6日
*/
@Configuration
@EnableSwagger2
public
class
SwaggerConfig
{
/**
* Every Docket bean is picked up by the swagger-mvc framework - allowing for multiple
* swagger groups i.e. same code base multiple swagger resource listings.
*/
@Bean
public
Docket
customDocket
(){
ParameterBuilder
ticketPar
=
new
ParameterBuilder
();
List
<
Parameter
>
pars
=
new
ArrayList
<
Parameter
>();
ticketPar
.
name
(
"Authorization"
).
description
(
"user Authorization"
)
.
modelRef
(
new
ModelRef
(
"string"
)).
parameterType
(
"header"
)
.
required
(
false
).
build
();
//header中的ticket参数非必填,传空也可以
pars
.
add
(
ticketPar
.
build
());
//根据每个方法名也知道当前方法在设置什么参数
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.github.wxiaoqi.security.auth"
))
//.apis(RequestHandlerSelectors.any())
.
build
()
.
globalOperationParameters
(
pars
)
.
apiInfo
(
apiInfo
());
}
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"api swagger document"
)
.
description
(
"前后端联调swagger api 文档"
)
.
version
(
"2.1.5.5"
)
.
build
();
}
}
\ No newline at end of file
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/controller/AuthController.java
View file @
4bd29ffb
...
...
@@ -5,6 +5,7 @@ import com.github.wxiaoqi.security.auth.service.AuthService;
import
com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest
;
import
com.github.wxiaoqi.security.common.constant.RequestTypeConstants
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
...
...
@@ -61,8 +62,58 @@ public class AuthController {
return
new
ObjectRestResponse
<>();
}
@RequestMapping
(
value
=
"/sendsms"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
sendsms
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"0"
)
Integer
type
)
throws
Exception
{
public
JSONObject
sendsms
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"0"
)
Integer
type
)
throws
Exception
{
log
.
info
(
username
+
"----require sendsms..."
);
return
authService
.
sendsms
(
username
,
type
);
return
a
ppA
uthService
.
sendsms
(
username
,
type
);
}
@RequestMapping
(
value
=
"/register"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
register
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
,
defaultValue
=
""
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
password
)
throws
Exception
{
log
.
info
(
username
+
"----require register..."
);
JSONObject
data
=
appAuthService
.
register
(
username
,
mobilecode
,
password
);
if
(
data
!=
null
&&
data
.
getInteger
(
"status"
)==
ResultCode
.
SUCCESS_CODE
){
JwtAuthenticationRequest
authenticationRequest
=
new
JwtAuthenticationRequest
();
authenticationRequest
.
setUsername
(
username
);
authenticationRequest
.
setPassword
(
password
);
String
token
=
appAuthService
.
login
(
authenticationRequest
);
data
.
put
(
"token"
,
token
);
}
return
data
;
}
@RequestMapping
(
value
=
"/wxregister"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
wxregister
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
,
defaultValue
=
""
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
password
,
@RequestParam
(
value
=
"nickname"
,
defaultValue
=
""
)
String
nickname
,
@RequestParam
(
value
=
"headimgurl"
,
defaultValue
=
""
)
String
headimgurl
,
@RequestParam
(
value
=
"openid"
,
defaultValue
=
""
)
String
openid
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
unionid
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"0"
)
Integer
type
,
@RequestParam
(
value
=
"isQQ"
,
defaultValue
=
"0"
)
Integer
isQQ
)
throws
Exception
{
log
.
info
(
username
+
"----require wxregister..."
);
JSONObject
data
=
appAuthService
.
wxregister
(
username
,
mobilecode
,
password
,
nickname
,
headimgurl
,
openid
,
unionid
,
type
,
isQQ
);
if
(
data
!=
null
&&
data
.
getInteger
(
"status"
)==
ResultCode
.
SUCCESS_CODE
){
JwtAuthenticationRequest
authenticationRequest
=
new
JwtAuthenticationRequest
();
authenticationRequest
.
setUsername
(
username
);
authenticationRequest
.
setPassword
(
password
);
String
token
=
appAuthService
.
login
(
authenticationRequest
);
data
.
put
(
"token"
,
token
);
}
return
data
;
}
@RequestMapping
(
value
=
"/checkBindWechat"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
checkBindWechat
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
)
throws
Exception
{
log
.
info
(
username
+
"----require checkBindWechat..."
);
return
appAuthService
.
checkBindWechat
(
username
);
}
@RequestMapping
(
value
=
"/wxlogin"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
wxlogin
(
@RequestParam
(
value
=
"openid"
,
defaultValue
=
""
)
String
openid
,
@RequestParam
(
value
=
"isQQ"
,
defaultValue
=
"0"
)
Integer
isQQ
)
throws
Exception
{
log
.
info
(
openid
+
"----require wxlogin..."
);
return
appAuthService
.
wxlogin
(
openid
,
isQQ
);
}
}
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/feign/IUserService.java
View file @
4bd29ffb
...
...
@@ -28,4 +28,18 @@ public interface IUserService {
@RequestMapping
(
value
=
"/api/app/user/sendsms"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
sendsms
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"0"
)
Integer
type
);
@RequestMapping
(
value
=
"/api/app/user/register"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
register
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
,
defaultValue
=
""
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
password
);
@RequestMapping
(
value
=
"/api/app/user/wxregister"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
wxregister
(
@RequestParam
(
value
=
"username"
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
)
String
password
,
@RequestParam
(
value
=
"nickname"
)
String
nickname
,
@RequestParam
(
value
=
"headimgurl"
)
String
headimgurl
,
@RequestParam
(
value
=
"openid"
)
String
openid
,
@RequestParam
(
value
=
"unionid"
)
String
unionid
,
@RequestParam
(
value
=
"type"
)
Integer
type
,
@RequestParam
(
value
=
"isQQ"
)
Integer
isQQ
);
@RequestMapping
(
value
=
"/api/app/checkBindWechat"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
checkBindWechat
(
@RequestParam
(
value
=
"username"
)
String
username
);
@RequestMapping
(
value
=
"/api/app/user/wxlogin"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
wxlogin
(
@RequestParam
(
value
=
"openid"
)
String
openid
,
@RequestParam
(
value
=
"isQQ"
)
Integer
isQQ
);
}
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/service/AuthService.java
View file @
4bd29ffb
...
...
@@ -9,4 +9,8 @@ public interface AuthService {
String
refresh
(
String
oldToken
)
throws
Exception
;
void
validate
(
String
token
)
throws
Exception
;
JSONObject
sendsms
(
String
username
,
Integer
type
)
throws
Exception
;
JSONObject
register
(
String
username
,
String
mobilecode
,
String
password
)
throws
Exception
;
JSONObject
wxregister
(
String
username
,
String
mobilecode
,
String
password
,
String
nickname
,
String
headimgurl
,
String
openid
,
String
unionid
,
Integer
type
,
Integer
isQQ
)
throws
Exception
;
JSONObject
checkBindWechat
(
String
username
)
throws
Exception
;
JSONObject
wxlogin
(
String
openid
,
Integer
isQQ
)
throws
Exception
;
}
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/service/impl/AppAuthServiceImpl.java
View file @
4bd29ffb
...
...
@@ -50,4 +50,24 @@ public class AppAuthServiceImpl implements AuthService {
return
userService
.
sendsms
(
username
,
type
);
}
@Override
public
JSONObject
register
(
String
username
,
String
mobilecode
,
String
password
)
throws
Exception
{
return
userService
.
register
(
username
,
mobilecode
,
password
);
}
@Override
public
JSONObject
wxregister
(
String
username
,
String
mobilecode
,
String
password
,
String
nickname
,
String
headimgurl
,
String
openid
,
String
unionid
,
Integer
type
,
Integer
isQQ
)
throws
Exception
{
return
userService
.
wxregister
(
username
,
mobilecode
,
password
,
nickname
,
headimgurl
,
openid
,
unionid
,
type
,
isQQ
);
}
@Override
public
JSONObject
checkBindWechat
(
String
username
)
throws
Exception
{
return
userService
.
checkBindWechat
(
username
);
}
@Override
public
JSONObject
wxlogin
(
String
openid
,
Integer
isQQ
)
throws
Exception
{
return
userService
.
wxlogin
(
openid
,
isQQ
);
}
}
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/service/impl/AuthServiceImpl.java
View file @
4bd29ffb
...
...
@@ -48,4 +48,23 @@ public class AuthServiceImpl implements AuthService {
public
JSONObject
sendsms
(
String
username
,
Integer
type
)
throws
Exception
{
return
userService
.
sendsms
(
username
,
type
);
}
@Override
public
JSONObject
register
(
String
username
,
String
mobilecode
,
String
password
)
throws
Exception
{
return
userService
.
register
(
username
,
mobilecode
,
password
);
}
@Override
public
JSONObject
wxregister
(
String
username
,
String
mobilecode
,
String
password
,
String
nickname
,
String
headimgurl
,
String
openid
,
String
unionid
,
Integer
type
,
Integer
isQQ
)
throws
Exception
{
return
userService
.
wxregister
(
username
,
mobilecode
,
password
,
nickname
,
headimgurl
,
openid
,
unionid
,
type
,
isQQ
);
}
@Override
public
JSONObject
checkBindWechat
(
String
username
)
throws
Exception
{
return
userService
.
checkBindWechat
(
username
);
}
@Override
public
JSONObject
wxlogin
(
String
openid
,
Integer
isQQ
)
throws
Exception
{
return
userService
.
wxlogin
(
openid
,
isQQ
);
}
}
ace-common/src/main/java/com/github/wxiaoqi/security/common/util/EmojiFilter.java
0 → 100644
View file @
4bd29ffb
package
com
.
github
.
wxiaoqi
.
security
.
common
.
util
;
import
org.apache.commons.lang3.StringUtils
;
public
class
EmojiFilter
{
/**
* 检测是否有emoji字符
*
* @param source
* @return 一旦含有就抛出
*/
public
static
boolean
containsEmoji
(
String
source
)
{
if
(
StringUtils
.
isBlank
(
source
))
{
return
false
;
}
int
len
=
source
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
codePoint
=
source
.
charAt
(
i
);
if
(
isEmojiCharacter
(
codePoint
))
{
// do nothing,判断到了这里表明,确认有表情字符
return
true
;
}
}
return
false
;
}
private
static
boolean
isEmojiCharacter
(
char
codePoint
)
{
return
(
codePoint
==
0x0
)
||
(
codePoint
==
0x9
)
||
(
codePoint
==
0xA
)
||
(
codePoint
==
0xD
)
||
((
codePoint
>=
0x20
)
&&
(
codePoint
<=
0xD7FF
))
||
((
codePoint
>=
0xE000
)
&&
(
codePoint
<=
0xFFFD
))
||
((
codePoint
>=
0x10000
)
&&
(
codePoint
<=
0x10FFFF
));
}
/**
* 过滤emoji 或者 其他非文字类型的字符
*
* @param source
* @return
*/
public
static
String
filterEmoji
(
String
source
)
{
if
(!
containsEmoji
(
source
))
{
return
source
;
// 如果不包含,直接返回
}
// 到这里铁定包含
StringBuilder
buf
=
null
;
int
len
=
source
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
codePoint
=
source
.
charAt
(
i
);
if
(
isEmojiCharacter
(
codePoint
))
{
if
(
buf
==
null
)
{
buf
=
new
StringBuilder
(
source
.
length
());
}
buf
.
append
(
codePoint
);
}
else
{
}
}
if
(
buf
==
null
)
{
return
source
;
// 如果没有找到 emoji表情,则返回源字符串
}
else
{
if
(
buf
.
length
()
==
len
)
{
// 这里的意义在于尽可能少的toString,因为会重新生成字符串
buf
=
null
;
return
source
;
}
else
{
return
buf
.
toString
();
}
}
}
// public static void main(String[] args) {
// String ss = "\uf0f0";
// System.out.println(ss);
// System.out.println(filterEmoji("<body>口口213这是一个有各种内容的消息, Hia Hia Hia !!!!
// xxxx@@@...*)!" +
// "(@*$&@(&#!)@*)!&$!)@^%@(!&#. 口口口], "));
// }
}
\ No newline at end of file
ace-common/src/main/java/com/github/wxiaoqi/security/common/util/process/SystemConfig.java
View file @
4bd29ffb
...
...
@@ -13,6 +13,10 @@ public class SystemConfig {
public
static
Integer
REDIS_ITOKEN_TIME
=
Integer
.
valueOf
(
SystemProperty
.
getConfig
(
"REDIS_ITOKEN_TIME"
));
// session有效时间
public
static
Integer
SESSION_TIME
=
Integer
.
valueOf
(
SystemProperty
.
getConfig
(
"SESSION_TIME"
));
// session有效时间
public
static
String
USER_HEADER_URL_DEFAULT
=
SystemProperty
.
getConfig
(
"USER_HEADER_URL_DEFAULT"
);
// session有效时间
public
static
String
USER_NIKENAME_DEFAULT
=
SystemProperty
.
getConfig
(
"USER_NIKENAME_DEFAULT"
);
// 根据key名获取value
public
static
String
getCongif
(
String
key
)
{
return
SystemProperty
.
getConfig
(
key
);
...
...
ace-common/src/main/resources/properties/resultcod.properties
View file @
4bd29ffb
#返回结果代码
#操作成功
SUCCESS_CODE
=
10
00
SUCCESS_CODE
=
2
00
#操作失败
FAILED_CODE
=
1001
#数据已存在
...
...
ace-common/src/main/resources/properties/systemconfig.properties
View file @
4bd29ffb
...
...
@@ -8,3 +8,7 @@ REDIS_ITOKEN_TIME=51840
REDIS_TOKEN_TIME
=
604800
#session有效期
SESSION_TIME
=
3600
#默认头像
USER_HEADER_URL_DEFAULT
=
https://retail.xiaochengxucms.com/images/12/2018/11/fDK7kkrmkMReK50l4r1Le740Kmra8.jpg
#默认昵称
USER_NIKENAME_DEFAULT
=
XX_
\ No newline at end of file
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/biz/AppUserDetailBiz.java
View file @
4bd29ffb
package
com
.
github
.
wxiaoqi
.
security
.
admin
.
biz
;
import
com.ace.cache.annotation.Cache
;
import
com.ace.cache.annotation.CacheClear
;
import
com.github.wxiaoqi.security.admin.entity.AppUserDetail
;
import
com.github.wxiaoqi.security.admin.mapper.AppUserDetailMapper
;
import
com.github.wxiaoqi.security.common.biz.BaseBiz
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
tk.mybatis.mapper.entity.Example
;
import
java.util.List
;
...
...
@@ -20,11 +22,27 @@ import java.util.List;
public
class
AppUserDetailBiz
extends
BaseBiz
<
AppUserDetailMapper
,
AppUserDetail
>
{
@Override
@CacheClear
(
pre
=
"user{1.user
name
}"
)
@CacheClear
(
pre
=
"user{1.user
id
}"
)
public
void
updateSelectiveById
(
AppUserDetail
entity
)
{
super
.
updateSelectiveById
(
entity
);
}
/**
* 根据用户id获取用户信息
* @param userid
* @return
*/
@Cache
(
key
=
"user{1}"
)
public
AppUserDetail
getUserByUserid
(
Integer
userid
){
Example
example
=
new
Example
(
AppUserDetail
.
class
);
example
.
createCriteria
().
andEqualTo
(
"userid"
,
userid
).
andEqualTo
(
"isdel"
,
0
);
List
<
AppUserDetail
>
list
=
mapper
.
selectByExample
(
example
);
if
(
list
!=
null
&&
list
.
size
()
!=
0
)
{
return
list
.
get
(
0
);
}
return
null
;
}
...
...
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/biz/AppUserLoginBiz.java
View file @
4bd29ffb
...
...
@@ -47,6 +47,7 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
super
.
updateSelectiveById
(
entity
);
}
/**
* 根据用户名获取用户信息
* @param username
...
...
@@ -100,6 +101,25 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
return
null
;
}
/**
* 根据微信号判断是否存在用户
* @param openid
* @return
*/
public
AppUserLogin
getUserByOpenid
(
String
openid
,
Integer
isQQ
)
{
Example
example
=
new
Example
(
AppUserLogin
.
class
);
if
(
isQQ
==
1
){
example
.
createCriteria
().
andEqualTo
(
"openid"
,
openid
).
andEqualTo
(
"isdel"
,
0
);
}
else
{
example
.
createCriteria
().
andEqualTo
(
"wx_openid"
,
openid
).
andEqualTo
(
"isdel"
,
0
);
}
List
<
AppUserLogin
>
userLoginList
=
mapper
.
selectByExample
(
example
);
if
(
userLoginList
!=
null
&&
userLoginList
.
size
()
!=
0
)
{
return
userLoginList
.
get
(
0
);
}
return
null
;
}
/**
* 根据手机号码判断是否已绑定微信
*
...
...
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/constant/RedisKey.java
0 → 100644
View file @
4bd29ffb
package
com
.
github
.
wxiaoqi
.
security
.
admin
.
constant
;
public
class
RedisKey
{
/**
*验证码key前缀
*/
public
static
final
String
CONSTANT_CODE_PREFIX
=
"cache:mobilecode:"
;
}
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/rpc/AppUserRest.java
View file @
4bd29ffb
...
...
@@ -7,6 +7,10 @@ import com.github.wxiaoqi.security.admin.rpc.service.PermissionService;
import
com.github.wxiaoqi.security.api.vo.authority.PermissionInfo
;
import
com.github.wxiaoqi.security.api.vo.user.AppUserInfo
;
import
com.github.wxiaoqi.security.api.vo.user.UserInfo
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
com.github.wxiaoqi.security.common.util.process.SystemConfig
;
import
com.github.wxiaoqi.security.common.util.result.JsonResultUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -53,5 +57,78 @@ public class AppUserRest {
return
appPermissionService
.
sendSMS
(
username
,
type
);
}
/**
* 注册
* @param username
* @param mobilecode
* @param password
* @return
*/
@RequestMapping
(
value
=
"/user/register"
,
method
=
RequestMethod
.
POST
)
public
@ResponseBody
JSONObject
register
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
,
defaultValue
=
""
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
password
){
//默认昵称
String
nickname
=
SystemConfig
.
USER_NIKENAME_DEFAULT
+(
int
)((
Math
.
random
()*
9
+
1
)*
100000
);
return
appPermissionService
.
register
(
username
,
password
,
SystemConfig
.
USER_HEADER_URL_DEFAULT
,
nickname
,
mobilecode
,
null
,
null
,
0
);
}
/**
* 微信注册/微信绑定
* @param username
* @param mobilecode
* @param password
* @param nickname
* @param headimgurl
* @param openid
* @param unionid
* @param type
* @return
*/
@RequestMapping
(
value
=
"/user/wxregister"
,
method
=
RequestMethod
.
POST
)
public
@ResponseBody
JSONObject
wxregister
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
,
defaultValue
=
""
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
password
,
@RequestParam
(
value
=
"nickname"
,
defaultValue
=
""
)
String
nickname
,
@RequestParam
(
value
=
"headimgurl"
,
defaultValue
=
""
)
String
headimgurl
,
@RequestParam
(
value
=
"openid"
,
defaultValue
=
""
)
String
openid
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
unionid
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"0"
)
Integer
type
,
@RequestParam
(
value
=
"isQQ"
,
defaultValue
=
"0"
)
Integer
isQQ
){
if
(
StringUtils
.
isBlank
(
headimgurl
)){
headimgurl
=
SystemConfig
.
USER_HEADER_URL_DEFAULT
;
}
if
(
StringUtils
.
isBlank
(
nickname
)){
nickname
=
SystemConfig
.
USER_NIKENAME_DEFAULT
+(
int
)((
Math
.
random
()*
9
+
1
)*
100000
);
}
return
appPermissionService
.
weCahtRegister
(
username
,
password
,
openid
,
unionid
,
nickname
,
headimgurl
,
type
,
mobilecode
,
isQQ
);
}
/**
* 手机号码检测是否已绑定
*
* @param username
* @return
*/
@RequestMapping
(
value
=
"/user/checkBindWechat"
)
public
@ResponseBody
JSONObject
checkBindWechat
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
)
{
if
(
StringUtils
.
isBlank
(
username
))
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
}
return
appPermissionService
.
checkBindWechat
(
username
);
}
@RequestMapping
(
value
=
"/user/wxlogin"
)
public
@ResponseBody
JSONObject
wxlogin
(
@RequestParam
(
value
=
"openid"
,
defaultValue
=
""
)
String
openid
,
@RequestParam
(
value
=
"isQQ"
,
defaultValue
=
"0"
)
Integer
isQQ
)
{
return
appPermissionService
.
weCahtLogin
(
openid
,
isQQ
);
}
}
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/rpc/service/AppPermissionService.java
View file @
4bd29ffb
...
...
@@ -5,9 +5,11 @@ import com.github.wxiaoqi.security.admin.biz.AppUserBiz;
import
com.github.wxiaoqi.security.admin.biz.AppUserDetailBiz
;
import
com.github.wxiaoqi.security.admin.biz.AppUserLoginBiz
;
import
com.github.wxiaoqi.security.admin.biz.ElementBiz
;
import
com.github.wxiaoqi.security.admin.constant.RedisKey
;
import
com.github.wxiaoqi.security.admin.entity.*
;
import
com.github.wxiaoqi.security.api.vo.authority.PermissionInfo
;
import
com.github.wxiaoqi.security.api.vo.user.AppUserInfo
;
import
com.github.wxiaoqi.security.common.util.EmojiFilter
;
import
com.github.wxiaoqi.security.common.util.VerificationUtils
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
com.github.wxiaoqi.security.common.util.process.SystemConfig
;
...
...
@@ -50,10 +52,10 @@ public class AppPermissionService {
public
AppUserInfo
validate
(
String
username
,
String
password
)
{
AppUserInfo
info
=
new
AppUserInfo
();
AppUser
user
=
appUserBiz
.
getUserByUsername
(
username
);
if
(
encoder
.
matches
(
password
,
user
.
getPassword
()))
{
BeanUtils
.
copyProperties
(
user
,
info
);
info
.
setId
(
user
.
getId
()
.
toString
()
);
AppUser
Login
user
=
appUserLoginBiz
.
checkeUserLogin
(
username
);
if
(
user
!=
null
&&
encoder
.
matches
(
password
,
user
.
getPassword
()))
{
info
.
setUsername
(
user
.
getUsername
()
);
info
.
setId
(
user
.
getId
()
+
""
);
}
return
info
;
}
...
...
@@ -142,7 +144,12 @@ public class AppPermissionService {
}*/
result
.
put
(
"mobilecode"
,
mobilecode
);
// redisDao.set(phone + mobilecode, String.class, mobilecode, 300);
userRedisTemplate
.
opsForValue
().
set
(
phone
+
mobilecode
,
mobilecode
,
300
,
TimeUnit
.
SECONDS
);
String
redisLockKey
=
RedisKey
.
CONSTANT_CODE_PREFIX
+
phone
+
mobilecode
;
Boolean
suc
=
userRedisTemplate
.
opsForValue
().
setIfAbsent
(
redisLockKey
,
mobilecode
);
if
(
suc
){
userRedisTemplate
.
expire
(
redisLockKey
,
5
,
TimeUnit
.
MINUTES
);
//5分钟内过期
}
//userRedisTemplate.opsForValue().set(phone + mobilecode,mobilecode,300, TimeUnit.SECONDS);
}
catch
(
Exception
e
)
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXCEPTION_CODE
,
"出现异常"
);
}
...
...
@@ -158,15 +165,17 @@ public class AppPermissionService {
* @param mobilecode
*/
@Transactional
public
JSONObject
register
(
HttpServletRequest
request
,
String
username
,
String
password
,
String
headimgurl
,
String
nickname
,
String
mobilecode
)
{
public
JSONObject
register
(
String
username
,
String
password
,
String
headimgurl
,
String
nickname
,
String
mobilecode
,
String
openId
,
String
unionid
,
Integer
type
)
{
// 判断参数和验证码
if
(
StringUtils
.
isBlank
(
username
)
||
StringUtils
.
isBlank
(
password
)
||
StringUtils
.
isBlank
(
mobilecode
))
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
}
String
mobilecodeRedis
=
userRedisTemplate
.
opsForValue
().
get
(
username
+
mobilecode
).
toString
();
// 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate
.
delete
(
username
+
mobilecode
);
String
redisLockKey
=
RedisKey
.
CONSTANT_CODE_PREFIX
+
username
+
mobilecode
;
String
mobilecodeRedis
=
String
.
valueOf
(
userRedisTemplate
.
opsForValue
().
get
(
redisLockKey
));
log
.
error
(
"注册接口,获取redis中的验证码:"
+
mobilecodeRedis
);
// 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate
.
delete
(
redisLockKey
);
if
(
mobilecodeRedis
==
null
)
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NOTEXIST_CODE
,
"验证码错误"
);
}
...
...
@@ -179,11 +188,21 @@ public class AppPermissionService {
try
{
Long
now
=
System
.
currentTimeMillis
()
/
1000
;
AppUserLogin
appUserLogin
=
new
AppUserLogin
();
//String userid = result.getJSONObject("data").getString("userid");
appUserLogin
.
setUsername
(
username
);
appUserLogin
.
setPassword
(
password
);
appUserLogin
.
setIsdel
(
0
);
appUserLogin
.
setStatus
(
0
);
//QQ
if
(
type
==
1
&&
StringUtils
.
isNotBlank
(
openId
)){
appUserLogin
.
setOpenid
(
openId
);
}
else
{
if
(
StringUtils
.
isNotBlank
(
openId
))
{
appUserLogin
.
setWxOpenid
(
openId
);
}
if
(
StringUtils
.
isNotBlank
(
unionid
))
{
appUserLogin
.
setUnionid
(
unionid
);
}
}
appUserLogin
.
setCreatetime
(
now
);
appUserLogin
.
setUpdatetime
(
now
);
appUserLoginBiz
.
insertSelective
(
appUserLogin
);
...
...
@@ -225,14 +244,171 @@ public class AppPermissionService {
// 缓存操作
String
token
=
""
;
String
imtoken_
=
""
;
userRedisTemplate
.
opsForValue
().
set
(
"token_"
+
userid
,
token
,
SystemConfig
.
REDISTOKENTIME
,
TimeUnit
.
SECONDS
);
userRedisTemplate
.
opsForValue
().
set
(
"imtoken_"
+
userid
,
imtoken_
,
SystemConfig
.
REDISTOKENTIME
,
TimeUnit
.
SECONDS
);
//
userRedisTemplate.opsForValue().set("token_" + userid,token, SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
//
userRedisTemplate.opsForValue().set("imtoken_" + userid,imtoken_,SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
// 返回结果
data
.
put
(
"token"
,
token
);
data
.
put
(
"imtoken"
,
imtoken_
);
// data.put("token", token);
data
.
put
(
"username"
,
username
);
data
.
put
(
"userid"
,
userid
);
data
.
put
(
"nickname"
,
nickname
);
data
.
put
(
"headerurl"
,
headimgurl
);
}
return
data
;
}
/**
* 微信绑定/注册
* @param username
* @param password
* @param openId
* @param unionid
* @param nickname
* @param headimgurl
* @param type
* @param mobilecode
* @return
*/
@Transactional
public
JSONObject
weCahtRegister
(
String
username
,
String
password
,
String
openId
,
String
unionid
,
String
nickname
,
String
headimgurl
,
int
type
,
String
mobilecode
,
Integer
isQQ
)
{
// 校验参数和验证码
if
(
StringUtils
.
isBlank
(
username
)
||
StringUtils
.
isBlank
(
mobilecode
))
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
}
if
(
type
==
2
)
{
if
(
StringUtils
.
isBlank
(
password
))
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"密码不能为空"
);
}
}
try
{
// 获取缓存用户信息
log
.
error
(
"weCahtRegister:"
+
openId
);
if
(
StringUtils
.
isNotBlank
(
openId
))
{
if
(
StringUtils
.
isNotBlank
(
nickname
))
{
// 转换特殊字符
nickname
=
EmojiFilter
.
filterEmoji
(
nickname
);
}
log
.
error
(
"微信昵称="
+
nickname
);
// 微信用户未设置头像时,默认头像
if
(
StringUtils
.
isBlank
(
headimgurl
))
{
headimgurl
=
SystemConfig
.
USER_HEADER_URL_DEFAULT
;
}
if
(
type
==
1
)
{
// 绑定
Long
now
=
System
.
currentTimeMillis
()
/
1000
;
AppUserLogin
userLogin
=
appUserLoginBiz
.
checkeUserLogin
(
username
);
if
((
isQQ
==
1
&&
StringUtils
.
isNotBlank
(
userLogin
.
getOpenid
()))||(
isQQ
==
0
&&
StringUtils
.
isNotBlank
(
userLogin
.
getWxOpenid
())))
{
// 已绑定微信
return
JsonResultUtil
.
createFailedResultMsg
(
ResultCode
.
WX_BIND_CODE
);
}
Integer
userid
=
userLogin
.
getId
();
if
(
isQQ
==
1
){
userLogin
.
setOpenid
(
openId
);
}
else
{
userLogin
.
setWxOpenid
(
openId
);
// 添加unionid
userLogin
.
setUnionid
(
unionid
);
}
userLogin
.
setUpdatetime
(
now
);
appUserLoginBiz
.
updateSelectiveById
(
userLogin
);
AppUserDetail
userDetail
=
appUserDetailBiz
.
getUserByUserid
(
userid
);
if
(
userDetail
==
null
){
userDetail
=
new
AppUserDetail
();
userDetail
.
setUserid
(
userid
);
userDetail
.
setHeadimgurl
(
headimgurl
);
userDetail
.
setNickname
(
nickname
);
userDetail
.
setCreatetime
(
now
);
userDetail
.
setUpdatetime
(
now
);
userDetail
.
setIsdel
(
0
);
appUserDetailBiz
.
insertSelective
(
userDetail
);
}
else
{
userDetail
.
setHeadimgurl
(
headimgurl
);
userDetail
.
setNickname
(
nickname
);
appUserDetailBiz
.
updateSelectiveById
(
userDetail
);
}
// 登录结果要做做统一处理
JSONObject
data
=
autoLogin
(
userid
,
username
,
headimgurl
,
nickname
);
if
(
data
!=
null
)
{
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
}
}
else
if
(
type
==
2
)
{
// 新增
JSONObject
register
=
register
(
username
,
password
,
nickname
,
headimgurl
,
mobilecode
,
openId
,
unionid
,
isQQ
);
if
(
register
.
getInteger
(
"status"
)
!=
ResultCode
.
SUCCESS_CODE
)
{
if
(
register
.
getInteger
(
"status"
)
==
ResultCode
.
EXIST_CODE
)
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXIST_CODE
,
"用户已存在"
);
}
return
JsonResultUtil
.
createFailedResult
(
register
.
getInteger
(
"code"
),
"操作失败"
);
}
return
register
;
}
}
return
JsonResultUtil
.
createDefaultFail
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXCEPTION_CODE
,
"出现异常"
);
}
}
/**
* 校验手机号码是否已绑定微信
*
* @param username
* @return
*/
public
JSONObject
checkBindWechat
(
String
username
)
{
JSONObject
data
=
new
JSONObject
();
try
{
AppUserLogin
userLogin
=
appUserLoginBiz
.
checkeUserLogin
(
username
);
if
(
userLogin
!=
null
)
{
String
openid
=
userLogin
.
getOpenid
();
if
(
StringUtils
.
isNotBlank
(
openid
))
{
data
.
put
(
"type"
,
0
);
// 已存在
}
else
{
data
.
put
(
"type"
,
1
);
// 绑定
}
}
else
{
data
.
put
(
"type"
,
2
);
// 新增
}
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXCEPTION_CODE
,
"出现异常"
);
}
}
/**
* 微信登录
* @param openId
* @return
*/
@Transactional
public
JSONObject
weCahtLogin
(
String
openId
,
Integer
isQQ
)
{
if
(
StringUtils
.
isBlank
(
openId
))
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
}
AppUserLogin
userLogin
=
appUserLoginBiz
.
getUserByOpenid
(
openId
,
isQQ
);
if
(
userLogin
==
null
){
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
WXNOTEXIST_CODE
,
"该微信号尚未绑定手机号"
,
openId
);
}
if
(
userLogin
.
getStatus
()==
1
){
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXIST_CODE
,
"用户已被禁用"
);
}
Integer
userid
=
userLogin
.
getId
();
AppUserDetail
userDetail
=
appUserDetailBiz
.
getUserByUserid
(
userid
);
String
headimgurl
=
""
;
String
nickname
=
""
;
if
(
userDetail
!=
null
){
headimgurl
=
userDetail
.
getHeadimgurl
();
nickname
=
userDetail
.
getNickname
();
}
JSONObject
data
=
autoLogin
(
userid
,
userLogin
.
getUsername
(),
headimgurl
,
nickname
);
if
(
data
!=
null
)
{
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
}
return
JsonResultUtil
.
createDefaultFail
();
}
}
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/util/JwtAuthenticationRequest.java
0 → 100644
View file @
4bd29ffb
package
com
.
github
.
wxiaoqi
.
security
.
admin
.
util
;
import
java.io.Serializable
;
public
class
JwtAuthenticationRequest
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
8445943548965154778L
;
private
String
username
;
private
String
password
;
public
JwtAuthenticationRequest
(
String
username
,
String
password
)
{
this
.
username
=
username
;
this
.
password
=
password
;
}
public
JwtAuthenticationRequest
()
{
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
}
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