Commit 60a642bb authored by 技术部-任文超's avatar 技术部-任文超

魔法值---完成

parent be80edab
...@@ -40,6 +40,9 @@ public interface Constants { ...@@ -40,6 +40,9 @@ public interface Constants {
int DAY_NO_MIN = 30; int DAY_NO_MIN = 30;
int MONTH_NO_MAX = 200; int MONTH_NO_MAX = 200;
int MONTH_NO_MIN = 30; int MONTH_NO_MIN = 30;
int AGE_MAX = 150;
int USER_QUERY_INFO_BATCH_SIZE = 3000;
int USER_ID_BATCH_SIZE = 500;
/** 垃圾,前辈竟然用这个办法来识别UUID */ /** 垃圾,前辈竟然用这个办法来识别UUID */
int UUID_MIN_LENGTH = 10; int UUID_MIN_LENGTH = 10;
String AUTO_SORT_TYPE = "auto"; String AUTO_SORT_TYPE = "auto";
...@@ -59,16 +62,23 @@ public interface Constants { ...@@ -59,16 +62,23 @@ public interface Constants {
String ERROR_MSG = "errorMsg"; String ERROR_MSG = "errorMsg";
String BANK_CARD = "bankCard"; String BANK_CARD = "bankCard";
String ADDRESS = "address"; String ADDRESS = "address";
/**
* 微信标识参数名
*/
String WECHAT_OPEN_ID = "wechat_open_id";
String PASSWORD = "password"; String PASSWORD = "password";
String RESULT_CODE = "code"; String RESULT_CODE = "code";
String RESULT_DATA = "data"; String RESULT_DATA = "data";
String SUCCESS_CODE = "0000"; String SUCCESS_CODE = "0000";
String PROTOCOL_HEAD_HTTPS = "https:"; String PROTOCOL_HEAD_HTTPS = "https:";
String PROTOCOL_HEAD_HTTP = "http"; String PROTOCOL_HEAD_HTTP = "http";
String REDIRECT = "redirect";
String LOCAL = "local";
String DOCKER_DOMAIN = "liangkebang";
/**
* 微信标识参数名
*/
String WECHAT_OPEN_ID = "wechat_open_id";
String MERCHANT_BAITIAO = "baitiao";
String MERCHANT_WECHAT_PAY = "wechat-pay";
// -- Start -- IPV4安全策略常量组 // -- Start -- IPV4安全策略常量组
/** /**
...@@ -156,8 +166,10 @@ public interface Constants { ...@@ -156,8 +166,10 @@ public interface Constants {
interface Channel { interface Channel {
long BAITIAO = 222L; long BAITIAO = 222L;
String LKB_CODE = "0002"; // 量化派channnel_code // 量化派channnel_code
String LKB_CODE = "0002";
long WECHAT = 198L; long WECHAT = 198L;
long HENGCHANG = 58L;
} }
interface Session { interface Session {
......
package cn.quantgroup.xyqb.controller; package cn.quantgroup.xyqb.controller;
import cn.quantgroup.xyqb.exception.PasswordErrorLimitException; import cn.quantgroup.xyqb.exception.*;
import cn.quantgroup.xyqb.exception.UserNotExistException;
import cn.quantgroup.xyqb.exception.VerificationCodeErrorException;
import cn.quantgroup.xyqb.exception.WechatRelateUserException;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.util.IpUtil; import cn.quantgroup.xyqb.util.IpUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -69,6 +66,18 @@ public class ExceptionHandlingController implements IBaseController { ...@@ -69,6 +66,18 @@ public class ExceptionHandlingController implements IBaseController {
return new JsonResult(unee.getMessage(), 401L, null); return new JsonResult(unee.getMessage(), 401L, null);
} }
/**
* 用户查询或导出异常
*
* @param uqle
* @return
*/
@ExceptionHandler(UserQueryLogException.class)
public JsonResult userQueryLogException(UserQueryLogException uqle) {
LOGGER.info("throw UserQueryLogException,msg={},businessCode={},code={}", uqle.getMessage(), 1L, 0L);
return JsonResult.buildErrorStateResult(uqle.getMessage(), null);
}
/** /**
* 微信关联异常 * 微信关联异常
* *
......
...@@ -191,7 +191,7 @@ public class WeChatController implements IBaseController { ...@@ -191,7 +191,7 @@ public class WeChatController implements IBaseController {
schema = extDataObj.getOrDefault("protocol", Constants.PROTOCOL_HEAD_HTTP).toString(); schema = extDataObj.getOrDefault("protocol", Constants.PROTOCOL_HEAD_HTTP).toString();
log.info("从微信登录extData中获得协议信息,protocol:{}", schema); log.info("从微信登录extData中获得协议信息,protocol:{}", schema);
registerFrom = Long.valueOf(extDataObj.getOrDefault("registerFrom", "1").toString()); registerFrom = Long.valueOf(extDataObj.getOrDefault("registerFrom", "1").toString());
redirect = (String) extDataObj.getOrDefault("redirect", "redirect"); redirect = (String) extDataObj.getOrDefault(Constants.REDIRECT, Constants.REDIRECT);
log.info("从微信登录,registerFrom:{}, redirect:{}", registerFrom, redirect); log.info("从微信登录,registerFrom:{}, redirect:{}", registerFrom, redirect);
receiveCodeWithDefault(code, systemKey, schema, registerFrom, redirect, response); receiveCodeWithDefault(code, systemKey, schema, registerFrom, redirect, response);
} }
...@@ -274,7 +274,7 @@ public class WeChatController implements IBaseController { ...@@ -274,7 +274,7 @@ public class WeChatController implements IBaseController {
public void redirectForTest(String redirect, HttpServletRequest request, HttpServletResponse response) throws MalformedURLException { public void redirectForTest(String redirect, HttpServletRequest request, HttpServletResponse response) throws MalformedURLException {
URL url = new URL(redirect); URL url = new URL(redirect);
String host = url.getHost(); String host = url.getHost();
if (!host.endsWith("liangkebang.com") && !host.endsWith("liangkebang.net")) { if (!host.contains(Constants.DOCKER_DOMAIN)) {
log.error("redirect 非法请求, host:{}", host); log.error("redirect 非法请求, host:{}", host);
return; return;
} }
...@@ -320,22 +320,22 @@ public class WeChatController implements IBaseController { ...@@ -320,22 +320,22 @@ public class WeChatController implements IBaseController {
private String createUserSession(User user, Merchant merchant, String redirect, String domain, Long registerFrom) { private String createUserSession(User user, Merchant merchant, String redirect, String domain, Long registerFrom) {
log.info("[WeChatController][createUserSession]微信授权及跳转:user:{},merchant:{},redirect:{},domain:{},registerFrom:{}", user, merchant, redirect, domain, registerFrom); log.info("[WeChatController][createUserSession]微信授权及跳转:user:{},merchant:{},redirect:{},domain:{},registerFrom:{}", user, merchant, redirect, domain, registerFrom);
LoginProperties loginProperties = new LoginProperties("", 4, Constants.Channel.WECHAT, registerFrom, String.valueOf(Constants.Channel.WECHAT), merchant.getId(), merchant.getName()); LoginProperties loginProperties = new LoginProperties("", 4, Constants.Channel.WECHAT, registerFrom, String.valueOf(Constants.Channel.WECHAT), merchant.getId(), merchant.getName());
if (StringUtils.isEmpty(redirect) || "redirect".equals(redirect)) { if (StringUtils.isEmpty(redirect) || Constants.REDIRECT.equals(redirect)) {
log.info("微信登录:redirect为null,走正常流程."); log.info("微信登录:redirect为null,走正常流程.");
if ("baitiao".equals(merchant.getName())) { if (Constants.MERCHANT_BAITIAO.equals(merchant.getName())) {
return loginInWechatWithSessionCreated(user, merchant, "cashTarget5", Constants.Channel.BAITIAO, domain, Constants.Channel.WECHAT); return loginInWechatWithSessionCreated(user, merchant, "cashTarget5", Constants.Channel.BAITIAO, domain, Constants.Channel.WECHAT);
} else if ("wechat-pay".equals(merchant.getName())) { } else if (Constants.MERCHANT_WECHAT_PAY.equals(merchant.getName())) {
AuthBean authBean = sessionService.createSession(user, loginProperties); AuthBean authBean = sessionService.createSession(user, loginProperties);
return domain + "/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 { } else {
return loginInWechatWithSessionCreated(user, merchant, "cashTarget4", 1L, domain, registerFrom); return loginInWechatWithSessionCreated(user, merchant, "cashTarget4", 1L, domain, registerFrom);
} }
} else if ("local".equals(redirect)) { } else if (Constants.LOCAL.equals(redirect)) {
log.info("微信登录:redirect不为null,创建session跳到指定前端页面."); log.info("微信登录:redirect不为null,创建session跳到指定前端页面.");
AuthBean authBean = sessionService.createSession(user, loginProperties); AuthBean authBean = sessionService.createSession(user, loginProperties);
log.info("微信登录:跳转地址{}", domain + "/weixin/callback?phoneNo=" + user.getPhoneNo() + "&token=" + authBean.getToken()); log.info("微信登录:跳转地址{}", domain + "/weixin/callback?phoneNo=" + user.getPhoneNo() + "&token=" + authBean.getToken());
Long channelId = "baitiao".equals(merchant.getName()) ? Constants.Channel.BAITIAO : 1L; Long channelId = Constants.MERCHANT_BAITIAO.equals(merchant.getName()) ? Constants.Channel.BAITIAO : 1L;
String target = "baitiao".equals(merchant.getName()) ? "cashTarget5" : "cashTarget4"; String target = Constants.MERCHANT_BAITIAO.equals(merchant.getName()) ? "cashTarget5" : "cashTarget4";
return domain + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom + return domain + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom +
"&channelId=" + channelId + "&key=" + merchant.getName() + "&target=" + target + "&isWechat=true"; "&channelId=" + channelId + "&key=" + merchant.getName() + "&target=" + target + "&isWechat=true";
} }
...@@ -364,13 +364,13 @@ public class WeChatController implements IBaseController { ...@@ -364,13 +364,13 @@ public class WeChatController implements IBaseController {
} }
private String assembleNormalRedirectUrl(Merchant merchant, Long registerFrom, String domain) { private String assembleNormalRedirectUrl(Merchant merchant, Long registerFrom, String domain) {
if ("baitiao".equals(merchant.getName())) { if (Constants.MERCHANT_BAITIAO.equals(merchant.getName())) {
if (registerFrom == 58L || registerFrom == 198L) { if (registerFrom == Constants.Channel.HENGCHANG || registerFrom == Constants.Channel.WECHAT) {
return domain + "/landing?key=baitiao&target=cashTarget5&channelId=222&registerFrom=" + registerFrom; return domain + "/landing?key=baitiao&target=cashTarget5&channelId=222&registerFrom=" + registerFrom;
} else { } else {
return domain + "/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())) { } else if (Constants.MERCHANT_WECHAT_PAY.equals(merchant.getName())) {
return domain + "/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 { } else {
return domain + "/landing?key=xyqb&target=cashTarget4&channelId=1&registerFrom=" + registerFrom; return domain + "/landing?key=xyqb&target=cashTarget4&channelId=1&registerFrom=" + registerFrom;
...@@ -378,13 +378,13 @@ public class WeChatController implements IBaseController { ...@@ -378,13 +378,13 @@ public class WeChatController implements IBaseController {
} }
private String assembleWechatRedirectUrl(Merchant merchant, WechatUserInfo userInfo, Long registerFrom, String domain) { private String assembleWechatRedirectUrl(Merchant merchant, WechatUserInfo userInfo, Long registerFrom, String domain) {
if ("baitiao".equals(merchant.getName())) { if (Constants.MERCHANT_BAITIAO.equals(merchant.getName())) {
if (registerFrom == 58L || registerFrom == 198L) { if (registerFrom == Constants.Channel.HENGCHANG || registerFrom == Constants.Channel.WECHAT) {
return domain + "/landing?key=baitiao&target=cashTarget5&registerFrom=" + registerFrom + "&channelId=222&isWechat=true&openId=" + userInfo.getOpenId(); return domain + "/landing?key=baitiao&target=cashTarget5&registerFrom=" + registerFrom + "&channelId=222&isWechat=true&openId=" + userInfo.getOpenId();
} else { } else {
return domain + "/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())) { } else if (Constants.MERCHANT_WECHAT_PAY.equals(merchant.getName())) {
return domain + "/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 { } else {
return domain + "/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();
......
...@@ -8,12 +8,15 @@ import java.util.*; ...@@ -8,12 +8,15 @@ import java.util.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import cn.quantgroup.xyqb.exception.UserQueryLogException;
import cn.quantgroup.xyqb.util.encrypt.Rsa; import cn.quantgroup.xyqb.util.encrypt.Rsa;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
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.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -21,8 +24,6 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -21,8 +24,6 @@ import org.springframework.web.bind.annotation.RestController;
import com.google.gson.*; import com.google.gson.*;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.entity.Address; import cn.quantgroup.xyqb.entity.Address;
...@@ -42,12 +43,11 @@ import cn.quantgroup.xyqb.util.encrypt.Md5Util; ...@@ -42,12 +43,11 @@ import cn.quantgroup.xyqb.util.encrypt.Md5Util;
/** /**
* Created by zenglibin on 17/06/13. * Created by zenglibin on 17/06/13.
*/ */
@Slf4j
@RestController @RestController
@RequestMapping("/query") @RequestMapping("/query")
public class UserQueryLogController { public class UserQueryLogController {
private static final Logger LOGGER = LoggerFactory.getLogger(UserQueryLogController.class);
@Autowired @Autowired
private IUserQueryLogService userQueryLogService; private IUserQueryLogService userQueryLogService;
@Autowired @Autowired
...@@ -73,14 +73,14 @@ public class UserQueryLogController { ...@@ -73,14 +73,14 @@ public class UserQueryLogController {
@RequestMapping("/queryLog") @RequestMapping("/queryLog")
@ApiOperation(value = "给运营系统提供的查询查询记录的", notes = "给运营系统提供的查询查询记录的", httpMethod = "POST") @ApiOperation(value = "给运营系统提供的查询查询记录的", notes = "给运营系统提供的查询查询记录的", httpMethod = "POST")
public JsonResult queryLog(HttpServletRequest request, @RequestParam(required = false) String beginDate, @RequestParam(required = false) String endDate, Integer pageId, Integer pageSize) { public JsonResult queryLog(HttpServletRequest request, @RequestParam(required = false) String beginDate, @RequestParam(required = false) String endDate, Integer pageId, Integer pageSize) {
LOGGER.info("查询日期:beginDate{},endDate{}", beginDate, endDate); log.info("查询日期:beginDate{},endDate{}", beginDate, endDate);
String token = request.getHeader(Constants.X_AUTH_TOKEN); String token = request.getHeader(Constants.X_AUTH_TOKEN);
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {
LOGGER.info("token为空,非法查询"); log.info("token为空,非法查询");
return JsonResult.buildErrorStateResult("缺少授权信息", null); return JsonResult.buildErrorStateResult("缺少授权信息", null);
} }
if (StringUtils.isEmpty(checkUserToken(token))) { if (StringUtils.isEmpty(checkUserToken(token))) {
LOGGER.info("token授权异常"); log.info("token授权异常");
return JsonResult.buildErrorStateResult("未授权查询", null); return JsonResult.buildErrorStateResult("未授权查询", null);
} }
try { try {
...@@ -115,7 +115,7 @@ public class UserQueryLogController { ...@@ -115,7 +115,7 @@ public class UserQueryLogController {
ll.setCreateDate(sdf.format(ll.getCreatedAt())); ll.setCreateDate(sdf.format(ll.getCreatedAt()));
} }
} catch (Exception e) { } catch (Exception e) {
LOGGER.info("日期时间转换异常"); log.info("日期时间转换异常");
return JsonResult.buildErrorStateResult("日期时间转换异常", null); return JsonResult.buildErrorStateResult("日期时间转换异常", null);
} }
uqp.setPageSize(pageSize); uqp.setPageSize(pageSize);
...@@ -133,36 +133,26 @@ public class UserQueryLogController { ...@@ -133,36 +133,26 @@ public class UserQueryLogController {
@RequestMapping("/queryUserInfo") @RequestMapping("/queryUserInfo")
@ApiOperation(value = "给运营系统提供的查询用户信息的接口", notes = "给运营系统提供的查询用户信息的接口", httpMethod = "POST") @ApiOperation(value = "给运营系统提供的查询用户信息的接口", notes = "给运营系统提供的查询用户信息的接口", httpMethod = "POST")
public JsonResult queryForResult(HttpServletRequest request, String key, String keyValues, String columns, Integer pageId, Integer pageSize) { public JsonResult queryForResult(HttpServletRequest request, String key, String keyValues, String columns, Integer pageId, Integer pageSize) {
LOGGER.info("查询条件:key{},columns{}", key, columns);
String token = request.getHeader(Constants.X_AUTH_TOKEN); String token = request.getHeader(Constants.X_AUTH_TOKEN);
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {
LOGGER.info("token为空,非法查询"); log.info("token为空,非法查询");
return JsonResult.buildErrorStateResult("缺少授权信息", null); return JsonResult.buildErrorStateResult("缺少授权信息", null);
} }
//columns=> userId,phoneNo,idNo,bankCard,address
//key=>phoneNo、idNo、userId
//checkKeysType;
//后台参数校验
//校验用户权限
String userName = checkUserToken(token); String userName = checkUserToken(token);
if (StringUtils.isEmpty(userName)) { if (StringUtils.isEmpty(userName)) {
LOGGER.info("token授权异常");
return JsonResult.buildErrorStateResult("未授权查询", null); return JsonResult.buildErrorStateResult("未授权查询", null);
} }
//输入enter换行\n if (StringUtils.isEmpty(keyValues)) {
if (org.apache.commons.lang3.StringUtils.isEmpty(keyValues)) {
return JsonResult.buildErrorStateResult("请输入查询条件", null); return JsonResult.buildErrorStateResult("请输入查询条件", null);
} }
String[] values = keyValues.split("\\n"); String[] values = keyValues.split(";");
List<String> queryV = Arrays.asList(values); List<String> queryV = Arrays.asList(values);
if (queryV != null && queryV.size() > 3000) { log.info("[UserQueryLogController][exportExcel]运营系统导出用户信息开始 size:{}, key:{}, keyValues:{}, columns:{}", queryV.size(), key, keyValues, columns);
return JsonResult.buildErrorStateResult("查询记录数是" + queryV.size() + ",超过3000条限制", null); if (queryV != null && queryV.size() > Constants.USER_QUERY_INFO_BATCH_SIZE) {
return JsonResult.buildErrorStateResult("查询记录数是" + queryV.size() + ",超过"+Constants.USER_QUERY_INFO_BATCH_SIZE +"条限制", null);
} }
List<UserQueryInfo> userQueryInfos = new ArrayList<>();
List<UserDetail> userDetails = new ArrayList<>(); List<UserDetail> userDetails = new ArrayList<>();
Page<UserDetail> userDetailPage = null; Page<UserDetail> userDetailPage = null;
List<Address> addresslist = new ArrayList<>();
HashMap<String, String> phonesCards = new HashMap<>();
if (pageSize == 0 || pageSize < 0) { if (pageSize == 0 || pageSize < 0) {
pageSize = Constants.PAGE_SIZE_MIN; pageSize = Constants.PAGE_SIZE_MIN;
} else if (pageSize > Constants.PAGE_SIZE_MAX) { } else if (pageSize > Constants.PAGE_SIZE_MAX) {
...@@ -204,57 +194,7 @@ public class UserQueryLogController { ...@@ -204,57 +194,7 @@ public class UserQueryLogController {
if (userDetailPage != null) { if (userDetailPage != null) {
userDetails = userDetailPage.getContent(); userDetails = userDetailPage.getContent();
} }
if (columns.contains(Constants.BANK_CARD)) { List<UserQueryInfo> userQueryInfos = toUserQueryInfo(key, columns, queryV, userDetails);
//需加银行卡信息
if (Objects.equals(key, Constants.PHONE_NO)) {
phonesCards = getBankCardsByPhoneNos(queryV);
if (phonesCards != null && phonesCards.get(Constants.ERROR_MSG) != null && !StringUtils.isEmpty(phonesCards.get(Constants.ERROR_MSG))) {
return JsonResult.buildErrorStateResult(phonesCards.get(Constants.ERROR_MSG), null);
}
} else {
List<String> phones = new ArrayList<>();
for (UserDetail uda : userDetails) {
phones.add(uda.getPhoneNo());
}
phonesCards = getBankCardsByPhoneNos(phones);
if (phonesCards != null && phonesCards.get(Constants.ERROR_MSG) != null && !StringUtils.isEmpty(phonesCards.get(Constants.ERROR_MSG))) {
return JsonResult.buildErrorStateResult(phonesCards.get(Constants.ERROR_MSG), null);
}
}
}
if (columns.contains(Constants.ADDRESS)) {
List<Long> uidss = new ArrayList<>();
//加地址信息
for (UserDetail ud : userDetails) {
uidss.add(ud.getUserId());
}
if (uidss != null && uidss.size() > 0) {
addresslist = addressService.findByUserIds(uidss);
}
}
for (UserDetail ud : userDetails) {
UserQueryInfo uqi = new UserQueryInfo();
if (columns.contains(Constants.ID_NO)) {
uqi.setIdNo(ud.getIdNo());
}
if (columns.contains(Constants.PHONE_NO)) {
uqi.setPhoneNo(ud.getPhoneNo());
}
if (columns.contains(Constants.USER_NAME)) {
uqi.setName(ud.getName());
}
if (columns.contains(Constants.USER_ID)) {
uqi.setUserId(ud.getUserId());
}
if (columns.contains(Constants.ADDRESS)) {
Optional<Address> oad = addresslist.stream().filter(addr -> Objects.equals(addr.getUserId(), ud.getUserId())).findFirst();
oad.ifPresent(address -> uqi.setAddress(address.toString()));
}
if (columns.contains(Constants.BANK_CARD) && phonesCards != null) {
uqi.setBankCards(phonesCards.get(ud.getPhoneNo()));
}
userQueryInfos.add(uqi);
}
//保存记录 //保存记录
UserQueryLog log = new UserQueryLog(); UserQueryLog log = new UserQueryLog();
log.setQueryItems(columns.replace(Constants.USER_ID, "用户ID").replace(Constants.PHONE_NO, "手机号").replace(Constants.USER_NAME, "姓名").replace(Constants.ID_NO, "身份证号").replace(Constants.BANK_CARD, "银行卡号").replace(Constants.ADDRESS, "地址")); log.setQueryItems(columns.replace(Constants.USER_ID, "用户ID").replace(Constants.PHONE_NO, "手机号").replace(Constants.USER_NAME, "姓名").replace(Constants.ID_NO, "身份证号").replace(Constants.BANK_CARD, "银行卡号").replace(Constants.ADDRESS, "地址"));
...@@ -286,12 +226,9 @@ public class UserQueryLogController { ...@@ -286,12 +226,9 @@ public class UserQueryLogController {
data = Rsa.encrypt(phoneNoStr, PUBLIC_KEY); data = Rsa.encrypt(phoneNoStr, PUBLIC_KEY);
sign = Md5Util.build(data); sign = Md5Util.build(data);
} catch (Exception e) { } catch (Exception e) {
LOGGER.info("参数加密异常"); log.info("参数加密异常", e);
phonesMap.put(Constants.ERROR_MSG, "参数加密异常"); throw new UserQueryLogException("参数加密异常", e);
return null;
} }
HashMap<String, String> parameters = new HashMap<>(); HashMap<String, String> parameters = new HashMap<>();
parameters.put(Constants.RESULT_DATA, data); parameters.put(Constants.RESULT_DATA, data);
parameters.put("sign", sign); parameters.put("sign", sign);
...@@ -322,13 +259,13 @@ public class UserQueryLogController { ...@@ -322,13 +259,13 @@ public class UserQueryLogController {
} }
} else { } else {
phonesMap.put(Constants.ERROR_MSG, "签名校验失败!"); log.info("签名校验失败!");
LOGGER.info("签名校验失败!"); throw new UserQueryLogException("签名校验失败");
} }
} }
} catch (Exception e) { } catch (Exception e) {
phonesMap.put(Constants.ERROR_MSG, "查询银行卡信息接口返回解析异常"); log.error("查询银行卡信息接口返回解析异常", e);
LOGGER.info("查询银行卡信息接口返回解析异常"); throw new UserQueryLogException("查询银行卡信息接口返回解析异常", e);
} }
return phonesMap; return phonesMap;
} }
...@@ -338,36 +275,27 @@ public class UserQueryLogController { ...@@ -338,36 +275,27 @@ public class UserQueryLogController {
public JsonResult exportExcel(final HttpServletResponse response, HttpServletRequest request, String key, String keyValues, String columns) { public JsonResult exportExcel(final HttpServletResponse response, HttpServletRequest request, String key, String keyValues, String columns) {
String token = request.getHeader(Constants.X_AUTH_TOKEN); String token = request.getHeader(Constants.X_AUTH_TOKEN);
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {
LOGGER.info("token为空,非法查询"); log.info("token为空,非法查询");
return JsonResult.buildErrorStateResult("缺少授权信息", null); return JsonResult.buildErrorStateResult("缺少授权信息", null);
} }
String userName = checkUserToken(token); String userName = checkUserToken(token);
if (StringUtils.isEmpty(userName)) { if (StringUtils.isEmpty(userName)) {
return JsonResult.buildErrorStateResult("未授权查询", null); return JsonResult.buildErrorStateResult("未授权查询", null);
} }
//输入enter换行\n if (StringUtils.isEmpty(keyValues)) {
if (org.apache.commons.lang3.StringUtils.isEmpty(keyValues)) {
return JsonResult.buildErrorStateResult("请输入查询条件", null); return JsonResult.buildErrorStateResult("请输入查询条件", null);
} }
List<UserQueryInfo> uqls = new ArrayList<>();
String[] values = keyValues.split(";"); String[] values = keyValues.split(";");
List<String> queryV = Arrays.asList(values); List<String> queryV = Arrays.asList(values);
LOGGER.info("[UserQueryLogController][exportExcel]运营系统导出用户信息开始 size:{}, key:{}, keyValues:{}, columns:{}", queryV.size(), key, keyValues, columns); log.info("[UserQueryLogController][exportExcel]运营系统导出用户信息开始 size:{}, key:{}, keyValues:{}, columns:{}", queryV.size(), key, keyValues, columns);
if (queryV != null && queryV.size() > 3000) { if (queryV != null && queryV.size() > Constants.USER_QUERY_INFO_BATCH_SIZE) {
return JsonResult.buildErrorStateResult("查询记录数是" + queryV.size() + ",超过3000条限制", null); return JsonResult.buildErrorStateResult("查询记录数是" + queryV.size() + ",超过"+Constants.USER_QUERY_INFO_BATCH_SIZE +"条限制", null);
} }
//如果维度里面没有保护查询条件则加入条件 //如果维度里面没有保护查询条件则加入条件
if (!columns.contains(key)) { if (!columns.contains(key)) {
columns = columns + "," + key; columns = columns + "," + key;
} }
List<UserQueryInfo> userQueryInfos = new ArrayList<>();
List<UserDetail> userDetails = new ArrayList<>(); List<UserDetail> userDetails = new ArrayList<>();
List<Address> addresslist = new ArrayList<>();
HashMap<String, String> phonesCards = new HashMap<>();
if (Objects.equals(key, Constants.USER_ID)) { if (Objects.equals(key, Constants.USER_ID)) {
List<Long> userIds = new ArrayList<>(); List<Long> userIds = new ArrayList<>();
try { try {
...@@ -378,11 +306,9 @@ public class UserQueryLogController { ...@@ -378,11 +306,9 @@ public class UserQueryLogController {
long uid = Long.valueOf(s); long uid = Long.valueOf(s);
userIds.add(uid); userIds.add(uid);
} }
} catch (Exception e) { } catch (Exception e) {
return JsonResult.buildErrorStateResult("查询的userId有误", null); return JsonResult.buildErrorStateResult("查询的userId有误", null);
} }
userDetails = userDetailService.findByUserIdIn(userIds); userDetails = userDetailService.findByUserIdIn(userIds);
} else if (Objects.equals(key, Constants.PHONE_NO)) { } else if (Objects.equals(key, Constants.PHONE_NO)) {
for (String pn : queryV) { for (String pn : queryV) {
...@@ -390,7 +316,6 @@ public class UserQueryLogController { ...@@ -390,7 +316,6 @@ public class UserQueryLogController {
return JsonResult.buildErrorStateResult("查询的手机号码" + pn + "格式有误", pn); return JsonResult.buildErrorStateResult("查询的手机号码" + pn + "格式有误", pn);
} }
} }
userDetails = userDetailService.findByPhoneNos(queryV); userDetails = userDetailService.findByPhoneNos(queryV);
} else if (Objects.equals(key, Constants.ID_NO)) { } else if (Objects.equals(key, Constants.ID_NO)) {
for (String idno : queryV) { for (String idno : queryV) {
...@@ -400,10 +325,40 @@ public class UserQueryLogController { ...@@ -400,10 +325,40 @@ public class UserQueryLogController {
} }
userDetails = userDetailService.findByIdnos(queryV); userDetails = userDetailService.findByIdnos(queryV);
} }
List<UserQueryInfo> userQueryInfos = toUserQueryInfo(key, columns, queryV, userDetails);
/*
* 将文件存到指定位置
* 采用时间戳命名方式,避免同主机出现并发同名文件冲突引起的文件流被动关闭现象
*/
try(OutputStream output = response.getOutputStream()){
String filename = "users-".concat(LocalDateTime.now().toString()).concat(".xlsx");
response.reset();
response.setHeader("Content-disposition", "attachment; filename=".concat(filename));
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setCharacterEncoding("utf-8");
HSSFWorkbook wb = getHssfWorkbook(userQueryInfos);
wb.write(output);
log.info("[UserQueryLogController][exportExcel]运营系统导出用户信息完成 filename:{}, size:{}, key:{}, keyValues:{}, columns:{}", filename, queryV.size(), key, keyValues, columns);
} catch (Exception e) {
log.error("解析运营系统用户token返回结果resultStr异常", e);
}
return JsonResult.buildSuccessResult("导出成功", null);
}
/**
* 数据类型转换
*
* @param key
* @param columns
* @param queryV
* @param userDetails
* @return
*/
private List<UserQueryInfo> toUserQueryInfo(String key, String columns, List<String> queryV, List<UserDetail> userDetails) {
HashMap<String, String> phonesCards = new HashMap<>();
if (columns.contains(Constants.BANK_CARD)) { if (columns.contains(Constants.BANK_CARD)) {
//需加银行卡信息 //需加银行卡信息
if (key.equals(Constants.PHONE_NO)) { if (Objects.equals(key, Constants.PHONE_NO)) {
phonesCards = getBankCardsByPhoneNos(queryV); phonesCards = getBankCardsByPhoneNos(queryV);
} else { } else {
List<String> phones = new ArrayList<>(); List<String> phones = new ArrayList<>();
...@@ -413,7 +368,7 @@ public class UserQueryLogController { ...@@ -413,7 +368,7 @@ public class UserQueryLogController {
phonesCards = getBankCardsByPhoneNos(phones); phonesCards = getBankCardsByPhoneNos(phones);
} }
} }
List<Address> addresslist = new ArrayList<>();
if (columns.contains(Constants.ADDRESS)) { if (columns.contains(Constants.ADDRESS)) {
List<Long> uidss = new ArrayList<>(); List<Long> uidss = new ArrayList<>();
//加地址信息 //加地址信息
...@@ -423,9 +378,8 @@ public class UserQueryLogController { ...@@ -423,9 +378,8 @@ public class UserQueryLogController {
if (uidss != null && uidss.size() > 0) { if (uidss != null && uidss.size() > 0) {
addresslist = addressService.findByUserIds(uidss); addresslist = addressService.findByUserIds(uidss);
} }
} }
List<UserQueryInfo> userQueryInfos = new ArrayList<>();
for (UserDetail ud : userDetails) { for (UserDetail ud : userDetails) {
UserQueryInfo uqi = new UserQueryInfo(); UserQueryInfo uqi = new UserQueryInfo();
if (columns.contains(Constants.ID_NO)) { if (columns.contains(Constants.ID_NO)) {
...@@ -447,11 +401,21 @@ public class UserQueryLogController { ...@@ -447,11 +401,21 @@ public class UserQueryLogController {
if (columns.contains(Constants.BANK_CARD) && phonesCards != null) { if (columns.contains(Constants.BANK_CARD) && phonesCards != null) {
uqi.setBankCards(phonesCards.get(ud.getPhoneNo())); uqi.setBankCards(phonesCards.get(ud.getPhoneNo()));
} }
uqls.add(uqi); userQueryInfos.add(uqi);
}
return userQueryInfos;
} }
/**
* 生成Excel
* @param uqls
* @return
*/
private HSSFWorkbook getHssfWorkbook(List<UserQueryInfo> uqls) {
HSSFWorkbook wb = new HSSFWorkbook(); HSSFWorkbook wb = new HSSFWorkbook();
if(CollectionUtils.isEmpty(uqls)){
return wb;
}
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("用户信息列表"); HSSFSheet sheet = wb.createSheet("用户信息列表");
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
...@@ -481,7 +445,6 @@ public class UserQueryLogController { ...@@ -481,7 +445,6 @@ public class UserQueryLogController {
cell.setCellStyle(style); cell.setCellStyle(style);
// 第五步,写入实体数据 实际应用中这些数据从数据库得到, // 第五步,写入实体数据 实际应用中这些数据从数据库得到,
for (int i = 0; i < uqls.size(); i++) { for (int i = 0; i < uqls.size(); i++) {
row = sheet.createRow(i + 1); row = sheet.createRow(i + 1);
UserQueryInfo user = uqls.get(i); UserQueryInfo user = uqls.get(i);
...@@ -491,50 +454,29 @@ public class UserQueryLogController { ...@@ -491,50 +454,29 @@ public class UserQueryLogController {
if (cell0 != null) { if (cell0 != null) {
cell0.setCellValue(user.getUserId() == null ? " " : String.valueOf(user.getUserId())); cell0.setCellValue(user.getUserId() == null ? " " : String.valueOf(user.getUserId()));
} }
HSSFCell cell1 = row.createCell(1); HSSFCell cell1 = row.createCell(1);
if (cell1 != null) { if (cell1 != null) {
cell1.setCellValue(user.getPhoneNo() == null ? " " : user.getPhoneNo()); cell1.setCellValue(user.getPhoneNo() == null ? " " : user.getPhoneNo());
} }
HSSFCell cell2 = row.createCell(2); HSSFCell cell2 = row.createCell(2);
if (cell2 != null) { if (cell2 != null) {
cell2.setCellValue(user.getName() == null ? " " : user.getName()); cell2.setCellValue(user.getName() == null ? " " : user.getName());
} }
HSSFCell cell3 = row.createCell(3); HSSFCell cell3 = row.createCell(3);
if (cell3 != null) { if (cell3 != null) {
cell3.setCellValue(user.getIdNo() == null ? " " : user.getIdNo()); cell3.setCellValue(user.getIdNo() == null ? " " : user.getIdNo());
} }
HSSFCell cell4 = row.createCell(4); HSSFCell cell4 = row.createCell(4);
if (cell4 != null) { if (cell4 != null) {
cell4.setCellValue(user.getBankCards() == null ? " " : user.getBankCards()); cell4.setCellValue(user.getBankCards() == null ? " " : user.getBankCards());
} }
HSSFCell cell5 = row.createCell(5); HSSFCell cell5 = row.createCell(5);
if (cell5 != null) { if (cell5 != null) {
cell5.setCellValue(user.getAddress() == null ? " " : user.getAddress()); cell5.setCellValue(user.getAddress() == null ? " " : user.getAddress());
} }
} }
} }
/* return wb;
* 第六步,将文件存到指定位置
* 采用时间戳命名方式,避免同主机出现并发同名文件冲突引起的文件流被动关闭现象
*/
try(OutputStream output = response.getOutputStream()){
String filename = "users-".concat(LocalDateTime.now().toString()).concat(".xlsx");
response.reset();
response.setHeader("Content-disposition", "attachment; filename=".concat(filename));
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setCharacterEncoding("utf-8");
wb.write(output);
LOGGER.info("[UserQueryLogController][exportExcel]运营系统导出用户信息完成 filename:{}, size:{}, key:{}, keyValues:{}, columns:{}", filename, queryV.size(), key, keyValues, columns);
} catch (Exception e) {
LOGGER.error("解析运营系统用户token返回结果resultStr异常", e);
}
return JsonResult.buildSuccessResult("导出成功", null);
} }
private String checkUserToken(String token) { private String checkUserToken(String token) {
...@@ -549,7 +491,7 @@ public class UserQueryLogController { ...@@ -549,7 +491,7 @@ public class UserQueryLogController {
return userName; return userName;
} }
} catch (Exception e) { } catch (Exception e) {
LOGGER.info("解析运营系统用户token返回结果resultStr异常"); log.info("解析运营系统用户token返回结果resultStr异常");
} }
return ""; return "";
} }
......
...@@ -37,12 +37,10 @@ import org.apache.commons.lang3.StringUtils; ...@@ -37,12 +37,10 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
...@@ -89,14 +87,9 @@ public class InnerController implements IBaseController { ...@@ -89,14 +87,9 @@ public class InnerController implements IBaseController {
private ISmsService smsService; private ISmsService smsService;
@Autowired @Autowired
private IUserRegisterService userRegisterService; private IUserRegisterService userRegisterService;
@Resource
private ApplicationEventPublisher applicationEventPublisher;
private static final char[] PWD_BASE = { private static final String RESET_PWD_TOKEN = "ecf75c1f-2ccb-4661-8e4b-2874c0f45a2b";
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', private static final String MODIFY_CONTACT_TOKEN = "@qwsdedad131323213w!";
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
};
/** /**
...@@ -209,7 +202,7 @@ public class InnerController implements IBaseController { ...@@ -209,7 +202,7 @@ public class InnerController implements IBaseController {
} }
List<Long> userIds = JSONObject.parseObject(userIdsString, new TypeReference<List<Long>>() { List<Long> userIds = JSONObject.parseObject(userIdsString, new TypeReference<List<Long>>() {
}); });
if (!CollectionUtils.isEmpty(userIds) && userIds.size() <= 500) { if (!CollectionUtils.isEmpty(userIds) && userIds.size() <= Constants.USER_ID_BATCH_SIZE) {
Map<Long, String> userIdAndPhoneMap = userService.findPhoneByIdsInDb(userIds); Map<Long, String> userIdAndPhoneMap = userService.findPhoneByIdsInDb(userIds);
return JsonResult.buildSuccessResult("", userIdAndPhoneMap); return JsonResult.buildSuccessResult("", userIdAndPhoneMap);
} else { } else {
...@@ -473,10 +466,9 @@ public class InnerController implements IBaseController { ...@@ -473,10 +466,9 @@ public class InnerController implements IBaseController {
@RequestParam(required = false) String phoneNo, @RequestParam(required = false) String phoneNo,
@RequestParam(required = false) Relation relation, String key, @RequestParam(required = false) Relation relation, String key,
@RequestParam String reason, HttpServletRequest request) { @RequestParam String reason, HttpServletRequest request) {
if (!"@qwsdedad131323213w!".equals(key) || contactId == null) { if (!MODIFY_CONTACT_TOKEN.equals(key) || contactId == null) {
return JsonResult.buildErrorStateResult("参数不合法", null); return JsonResult.buildErrorStateResult("参数不合法", null);
} }
if (StringUtils.isEmpty(name) && StringUtils.isEmpty(phoneNo)) { if (StringUtils.isEmpty(name) && StringUtils.isEmpty(phoneNo)) {
return JsonResult.buildErrorStateResult("修改联系人修改条件不能都为空", null); return JsonResult.buildErrorStateResult("修改联系人修改条件不能都为空", null);
} }
...@@ -986,8 +978,8 @@ public class InnerController implements IBaseController { ...@@ -986,8 +978,8 @@ public class InnerController implements IBaseController {
} }
List<String> phones = JSONObject.parseObject(userPhones, new TypeReference<List<String>>() { List<String> phones = JSONObject.parseObject(userPhones, new TypeReference<List<String>>() {
}); });
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(phones)) { if (!CollectionUtils.isEmpty(phones)) {
if (!(phones.size() > MAX_SIZE)) { if (phones.size() <= MAX_SIZE) {
List<User> users = userService.findByPhones(phones); List<User> users = userService.findByPhones(phones);
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(users)) { if (org.apache.commons.collections.CollectionUtils.isNotEmpty(users)) {
return JsonResult.buildSuccessResult(null, users.stream().collect(Collectors.toMap(User::getPhoneNo, User::getId))); return JsonResult.buildSuccessResult(null, users.stream().collect(Collectors.toMap(User::getPhoneNo, User::getId)));
...@@ -1013,16 +1005,14 @@ public class InnerController implements IBaseController { ...@@ -1013,16 +1005,14 @@ public class InnerController implements IBaseController {
@ApiOperation(value = "根据手机号批量查询UUID", httpMethod = "POST") @ApiOperation(value = "根据手机号批量查询UUID", httpMethod = "POST")
@TargetDataSource(type = DSType.SLAVE) @TargetDataSource(type = DSType.SLAVE)
public JsonResult getUuidsByPhones(@RequestParam("userPhones") String userPhones) { public JsonResult getUuidsByPhones(@RequestParam("userPhones") String userPhones) {
if (StringUtils.isBlank(userPhones)) { if (StringUtils.isBlank(userPhones)) {
return JsonResult.buildErrorStateResult("传入用户手机号不可为空", null); return JsonResult.buildErrorStateResult("传入用户手机号不可为空", null);
} }
List<String> phones = JSONObject.parseObject(userPhones, new TypeReference<List<String>>() { List<String> phones = JSONObject.parseObject(userPhones, new TypeReference<List<String>>() {
}); });
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(phones)) { if (org.apache.commons.collections.CollectionUtils.isNotEmpty(phones)) {
if (!(phones.size() > MAX_SIZE)) { if (phones.size() <= MAX_SIZE) {
List<UserInfo> userInfos = userService.findUserInfosByPhones(phones); List<UserInfo> userInfos = userService.findUserInfosByPhones(phones);
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(userInfos)) { if (org.apache.commons.collections.CollectionUtils.isNotEmpty(userInfos)) {
Map<String, UserInfo> userInfoMap = Maps.newHashMapWithExpectedSize(userInfos.size()); Map<String, UserInfo> userInfoMap = Maps.newHashMapWithExpectedSize(userInfos.size());
...@@ -1079,7 +1069,6 @@ public class InnerController implements IBaseController { ...@@ -1079,7 +1069,6 @@ public class InnerController implements IBaseController {
if (!isIdCard) { if (!isIdCard) {
return JsonResult.buildErrorStateResult("用户身份证号异常.", null); return JsonResult.buildErrorStateResult("用户身份证号异常.", null);
} }
Address addressObj = null; Address addressObj = null;
//地址信息,同时存在provinceCode和address时才校验地址信息 //地址信息,同时存在provinceCode和address时才校验地址信息
if (StringUtils.isNotEmpty(provinceCode) && StringUtils.isNotEmpty(address)) { if (StringUtils.isNotEmpty(provinceCode) && StringUtils.isNotEmpty(address)) {
...@@ -1114,14 +1103,12 @@ public class InnerController implements IBaseController { ...@@ -1114,14 +1103,12 @@ public class InnerController implements IBaseController {
addressObj.setDistrict(district); addressObj.setDistrict(district);
addressObj.setAddress(address); addressObj.setAddress(address);
} }
channelId = MoreObjects.firstNonNull(channelId, "-1"); channelId = MoreObjects.firstNonNull(channelId, "-1");
// 验证用户是否已存在 // 验证用户是否已存在
User user = userService.findByPhoneInDb(phoneNo); User user = userService.findByPhoneInDb(phoneNo);
if (null != user) { if (null != user) {
return JsonResult.buildErrorStateResult("用户已存在,手机号被占用", null); return JsonResult.buildErrorStateResult("用户已存在,手机号被占用", null);
} }
List<Contact> contactList = null; List<Contact> contactList = null;
// 目前对空白字符串和null值容错,因是api调用,不考虑对非法格式容错(会阻断注册) // 目前对空白字符串和null值容错,因是api调用,不考虑对非法格式容错(会阻断注册)
if (StringUtils.isNotBlank(contacts)) { if (StringUtils.isNotBlank(contacts)) {
...@@ -1135,9 +1122,7 @@ public class InnerController implements IBaseController { ...@@ -1135,9 +1122,7 @@ public class InnerController implements IBaseController {
} }
} }
} }
user = userRegisterService.register(Long.valueOf(registeredFrom), Long.valueOf(channelId), phoneNo, name, idNo, addressObj, contacts, contactList, btRegisterChannelId); user = userRegisterService.register(Long.valueOf(registeredFrom), Long.valueOf(channelId), phoneNo, name, idNo, addressObj, contacts, contactList, btRegisterChannelId);
UserRet userRet = new UserRet(user); UserRet userRet = new UserRet(user);
return JsonResult.buildSuccessResult(null, userRet); return JsonResult.buildSuccessResult(null, userRet);
} }
...@@ -1406,7 +1391,7 @@ public class InnerController implements IBaseController { ...@@ -1406,7 +1391,7 @@ public class InnerController implements IBaseController {
@RequestMapping("/user/password/reset/{key}/{phone}") @RequestMapping("/user/password/reset/{key}/{phone}")
public JsonResult resetPasswordByKey(@PathVariable("key") String key, @PathVariable("phone") String phone) { public JsonResult resetPasswordByKey(@PathVariable("key") String key, @PathVariable("phone") String phone) {
log.info("密码重置请求,phone:[{}]", phone); log.info("密码重置请求,phone:[{}]", phone);
if (!"ecf75c1f-2ccb-4661-8e4b-2874c0f45a2b".equalsIgnoreCase(key)) { if (!RESET_PWD_TOKEN.equalsIgnoreCase(key)) {
log.error("密码重置失败,key错误!@!,phone:[{}]", phone); log.error("密码重置失败,key错误!@!,phone:[{}]", phone);
return JsonResult.buildErrorStateResult("用户密码重置失败.", HttpStatus.SC_UNAUTHORIZED); return JsonResult.buildErrorStateResult("用户密码重置失败.", HttpStatus.SC_UNAUTHORIZED);
} }
......
package cn.quantgroup.xyqb.exception;
/**
* @author renwc
* @time 2019-10-30
*/
public class UserQueryLogException extends RuntimeException {
private static final long serialVersionUID = -1L;
public UserQueryLogException(String msg, Throwable t) {
super(msg, t);
}
public UserQueryLogException(String msg) {
super(msg);
}
}
...@@ -105,7 +105,7 @@ public class IdCardServiceImpl implements IIdCardService { ...@@ -105,7 +105,7 @@ public class IdCardServiceImpl implements IIdCardService {
} }
GregorianCalendar gc = new GregorianCalendar(); GregorianCalendar gc = new GregorianCalendar();
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateStr); Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateStr);
if (gc.get(Calendar.YEAR) - year > 150 || gc.getTime().getTime() - date.getTime() < 0) { if (gc.get(Calendar.YEAR) - year > Constants.AGE_MAX || gc.getTime().getTime() - date.getTime() < 0) {
return false; return false;
} }
if (month < Constants.MONTH_NO_MIN || month > Constants.MONTH_NO_MAX) { if (month < Constants.MONTH_NO_MIN || month > Constants.MONTH_NO_MAX) {
...@@ -169,7 +169,7 @@ public class IdCardServiceImpl implements IIdCardService { ...@@ -169,7 +169,7 @@ public class IdCardServiceImpl implements IIdCardService {
return null; return null;
} }
if (gc.get(Calendar.YEAR) - year > 150 || gc.getTime().getTime() - date.getTime() < 0) { if (gc.get(Calendar.YEAR) - year > Constants.AGE_MAX || gc.getTime().getTime() - date.getTime() < 0) {
return cardInfo; return cardInfo;
} }
if (month < Constants.MONTH_NO_MIN || month > Constants.MONTH_NO_MAX) { if (month < Constants.MONTH_NO_MIN || month > Constants.MONTH_NO_MAX) {
...@@ -241,7 +241,7 @@ public class IdCardServiceImpl implements IIdCardService { ...@@ -241,7 +241,7 @@ public class IdCardServiceImpl implements IIdCardService {
} }
GregorianCalendar gc = new GregorianCalendar(); GregorianCalendar gc = new GregorianCalendar();
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateStr); Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateStr);
if (gc.get(Calendar.YEAR) - year > 150 || gc.getTime().getTime() - date.getTime() < 0) { if (gc.get(Calendar.YEAR) - year > Constants.AGE_MAX || gc.getTime().getTime() - date.getTime() < 0) {
throw new IdCardException("身份证出生年份不正确"); throw new IdCardException("身份证出生年份不正确");
} }
if (month < Constants.MONTH_NO_MIN || month > Constants.MONTH_NO_MAX) { if (month < Constants.MONTH_NO_MIN || month > Constants.MONTH_NO_MAX) {
......
...@@ -63,6 +63,18 @@ class Base64 { ...@@ -63,6 +63,18 @@ class Base64 {
*/ */
private static final byte PAD = (byte) '='; private static final byte PAD = (byte) '=';
private static final byte LAST_2_BIT = 0x3;
private static final byte LAST_4_BIT = 0xf;
private static final char ASCII_A_UPPER = 'A';
private static final char ASCII_Z_UPPER = 'Z';
private static final char ASCII_A_LOWER = 'a';
private static final char ASCII_Z_LOWER = 'z';
private static final char ASCII_0 = '0';
private static final char ASCII_9 = '9';
private static final char A_Z_COUNT = 26;
private static final char A_Z_LOWER_COUNT = 26;
private static final char NUMBER_0_9_COUNT = 10;
// Create arrays to hold the base64 characters and a // Create arrays to hold the base64 characters and a
// lookup for base64 chars // lookup for base64 chars
private static byte[] base64Alphabet = new byte[BASELENGTH]; private static byte[] base64Alphabet = new byte[BASELENGTH];
...@@ -73,29 +85,29 @@ class Base64 { ...@@ -73,29 +85,29 @@ class Base64 {
for (int i = 0; i < BASELENGTH; i++) { for (int i = 0; i < BASELENGTH; i++) {
base64Alphabet[i] = (byte) -1; base64Alphabet[i] = (byte) -1;
} }
for (int i = 'Z'; i >= 'A'; i--) { for (int i = ASCII_Z_UPPER; i >= ASCII_A_UPPER; i--) {
base64Alphabet[i] = (byte) (i - 'A'); base64Alphabet[i] = (byte) (i - ASCII_A_UPPER);
} }
for (int i = 'z'; i >= 'a'; i--) { for (int i = ASCII_Z_LOWER; i >= ASCII_A_LOWER; i--) {
base64Alphabet[i] = (byte) (i - 'a' + 26); base64Alphabet[i] = (byte) (i - ASCII_A_LOWER + 26);
} }
for (int i = '9'; i >= '0'; i--) { for (int i = ASCII_9; i >= ASCII_0; i--) {
base64Alphabet[i] = (byte) (i - '0' + 52); base64Alphabet[i] = (byte) (i - ASCII_0 + 52);
} }
base64Alphabet['+'] = 62; base64Alphabet['+'] = 62;
base64Alphabet['/'] = 63; base64Alphabet['/'] = 63;
for (int i = 0; i <= 25; i++) { for (int i = 0; i < A_Z_COUNT; i++) {
lookUpBase64Alphabet[i] = (byte) ('A' + i); lookUpBase64Alphabet[i] = (byte) (ASCII_A_UPPER + i);
} }
for (int i = 26, j = 0; i <= 51; i++, j++) { for (int i = A_Z_COUNT, j = 0; i < A_Z_COUNT + A_Z_LOWER_COUNT; i++, j++) {
lookUpBase64Alphabet[i] = (byte) ('a' + j); lookUpBase64Alphabet[i] = (byte) (ASCII_A_LOWER + j);
} }
for (int i = 52, j = 0; i <= 61; i++, j++) { for (int i = A_Z_COUNT + A_Z_LOWER_COUNT, j = 0; i < A_Z_COUNT + A_Z_LOWER_COUNT + NUMBER_0_9_COUNT; i++, j++) {
lookUpBase64Alphabet[i] = (byte) ('0' + j); lookUpBase64Alphabet[i] = (byte) (ASCII_0 + j);
} }
lookUpBase64Alphabet[62] = (byte) '+'; lookUpBase64Alphabet[62] = (byte) '+';
...@@ -187,7 +199,6 @@ class Base64 { ...@@ -187,7 +199,6 @@ class Base64 {
byte encodedData[] = null; byte encodedData[] = null;
int encodedDataLength = 0; int encodedDataLength = 0;
int nbrChunks = 0; int nbrChunks = 0;
if (fewerThan24bits != 0) { if (fewerThan24bits != 0) {
//data not divisible by 24 bit //data not divisible by 24 bit
encodedDataLength = (numberTriplets + 1) * 4; encodedDataLength = (numberTriplets + 1) * 4;
...@@ -195,122 +206,70 @@ class Base64 { ...@@ -195,122 +206,70 @@ class Base64 {
// 16 or 8 bit // 16 or 8 bit
encodedDataLength = numberTriplets * 4; encodedDataLength = numberTriplets * 4;
} }
// If the output is to be "chunked" into 76 character sections, for compliance with RFC 2045 MIME, then it is important to allow for extra length to account for the separator(s)
// If the output is to be "chunked" into 76 character sections,
// for compliance with RFC 2045 MIME, then it is important to
// allow for extra length to account for the separator(s)
if (isChunked) { if (isChunked) {
nbrChunks = (CHUNK_SEPARATOR.length == 0 ? 0 : (int)Math.ceil((double) encodedDataLength / (double)CHUNK_SIZE));
nbrChunks =
(CHUNK_SEPARATOR.length == 0 ? 0 : (int)Math.ceil((double) encodedDataLength / (double)CHUNK_SIZE));
encodedDataLength += nbrChunks * CHUNK_SEPARATOR.length; encodedDataLength += nbrChunks * CHUNK_SEPARATOR.length;
} }
encodedData = new byte[encodedDataLength]; encodedData = new byte[encodedDataLength];
byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0; byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0;
int encodedIndex = 0, dataIndex = 0, chunksSoFar = 0;
int encodedIndex = 0;
int dataIndex = 0;
int i = 0; int i = 0;
int nextSeparatorIndex = CHUNK_SIZE; int nextSeparatorIndex = CHUNK_SIZE;
int chunksSoFar = 0;
//log.debug("number of triplets = " + numberTriplets);
for (i = 0; i < numberTriplets; i++) { for (i = 0; i < numberTriplets; i++) {
dataIndex = i * 3; dataIndex = i * 3;
b1 = binaryData[dataIndex]; b1 = binaryData[dataIndex];
b2 = binaryData[dataIndex + 1]; b2 = binaryData[dataIndex + 1];
b3 = binaryData[dataIndex + 2]; b3 = binaryData[dataIndex + 2];
//log.debug("b1= " + b1 +", b2= " + b2 + ", b3= " + b3);
l = (byte) (b2 & 0x0f); l = (byte) (b2 & 0x0f);
k = (byte) (b1 & 0x03); k = (byte) (b1 & 0x03);
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
byte val1 = byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
byte val2 =
((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
byte val3 =
((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
encodedData[encodedIndex] = lookUpBase64Alphabet[val1]; encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
//log.debug( "val2 = " + val2 ); encodedData[encodedIndex + 1] = lookUpBase64Alphabet[val2 | (k << 4)];
//log.debug( "k4 = " + (k<<4) ); encodedData[encodedIndex + 2] = lookUpBase64Alphabet[(l << 2) | val3];
//log.debug( "vak = " + (val2 | (k<<4)) );
encodedData[encodedIndex + 1] =
lookUpBase64Alphabet[val2 | (k << 4)];
encodedData[encodedIndex + 2] =
lookUpBase64Alphabet[(l << 2) | val3];
encodedData[encodedIndex + 3] = lookUpBase64Alphabet[b3 & 0x3f]; encodedData[encodedIndex + 3] = lookUpBase64Alphabet[b3 & 0x3f];
encodedIndex += 4; encodedIndex += 4;
// If we are chunking, let's put a chunk separator down. // If we are chunking, let's put a chunk separator down.
if (isChunked) { if (isChunked) {
// this assumes that CHUNK_SIZE % 4 == 0 // this assumes that CHUNK_SIZE % 4 == 0
if (encodedIndex == nextSeparatorIndex) { if (encodedIndex == nextSeparatorIndex) {
System.arraycopy( System.arraycopy(CHUNK_SEPARATOR, 0, encodedData, encodedIndex, CHUNK_SEPARATOR.length);
CHUNK_SEPARATOR,
0,
encodedData,
encodedIndex,
CHUNK_SEPARATOR.length);
chunksSoFar++; chunksSoFar++;
nextSeparatorIndex = nextSeparatorIndex = (CHUNK_SIZE * (chunksSoFar + 1)) + (chunksSoFar * CHUNK_SEPARATOR.length);
(CHUNK_SIZE * (chunksSoFar + 1)) +
(chunksSoFar * CHUNK_SEPARATOR.length);
encodedIndex += CHUNK_SEPARATOR.length; encodedIndex += CHUNK_SEPARATOR.length;
} }
} }
} }
// form integral number of 6-bit groups // form integral number of 6-bit groups
dataIndex = i * 3; dataIndex = i * 3;
if (fewerThan24bits == EIGHTBIT) { if (fewerThan24bits == EIGHTBIT) {
b1 = binaryData[dataIndex]; b1 = binaryData[dataIndex];
k = (byte) (b1 & 0x03); k = (byte) (b1 & 0x03);
//log.debug("b1=" + b1); byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
//log.debug("b1<<2 = " + (b1>>2) );
byte val1 =
((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
encodedData[encodedIndex] = lookUpBase64Alphabet[val1]; encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
encodedData[encodedIndex + 1] = lookUpBase64Alphabet[k << 4]; encodedData[encodedIndex + 1] = lookUpBase64Alphabet[k << 4];
encodedData[encodedIndex + 2] = PAD; encodedData[encodedIndex + 2] = PAD;
encodedData[encodedIndex + 3] = PAD; encodedData[encodedIndex + 3] = PAD;
} else if (fewerThan24bits == SIXTEENBIT) { } else if (fewerThan24bits == SIXTEENBIT) {
b1 = binaryData[dataIndex]; b1 = binaryData[dataIndex];
b2 = binaryData[dataIndex + 1]; b2 = binaryData[dataIndex + 1];
l = (byte) (b2 & 0x0f); l = (byte) (b2 & 0x0f);
k = (byte) (b1 & 0x03); k = (byte) (b1 & 0x03);
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
byte val1 = byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
byte val2 =
((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
encodedData[encodedIndex] = lookUpBase64Alphabet[val1]; encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
encodedData[encodedIndex + 1] = encodedData[encodedIndex + 1] = lookUpBase64Alphabet[val2 | (k << 4)];
lookUpBase64Alphabet[val2 | (k << 4)];
encodedData[encodedIndex + 2] = lookUpBase64Alphabet[l << 2]; encodedData[encodedIndex + 2] = lookUpBase64Alphabet[l << 2];
encodedData[encodedIndex + 3] = PAD; encodedData[encodedIndex + 3] = PAD;
} }
if (isChunked) { if (isChunked) {
// we also add a separator to the end of the final chunk. // we also add a separator to the end of the final chunk.
if (chunksSoFar < nbrChunks) { if (chunksSoFar < nbrChunks) {
System.arraycopy( System.arraycopy(CHUNK_SEPARATOR, 0, encodedData, encodedDataLength - CHUNK_SEPARATOR.length, CHUNK_SEPARATOR.length);
CHUNK_SEPARATOR,
0,
encodedData,
encodedDataLength - CHUNK_SEPARATOR.length,
CHUNK_SEPARATOR.length);
} }
} }
return encodedData; return encodedData;
} }
...@@ -364,7 +323,7 @@ class Base64 { ...@@ -364,7 +323,7 @@ class Base64 {
decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex + 1] = decodedData[encodedIndex + 1] =
(byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); (byte) (((b2 & LAST_4_BIT) << 4) | ((b3 >> 2) & LAST_4_BIT));
decodedData[encodedIndex + 2] = (byte) (b3 << 6 | b4); decodedData[encodedIndex + 2] = (byte) (b3 << 6 | b4);
} else if (marker0 == PAD) { } else if (marker0 == PAD) {
//Two PAD e.g. 3c[Pad][Pad] //Two PAD e.g. 3c[Pad][Pad]
...@@ -375,7 +334,7 @@ class Base64 { ...@@ -375,7 +334,7 @@ class Base64 {
decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex + 1] = decodedData[encodedIndex + 1] =
(byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); (byte) (((b2 & LAST_4_BIT) << 4) | ((b3 >> 2) & LAST_4_BIT));
} }
encodedIndex += 3; encodedIndex += 3;
} }
...@@ -456,65 +415,55 @@ class Base64 { ...@@ -456,65 +415,55 @@ class Base64 {
* @return Array containind decoded data. * @return Array containind decoded data.
*/ */
public static byte[] decode2(String encoded) { public static byte[] decode2(String encoded) {
if (encoded == null) { if (encoded == null) {
return null; return null;
} }
char[] base64Data = encoded.toCharArray(); char[] base64Data = encoded.toCharArray();
// remove white spaces // remove white spaces
int len = removeWhiteSpace(base64Data); int len = removeWhiteSpace(base64Data);
if (len % FOURBYTE != 0) { if (len % FOURBYTE != 0) {
return null;//should be divisible by four //should be divisible by four
return null;
} }
int numberQuadruple = (len / FOURBYTE); int numberQuadruple = (len / FOURBYTE);
if (numberQuadruple == 0) { if (numberQuadruple == 0) {
return new byte[0]; return new byte[0];
} }
byte decodedData[] = null; byte decodedData[] = null;
byte b1 = 0, b2 = 0, b3 = 0, b4 = 0; byte b1 = 0, b2 = 0, b3 = 0, b4 = 0;
char d1 = 0, d2 = 0, d3 = 0, d4 = 0; char d1 = 0, d2 = 0, d3 = 0, d4 = 0;
int i = 0; int i = 0;
int encodedIndex = 0; int encodedIndex = 0;
int dataIndex = 0; int dataIndex = 0;
decodedData = new byte[(numberQuadruple) * 3]; decodedData = new byte[(numberQuadruple) * 3];
for (; i < numberQuadruple - 1; i++) { for (; i < numberQuadruple - 1; i++) {
if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++])) if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))
|| !isData((d3 = base64Data[dataIndex++])) || !isData((d3 = base64Data[dataIndex++]))
|| !isData((d4 = base64Data[dataIndex++]))) { || !isData((d4 = base64Data[dataIndex++]))) {
//if found "no data" just return null
return null; return null;
}//if found "no data" just return null }
b1 = base64Alphabet[d1]; b1 = base64Alphabet[d1];
b2 = base64Alphabet[d2]; b2 = base64Alphabet[d2];
b3 = base64Alphabet[d3]; b3 = base64Alphabet[d3];
b4 = base64Alphabet[d4]; b4 = base64Alphabet[d4];
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); decodedData[encodedIndex++] = (byte) (((b2 & LAST_4_BIT) << 4) | ((b3 >> 2) & LAST_4_BIT));
decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);
} }
//if found "no data" just return null
if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))) { if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))) {
return null;//if found "no data" just return null return null;
} }
b1 = base64Alphabet[d1]; b1 = base64Alphabet[d1];
b2 = base64Alphabet[d2]; b2 = base64Alphabet[d2];
d3 = base64Data[dataIndex++]; d3 = base64Data[dataIndex++];
d4 = base64Data[dataIndex++]; d4 = base64Data[dataIndex++];
if (!isData((d3)) || !isData((d4))) {//Check if they are PAD characters if (!isData((d3)) || !isData((d4))) {
//Check if they are PAD characters
if (isPad(d3) && isPad(d4)) { if (isPad(d3) && isPad(d4)) {
if ((b2 & 0xf) != 0)//last 4 bits should be zero //last 4 bits should be zero
{ if ((b2 & LAST_4_BIT) != 0){
return null; return null;
} }
byte[] tmp = new byte[i * 3 + 1]; byte[] tmp = new byte[i * 3 + 1];
...@@ -523,27 +472,26 @@ class Base64 { ...@@ -523,27 +472,26 @@ class Base64 {
return tmp; return tmp;
} else if (!isPad(d3) && isPad(d4)) { } else if (!isPad(d3) && isPad(d4)) {
b3 = base64Alphabet[d3]; b3 = base64Alphabet[d3];
if ((b3 & 0x3) != 0)//last 2 bits should be zero //last 2 bits should be zero
{ if ((b3 & LAST_2_BIT) != 0){
return null; return null;
} }
byte[] tmp = new byte[i * 3 + 2]; byte[] tmp = new byte[i * 3 + 2];
System.arraycopy(decodedData, 0, tmp, 0, i * 3); System.arraycopy(decodedData, 0, tmp, 0, i * 3);
tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); tmp[encodedIndex] = (byte) (((b2 & LAST_4_BIT) << 4) | ((b3 >> 2) & LAST_4_BIT));
return tmp; return tmp;
} else { } else {
return null; return null;
} }
} else { //No PAD e.g 3cQl } else {
//No PAD e.g 3cQl
b3 = base64Alphabet[d3]; b3 = base64Alphabet[d3];
b4 = base64Alphabet[d4]; b4 = base64Alphabet[d4];
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); decodedData[encodedIndex++] = (byte) (((b2 & LAST_4_BIT) << 4) | ((b3 >> 2) & LAST_4_BIT));
decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);
} }
return decodedData; return decodedData;
} }
......
...@@ -77,7 +77,8 @@ public class UserLoginTest { ...@@ -77,7 +77,8 @@ public class UserLoginTest {
//String userId = "8c02a7b8-815f-4ba0-b39c-a9e6e52904de"; //String userId = "8c02a7b8-815f-4ba0-b39c-a9e6e52904de";
//测试userId为空的情况 //测试userId为空的情况
String userId = ""; String userId = "";
request.addHeader("x-original-client-ip", "172.16.0.1"); String ip = "172.16.0.1";
request.addHeader("x-original-client-ip", ip);
request.addHeader("authorization", "Basic MTg1MTMzNDE4MDg6MTIzNDU2"); request.addHeader("authorization", "Basic MTg1MTMzNDE4MDg6MTIzNDU2");
JsonResult jsonResult = userController.login(channelId, appChannel, createFrom, userId,"xyqb","xyqb", request); JsonResult jsonResult = userController.login(channelId, appChannel, createFrom, userId,"xyqb","xyqb", request);
AuthBean authBean = (AuthBean) jsonResult.getData(); AuthBean authBean = (AuthBean) jsonResult.getData();
......
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