Commit c88d1ea1 authored by 贷前—徐菲's avatar 贷前—徐菲

Merge remote-tracking branch 'origin/master'

parents 865c856e e92fa962
......@@ -13,6 +13,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import sun.misc.Signal;
......@@ -38,6 +39,10 @@ public class Bootstrap {
log.info("server start...");
// 启用平滑退出功能
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);
}
}
......@@ -8,13 +8,11 @@ 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.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Objects;
/**
* IP白名单检验
......@@ -27,18 +25,12 @@ import java.util.Objects;
public class IpValidateAdvisor {
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)")
private void whiteIpMatch() {
}
@Around("whiteIpMatch()")
private Object doWhiteIpMatch(ProceedingJoinPoint pjp) throws Throwable {
if(Objects.equals(isDebug, 0)){
return pjp.proceed();
}
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
// 客户端IP
String clientIp = IPUtil.getRemoteIP(request);
......
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;
}
}
}
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 {
}
package cn.quantgroup.xyqb.aspect.captcha;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService;
......@@ -78,19 +77,16 @@ public class CaptchaValidateAdvisor {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String registerFrom = Optional.ofNullable(request.getParameter("registerFrom")).orElse("");
String captchaId = Optional.ofNullable(request.getParameter("captchaId")).orElse("");
Object captchaValue = request.getParameter("captchaValue");
String captchaValue = request.getParameter("captchaValue");
if (shouldSkipCaptchaValidate(registerFrom, captchaId, captchaValue)) {
LOGGER.info("使用超级图形验证码校验, registerFrom={}, clientIp={}", registerFrom, IPUtil.getRemoteIP(request));
return pjp.proceed();
}
JsonResult result = JsonResult.buildSuccessResult("图形验证码不正确", "");
result.setBusinessCode("0002");
if (captchaValue != null) {
String captcha = String.valueOf(captchaValue);
if (StringUtils.isNotBlank(captchaValue)) {
// 忽略用户输入的大小写
captcha = StringUtils.lowerCase(captcha);
String captcha = StringUtils.lowerCase(captchaValue);
// 验证码校验
Boolean validCaptcha = false;
try {
......@@ -98,7 +94,6 @@ public class CaptchaValidateAdvisor {
} catch (CaptchaServiceException ex) {
LOGGER.error("验证码校验异常, {}, {}", ex.getMessage(), ex);
}
if (validCaptcha) {
return pjp.proceed();
}
......
......@@ -13,9 +13,6 @@ 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.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
......@@ -38,10 +35,6 @@ public class PasswordFreeAccessValidateAdvisor {
private static final String PHONE_NO = "phoneNo";
private static final String USER_ID = "userId";
@Autowired
@Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> redisTemplate;
/**
* 免密访问校验切面
*/
......
......@@ -17,7 +17,6 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
......@@ -25,21 +24,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
* Created by 11 on 2017/1/17.
......@@ -66,12 +59,19 @@ public class WeChatController implements IBaseController {
@Autowired
private IUserService userService;
// https://passport.xyqb.com/landing?key=xxx&target=cashTarget5&registerFrom=198&channelId=%d
/**
* 用户中心UI的http协议头域名
* http://passport.xyqb.com
*/
@Value("${passport.http}")
private String userUIAddr;
private String userUiDomain;
@Value("${passport.http}")
private String userDomainStr;
/**
* 用户中心UI的https协议头域名
* https://passport.xyqb.com
*/
@Value("${passport.https}")
private String userUiDomainS;
@Value("${api.http}")
private String xyqbDomainStr;
......@@ -79,10 +79,6 @@ public class WeChatController implements IBaseController {
@Autowired
private IHttpService httpService;
//加https地址
@Value("${passport.https}")
private String userUIAddrS;
/**
* 开发者资质认证,有必要吗?
*
......@@ -169,140 +165,64 @@ public class WeChatController implements IBaseController {
* @return
*/
@RequestMapping("/receiveCode/extdata/{key}/{extdata}")
public void receiveCodeWithExtData(
String code, @PathVariable(value = "key") String systemKey,
@PathVariable(value = "extdata") String extData, HttpServletResponse response
) {
try {
String schema = getProtocol();
public void receiveCodeWithExtData(String code, @PathVariable(value = "key") String systemKey,
@PathVariable(value = "extdata") String extData, HttpServletResponse response) {
Long registerFrom = null;
String redirect = null;
String schema = null;
try {
extData = new String(Base64.decodeBase64(extData), "UTF-8");
} catch (Exception ex) {
extData = "";
}
String protocol="http:";
LOGGER.info("从微信extdata版本接口进入:{}, extData:{}", schema, extData);
if (StringUtils.isEmpty(extData)) {
// 从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);
if (StringUtils.isBlank(extData)) {
receiveCodeWithDefault(code, systemKey, schema, registerFrom, redirect, response);
return;
}
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
String redirectUrl =
createUserSession(user, merchant, "", schema, Constants.Channel.WECHAT);
response.setHeader("Location", redirectUrl);
response.setStatus(301);
} else {
LOGGER.info("从微信extdata版本接口进入:{}, extData:{}", schema, extData);
HashMap<String, Object> extDataObj;
try {
extDataObj =
JSON.parseObject(extData, new TypeReference<HashMap<String, Object>>() {
});
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);
receiveCodeWithDefault(code, systemKey, schema, registerFrom, redirect, response);
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;
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);
}
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
String redirectUrl =
createUserSession(user, merchant, "", schema, Constants.Channel.WECHAT);
response.setHeader("Location", redirectUrl);
response.setStatus(301);
return;
/**
* 前端微信跳转页面
* @param code
* @param systemKey
* @param schema
* @param registerFrom
* @param redirect
* @param response
*/
private void receiveCodeWithDefault(String code, String systemKey, String schema, Long registerFrom, String redirect, HttpServletResponse response){
/*
* 预处理(容错)
*/
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;
}
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);
// 从code获取token
Merchant merchant = merchantService.findMerchantByName(systemKey);
AccessTokenResponse token = wechatService.getToken(code);
if (token == null) {
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl(response, merchant, registerFrom,protocol);
redirectNormalUrl(response, merchant, registerFrom,domain);
return;
}
WechatUserInfo userInfo =
......@@ -310,7 +230,7 @@ public class WeChatController implements IBaseController {
token.getOpenId());
if (userInfo == null || StringUtils.isEmpty(userInfo.getOpenId())) {
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl(response, merchant, registerFrom,protocol);
redirectNormalUrl(response, merchant, registerFrom, domain);
return;
}
WechatUserInfo userInfoInDb = wechatService.findWechatUserInfoFromDb(userInfo.getOpenId());
......@@ -322,31 +242,25 @@ public class WeChatController implements IBaseController {
userInfo.setNickName(nickName);
}
userInfo = wechatService.saveWechatUserInfo(userInfo);
redirectWechatLoginUrlWithoutLogin(response, merchant, userInfo, registerFrom,protocol);
redirectWechatLoginUrlWithoutLogin(response, merchant, userInfo, registerFrom, domain);
return;
}
if (userInfoInDb.getUserId() == null) {
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin(response, merchant, userInfoInDb, registerFrom,protocol);
redirectWechatLoginUrlWithoutLogin(response, merchant, userInfoInDb, registerFrom, domain);
return;
}
User user = userService.findById(userInfoInDb.getUserId());
if (user == null) {
redirectWechatLoginUrlWithoutLogin(response, merchant, userInfoInDb, registerFrom,protocol);
redirectWechatLoginUrlWithoutLogin(response, merchant, userInfoInDb, registerFrom, domain);
return;
}
// 已经关联了用户
// create session, 登进去,该怎么玩怎么玩。
String redirectUrl = createUserSession(user, merchant, redirect, schema, registerFrom);
LOGGER.info("Location:[{}]",redirectUrl);
String redirectUrl = createUserSession(user, merchant, redirect, domain, registerFrom);
response.setHeader("Location", redirectUrl);
response.setStatus(301);
}
} catch (Exception ex) {
LOGGER.error("发生异常", ex);
throw ex;
}
}
/**
* 通过redirect_url获取code
......@@ -356,140 +270,82 @@ public class WeChatController implements IBaseController {
*/
@RequestMapping("/receiveCode/{key}")
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);
// 从code获取token
Merchant merchant = merchantService.findMerchantByName(systemKey);
AccessTokenResponse token = wechatService.getToken(code);
if (token == null) {
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl(response, merchant, Constants.Channel.WECHAT,protocol);
return;
Long registerFrom = null;
String redirect = null;
String schema = "http:";
if(Objects.equals("https:", request.getScheme())){
schema = "https:";
}
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);
LOGGER.info("Location=[{}]", redirectUrl);
response.setHeader("Location", redirectUrl);
response.setStatus(301);
receiveCodeWithDefault(code, systemKey, schema, registerFrom, redirect, response);
}
private String createUserSession(User user, Merchant merchant, String redirect, String schema, Long registerFrom) {
//String url = "http://passport.xyqb.com";
String url = "http://"+userDomainStr;
if ("https:".equals(schema)) {
url = "https://"+userDomainStr;
}
private String createUserSession(User user, Merchant merchant, String redirect, String domain, Long registerFrom) {
if (StringUtils.isEmpty(redirect) || "redirect".equals(redirect)) {
LOGGER.info("微信登录:redirect为null,走正常流程.");
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())) {
AuthBean authBean = sessionService.createSession(Constants.Channel.WECHAT, registerFrom, "", user, merchant);
return url + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom + "&channelId=" + Constants.Channel.WECHAT + "&key=" + merchant.getName() + "&target=cashTarget5";
return domain + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom + "&channelId=" + Constants.Channel.WECHAT + "&key=" + merchant.getName() + "&target=cashTarget5";
} else {
return loginInWechatWithSessionCreated(user, merchant, "cashTarget4", 1L, url, registerFrom);
return loginInWechatWithSessionCreated(user, merchant, "cashTarget4", 1L, domain, registerFrom);
}
} else if ("local".equals(redirect)) {
LOGGER.info("微信登录:redirect不为null,创建session跳到指定前端页面.");
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;
String target = "baitiao".equals(merchant.getName()) ? "cashTarget5" : "cashTarget4";
return url + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom +
return domain + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom +
"&channelId=" + channelId + "&key=" + merchant.getName() + "&target=" + target + "&isWechat=true";
}
return null;
}
private String loginInWechatWithSessionCreated(User user, Merchant merchant, String target, Long channelId, String url, Long registerFrom) {
private String loginInWechatWithSessionCreated(User user, Merchant merchant, String target, Long channelId, String domain, Long registerFrom) {
AuthBean authBean = sessionService.createSession(channelId, registerFrom, "", user, merchant);
return url + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom + "&channelId=" + channelId + "&key=" + merchant.getName() + "&target=" + target;
return domain + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom + "&channelId=" + channelId + "&key=" + merchant.getName() + "&target=" + target;
}
private void redirectWechatLoginUrlWithoutLogin(HttpServletResponse response, Merchant merchant, WechatUserInfo userInfo, Long registerFrom,String protocol) {
String redirectUrl = assembleWechatRedirectUrl(merchant, userInfo, registerFrom,protocol);
private void redirectWechatLoginUrlWithoutLogin(HttpServletResponse response, Merchant merchant, WechatUserInfo userInfo, Long registerFrom,String domain) {
String redirectUrl = assembleWechatRedirectUrl(merchant, userInfo, registerFrom,domain);
LOGGER.info("redirectWechatLoginUrlWithoutLogin redirectUrl:[{}]",redirectUrl);
response.setHeader("Location", redirectUrl);
response.setStatus(301);
}
private void redirectNormalUrl(HttpServletResponse response, Merchant merchant, Long registerFrom,String protocol) {
String redirectUrl = assembleNormalRedirectUrl(merchant, registerFrom,protocol);
private void redirectNormalUrl(HttpServletResponse response, Merchant merchant, Long registerFrom,String domain) {
String redirectUrl = assembleNormalRedirectUrl(merchant, registerFrom,domain);
LOGGER.info("redirectNormalUrl redirectUrl:[{}]",redirectUrl);
response.setHeader("Location", redirectUrl);
response.setStatus(301);
}
private String assembleNormalRedirectUrl(Merchant merchant, Long registerFrom,String protocol) {
String domains=userUIAddr;
if(protocol!=null&&protocol.equals("https:")){
domains=userUIAddrS;
}
private String assembleNormalRedirectUrl(Merchant merchant, Long registerFrom,String domain) {
if ("baitiao".equals(merchant.getName())) {
if(registerFrom==58l||registerFrom==198l){
return domains + "/landing?key=baitiao&target=cashTarget5&channelId=222&registerFrom="+registerFrom;
if(registerFrom == 58L || registerFrom == 198L){
return domain + "/landing?key=baitiao&target=cashTarget5&channelId=222&registerFrom="+registerFrom;
}else{
return domains + "/landing?key=baitiao&target=cashTarget5&channelId=222&registerFrom=198";
return domain + "/landing?key=baitiao&target=cashTarget5&channelId=222&registerFrom=198";
}
} else if ("wechat-pay".equals(merchant.getName())) {
return domains + "/landing?key=wechat-pay&target=cashTarget5&channelId=1&page=landing/4&registerFrom" + registerFrom;
return domain + "/landing?key=wechat-pay&target=cashTarget5&channelId=1&page=landing/4&registerFrom=" + registerFrom;
} else {
return domains + "/landing?key=xyqb&target=cashTarget4&channelId=1&registerFrom=" + registerFrom;
return domain + "/landing?key=xyqb&target=cashTarget4&channelId=1&registerFrom=" + registerFrom;
}
}
private String assembleWechatRedirectUrl(Merchant merchant, WechatUserInfo userInfo, Long registerFrom,String protocol) {
String domains=userUIAddr;
if(protocol!=null&&protocol.equals("https:")){
domains=userUIAddrS;
}
private String assembleWechatRedirectUrl(Merchant merchant, WechatUserInfo userInfo, Long registerFrom,String domain) {
if ("baitiao".equals(merchant.getName())) {
if(registerFrom==58l||registerFrom==198l){
return domains + "/landing?key=baitiao&target=cashTarget5&registerFrom=" + registerFrom + "&channelId=222&isWechat=true&openId=" + userInfo.getOpenId();
if(registerFrom == 58L || registerFrom == 198L){
return domain + "/landing?key=baitiao&target=cashTarget5&registerFrom=" + registerFrom + "&channelId=222&isWechat=true&openId=" + userInfo.getOpenId();
}else{
return domains + "/landing?key=baitiao&target=cashTarget5&registerFrom=198&channelId=222&isWechat=true&openId=" + userInfo.getOpenId();
return domain + "/landing?key=baitiao&target=cashTarget5&registerFrom=198&channelId=222&isWechat=true&openId=" + userInfo.getOpenId();
}
} else if ("wechat-pay".equals(merchant.getName())) {
return domains + "/landing?key=wechat-pay&target=cashTarget5&page=landing/4&registerFrom= " + registerFrom + "&channelId=1&isWechat=true&openId=" + userInfo.getOpenId();
return domain + "/landing?key=wechat-pay&target=cashTarget5&page=landing/4&registerFrom= " + registerFrom + "&channelId=1&isWechat=true&openId=" + userInfo.getOpenId();
} else {
return domains + "/landing?key=xyqb&target=cashTarget4&registerFrom= " + registerFrom + "&channelId=1&isWechat=true&openId=" + userInfo.getOpenId();
return domain + "/landing?key=xyqb&target=cashTarget4&registerFrom= " + registerFrom + "&channelId=1&isWechat=true&openId=" + userInfo.getOpenId();
}
}
......
......@@ -2,7 +2,6 @@ package cn.quantgroup.xyqb.controller.internal.sms;
import cn.quantgroup.sms.MsgParams;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.aspect.captcha.CaptchaNewValidator;
import cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator;
import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.model.JsonResult;
......@@ -200,7 +199,7 @@ public class SmsController implements IBaseController {
/**
* 快速登陆发送验证码新版
*/
@CaptchaNewValidator
@CaptchaValidator
@RequestMapping("/send_login_code_voice_new")
public JsonResult sendLoginCodeVoiceNew(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,
String usage, @RequestParam(required = false) String deviceId) {
......@@ -216,7 +215,7 @@ public class SmsController implements IBaseController {
/**
* 快速登陆发送短信验证码
*/
@CaptchaNewValidator
@CaptchaValidator
@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) {
LOGGER.info("快速登陆-发送验证码, phoneNo:{}, registerFrom:{}", phoneNo, registerFrom);
......@@ -225,7 +224,7 @@ public class SmsController implements IBaseController {
/**
* 快速登陆发送短信验证码
*/
@CaptchaNewValidator
@CaptchaValidator
@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) {
LOGGER.info("快速登陆-发送验证码, phoneNo:{}, registerFrom:{}", phoneNo, registerFrom);
......
......@@ -9,11 +9,13 @@ import cn.quantgroup.xyqb.service.auth.IUserAuthorizedService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.Objects;
/**
* @author xufei on 2018/1/5.
......@@ -27,6 +29,7 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
@Resource
private IUserAuthorizedRepository userAuthorizedRepository;
@Cacheable(value = "user_authorized_idno_cache", key = "#idNo", unless = "#result == null", cacheManager = "cacheManager")
@Override
public Boolean hasUserAuthorized(String idNo) {
try {
......@@ -35,6 +38,7 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
}
} catch (ParseException e) {
LOGGER.error("[hasUserAuthorized]参数异常e:{}", e);
return Boolean.FALSE;
}
UserAuthorized userAuthorized = userAuthorizedRepository.findByIdNo(idNo);
......@@ -62,6 +66,10 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
@Override
public UserAuthorized createUserAuthorized(UserAuthorizedParam userAuthorizedParam) {
// 数据检查
if(Objects.isNull(userAuthorizedParam) || this.hasUserAuthorized(userAuthorizedParam.getIdNo())){
return null;
}
AuthPattern authPatternEnum = AuthPattern.valueOf(userAuthorizedParam.getAuthPattern());
UserAuthorized userAuthorized = new UserAuthorized();
......@@ -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
public String getUserAuthorizedId(String userUuid) {
if (StringUtils.isBlank(userUuid)) {
......
......@@ -32,6 +32,7 @@ public class IPUtil {
String jvmTest = System.getProperty("test");
if(Boolean.valueOf(jvmTest)){
WHITE_ADDRESS.add("192.168.");
WHITE_ADDRESS.add("10.");
WHITE_ADDRESS.add(LOCAL_ADDRESS);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment