提交 a94fcbb7 编写于 作者: hujun's avatar hujun

Merge branch 'dev-20200109-smscode' into 'release'

Dev 20200109 smscode

合并当前分支到release分支

See merge request !10
流水线 #20752 已失败 于阶段
in 0 second
......@@ -106,8 +106,8 @@ public class Test {
System.out.println("--------------------获取验证码接口-------------");
BaseRequest authCode = new BaseRequest();
authCode.setFlag(4);
authCode.setMobile("13024112688");
authCode.setFlag(1);
authCode.setMobile("13024119988");
String authCodeStr = JSONObject.toJSONString(authCode);
System.out.println(authCodeStr);
String contentResult2 = AESUtil.aesEncrypt(authCodeStr, "YCPQPx4qpQjEjDea");
......@@ -121,9 +121,9 @@ public class Test {
//获取注册参数
BaseRequest register = null;
register = new BaseRequest();
register.setMobile("13024112688");
register.setMobile("13024119988");
register.setPassword("D0DCBF0D12A6B1E7FBFA2CE5848F3EFF");
register.setAuthCode("113058");
register.setAuthCode("868578");
String registerString3 = JSONObject.toJSONString(register);
String contentResult3 = AESUtil.aesEncrypt(registerString3, "YCPQPx4qpQjEjDea");
String keyResult3 = RSAUtil.encrypt("YCPQPx4qpQjEjDea",publicKey);
......@@ -136,8 +136,8 @@ public class Test {
BaseRequest loginRegister = null;
loginRegister = new BaseRequest();
loginRegister.setMobile("13024112081");
loginRegister.setAuthCode("163173");
loginRegister.setMobile("13024112588");
loginRegister.setAuthCode("529196");
String registerString4 = JSONObject.toJSONString(loginRegister);
//AES CONTENT
String contentResult4 = AESUtil.aesEncrypt(registerString4, "YCPQPx4qpQjEjDea");
......@@ -196,6 +196,24 @@ public class Test {
changeMobileEntity.setContent(changeMobileContent);
System.out.println(JSONObject.toJSONString(changeMobileEntity));
System.out.println("---------------------------------------------------------------");
BaseRequest changeMobileu = new BaseRequest();
changeMobileu.setMobile("13024112588");
changeMobileu.setAuthCode("871756");
changeMobileu.setUnionId("o3EP_wNH2g4FGcUNByXJIbQyUVPI");
changeMobileu.setFlag(2);
String string1u= JSONObject.toJSONString(changeMobileu);
System.out.println(string1u);
String changeMobileContentu = AESUtil.aesEncrypt(string1u, "YCPQPx4qpQjEjDea");
String changeMobileKeyu = RSAUtil.encrypt("YCPQPx4qpQjEjDea",publicKey);
EncryptEntity changeMobileEntityu = new EncryptEntity();
changeMobileEntityu.setKey(changeMobileKeyu);
changeMobileEntityu.setContent(changeMobileContentu);
System.out.println(JSONObject.toJSONString(changeMobileEntityu));
}
......
......@@ -9,6 +9,7 @@ import com.pica.cloud.account.account.server.req.AccountReq;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.service.AccountService;
import com.pica.cloud.account.account.server.service.CaptchaService;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.CryptoUtil;
import com.pica.cloud.foundation.encryption.common.constants.EncryptConstants;
import com.pica.cloud.foundation.encryption.util.EncryptUtils;
......@@ -53,8 +54,9 @@ public class AccountController extends AccountBaseController {
@Autowired
private CaptchaService captchaService;
@Autowired
private ICacheClient redisClient;
@Autowired
private AccountUtils accountUtils;
@GetMapping("/test")
public String test() {
......@@ -159,7 +161,7 @@ public class AccountController extends AccountBaseController {
// @PostMapping("/register")
public PicaResponse<LoginResult> register(@RequestBody AccountReq req) {
this.checkMobilePhone(req.getMobilePhone());
this.checkAuthCode(req);
accountUtils.checkRegisterMobilePhoneAndAuthCode(req.getMobilePhone(),req.getFlag(),req.getAuthCode());
String deviceType = super.getDeviceInfo("device_type"); //1:pc 2:android 3:ios
Account account = new Account();
account.setMobilePhone(EncryptUtils.encryptContent(req.getMobilePhone(), EncryptConstants.ENCRYPT_TYPE_MOBILE));
......
......@@ -15,6 +15,7 @@ import com.pica.cloud.account.account.server.service.CaptchaService;
import com.pica.cloud.account.account.server.util.AESUtil;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.CryptoUtil;
import com.pica.cloud.account.account.server.util.RegisterCodeKeyUtils;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
......@@ -150,9 +151,14 @@ public class AutoCodeController extends AccountBaseController {
String message = "您的验证码是" + authCode + ",在10分钟内有效。如非本人操作,请忽略本短信!";
Integer accountIdByMobilePhone = accountService.getAccountIdByMobilePhone(mobilePhone);
long senderId = accountIdByMobilePhone == null ? 0L : accountIdByMobilePhone;
cacheClient.set(this.getAuthCodeKey(mobilePhone, flag.toString()), authCode, 600);
logger.info("验证码缓存信息----->:"+this.getAuthCodeKey(mobilePhone, flag.toString()));
String authCodeKey = getAuthCodeKey(mobilePhone, flag.toString());
boolean set = cacheClient.set(authCodeKey, authCode, 600);
logger.info(cacheClient.get(authCodeKey));
logger.info("验证码缓存是否成功----->:"+set);
logger.info("验证码缓存信息----->:"+authCodeKey);
cacheClient.set(authCodeKeySecure, System.currentTimeMillis(), 60);
//处理验证码原子性的问题
cacheClient.set(RegisterCodeKeyUtils.getRegisterKey(mobilePhone,authCode), 100, 600);
super.sendMobileMessage(mobilePhone, message, senderId);
}
......@@ -167,4 +173,15 @@ public class AutoCodeController extends AccountBaseController {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的手机号");
}
}
@ApiOperation("微信获取验证码")
@PostMapping(value = "/authCode/get")
public PicaResponse getAuthCode(){
String cacheCode = cacheClient.get("authCode-2-j1VrU5MSc1uuZaEa82ZKfQ==");
return PicaResponse.toResponse(cacheCode);
}
}
......@@ -84,7 +84,6 @@ public class LoginController extends AccountBaseController {
@PostMapping(value = "/login-register")
public PicaResponse<LoginResult> loginAndRegister(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
accountUtils.checkMobilePhoneAndAuthCode(request.getMobile(), AccountTypeEnum.SYSCODE_TYPE_LOGIN.getCode() + "", request.getAuthCode());
request.setProductType(super.getProductType());
Integer sourceType = super.getSourceType();
request.setSourceType(sourceType);
......
......@@ -41,7 +41,8 @@ public class RegisterController extends AccountBaseController {
//接口幂等性处理(redis中没有就进行注册逻辑,如果已经存在,就不处理)
String authCode = request.getAuthCode();
String flag = AccountTypeEnum.SYSCODE_TYPE_REGISTER.getCode() + "";
accountUtils.checkMobilePhoneAndAuthCode(mobile, flag, authCode);
//验证码验证的原子操作
accountUtils.checkRegisterMobilePhoneAndAuthCode(mobile, flag, authCode);
accountUtils.checkPassword(request.getPassword());
LoginResult result = null;
request.setFlag(AccountTypeEnum.SYSCODE_TYPE_REGISTER.getCode());
......
......@@ -25,8 +25,5 @@ public class AccountRepeatDataJob extends IJobHandler {
accountInfoDetailMapper.processAccountRepeatData();
XxlJobLogger.log("repeat date-----");
return SUCCESS;
}
}
......@@ -13,18 +13,18 @@ import org.springframework.stereotype.Component;
* author:crs
* Description:记录doctor修改记录日志
*/
@JobHandler(value = "DoctorLogHandler")
@Component
public class DoctorLogHandler extends IJobHandler {
@Autowired
private DoctorMapper doctorMapper;
@Override
public ReturnT<String> execute(String s) throws Exception {
XxlJobLogger.log("doctorLogRecord start-----");
Integer rows = doctorMapper.updateDoctorModifyRecord();
XxlJobLogger.log("doctorLogRecord end-----"+rows);
return SUCCESS;
}
}
//@JobHandler(value = "DoctorLogHandler")
//@Component
//public class DoctorLogHandler extends IJobHandler {
//
// @Autowired
// private DoctorMapper doctorMapper;
//
// @Override
// public ReturnT<String> execute(String s) throws Exception {
// XxlJobLogger.log("doctorLogRecord start-----");
// Integer rows = doctorMapper.updateDoctorModifyRecord();
// XxlJobLogger.log("doctorLogRecord end-----"+rows);
// return SUCCESS;
// }
//}
//package com.pica.cloud.account.account.server.job;
//
//import com.pica.cloud.account.account.server.mapper.DoctorMapper;
//import com.pica.cloud.foundation.redis.ICacheClient;
//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.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
///**
// * Created on 2019/10/29 15:37
// * author:crs
// * Description:doctor表重复记录处理
// */
package com.pica.cloud.account.account.server.job;
import com.pica.cloud.account.account.server.mapper.DoctorMapper;
import com.pica.cloud.foundation.redis.ICacheClient;
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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Created on 2019/10/29 15:37
* author:crs
* Description:doctor表重复记录处理
*/
//@Component
//public class DoctorRepeatDataJob {
// private final String KEY = "cacheProcessDoctorRepeat";
......
......@@ -13,18 +13,18 @@ import org.springframework.stereotype.Component;
* author:crs
* Description:记录doctor修改记录日志
*/
@JobHandler(value = "HospitalLogHandler")
@Component
public class HospitalLogHandler extends IJobHandler {
@Autowired
private HospitalMapper hospitalMapper;
@Override
public ReturnT<String> execute(String s) throws Exception {
XxlJobLogger.log("hospitalLogRecord start-----");
Integer rows = hospitalMapper.updateDoctorModifyRecord();
XxlJobLogger.log("hospitalLogRecord end-----"+rows);
return SUCCESS;
}
}
//@JobHandler(value = "HospitalLogHandler")
//@Component
//public class HospitalLogHandler extends IJobHandler {
//
// @Autowired
// private HospitalMapper hospitalMapper;
//
// @Override
// public ReturnT<String> execute(String s) throws Exception {
// XxlJobLogger.log("hospitalLogRecord start-----");
// Integer rows = hospitalMapper.updateDoctorModifyRecord();
// XxlJobLogger.log("hospitalLogRecord end-----"+rows);
// return SUCCESS;
// }
//}
......@@ -151,8 +151,12 @@ public class LoginServiceImpl implements LoginService {
String mobile = baseRequest.getMobile();
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
if (accountInfoEntity == null) {
//说明是注册功能
accountUtils.checkRegisterMobilePhoneAndAuthCode(baseRequest.getMobile(),baseRequest.getFlag()+"",baseRequest.getAuthCode());
return registerService.register(baseRequest);
} else {
//登录功能
accountUtils.checkMobilePhoneAndAuthCode(baseRequest.getMobile(), AccountTypeEnum.SYSCODE_TYPE_LOGIN.getCode() + "", baseRequest.getAuthCode());
return processLogin(baseRequest, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_CODE.getCode());
}
}
......
......@@ -111,16 +111,6 @@ public class RegisterServiceImpl implements RegisterService {
accountInfoDetailMapper.insertSelective(accountInfo);
Integer acctId = accountInfo.getId();
accountInfoDetailMapper.updateCreateInfo(acctId);
if (productType == AccountTypeEnum.PRODUCT_TYPE_HEALTH.getCode()) {
AccountPatientInfoEntity accountPatientInfoEntity = new AccountPatientInfoEntity();
accountPatientInfoEntity.setAcctId(acctId);
accountPatientInfoEntity.setDeleteFlag(1);
accountPatientInfoEntity.setCreateId(acctId);
accountPatientInfoEntity.setModifyId(acctId);
accountPatientInfoEntity.setCreateTime(currentTime);
accountPatientInfoEntity.setModifyTime(currentTime);
accountUserInfoMapper.insertSelective(accountPatientInfoEntity);
} else {
Account account = new Account();
account.setAcctId(acctId);
account.setMobilePhone(mobileEncrypt);
......@@ -133,24 +123,23 @@ public class RegisterServiceImpl implements RegisterService {
account.setLastLoginTime(currentTime);
account.setRegisterSource(sourceType);
account.setPassword(password);
if (!StringUtils.isBlank(password)){
if (!StringUtils.isBlank(password)) {
account.setEntireFlag(3);
}
accountMapper.insertSelective(account);
}
Long userId = accountUtils.getUserIdByAcctId(productType, acctId);
Account account = new Account();
account.setId(userId);
account.setAcctId(acctId);
account.setCreatTime(currentTime);
account.setMobilePhone(mobile);
account.setRegisterSource(sourceType);
String newToken = tokenUtils.generateToken(account);
Long userId = account.getId();
Account accountToken = new Account();
accountToken.setId(userId);
accountToken.setAcctId(acctId);
accountToken.setCreatTime(currentTime);
accountToken.setMobilePhone(mobile);
accountToken.setRegisterSource(sourceType);
String newToken = tokenUtils.generateToken(accountToken);
LoginResult result = new LoginResult();
result.setToken(newToken);
result.setUserId(userId);
result.setEntireFlag(1);
result.setDoctorId(EncryptUtils.encryptContent(userId+"", EncryptConstants.ENCRYPT_TYPE_ID));
result.setDoctorId(EncryptUtils.encryptContent(userId + "", EncryptConstants.ENCRYPT_TYPE_ID));
result.setMobile(mobile);
/* ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
......@@ -185,6 +174,7 @@ public class RegisterServiceImpl implements RegisterService {
/**
* 异步处理用户角色
*
* @param userId
*/
private void processRoleMap(Long userId) {
......
......@@ -194,10 +194,10 @@ public class AESUtil {
// System.out.println("解密后:" + decrypt);
//请求参数解密处理
String key="aPzpkXKhX0xsgwG0L7uOiz47fKQKKW1pzzIyx9wRSoCtm4vux1+ctjKzQ77jb+Vvt4zB/z0wr7U5nszk7kXLKQR4A6nU5nt8O44CHjCHUU0dWbpPyd2TKFdZ58ZyKLsk1+Xc4wJ1HB0FQjxJefWvo5ioFYLasOpxSbKU7oHqXq4=";
String decrypt = RSAUtil.decrypt(key,procPrivateKey);
String key="am1pnysCRlz80Rl/eTDj/UE/Pe8zkxb2yP73jvrUWEk3x5/lK9hi104MSmsKbl45cPzJfJXBxO+VeItkA63ZqfaUNA0ezdMd7Ord7rGqvWK+4RqAm1T3Qo3lw/5bT0GwgWMWZBrDr30NHCYLmjg6vwVbv3YCEewwQK+rL7bUXu0=";
String decrypt = RSAUtil.decrypt(key,privateKey);
System.out.println(decrypt);
String content="x/119w4nmos1xMG1DFNzBDeUP7BmyGViwXB66UCCk2HaCoJWhNg6qL1WoDMLGkiMJni8GV8fzEpd+1h9z4LA99wEkn47rbK6+MLaGkMIv+QmXzMLxThpLJNxadb2ltRyKgz5wERoFB/AH/xxgRn8kw==";
String content="d9eKA7DGhNx7295N0g82rqzaUOeAvBeuR2gXtOX3Y+VV3ei+zW0BQn9moQgN4mRT8XIzq3x2n3qiqCuOzcDvrlGC0kIcUClM0gt8xDaBw+haVpMAw/7R4FgWNPeVRL5k";
String result = AESUtil.aesDecrypt(content, decrypt);
System.out.println(result);
......
......@@ -2,9 +2,7 @@ package com.pica.cloud.account.account.server.util;
import com.alibaba.fastjson.JSONObject;
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.AccountTypeEnum;
import com.pica.cloud.account.account.server.mapper.AccountPatientInfoMapper;
import com.pica.cloud.account.account.server.mapper.DoctorMapper;
import com.pica.cloud.foundation.entity.PicaException;
......@@ -15,7 +13,6 @@ import org.apache.commons.lang3.StringUtils;
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.stereotype.Component;
/**
......@@ -58,67 +55,45 @@ public class AccountUtils {
return AUTH_CODE_PREFIX + flag + "-" + AESUtil.encryptV0(mobilePhone);
}
//校验验证码
public void checkAuthCode(String mobile, String type, String sysCode) {
//手机号和验证码校验
public void checkMobilePhoneAndAuthCode(String mobile, String type, String sysCode) {
if (StringUtils.isBlank(mobile) || !ValidateUtils.isMobile(mobile)) {
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)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
}
String authCodeKey = AccountUtils.getAuthCodeKey(mobile, flag);
String authCodeKey = getAuthCodeKey(mobile, flag);
logger.info("验证码缓存信息----->:" + this.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 checkRegisterMobilePhoneAndAuthCode(String mobile, String type, String sysCode) {
if (StringUtils.isBlank(mobile) || !ValidateUtils.isMobile(mobile)) {
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)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
}
String authCodeKey = AccountUtils.getAuthCodeKey(mobile, flag);
//验证码3次校验测试不通过,直接删除
String authCodeCount = AUTH_CODE_COUNT_PREFIX + flag + "-" + AESUtil.encryptV0(mobile);
logger.info("验证码缓存信息----->:"+this.getAuthCodeKey(mobile, flag));
if (cacheClient.exists(authCodeCount) && Integer.parseInt(cacheClient.get(authCodeCount)) > 2) {
cacheClient.del(authCodeKey);
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码为空");
}
String cacheCode = cacheClient.get(authCodeKey); //从redis获取验证码
if (org.apache.commons.lang.StringUtils.isBlank(cacheCode)) {
//第四次删除计数器
cacheClient.del(authCodeCount);
String authCodeKey = RegisterCodeKeyUtils.getRegisterKey(mobile, sysCode);
Long num = cacheClient.decr(authCodeKey);
logger.info("key" + authCodeKey);
logger.info("success" + num);
if (num == -1) {
throw new PicaException(PicaResultCode.RESULE_DATA_NONE.code(), "短信验证码已失效,请重新获取");
}
if (!org.apache.commons.lang.StringUtils.equals(sysCode, cacheCode)) {
cacheClient.incr(authCodeCount);
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
if (num > 0 && num < 99) {
throw new PicaException(PicaResultCode.RESULE_DATA_NONE.code(), "您已注册成功,请直接登录");
}
//验证成功以后删除验证码
cacheClient.del(authCodeKey);
}
/**
* 请求参数解密、反序列化
*
* @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);
}
/**
......@@ -153,25 +128,6 @@ public class AccountUtils {
* @return
*/
public Long getUserIdByAcctId(Integer productType, Integer AcctId) {
Long userId = null;
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;
return doctorInfoMapper.selectUserIdByAcctId(AcctId);
}
/**
* 校验手机号是否注册过
*
* @param mobile
*/
// public boolean checkRegisterMobile(String mobile) {
// String encrypt = AESUtil.encryptV0(mobile);
// AccountContact accountContact = accountContactServer.selectByMobile(encrypt);
// return (accountContact != null && accountContact.getAcctId() != null);
// }
}
package com.pica.cloud.account.account.server.util;
/**
* Created on 2020/1/9 16:18
* author:crs
* Description:注册验证码的key规则
*/
public class RegisterCodeKeyUtils {
private static final String AUTH_CODE_PREFIX = "authCode-";
/**
* 获取注册验证码的key
*
* @param mobilePhone
* @param authCode
* @return
*/
public static String getRegisterKey(String mobilePhone, String authCode) {
return AUTH_CODE_PREFIX + AESUtil.encryptV0(mobilePhone) +"-"+ authCode;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册