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
c88d1ea1
Commit
c88d1ea1
authored
Jan 24, 2018
by
贷前—徐菲
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
865c856e
e92fa962
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
128 additions
and
458 deletions
+128
-458
Bootstrap.java
src/main/java/cn/quantgroup/xyqb/Bootstrap.java
+6
-1
IpValidateAdvisor.java
.../quantgroup/xyqb/aspect/accessable/IpValidateAdvisor.java
+0
-8
CaptchaNewValidateAdvisor.java
...tgroup/xyqb/aspect/captcha/CaptchaNewValidateAdvisor.java
+0
-167
CaptchaNewValidator.java
...n/quantgroup/xyqb/aspect/captcha/CaptchaNewValidator.java
+0
-13
CaptchaValidateAdvisor.java
...uantgroup/xyqb/aspect/captcha/CaptchaValidateAdvisor.java
+3
-8
PasswordFreeAccessValidateAdvisor.java
.../xyqb/aspect/limit/PasswordFreeAccessValidateAdvisor.java
+0
-7
WeChatController.java
...group/xyqb/controller/external/user/WeChatController.java
+105
-249
SmsController.java
...uantgroup/xyqb/controller/internal/sms/SmsController.java
+3
-4
UserDetailController.java
...p/xyqb/controller/internal/user/UserDetailController.java
+1
-1
UserAuthorizedServiceImpl.java
...oup/xyqb/service/auth/impl/UserAuthorizedServiceImpl.java
+9
-0
IPUtil.java
src/main/java/cn/quantgroup/xyqb/util/IPUtil.java
+1
-0
No files found.
src/main/java/cn/quantgroup/xyqb/Bootstrap.java
View file @
c88d1ea1
...
@@ -13,6 +13,7 @@ import org.springframework.context.ConfigurableApplicationContext;
...
@@ -13,6 +13,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.core.env.Environment
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
sun.misc.Signal
;
import
sun.misc.Signal
;
...
@@ -38,6 +39,10 @@ public class Bootstrap {
...
@@ -38,6 +39,10 @@ public class Bootstrap {
log
.
info
(
"server start..."
);
log
.
info
(
"server start..."
);
// 启用平滑退出功能
// 启用平滑退出功能
Signal
.
handle
(
new
Signal
(
"INT"
),
new
DefaultSignalHandler
(
run
));
Signal
.
handle
(
new
Signal
(
"INT"
),
new
DefaultSignalHandler
(
run
));
Sentry
.
init
(
"http://13ef5642903a414c910f8d0e0a2c56ee:8b351ad1abf44de3b4c25f39105fb927@172.16.4.89:9000/6"
);
// 异常log捕获
Environment
environment
=
run
.
getBean
(
Environment
.
class
);
String
dsn
=
environment
.
getProperty
(
"dsn"
);
Sentry
.
init
(
dsn
);
}
}
}
}
src/main/java/cn/quantgroup/xyqb/aspect/accessable/IpValidateAdvisor.java
View file @
c88d1ea1
...
@@ -8,13 +8,11 @@ import org.aspectj.lang.annotation.Aspect;
...
@@ -8,13 +8,11 @@ import org.aspectj.lang.annotation.Aspect;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Objects
;
/**
/**
* IP白名单检验
* IP白名单检验
...
@@ -27,18 +25,12 @@ import java.util.Objects;
...
@@ -27,18 +25,12 @@ import java.util.Objects;
public
class
IpValidateAdvisor
{
public
class
IpValidateAdvisor
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
IpValidateAdvisor
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
IpValidateAdvisor
.
class
);
@Value
(
"${configserver.disable}"
)
private
Integer
isDebug
;
@Pointcut
(
"execution(public * cn.quantgroup.xyqb.controller.external.user.InnerController.*(..)) || @annotation(cn.quantgroup.xyqb.aspect.accessable.IpValidator)"
)
@Pointcut
(
"execution(public * cn.quantgroup.xyqb.controller.external.user.InnerController.*(..)) || @annotation(cn.quantgroup.xyqb.aspect.accessable.IpValidator)"
)
private
void
whiteIpMatch
()
{
private
void
whiteIpMatch
()
{
}
}
@Around
(
"whiteIpMatch()"
)
@Around
(
"whiteIpMatch()"
)
private
Object
doWhiteIpMatch
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
private
Object
doWhiteIpMatch
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
if
(
Objects
.
equals
(
isDebug
,
0
)){
return
pjp
.
proceed
();
}
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
// 客户端IP
// 客户端IP
String
clientIp
=
IPUtil
.
getRemoteIP
(
request
);
String
clientIp
=
IPUtil
.
getRemoteIP
(
request
);
...
...
src/main/java/cn/quantgroup/xyqb/aspect/captcha/CaptchaNewValidateAdvisor.java
deleted
100644 → 0
View file @
865c856e
package
cn
.
quantgroup
.
xyqb
.
aspect
.
captcha
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService
;
import
cn.quantgroup.xyqb.util.IPUtil
;
import
com.octo.captcha.service.CaptchaServiceException
;
import
java.nio.charset.Charset
;
import
java.util.Optional
;
import
java.util.UUID
;
import
java.util.concurrent.TimeUnit
;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.commons.lang3.StringUtils
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
/**
* 类名称:CaptchaValidateAdvisor
* 类描述:
*
* @author 李宁
* @version 1.0.0 创建时间:15/11/17 14:49
*/
@Aspect
@Component
public
class
CaptchaNewValidateAdvisor
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
CaptchaNewValidateAdvisor
.
class
);
private
static
final
String
SUPER_CAPTCHA_ID
=
UUID
.
nameUUIDFromBytes
(
"__QG_APPCLIENT_AGENT__"
.
getBytes
(
Charset
.
forName
(
"UTF-8"
))).
toString
();
private
static
final
String
SUPER_CAPTCHA
=
"__SUPERQG__"
;
@Autowired
@Qualifier
(
"stringRedisTemplate"
)
private
RedisTemplate
<
String
,
String
>
redisTemplate
;
@Autowired
@Qualifier
(
"customCaptchaService"
)
private
AbstractManageableImageCaptchaService
imageCaptchaService
;
/**
* 自动化测试忽略验证码
*/
@Value
(
"${xyqb.auth.captcha.autotest.enable:false}"
)
private
boolean
autoTestCaptchaEnabled
;
private
static
final
String
IMAGE_IP_COUNT
=
"image:ip"
;
private
static
final
String
IMAGE_PHONE_COUNT
=
"image:phone"
;
private
static
final
String
IMAGE_DEVICEID_COUNT
=
"image:deviceId:"
;
private
static
final
Long
FIVE_MIN
=
24
*
5L
;
/**
* 图形验证码切面
*/
@Pointcut
(
"@annotation(cn.quantgroup.xyqb.aspect.captcha.CaptchaNewValidator)"
)
private
void
needNewCaptchaValidate
()
{
}
/**
* 在受图形验证码保护的接口方法执行前, 执行图形验证码校验
* captchaId 图形验证码key
* captchaValue 图形验证码value
*
* @throws Throwable
*/
@Around
(
"needNewCaptchaValidate()"
)
private
Object
doCapchaValidate
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
String
registerFrom
=
Optional
.
ofNullable
(
request
.
getParameter
(
"registerFrom"
)).
orElse
(
""
);
String
captchaId
=
Optional
.
ofNullable
(
request
.
getParameter
(
"captchaId"
)).
orElse
(
""
);
String
captchaValue
=
request
.
getParameter
(
"captchaValue"
);
String
phoneNo
=
request
.
getParameter
(
"phoneNo"
);
String
deviceId
=
Optional
.
ofNullable
(
request
.
getParameter
(
"deviceId"
)).
orElse
(
""
);
String
clientIp
=
IPUtil
.
getRemoteIP
(
request
);
Long
countIP
=
countByClientId
(
clientIp
,
false
);
Long
countPhone
=
countPhone
(
phoneNo
);
Long
countDeviceId
=
countByClientId
(
deviceId
,
true
);
IPUtil
.
logIp
(
LOGGER
,
request
);
LOGGER
.
info
(
"使用图形验证码, registerFrom={}, clientIp={},手机号次数:{},设备次数:{},ip次数:{},phone:{}"
,
registerFrom
,
clientIp
,
countPhone
,
countDeviceId
,
countIP
,
phoneNo
);
//if (countIP > Constants.Image_Need_Count || countPhone > Constants.Image_Need_Count || countDeviceId > Constants.Image_Need_Count) {
if
(
true
){
if
(
shouldSkipCaptchaValidate
(
registerFrom
,
captchaId
,
captchaValue
))
{
LOGGER
.
info
(
"使用超级图形验证码校验, registerFrom={}, clientIp={}"
,
registerFrom
,
clientIp
);
return
pjp
.
proceed
();
}
JsonResult
result
=
JsonResult
.
buildSuccessResult
(
"图形验证码不正确"
,
""
);
result
.
setBusinessCode
(
"0002"
);
if
(
StringUtils
.
isNotBlank
(
captchaValue
))
{
// 忽略用户输入的大小写
String
captcha
=
StringUtils
.
lowerCase
(
captchaValue
);
// 验证码校验
Boolean
validCaptcha
=
false
;
try
{
validCaptcha
=
imageCaptchaService
.
validateResponseForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
captchaId
,
captcha
);
}
catch
(
CaptchaServiceException
ex
)
{
LOGGER
.
error
(
"验证码校验异常, {}, {}"
,
ex
.
getMessage
(),
ex
);
}
if
(
validCaptcha
)
{
return
pjp
.
proceed
();
}
return
result
;
}
LOGGER
.
info
(
"使用错误图形验证码, registerFrom={}, clientIp={},手机号次数:{},设备次数:{},ip次数:{},phone:{}"
,
registerFrom
,
clientIp
,
countPhone
,
countDeviceId
,
countIP
,
phoneNo
);
result
.
setMsg
(
"请输入图形验证码"
);
return
result
;
}
return
pjp
.
proceed
();
}
private
boolean
shouldSkipCaptchaValidate
(
String
registerFrom
,
String
captchaId
,
Object
captchaValue
)
{
// 如果启用了超级验证码功能, 检查超级验证码, 超级验证码区分大小写
if
(
autoTestCaptchaEnabled
)
{
return
true
;
}
return
StringUtils
.
equals
(
SUPER_CAPTCHA_ID
,
String
.
valueOf
(
captchaId
))
&&
StringUtils
.
equals
(
SUPER_CAPTCHA
,
String
.
valueOf
(
captchaValue
));
}
private
Long
countPhone
(
String
phoneNo
)
{
Long
count
=
1L
;
String
countString
=
redisTemplate
.
opsForValue
().
get
(
IMAGE_PHONE_COUNT
+
phoneNo
);
if
(
StringUtils
.
isBlank
(
countString
))
{
redisTemplate
.
opsForValue
().
set
(
IMAGE_PHONE_COUNT
+
phoneNo
,
String
.
valueOf
(
count
),
FIVE_MIN
,
TimeUnit
.
SECONDS
);
}
else
{
count
=
Long
.
valueOf
(
countString
)
+
1L
;
redisTemplate
.
opsForValue
().
set
(
IMAGE_PHONE_COUNT
+
phoneNo
,
String
.
valueOf
(
count
),
FIVE_MIN
,
TimeUnit
.
SECONDS
);
}
return
count
;
}
/**
* 短信发送限制
* @param clientId - 设备ID或IP
* @param device - true - 设备,false - IP
* @return
*/
private
Long
countByClientId
(
String
clientId
,
boolean
device
)
{
Long
count
=
1L
;
if
(
StringUtils
.
isBlank
(
clientId
))
{
return
count
;
}
else
{
String
key
=
(
device
?
IMAGE_DEVICEID_COUNT
:
IMAGE_IP_COUNT
)
+
clientId
;
String
countString
=
redisTemplate
.
opsForValue
().
get
(
key
);
if
(
StringUtils
.
isBlank
(
countString
))
{
redisTemplate
.
opsForValue
().
set
(
key
,
String
.
valueOf
(
count
),
FIVE_MIN
,
TimeUnit
.
SECONDS
);
}
else
{
count
=
Long
.
valueOf
(
countString
)
+
1L
;
redisTemplate
.
opsForValue
().
set
(
key
,
String
.
valueOf
(
count
),
FIVE_MIN
,
TimeUnit
.
SECONDS
);
}
return
count
;
}
}
}
src/main/java/cn/quantgroup/xyqb/aspect/captcha/CaptchaNewValidator.java
deleted
100644 → 0
View file @
865c856e
package
cn
.
quantgroup
.
xyqb
.
aspect
.
captcha
;
import
java.lang.annotation.*
;
/**
* Created by xuran on 2017/8/28.
*/
@Documented
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
CaptchaNewValidator
{
}
src/main/java/cn/quantgroup/xyqb/aspect/captcha/CaptchaValidateAdvisor.java
View file @
c88d1ea1
package
cn
.
quantgroup
.
xyqb
.
aspect
.
captcha
;
package
cn
.
quantgroup
.
xyqb
.
aspect
.
captcha
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService
;
import
cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService
;
...
@@ -78,19 +77,16 @@ public class CaptchaValidateAdvisor {
...
@@ -78,19 +77,16 @@ public class CaptchaValidateAdvisor {
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
String
registerFrom
=
Optional
.
ofNullable
(
request
.
getParameter
(
"registerFrom"
)).
orElse
(
""
);
String
registerFrom
=
Optional
.
ofNullable
(
request
.
getParameter
(
"registerFrom"
)).
orElse
(
""
);
String
captchaId
=
Optional
.
ofNullable
(
request
.
getParameter
(
"captchaId"
)).
orElse
(
""
);
String
captchaId
=
Optional
.
ofNullable
(
request
.
getParameter
(
"captchaId"
)).
orElse
(
""
);
Object
captchaValue
=
request
.
getParameter
(
"captchaValue"
);
String
captchaValue
=
request
.
getParameter
(
"captchaValue"
);
if
(
shouldSkipCaptchaValidate
(
registerFrom
,
captchaId
,
captchaValue
))
{
if
(
shouldSkipCaptchaValidate
(
registerFrom
,
captchaId
,
captchaValue
))
{
LOGGER
.
info
(
"使用超级图形验证码校验, registerFrom={}, clientIp={}"
,
registerFrom
,
IPUtil
.
getRemoteIP
(
request
));
LOGGER
.
info
(
"使用超级图形验证码校验, registerFrom={}, clientIp={}"
,
registerFrom
,
IPUtil
.
getRemoteIP
(
request
));
return
pjp
.
proceed
();
return
pjp
.
proceed
();
}
}
JsonResult
result
=
JsonResult
.
buildSuccessResult
(
"图形验证码不正确"
,
""
);
JsonResult
result
=
JsonResult
.
buildSuccessResult
(
"图形验证码不正确"
,
""
);
result
.
setBusinessCode
(
"0002"
);
result
.
setBusinessCode
(
"0002"
);
if
(
captchaValue
!=
null
)
{
if
(
StringUtils
.
isNotBlank
(
captchaValue
))
{
String
captcha
=
String
.
valueOf
(
captchaValue
);
// 忽略用户输入的大小写
// 忽略用户输入的大小写
captcha
=
StringUtils
.
lowerCase
(
captcha
);
String
captcha
=
StringUtils
.
lowerCase
(
captchaValue
);
// 验证码校验
// 验证码校验
Boolean
validCaptcha
=
false
;
Boolean
validCaptcha
=
false
;
try
{
try
{
...
@@ -98,7 +94,6 @@ public class CaptchaValidateAdvisor {
...
@@ -98,7 +94,6 @@ public class CaptchaValidateAdvisor {
}
catch
(
CaptchaServiceException
ex
)
{
}
catch
(
CaptchaServiceException
ex
)
{
LOGGER
.
error
(
"验证码校验异常, {}, {}"
,
ex
.
getMessage
(),
ex
);
LOGGER
.
error
(
"验证码校验异常, {}, {}"
,
ex
.
getMessage
(),
ex
);
}
}
if
(
validCaptcha
)
{
if
(
validCaptcha
)
{
return
pjp
.
proceed
();
return
pjp
.
proceed
();
}
}
...
...
src/main/java/cn/quantgroup/xyqb/aspect/limit/PasswordFreeAccessValidateAdvisor.java
View file @
c88d1ea1
...
@@ -13,9 +13,6 @@ import org.aspectj.lang.annotation.Aspect;
...
@@ -13,9 +13,6 @@ import org.aspectj.lang.annotation.Aspect;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
...
@@ -38,10 +35,6 @@ public class PasswordFreeAccessValidateAdvisor {
...
@@ -38,10 +35,6 @@ public class PasswordFreeAccessValidateAdvisor {
private
static
final
String
PHONE_NO
=
"phoneNo"
;
private
static
final
String
PHONE_NO
=
"phoneNo"
;
private
static
final
String
USER_ID
=
"userId"
;
private
static
final
String
USER_ID
=
"userId"
;
@Autowired
@Qualifier
(
"stringRedisTemplate"
)
private
RedisTemplate
<
String
,
String
>
redisTemplate
;
/**
/**
* 免密访问校验切面
* 免密访问校验切面
*/
*/
...
...
src/main/java/cn/quantgroup/xyqb/controller/external/user/WeChatController.java
View file @
c88d1ea1
...
@@ -17,7 +17,6 @@ import com.alibaba.fastjson.JSON;
...
@@ -17,7 +17,6 @@ import com.alibaba.fastjson.JSON;
import
com.alibaba.fastjson.TypeReference
;
import
com.alibaba.fastjson.TypeReference
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Joiner
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableMap
;
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
;
...
@@ -25,21 +24,15 @@ import org.slf4j.Logger;
...
@@ -25,21 +24,15 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.security.MessageDigest
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Arrays
;
import
java.util.*
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
/**
* Created by 11 on 2017/1/17.
* Created by 11 on 2017/1/17.
...
@@ -66,12 +59,19 @@ public class WeChatController implements IBaseController {
...
@@ -66,12 +59,19 @@ public class WeChatController implements IBaseController {
@Autowired
@Autowired
private
IUserService
userService
;
private
IUserService
userService
;
// https://passport.xyqb.com/landing?key=xxx&target=cashTarget5®isterFrom=198&channelId=%d
/**
* 用户中心UI的http协议头域名
* http://passport.xyqb.com
*/
@Value
(
"${passport.http}"
)
@Value
(
"${passport.http}"
)
private
String
userU
IAddr
;
private
String
userU
iDomain
;
@Value
(
"${passport.http}"
)
/**
private
String
userDomainStr
;
* 用户中心UI的https协议头域名
* https://passport.xyqb.com
*/
@Value
(
"${passport.https}"
)
private
String
userUiDomainS
;
@Value
(
"${api.http}"
)
@Value
(
"${api.http}"
)
private
String
xyqbDomainStr
;
private
String
xyqbDomainStr
;
...
@@ -79,10 +79,6 @@ public class WeChatController implements IBaseController {
...
@@ -79,10 +79,6 @@ public class WeChatController implements IBaseController {
@Autowired
@Autowired
private
IHttpService
httpService
;
private
IHttpService
httpService
;
//加https地址
@Value
(
"${passport.https}"
)
private
String
userUIAddrS
;
/**
/**
* 开发者资质认证,有必要吗?
* 开发者资质认证,有必要吗?
*
*
...
@@ -169,209 +165,72 @@ public class WeChatController implements IBaseController {
...
@@ -169,209 +165,72 @@ public class WeChatController implements IBaseController {
* @return
* @return
*/
*/
@RequestMapping
(
"/receiveCode/extdata/{key}/{extdata}"
)
@RequestMapping
(
"/receiveCode/extdata/{key}/{extdata}"
)
public
void
receiveCodeWithExtData
(
public
void
receiveCodeWithExtData
(
String
code
,
@PathVariable
(
value
=
"key"
)
String
systemKey
,
String
code
,
@PathVariable
(
value
=
"key"
)
String
systemKey
,
@PathVariable
(
value
=
"extdata"
)
String
extData
,
HttpServletResponse
response
)
{
@PathVariable
(
value
=
"extdata"
)
String
extData
,
HttpServletResponse
response
Long
registerFrom
=
null
;
)
{
String
redirect
=
null
;
String
schema
=
null
;
try
{
try
{
String
schema
=
getProtocol
();
extData
=
new
String
(
Base64
.
decodeBase64
(
extData
),
"UTF-8"
);
try
{
}
catch
(
Exception
ex
)
{
extData
=
new
String
(
Base64
.
decodeBase64
(
extData
),
"UTF-8"
);
extData
=
""
;
}
catch
(
Exception
ex
)
{
}
extData
=
""
;
if
(
StringUtils
.
isBlank
(
extData
))
{
}
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
response
);
return
;
String
protocol
=
"http:"
;
}
LOGGER
.
info
(
"从微信extdata版本接口进入:{}, extData:{}"
,
schema
,
extData
);
LOGGER
.
info
(
"从微信extdata版本接口进入:{}, extData:{}"
,
schema
,
extData
);
HashMap
<
String
,
Object
>
extDataObj
;
if
(
StringUtils
.
isEmpty
(
extData
))
{
try
{
// 从code获取token
extDataObj
=
JSON
.
parseObject
(
extData
,
new
TypeReference
<
HashMap
<
String
,
Object
>>(){});
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
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
,
protocol
);
return
;
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
// welcome 首次登录
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
,
protocol
);
return
;
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
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
,
protocol
);
return
;
}
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
String
redirectUrl
=
createUserSession
(
user
,
merchant
,
""
,
schema
,
Constants
.
Channel
.
WECHAT
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
}
else
{
HashMap
<
String
,
Object
>
extDataObj
;
try
{
extDataObj
=
JSON
.
parseObject
(
extData
,
new
TypeReference
<
HashMap
<
String
,
Object
>>()
{
});
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"解析extData发生错误"
,
ex
);
// 从code获取token
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
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
,
protocol
);
return
;
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
// welcome 首次登录
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
,
protocol
);
return
;
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
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
,
protocol
);
return
;
}
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
String
redirectUrl
=
createUserSession
(
user
,
merchant
,
""
,
schema
,
Constants
.
Channel
.
WECHAT
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
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
);
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
if
(
token
==
null
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
protocol
);
return
;
}
WechatUserInfo
userInfo
=
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
token
.
getOpenId
());
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
protocol
);
return
;
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
// welcome 首次登录
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
,
registerFrom
,
protocol
);
return
;
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
protocol
);
return
;
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
protocol
);
return
;
}
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
String
redirectUrl
=
createUserSession
(
user
,
merchant
,
redirect
,
schema
,
registerFrom
);
LOGGER
.
info
(
"Location:[{}]"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
}
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"发生异常"
,
ex
);
LOGGER
.
error
(
"解析extData发生错误"
,
ex
);
throw
ex
;
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
response
);
return
;
}
}
schema
=
extDataObj
.
getOrDefault
(
"protocol"
,
"http:"
).
toString
();
LOGGER
.
info
(
"从微信登录extData中获得协议信息,protocol:{}"
,
schema
);
registerFrom
=
Long
.
valueOf
(
extDataObj
.
getOrDefault
(
"registerFrom"
,
"1"
).
toString
());
redirect
=
(
String
)
extDataObj
.
getOrDefault
(
"redirect"
,
"redirect"
);
LOGGER
.
info
(
"从微信登录,registerFrom:{}, redirect:{}"
,
registerFrom
,
redirect
);
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
response
);
}
}
/**
/**
* 通过redirect_url获取code
* 前端微信跳转页面
*
* @param code
* @param systemKey
* @param schema
* @param registerFrom
* @param redirect
* @param response
* @param response
* @return
*/
*/
@RequestMapping
(
"/receiveCode/{key}"
)
private
void
receiveCodeWithDefault
(
String
code
,
String
systemKey
,
String
schema
,
Long
registerFrom
,
String
redirect
,
HttpServletResponse
response
){
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
);
registerFrom
=
Optional
.
ofNullable
(
registerFrom
).
orElse
(
Constants
.
Channel
.
WECHAT
);
redirect
=
Optional
.
ofNullable
(
redirect
).
orElse
(
""
);
schema
=
StringUtils
.
isBlank
(
schema
)
?
getProtocol
()
:
schema
;
String
domain
=
userUiDomain
;
if
(
Objects
.
equals
(
schema
,
"https:"
)){
domain
=
userUiDomainS
;
}
// 从code获取token
// 从code获取token
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
,
Constants
.
Channel
.
WECHAT
,
protocol
);
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
domain
);
return
;
return
;
}
}
WechatUserInfo
userInfo
=
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
token
.
getOpenId
());
WechatUserInfo
userInfo
=
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
,
protocol
);
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
domain
);
return
;
return
;
}
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
...
@@ -383,113 +242,110 @@ public class WeChatController implements IBaseController {
...
@@ -383,113 +242,110 @@ public class WeChatController implements IBaseController {
userInfo
.
setNickName
(
nickName
);
userInfo
.
setNickName
(
nickName
);
}
}
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
userInfo
=
wechatService
.
saveWechatUserInfo
(
userInfo
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
Constants
.
Channel
.
WECHAT
,
protocol
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
,
domain
);
return
;
return
;
}
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
,
protocol
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
domain
);
return
;
return
;
}
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
if
(
user
==
null
)
{
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
Constants
.
Channel
.
WECHAT
,
protocol
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
domain
);
return
;
return
;
}
}
// 已经关联了用户
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
// create session, 登进去,该怎么玩怎么玩。
String
redirectUrl
=
createUserSession
(
user
,
merchant
,
""
,
schema
,
Constants
.
Channel
.
WECHAT
);
String
redirectUrl
=
createUserSession
(
user
,
merchant
,
redirect
,
domain
,
registerFrom
);
LOGGER
.
info
(
"Location=[{}]"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
response
.
setStatus
(
301
);
}
}
private
String
createUserSession
(
User
user
,
Merchant
merchant
,
String
redirect
,
String
schema
,
Long
registerFrom
)
{
/**
//String url = "http://passport.xyqb.com";
* 通过redirect_url获取code
String
url
=
"http://"
+
userDomainStr
;
*
if
(
"https:"
.
equals
(
schema
))
{
* @param response
url
=
"https://"
+
userDomainStr
;
* @return
*/
@RequestMapping
(
"/receiveCode/{key}"
)
public
void
receiveCodeNoRedirect
(
String
code
,
@PathVariable
(
value
=
"key"
)
String
systemKey
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
Long
registerFrom
=
null
;
String
redirect
=
null
;
String
schema
=
"http:"
;
if
(
Objects
.
equals
(
"https:"
,
request
.
getScheme
())){
schema
=
"https:"
;
}
}
receiveCodeWithDefault
(
code
,
systemKey
,
schema
,
registerFrom
,
redirect
,
response
);
}
private
String
createUserSession
(
User
user
,
Merchant
merchant
,
String
redirect
,
String
domain
,
Long
registerFrom
)
{
if
(
StringUtils
.
isEmpty
(
redirect
)
||
"redirect"
.
equals
(
redirect
))
{
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
,
domain
,
Constants
.
Channel
.
WECHAT
);
}
else
if
(
"wechat-pay"
.
equals
(
merchant
.
getName
()))
{
}
else
if
(
"wechat-pay"
.
equals
(
merchant
.
getName
()))
{
AuthBean
authBean
=
sessionService
.
createSession
(
Constants
.
Channel
.
WECHAT
,
registerFrom
,
""
,
user
,
merchant
);
AuthBean
authBean
=
sessionService
.
createSession
(
Constants
.
Channel
.
WECHAT
,
registerFrom
,
""
,
user
,
merchant
);
return
url
+
"/landing?token="
+
authBean
.
getToken
()
+
"®isterFrom="
+
registerFrom
+
"&channelId="
+
Constants
.
Channel
.
WECHAT
+
"&key="
+
merchant
.
getName
()
+
"&target=cashTarget5"
;
return
domain
+
"/landing?token="
+
authBean
.
getToken
()
+
"®isterFrom="
+
registerFrom
+
"&channelId="
+
Constants
.
Channel
.
WECHAT
+
"&key="
+
merchant
.
getName
()
+
"&target=cashTarget5"
;
}
else
{
}
else
{
return
loginInWechatWithSessionCreated
(
user
,
merchant
,
"cashTarget4"
,
1L
,
url
,
registerFrom
);
return
loginInWechatWithSessionCreated
(
user
,
merchant
,
"cashTarget4"
,
1L
,
domain
,
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
(
"微信登录:跳转地址{}"
,
domain
+
"/weixin/callback?phoneNo="
+
user
.
getPhoneNo
()
+
"&token="
+
authBean
.
getToken
());
Long
channelId
=
"baitiao"
.
equals
(
merchant
.
getName
())
?
222L
:
1L
;
Long
channelId
=
"baitiao"
.
equals
(
merchant
.
getName
())
?
222L
:
1L
;
String
target
=
"baitiao"
.
equals
(
merchant
.
getName
())
?
"cashTarget5"
:
"cashTarget4"
;
String
target
=
"baitiao"
.
equals
(
merchant
.
getName
())
?
"cashTarget5"
:
"cashTarget4"
;
return
url
+
"/landing?token="
+
authBean
.
getToken
()
+
"®isterFrom="
+
registerFrom
+
return
domain
+
"/landing?token="
+
authBean
.
getToken
()
+
"®isterFrom="
+
registerFrom
+
"&channelId="
+
channelId
+
"&key="
+
merchant
.
getName
()
+
"&target="
+
target
+
"&isWechat=true"
;
"&channelId="
+
channelId
+
"&key="
+
merchant
.
getName
()
+
"&target="
+
target
+
"&isWechat=true"
;
}
}
return
null
;
return
null
;
}
}
private
String
loginInWechatWithSessionCreated
(
User
user
,
Merchant
merchant
,
String
target
,
Long
channelId
,
String
domain
,
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
domain
+
"/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
protocol
)
{
private
void
redirectWechatLoginUrlWithoutLogin
(
HttpServletResponse
response
,
Merchant
merchant
,
WechatUserInfo
userInfo
,
Long
registerFrom
,
String
domain
)
{
String
redirectUrl
=
assembleWechatRedirectUrl
(
merchant
,
userInfo
,
registerFrom
,
protocol
);
String
redirectUrl
=
assembleWechatRedirectUrl
(
merchant
,
userInfo
,
registerFrom
,
domain
);
LOGGER
.
info
(
"redirectWechatLoginUrlWithoutLogin redirectUrl:[{}]"
,
redirectUrl
);
LOGGER
.
info
(
"redirectWechatLoginUrlWithoutLogin redirectUrl:[{}]"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
response
.
setStatus
(
301
);
}
}
private
void
redirectNormalUrl
(
HttpServletResponse
response
,
Merchant
merchant
,
Long
registerFrom
,
String
protocol
)
{
private
void
redirectNormalUrl
(
HttpServletResponse
response
,
Merchant
merchant
,
Long
registerFrom
,
String
domain
)
{
String
redirectUrl
=
assembleNormalRedirectUrl
(
merchant
,
registerFrom
,
protocol
);
String
redirectUrl
=
assembleNormalRedirectUrl
(
merchant
,
registerFrom
,
domain
);
LOGGER
.
info
(
"redirectNormalUrl redirectUrl:[{}]"
,
redirectUrl
);
LOGGER
.
info
(
"redirectNormalUrl redirectUrl:[{}]"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setHeader
(
"Location"
,
redirectUrl
);
response
.
setStatus
(
301
);
response
.
setStatus
(
301
);
}
}
private
String
assembleNormalRedirectUrl
(
Merchant
merchant
,
Long
registerFrom
,
String
protocol
)
{
private
String
assembleNormalRedirectUrl
(
Merchant
merchant
,
Long
registerFrom
,
String
domain
)
{
String
domains
=
userUIAddr
;
if
(
protocol
!=
null
&&
protocol
.
equals
(
"https:"
)){
domains
=
userUIAddrS
;
}
if
(
"baitiao"
.
equals
(
merchant
.
getName
()))
{
if
(
"baitiao"
.
equals
(
merchant
.
getName
()))
{
if
(
registerFrom
==
58
l
||
registerFrom
==
198
l
){
if
(
registerFrom
==
58L
||
registerFrom
==
198L
){
return
domain
s
+
"/landing?key=baitiao&target=cashTarget5&channelId=222®isterFrom="
+
registerFrom
;
return
domain
+
"/landing?key=baitiao&target=cashTarget5&channelId=222®isterFrom="
+
registerFrom
;
}
else
{
}
else
{
return
domain
s
+
"/landing?key=baitiao&target=cashTarget5&channelId=222®isterFrom=198"
;
return
domain
+
"/landing?key=baitiao&target=cashTarget5&channelId=222®isterFrom=198"
;
}
}
}
else
if
(
"wechat-pay"
.
equals
(
merchant
.
getName
()))
{
}
else
if
(
"wechat-pay"
.
equals
(
merchant
.
getName
()))
{
return
domain
s
+
"/landing?key=wechat-pay&target=cashTarget5&channelId=1&page=landing/4®isterFrom
"
+
registerFrom
;
return
domain
+
"/landing?key=wechat-pay&target=cashTarget5&channelId=1&page=landing/4®isterFrom=
"
+
registerFrom
;
}
else
{
}
else
{
return
domain
s
+
"/landing?key=xyqb&target=cashTarget4&channelId=1®isterFrom="
+
registerFrom
;
return
domain
+
"/landing?key=xyqb&target=cashTarget4&channelId=1®isterFrom="
+
registerFrom
;
}
}
}
}
private
String
assembleWechatRedirectUrl
(
Merchant
merchant
,
WechatUserInfo
userInfo
,
Long
registerFrom
,
String
protocol
)
{
private
String
assembleWechatRedirectUrl
(
Merchant
merchant
,
WechatUserInfo
userInfo
,
Long
registerFrom
,
String
domain
)
{
String
domains
=
userUIAddr
;
if
(
protocol
!=
null
&&
protocol
.
equals
(
"https:"
)){
domains
=
userUIAddrS
;
}
if
(
"baitiao"
.
equals
(
merchant
.
getName
()))
{
if
(
"baitiao"
.
equals
(
merchant
.
getName
()))
{
if
(
registerFrom
==
58
l
||
registerFrom
==
198
l
){
if
(
registerFrom
==
58L
||
registerFrom
==
198L
){
return
domain
+
"/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
{
}
else
{
return
domain
s
+
"/landing?key=baitiao&target=cashTarget5®isterFrom=198&channelId=222&isWechat=true&openId="
+
userInfo
.
getOpenId
();
return
domain
+
"/landing?key=baitiao&target=cashTarget5®isterFrom=198&channelId=222&isWechat=true&openId="
+
userInfo
.
getOpenId
();
}
}
}
else
if
(
"wechat-pay"
.
equals
(
merchant
.
getName
()))
{
}
else
if
(
"wechat-pay"
.
equals
(
merchant
.
getName
()))
{
return
domain
s
+
"/landing?key=wechat-pay&target=cashTarget5&page=landing/4®isterFrom= "
+
registerFrom
+
"&channelId=1&isWechat=true&openId="
+
userInfo
.
getOpenId
();
return
domain
+
"/landing?key=wechat-pay&target=cashTarget5&page=landing/4®isterFrom= "
+
registerFrom
+
"&channelId=1&isWechat=true&openId="
+
userInfo
.
getOpenId
();
}
else
{
}
else
{
return
domain
s
+
"/landing?key=xyqb&target=cashTarget4®isterFrom= "
+
registerFrom
+
"&channelId=1&isWechat=true&openId="
+
userInfo
.
getOpenId
();
return
domain
+
"/landing?key=xyqb&target=cashTarget4®isterFrom= "
+
registerFrom
+
"&channelId=1&isWechat=true&openId="
+
userInfo
.
getOpenId
();
}
}
}
}
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/sms/SmsController.java
View file @
c88d1ea1
...
@@ -2,7 +2,6 @@ package cn.quantgroup.xyqb.controller.internal.sms;
...
@@ -2,7 +2,6 @@ package cn.quantgroup.xyqb.controller.internal.sms;
import
cn.quantgroup.sms.MsgParams
;
import
cn.quantgroup.sms.MsgParams
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaNewValidator
;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator
;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator
;
import
cn.quantgroup.xyqb.controller.IBaseController
;
import
cn.quantgroup.xyqb.controller.IBaseController
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
...
@@ -200,7 +199,7 @@ public class SmsController implements IBaseController {
...
@@ -200,7 +199,7 @@ public class SmsController implements IBaseController {
/**
/**
* 快速登陆发送验证码新版
* 快速登陆发送验证码新版
*/
*/
@Captcha
New
Validator
@CaptchaValidator
@RequestMapping
(
"/send_login_code_voice_new"
)
@RequestMapping
(
"/send_login_code_voice_new"
)
public
JsonResult
sendLoginCodeVoiceNew
(
@RequestParam
String
phoneNo
,
@RequestParam
(
required
=
false
)
String
registerFrom
,
public
JsonResult
sendLoginCodeVoiceNew
(
@RequestParam
String
phoneNo
,
@RequestParam
(
required
=
false
)
String
registerFrom
,
String
usage
,
@RequestParam
(
required
=
false
)
String
deviceId
)
{
String
usage
,
@RequestParam
(
required
=
false
)
String
deviceId
)
{
...
@@ -216,7 +215,7 @@ public class SmsController implements IBaseController {
...
@@ -216,7 +215,7 @@ public class SmsController implements IBaseController {
/**
/**
* 快速登陆发送短信验证码
* 快速登陆发送短信验证码
*/
*/
@Captcha
New
Validator
@CaptchaValidator
@RequestMapping
(
"/send_login_code_new"
)
@RequestMapping
(
"/send_login_code_new"
)
public
JsonResult
sendLoginSmsCodeNew
(
@RequestParam
String
phoneNo
,
@RequestParam
(
required
=
false
)
String
registerFrom
,
@RequestParam
(
required
=
false
)
String
deviceId
,
@RequestParam
(
required
=
false
,
defaultValue
=
""
)
String
appName
)
{
public
JsonResult
sendLoginSmsCodeNew
(
@RequestParam
String
phoneNo
,
@RequestParam
(
required
=
false
)
String
registerFrom
,
@RequestParam
(
required
=
false
)
String
deviceId
,
@RequestParam
(
required
=
false
,
defaultValue
=
""
)
String
appName
)
{
LOGGER
.
info
(
"快速登陆-发送验证码, phoneNo:{}, registerFrom:{}"
,
phoneNo
,
registerFrom
);
LOGGER
.
info
(
"快速登陆-发送验证码, phoneNo:{}, registerFrom:{}"
,
phoneNo
,
registerFrom
);
...
@@ -225,7 +224,7 @@ public class SmsController implements IBaseController {
...
@@ -225,7 +224,7 @@ public class SmsController implements IBaseController {
/**
/**
* 快速登陆发送短信验证码
* 快速登陆发送短信验证码
*/
*/
@Captcha
New
Validator
@CaptchaValidator
@RequestMapping
(
"/send_login_code_new_forH5"
)
@RequestMapping
(
"/send_login_code_new_forH5"
)
public
JsonResult
sendLoginSmsCodeNewForH5
(
@RequestParam
String
phoneNo
,
@RequestParam
(
required
=
false
)
String
registerFrom
,
@RequestParam
(
required
=
false
)
String
deviceId
,
@RequestParam
(
required
=
false
,
defaultValue
=
""
)
String
appName
)
{
public
JsonResult
sendLoginSmsCodeNewForH5
(
@RequestParam
String
phoneNo
,
@RequestParam
(
required
=
false
)
String
registerFrom
,
@RequestParam
(
required
=
false
)
String
deviceId
,
@RequestParam
(
required
=
false
,
defaultValue
=
""
)
String
appName
)
{
LOGGER
.
info
(
"快速登陆-发送验证码, phoneNo:{}, registerFrom:{}"
,
phoneNo
,
registerFrom
);
LOGGER
.
info
(
"快速登陆-发送验证码, phoneNo:{}, registerFrom:{}"
,
phoneNo
,
registerFrom
);
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserDetailController.java
View file @
c88d1ea1
...
@@ -76,5 +76,5 @@ public class UserDetailController implements IBaseController {
...
@@ -76,5 +76,5 @@ public class UserDetailController implements IBaseController {
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"身份证号码错误"
,
null
);
}
}
}
}
}
}
src/main/java/cn/quantgroup/xyqb/service/auth/impl/UserAuthorizedServiceImpl.java
View file @
c88d1ea1
...
@@ -9,11 +9,13 @@ import cn.quantgroup.xyqb.service.auth.IUserAuthorizedService;
...
@@ -9,11 +9,13 @@ import cn.quantgroup.xyqb.service.auth.IUserAuthorizedService;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.util.Objects
;
/**
/**
* @author xufei on 2018/1/5.
* @author xufei on 2018/1/5.
...
@@ -27,6 +29,7 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
...
@@ -27,6 +29,7 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
@Resource
@Resource
private
IUserAuthorizedRepository
userAuthorizedRepository
;
private
IUserAuthorizedRepository
userAuthorizedRepository
;
@Cacheable
(
value
=
"user_authorized_idno_cache"
,
key
=
"#idNo"
,
unless
=
"#result == null"
,
cacheManager
=
"cacheManager"
)
@Override
@Override
public
Boolean
hasUserAuthorized
(
String
idNo
)
{
public
Boolean
hasUserAuthorized
(
String
idNo
)
{
try
{
try
{
...
@@ -35,6 +38,7 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
...
@@ -35,6 +38,7 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
}
}
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
LOGGER
.
error
(
"[hasUserAuthorized]参数异常e:{}"
,
e
);
LOGGER
.
error
(
"[hasUserAuthorized]参数异常e:{}"
,
e
);
return
Boolean
.
FALSE
;
}
}
UserAuthorized
userAuthorized
=
userAuthorizedRepository
.
findByIdNo
(
idNo
);
UserAuthorized
userAuthorized
=
userAuthorizedRepository
.
findByIdNo
(
idNo
);
...
@@ -62,6 +66,10 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
...
@@ -62,6 +66,10 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
@Override
@Override
public
UserAuthorized
createUserAuthorized
(
UserAuthorizedParam
userAuthorizedParam
)
{
public
UserAuthorized
createUserAuthorized
(
UserAuthorizedParam
userAuthorizedParam
)
{
// 数据检查
if
(
Objects
.
isNull
(
userAuthorizedParam
)
||
this
.
hasUserAuthorized
(
userAuthorizedParam
.
getIdNo
())){
return
null
;
}
AuthPattern
authPatternEnum
=
AuthPattern
.
valueOf
(
userAuthorizedParam
.
getAuthPattern
());
AuthPattern
authPatternEnum
=
AuthPattern
.
valueOf
(
userAuthorizedParam
.
getAuthPattern
());
UserAuthorized
userAuthorized
=
new
UserAuthorized
();
UserAuthorized
userAuthorized
=
new
UserAuthorized
();
...
@@ -84,6 +92,7 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
...
@@ -84,6 +92,7 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
}
}
}
}
@Cacheable
(
value
=
"user_authorized_uuid_2_id_cache"
,
key
=
"#userUuid"
,
unless
=
"#result == null"
,
cacheManager
=
"cacheManager"
)
@Override
@Override
public
String
getUserAuthorizedId
(
String
userUuid
)
{
public
String
getUserAuthorizedId
(
String
userUuid
)
{
if
(
StringUtils
.
isBlank
(
userUuid
))
{
if
(
StringUtils
.
isBlank
(
userUuid
))
{
...
...
src/main/java/cn/quantgroup/xyqb/util/IPUtil.java
View file @
c88d1ea1
...
@@ -32,6 +32,7 @@ public class IPUtil {
...
@@ -32,6 +32,7 @@ public class IPUtil {
String
jvmTest
=
System
.
getProperty
(
"test"
);
String
jvmTest
=
System
.
getProperty
(
"test"
);
if
(
Boolean
.
valueOf
(
jvmTest
)){
if
(
Boolean
.
valueOf
(
jvmTest
)){
WHITE_ADDRESS
.
add
(
"192.168."
);
WHITE_ADDRESS
.
add
(
"192.168."
);
WHITE_ADDRESS
.
add
(
"10."
);
WHITE_ADDRESS
.
add
(
LOCAL_ADDRESS
);
WHITE_ADDRESS
.
add
(
LOCAL_ADDRESS
);
}
}
}
}
...
...
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