Commit 5b800aeb authored by 技术部-任文超's avatar 技术部-任文超

Merge branch 'master' into 20180301-Fixed_LogException

parents 953c4bf0 73189d4d
......@@ -24,6 +24,12 @@ public class RegisterMqConfig {
private String queueName;
@Value("${register.rabbitmq.exchange}")
private String registerMqExchange;
@Value("${register.rabbitmq.queue.qq_gdt}")
private String queueName4Gdt;
@Value("${register.rabbitmq.routing_key.qq_gdt}")
private String routingKey4Gdt;
@Value("${register.rabbitmq.exchange.qq_gdt}")
private String exchange4Gdt;
@Value("${register.rabbitmq.connection.host}")
private String host;
......@@ -75,11 +81,36 @@ public class RegisterMqConfig {
return binding;
}
@Bean(name = "registerRabbitTemplate")
public RabbitTemplate registerTemplate(@Qualifier("registerMqFactory") ConnectionFactory registerMqFactory) {
RabbitTemplate template = new RabbitTemplate(registerMqFactory);
template.setExchange(registerMqExchange);
return template;
}
@Bean(name = "registerMqExchange4Gdt")
public FanoutExchange registerMqExchange4Gdt() {
return new FanoutExchange(exchange4Gdt);
}
@Bean(name = "registerMqQueue4Gdt")
public Queue registerMqQueue4Gdt() {
return new Queue(queueName4Gdt);
}
@Bean(name = "registerMqBinding4Gdt")
public Binding registerMqBinding4Gdt(@Qualifier("registerMqAmqpAdmin")AmqpAdmin registerMqAmqpAdmin, @Qualifier("registerMqQueue4Gdt")Queue registerMqQueue4Gdt, @Qualifier("registerMqExchange4Gdt")FanoutExchange registerMqExchange4Gdt) {
Binding binding = BindingBuilder.bind(registerMqQueue4Gdt).to(registerMqExchange4Gdt);
registerMqAmqpAdmin.declareBinding(binding);
return binding;
}
@Bean(name = "registerRabbitTemplate4Gdt")
public RabbitTemplate registerTemplate4Gdt(@Qualifier("registerMqFactory") ConnectionFactory registerMqFactory) {
RabbitTemplate template = new RabbitTemplate(registerMqFactory);
template.setExchange(exchange4Gdt);
return template;
}
}
package cn.quantgroup.xyqb.controller.external.captcha;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService;
import java.util.*;
......@@ -58,5 +59,13 @@ public class ImageCaptchaController {
data.put("image", String.format(IMG_BASE64_PATTREN, imageBase64));
return JsonResult.buildSuccessResult("", data);
}
/**
* 图片验证码验证
* 注意:本方法有中间层在用,用于QG图形验证码检验
*/
@CaptchaValidator
@RequestMapping("/verification_image_code")
public JsonResult verificationImageCode() {
return JsonResult.buildSuccessResult("", null);
}
}
......@@ -237,8 +237,8 @@ public class InnerController implements IBaseController {
*/
@RequestMapping("/user_detail/save")
public JsonResult saveUserDetail(Long userId, String phoneNo, String name, String idNo,
String email, Long id) {
LOGGER.info("保存用户详细信息,phoneNo:{},userId;{},name:{},idNo:{},email;{}", phoneNo, userId, name, idNo, email);
String email, String qq, Long id) {
LOGGER.info("保存用户详细信息,phoneNo:{},userId;{},name:{},idNo:{},email;{},qq;{}", phoneNo, userId, name, idNo, email, qq);
//参数验证
if (userId == null || userId == 0L) {
return JsonResult.buildErrorStateResult("用户id为空.", null);
......@@ -282,6 +282,7 @@ public class InnerController implements IBaseController {
userDetail.setIdType(IdType.ID_CARD);
userDetail.setGender(info.getGender());
userDetail.setEmail(email);
userDetail.setQq(qq);
userDetail = userDetailService.saveUserDetail(userDetail);
if (userDetail != null) {
return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail));
......@@ -1156,6 +1157,9 @@ public class InnerController implements IBaseController {
}else {
return JsonResult.buildErrorStateResult("校验失败", "");
}
if (user == null) {
user = userRegisterService.register(phoneNo, "", null);
}
if (Objects.isNull(user)) {
return JsonResult.buildErrorStateResult("用户不存在", "");
}else{
......
......@@ -8,6 +8,8 @@ import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.service.http.IHttpService;
import cn.quantgroup.xyqb.service.user.IUserBtRegisterService;
import cn.quantgroup.xyqb.service.user.IUserService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -46,6 +48,8 @@ public class AuthInfoController implements IBaseController {
context.setBtMerchantId(sessionStruct.getValues().getLoginProperties().getBtMerchantId());
//有ThreadLocal不释放的问题,不可再使用原来方式了
loginInfo.setLoginContext(context);
log.info("[/auth/info/login] SessionStruct数据:{}", JSONObject.toJSONString(sessionStruct));
log.info("[/auth/info/login] LoginInfo数据:{}", JSONObject.toJSONString(loginInfo));
return JsonResult.buildSuccessResult("", loginInfo);
}
return JsonResult.buildErrorStateResult("用户未登录",null);
......
package cn.quantgroup.xyqb.controller.internal.user;
import cn.quantgroup.tech.util.TechEnvironment;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.aspect.captcha.CaptchaFiniteValidator;
import cn.quantgroup.xyqb.aspect.lock.PasswordErrorFiniteValidator;
......@@ -26,6 +27,8 @@ import cn.quantgroup.xyqb.util.IPUtil;
import cn.quantgroup.xyqb.util.MqUtils;
import cn.quantgroup.xyqb.util.PasswordUtil;
import cn.quantgroup.xyqb.util.ValidationUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
......@@ -114,31 +117,6 @@ public class UserController implements IBaseController {
return login(channelId, appChannel, createdFrom, userId, key, request, openId, dimension);
}
/**
* 快速登录(手机号 + 短信验证码),H5专用入口
* 短信验证码错误达到限定次数时执行图形验证码校验
* 图形验证码累计错误达到限定次数时须重新获取
*
* @param channelId
* @param appChannel
* @param createdFrom
* @param key
* @param btRegisterChannelId
* @param dimension
* @param request
* @return
*/
@RequestMapping("/login/fastV1")
public JsonResult loginFastV1(
@RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel,
@RequestParam(required = false, defaultValue = "1") Long createdFrom,
@RequestParam(required = false,defaultValue = "xyqb") String key,
@RequestParam(required = false)Long btRegisterChannelId,
@RequestParam(required = false) String dimension ,HttpServletRequest request) {
LOGGER.info("login/fastV1 -> channelId:{},appChennel:{},createdFrom:{},key:{},btRegisterChannelId:{},dimension:{}",channelId, appChannel, createdFrom, key, btRegisterChannelId, dimension);
return loginFast(channelId, appChannel, createdFrom, key, btRegisterChannelId, dimension, request);
}
@LogHttpCaller
@PasswordErrorFiniteValidator
@RequestMapping("/login")
......@@ -162,15 +140,44 @@ public class UserController implements IBaseController {
}
}
/**
* 快速登录(手机号 + 短信验证码),H5专用入口
* 短信验证码错误达到限定次数时执行图形验证码校验
* 图形验证码累计错误达到限定次数时须重新获取
*
* @param channelId
* @param appChannel
* @param createdFrom
* @param key
* @param btRegisterChannelId
* @param dimension
* @param request
* @return
*/
@RequestMapping("/login/fastV1")
public JsonResult loginFastV1(
@RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel,
@RequestParam(required = false, defaultValue = "1") Long createdFrom,
@RequestParam(required = false,defaultValue = "xyqb") String key,
@RequestParam(required = false) Long btRegisterChannelId,
@RequestParam(required = false) String dimension,
@RequestParam(name = "click_id", required = false) String clickId,
HttpServletRequest request) {
LOGGER.info("login/fastV1 -> channelId:{},appChennel:{},createdFrom:{},key:{},btRegisterChannelId:{},dimension:{},clickId:{}",channelId, appChannel, createdFrom, key, btRegisterChannelId, dimension, clickId);
return loginFast(channelId, appChannel, createdFrom, key, btRegisterChannelId, dimension, clickId, request);
}
@RequestMapping("/login/fast")
public JsonResult loginFast(
@RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel,
@RequestParam(required = false, defaultValue = "1") Long createdFrom,
@RequestParam(required = false,defaultValue = "xyqb") String key,
@RequestParam(required = false)Long btRegisterChannelId,
@RequestParam(required = false) String dimension ,HttpServletRequest request) {
@RequestParam(required = false) String dimension,
@RequestParam(name = "click_id", required = false) String clickId,
HttpServletRequest request) {
Map<String, JsonResult> validMap = getHeaderParam(request);
LOGGER.info("login/fast -> channelId:{},appChannel:{},createdFrom:{},btRegisterChannelId:{},key:{},dimension:{}",channelId,appChannel,createdFrom,btRegisterChannelId,key,dimension);
LOGGER.info("login/fast -> channelId:{},appChannel:{},createdFrom:{},btRegisterChannelId:{},key:{},dimension:{},clickId:{}",channelId,appChannel,createdFrom,btRegisterChannelId,key,dimension, clickId);
if (null != validMap.get("fail")) {
return validMap.get("fail");
}
......@@ -181,29 +188,31 @@ public class UserController implements IBaseController {
JsonResult successResult = validMap.get("success");
String phoneNo = successResult.getData().toString();
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("用户快速登录失败,手机号错误, createdFrom:{},phoneNo:{}", createdFrom, phoneNo);
LOGGER.info("用户快速注册失败,手机号错误, createdFrom:{},phoneNo:{}", createdFrom, phoneNo);
throw new UserNotExistException("手机号错误");
}
String verificationCode = successResult.getMsg();
// 执行短信验证码检查
verifyPhoneAndCode(phoneNo, verificationCode);
User user = userService.findByPhoneWithCache(phoneNo);
// 缓存未命中时查DB
if (user == null) {
user = userService.findByPhoneInDb(phoneNo);
}
if (user != null && !user.getEnable()) {
LOGGER.error("用户不存在,或者已经注销,phoneNo:{}",phoneNo);
return JsonResult.buildErrorStateResult("登录失败", null);
}
UserStatistics statistics = null;
JSONObject qqGdt = null;
if (user == null) {
user = userRegisterService.register(phoneNo, channelId, createdFrom, appChannel,btRegisterChannelId,dimension);
if (user == null) {
throw new UserNotExistException("用户未找到");
}
//广点通转化注册 - 发送消息 - 方法内过滤
MqUtils.sendRegisterMessageForGdt(phoneNo, clickId);
statistics = new UserStatistics(user,dimension,2,channelId);
}else{
statistics = new UserStatistics(user,dimension,3,channelId);
}
//增加登陆统计发送
UserStatistics statistics=new UserStatistics(user,dimension,3,channelId);
MqUtils.sendLoanVest(statistics);
return new JsonResult(sessionService.createSession(channelId, createdFrom, appChannel, user, merchant));
// return createSession(channelId, createdFrom, appChannel, user);
......@@ -452,7 +461,7 @@ public class UserController implements IBaseController {
//用户信息存在,更新session中的最后访问时间,重新写入缓存.
if (null != user || !user.getEnable()) {
//增加登陆统计发送
UserStatistics statistics=new UserStatistics(user,dimension,1,channelId);
UserStatistics statistics=new UserStatistics(user,dimension,4,channelId);
MqUtils.sendLoanVest(statistics);
return new JsonResult(sessionService.createSession(channelId, createdFrom, appChannel, user, merchant));
} else {
......@@ -495,6 +504,10 @@ public class UserController implements IBaseController {
* @param verificationCode
*/
private void verifyPhoneAndCode(String phoneNo, String verificationCode) {
// 非生产环境直接跳过验证码检验
if(!TechEnvironment.isPro()){
return;
}
if (!smsService.verifyPhoneAndCode(phoneNo, verificationCode)) {
smsReSendOrNot(phoneNo);
LOGGER.info("验证码校验失败,phoneNo:{} , verificationCode:{}", phoneNo, verificationCode);
......
......@@ -12,17 +12,29 @@ import java.io.Serializable;
@Data
public class UserQueryInfo implements Serializable {
private static final long serialVersionUID = -1L;
/**
* 用户主键
*/
private Long userId;
/**
* 登录手机号/账号
*/
private String phoneNo;
/**
* 姓名
*/
private String name;
/**
* 银行卡号
*/
private String bankCards;
//证件号
/**
* 证件号
*/
private String idNo;
//0 身份证 1 军官证 2 护照
/**
* 地址
*/
private String address;
......
......@@ -12,7 +12,13 @@ public class UserStatistics {
private String uuid;
private Long registerFrom;
private String dimension;
private int action;//登录0,注册1,快捷登录2,免密登录3
/**
* 1-登录
* 2-注册
* 3-快捷登录
* 4-免密登录
*/
private int action;
private Long channel;
public UserStatistics() {
......
package cn.quantgroup.xyqb.service.mq;
import cn.quantgroup.xyqb.model.UserRegisterMqMessage;
import cn.quantgroup.xyqb.model.UserStatistics;
import java.io.Serializable;
/**
* Created by xuran on 2017/9/7.
* 用户注册信息广播
*/
public interface IRegisterMqService {
void send(UserRegisterMqMessage message);
void send(Serializable message);
void send4Gdt(Serializable message);
}
package cn.quantgroup.xyqb.service.mq.Impl;
import cn.quantgroup.xyqb.model.UserRegisterMqMessage;
import cn.quantgroup.xyqb.service.mq.IRegisterMqService;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
......@@ -12,6 +11,8 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.io.Serializable;
/**
* Created by xuran on 2017/9/7.
*/
......@@ -22,34 +23,44 @@ public class IRegisterMqServiceImpl implements IRegisterMqService {
@Autowired
@Qualifier("registerRabbitTemplate")
RabbitTemplate registerRabTemplate;
@Autowired
@Qualifier("registerRabbitTemplate4Gdt")
RabbitTemplate registerRabbitTemplate4Gdt;
@Autowired
@Qualifier(value = "registerMqQueue")
Queue registerMqQueue;
/**
* 发送用登陆统计信息
* @param message 订单信息
*/
@Override
@Async
public void send(UserRegisterMqMessage message){
public void send(Serializable message){
if(null==message){
LOGGER.error("广播用户注册消息不能为空");
}
LOGGER.info("广播用户注册消息,message={}",message);
String msg = JSONObject.toJSONString(message);
registerRabTemplate.convertAndSend(msg);
LOGGER.info("广播用户注册消息,message={}",msg);
}
/**
* 发送用登陆统计信息
* @param message 订单信息
*/
@Override
@Async
public void send4Gdt(Serializable message){
if(null==message){
LOGGER.error("广点通用户注册消息不能为空");
}
LOGGER.info("广点通用户注册消息,message={}",message);
String msg = JSONObject.toJSONString(message);
registerRabbitTemplate4Gdt.convertAndSend(msg);
LOGGER.info("广点通用户注册消息,message={}",msg);
}
}
......@@ -62,6 +62,7 @@ public class SessionServiceImpl implements ISessionService {
sessionStruct.setAttribute("channelId", String.valueOf(channelId));
sessionStruct.setAttribute("createdFrom", String.valueOf(createdFrom));
sessionStruct.setAttribute("appChannel", String.valueOf(appChannel));
sessionStruct.getValues().setLoginProperties(properties);
authBean.setPhoneNo(user.getPhoneNo());
authBean.setToken(sessionStruct.getSid());
persistSession(sessionStruct.getSid(), sessionStruct.getValues());
......
......@@ -48,12 +48,16 @@ public class SmsServiceImpl implements ISmsService {
}
/**
* 24-“【信用钱包】么么哒,等您好久了~感谢您注册信用钱包,我们来给您送钱啦,点击提交借款申请,万元现金立即到手 s.xyqb.com/a”
* 1005-“【信用钱包】等您好久了~感谢您的注册,尊享息费5折优惠。登录 s.xyqb.com/a 享更多优惠(合理消费,理性借贷)”
* @param phoneNo
*/
@Override
public void sendAfterRegister(String phoneNo) {
try {
MsgParams msgParams =
new MsgParams(Collections.singletonList(2), phoneNo, "1", "24", Collections.emptyList());
new MsgParams(Collections.singletonList(2), phoneNo, "1", "1005", Collections.emptyList());
getSmsSender().sendMsg(msgParams);
//smsSender.sendAndForget(new SendAndForgetMsg(Collections.emptyList(), "24", "1", phoneNo));
log.info("注册完成,发送短信, phoneNo:{}", phoneNo);
......
......@@ -6,7 +6,9 @@ import cn.quantgroup.xyqb.model.UserRet;
import cn.quantgroup.xyqb.model.UserStatistics;
import cn.quantgroup.xyqb.service.mq.IRegisterMqService;
import cn.quantgroup.xyqb.service.mq.IVestService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
/**
* Created by xuran on 2017/6/23.
......@@ -26,6 +28,7 @@ public class MqUtils {
vest, e);
}
}
/**
* 用户注册消息进行广播
* @param message
......@@ -50,4 +53,25 @@ public class MqUtils {
MqUtils.sendRegisterMessage(registerMqMessage);
return userRet;
}
/**
* 腾讯广点通转化的用户注册消息推送
* @param phoneNo - 转化成功的用户手机号
* @param clickId - 转化成功的点击动作唯一标识
*/
public static void sendRegisterMessageForGdt(String phoneNo, String clickId){
if(ValidationUtil.validatePhoneNo(phoneNo) && StringUtils.isNotBlank(clickId)){
//填充广点通消息
JSONObject message = new JSONObject();
message.put("phoneNo", phoneNo);
message.put("clickId", clickId);
try {
IRegisterMqService rService = ApplicationContextHolder.getBean("registerMqService");
rService.send4Gdt(message);
} catch (Exception e) {
log.error("[MQUtils][MQUtils_exception]发送广点通用户注册信息,message={},error={}",
message, e);
}
}
}
}
......@@ -6,23 +6,39 @@ import java.util.Base64;
public class TestStringCode {
public static void main(String[] args) {
System.out.println(base64("13511112222", "000000"));
System.out.println(base64("18022223333", "000000"));
System.out.println(ap_base64("13511112222", "000000"));
System.out.println(pc_base64("15566660006", "0000"));
}
final static String AUTHORIZATION = "authorization";
final static String PREFIX = "Basic ";
final static String PREFIX_AP = "Basic ";
final static String PREFIX_PC = "Verification ";
/*
* 4.153
* 13576450525 123456 318e235d3e52648b236faa3f748000d5
* 13724823305 123456 318e235d3e52648b236faa3f748000d5
* Basic MTM1MTExMTIyMjI6MDAwMDAw
* Basic MTgwMjIyMjMzMzM6MDAwMDAw
*
* 4.155
* 13511112222 000000 c8937b92506c0e2918de053dea69edd3
* 18022223333 000000 c8937b92506c0e2918de053dea69edd3
*/
final static String base64(String account, String password) {
String authorization = PREFIX + new String(Base64.getEncoder().encodeToString((account+":"+password).getBytes(Charset.forName("UTF-8"))));
final static String ap_base64(String account, String password) {
String authorization = PREFIX_AP + new String(Base64.getEncoder().encodeToString((account+":"+password).getBytes(Charset.forName("UTF-8"))));
return authorization;
}
/*
* 4.153
* 13576450525 123456 318e235d3e52648b236faa3f748000d5
* 13724823305 123456 318e235d3e52648b236faa3f748000d5
*
* 4.155
* 13511112222 000000 c8937b92506c0e2918de053dea69edd3
* 18022223333 000000 c8937b92506c0e2918de053dea69edd3
*/
final static String pc_base64(String phone, String code) {
String authorization = PREFIX_PC + new String(Base64.getEncoder().encodeToString((phone+":"+code).getBytes(Charset.forName("UTF-8"))));
return authorization;
}
......
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