提交 e4ba1910 编写于 作者: rushui.chen's avatar rushui.chen

20200113 完善验证码注册流程

上级 f5a75439
流水线 #20726 已失败 于阶段
in 0 second
...@@ -136,8 +136,8 @@ public class Test { ...@@ -136,8 +136,8 @@ public class Test {
BaseRequest loginRegister = null; BaseRequest loginRegister = null;
loginRegister = new BaseRequest(); loginRegister = new BaseRequest();
loginRegister.setMobile("13024119995"); loginRegister.setMobile("13024112588");
loginRegister.setAuthCode("439160"); loginRegister.setAuthCode("529196");
String registerString4 = JSONObject.toJSONString(loginRegister); String registerString4 = JSONObject.toJSONString(loginRegister);
//AES CONTENT //AES CONTENT
String contentResult4 = AESUtil.aesEncrypt(registerString4, "YCPQPx4qpQjEjDea"); String contentResult4 = AESUtil.aesEncrypt(registerString4, "YCPQPx4qpQjEjDea");
......
...@@ -151,10 +151,11 @@ public class LoginServiceImpl implements LoginService { ...@@ -151,10 +151,11 @@ public class LoginServiceImpl implements LoginService {
String mobile = baseRequest.getMobile(); String mobile = baseRequest.getMobile();
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile)); AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
if (accountInfoEntity == null) { if (accountInfoEntity == null) {
//一键注册和登录验证码的逻辑不同 //说明是注册功能
accountUtils.checkRegisterMobilePhoneAndAuthCode(baseRequest.getMobile(),baseRequest.getFlag()+"",baseRequest.getAuthCode()); accountUtils.checkRegisterMobilePhoneAndAuthCode(baseRequest.getMobile(),baseRequest.getFlag()+"",baseRequest.getAuthCode());
return registerService.register(baseRequest); return registerService.register(baseRequest);
} else { } else {
//登录功能
accountUtils.checkMobilePhoneAndAuthCode(baseRequest.getMobile(), AccountTypeEnum.SYSCODE_TYPE_LOGIN.getCode() + "", baseRequest.getAuthCode()); accountUtils.checkMobilePhoneAndAuthCode(baseRequest.getMobile(), AccountTypeEnum.SYSCODE_TYPE_LOGIN.getCode() + "", baseRequest.getAuthCode());
return processLogin(baseRequest, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_CODE.getCode()); return processLogin(baseRequest, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_CODE.getCode());
} }
......
...@@ -2,9 +2,7 @@ package com.pica.cloud.account.account.server.util; ...@@ -2,9 +2,7 @@ package com.pica.cloud.account.account.server.util;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.controller.AccountController; import com.pica.cloud.account.account.server.controller.AccountController;
import com.pica.cloud.account.account.server.entity.AccountPatientInfoEntity;
import com.pica.cloud.account.account.server.enums.AccountExceptionEnum; import com.pica.cloud.account.account.server.enums.AccountExceptionEnum;
import com.pica.cloud.account.account.server.enums.AccountTypeEnum;
import com.pica.cloud.account.account.server.mapper.AccountPatientInfoMapper; import com.pica.cloud.account.account.server.mapper.AccountPatientInfoMapper;
import com.pica.cloud.account.account.server.mapper.DoctorMapper; import com.pica.cloud.account.account.server.mapper.DoctorMapper;
import com.pica.cloud.foundation.entity.PicaException; import com.pica.cloud.foundation.entity.PicaException;
...@@ -15,7 +13,6 @@ import org.apache.commons.lang3.StringUtils; ...@@ -15,7 +13,6 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
...@@ -58,24 +55,6 @@ public class AccountUtils { ...@@ -58,24 +55,6 @@ public class AccountUtils {
return AUTH_CODE_PREFIX + flag + "-" + AESUtil.encryptV0(mobilePhone); return AUTH_CODE_PREFIX + flag + "-" + AESUtil.encryptV0(mobilePhone);
} }
//校验验证码
public void checkAuthCode(String mobile, String type, String sysCode) {
String flag = org.apache.commons.lang.StringUtils.isBlank(type) ? "0" : type;
if (org.apache.commons.lang.StringUtils.isBlank(sysCode)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
}
String authCodeKey = AccountUtils.getAuthCodeKey(mobile, flag);
String cacheCode = cacheClient.get(authCodeKey); //从redis获取验证码
if (org.apache.commons.lang.StringUtils.isBlank(cacheCode)) {
throw new PicaException(PicaResultCode.RESULE_DATA_NONE.code(), "短信验证码已过期,请重新获取");
}
if (!org.apache.commons.lang.StringUtils.equals(sysCode, cacheCode)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
}
//清除验证码
cacheClient.del(authCodeKey);
}
//手机号和验证码校验 //手机号和验证码校验
public void checkMobilePhoneAndAuthCode(String mobile, String type, String sysCode) { public void checkMobilePhoneAndAuthCode(String mobile, String type, String sysCode) {
if (StringUtils.isBlank(mobile) || !ValidateUtils.isMobile(mobile)) { if (StringUtils.isBlank(mobile) || !ValidateUtils.isMobile(mobile)) {
...@@ -86,20 +65,9 @@ public class AccountUtils { ...@@ -86,20 +65,9 @@ public class AccountUtils {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误"); throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
} }
String authCodeKey = getAuthCodeKey(mobile, flag); String authCodeKey = getAuthCodeKey(mobile, flag);
String authCodeCount = AUTH_CODE_COUNT_PREFIX + flag + "-" + AESUtil.encryptV0(mobile);
logger.info("验证码缓存信息----->:" + this.getAuthCodeKey(mobile, flag)); logger.info("验证码缓存信息----->:" + this.getAuthCodeKey(mobile, flag));
// if (cacheClient.exists(authCodeCount) && Integer.parseInt(cacheClient.get(authCodeCount)) > 2) {
// cacheClient.del(authCodeKey);
// }
String cacheCode = cacheClient.get(authCodeKey); //从redis获取验证码 String cacheCode = cacheClient.get(authCodeKey); //从redis获取验证码
// if (org.apache.commons.lang.StringUtils.isBlank(cacheCode)) {
// //第四次删除计数器
// cacheClient.del(authCodeCount);
// throw new PicaException(PicaResultCode.RESULE_DATA_NONE.code(), "短信验证码已失效,请重新获取");
// }
if (!org.apache.commons.lang.StringUtils.equals(sysCode, cacheCode)) { if (!org.apache.commons.lang.StringUtils.equals(sysCode, cacheCode)) {
cacheClient.incr(authCodeCount);
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误"); throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
} }
cacheClient.del(authCodeKey); cacheClient.del(authCodeKey);
...@@ -110,14 +78,10 @@ public class AccountUtils { ...@@ -110,14 +78,10 @@ public class AccountUtils {
if (StringUtils.isBlank(mobile) || !ValidateUtils.isMobile(mobile)) { if (StringUtils.isBlank(mobile) || !ValidateUtils.isMobile(mobile)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的手机号"); throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的手机号");
} }
String flag = org.apache.commons.lang.StringUtils.isBlank(type) ? "0" : type;
if (org.apache.commons.lang.StringUtils.isBlank(sysCode)) { if (org.apache.commons.lang.StringUtils.isBlank(sysCode)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码为空"); throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码为空");
} }
//获取验证码的key
String authCodeKey = RegisterCodeKeyUtils.getRegisterKey(mobile, sysCode); String authCodeKey = RegisterCodeKeyUtils.getRegisterKey(mobile, sysCode);
//从redis中删除短信验证码,如果能够删除成功,说明验证码正确
//100,99
Long num = cacheClient.decr(authCodeKey); Long num = cacheClient.decr(authCodeKey);
logger.info("key" + authCodeKey); logger.info("key" + authCodeKey);
logger.info("success" + num); logger.info("success" + num);
...@@ -132,19 +96,6 @@ public class AccountUtils { ...@@ -132,19 +96,6 @@ public class AccountUtils {
} }
/**
* 请求参数解密、反序列化
*
* @param params
* @param zClass
* @param <T>
* @return
*/
public static <T> T getRequestEntity(String params, Class<T> zClass) throws Exception {
String json = AESUtil.decryptV0(params);
return JSONObject.parseObject(json, zClass);
}
/** /**
* 获取终端来源 * 获取终端来源
* *
...@@ -177,26 +128,6 @@ public class AccountUtils { ...@@ -177,26 +128,6 @@ public class AccountUtils {
* @return * @return
*/ */
public Long getUserIdByAcctId(Integer productType, Integer AcctId) { public Long getUserIdByAcctId(Integer productType, Integer AcctId) {
Long userId = null; return doctorInfoMapper.selectUserIdByAcctId(AcctId);
if (productType == AccountTypeEnum.PRODUCT_TYPE_DOCTOR.getCode()) {
userId = doctorInfoMapper.selectUserIdByAcctId(AcctId);
}
// else if (productType == AccountTypeEnum.PRODUCT_TYPE_HEALTH.getCode()) {
// AccountPatientInfoEntity accountPatientInfoEntity = accountPatientInfoMapper.selectByAcctId(AcctId);
// userId = accountPatientInfoEntity.getId().longValue();
// }
return userId;
} }
/**
* 校验手机号是否注册过
*
* @param mobile
*/
// public boolean checkRegisterMobile(String mobile) {
// String encrypt = AESUtil.encryptV0(mobile);
// AccountContact accountContact = accountContactServer.selectByMobile(encrypt);
// return (accountContact != null && accountContact.getAcctId() != null);
// }
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册