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

“20191014 患者招募短信验证码逻辑处理

上级 58ea0329
流水线 #15749 已失败 于阶段
in 0 second
...@@ -24,12 +24,14 @@ import org.slf4j.LoggerFactory; ...@@ -24,12 +24,14 @@ 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.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
/** /**
* 账号相关controller * 账号相关controller
*
* @author andong * @author andong
* @create 2019/5/20 * @create 2019/5/20
*/ */
...@@ -49,12 +51,14 @@ public class AccountController extends AccountBaseController { ...@@ -49,12 +51,14 @@ public class AccountController extends AccountBaseController {
private ICacheClient redisClient; private ICacheClient redisClient;
@GetMapping("/test") @GetMapping("/test")
public String test() {return "test";} public String test() {
return "test";
}
@ApiOperation("获取登录验证码") @ApiOperation("获取登录验证码")
@GetMapping("/authCode") @GetMapping("/authCode")
public PicaResponse<String> getAuthCode(@ApiParam(value = "手机号", required = true) @RequestParam("mobilePhone") String mobilePhone, public PicaResponse<String> getAuthCode(@ApiParam(value = "手机号", required = true) @RequestParam("mobilePhone") String mobilePhone,
@ApiParam(value = "验证码类型 0默认 1注册 2修改密码 4微信登录绑定手机 5修改手机 6重置密码") @RequestParam(value = "flag", defaultValue = "0") String flag, @ApiParam(value = "验证码类型 0默认 1注册 2修改密码 4微信登录绑定手机 5修改手机 6重置密码 7患者招募提交问卷(效验") @RequestParam(value = "flag", defaultValue = "0") String flag,
@ApiParam(value = "图形验证码token", required = true) @RequestParam("captchaToken") String captchaToken, @ApiParam(value = "图形验证码token", required = true) @RequestParam("captchaToken") String captchaToken,
@ApiParam(value = "图形验证码答案", required = true) @RequestParam("captchaAnswer") String captchaAnswer) { @ApiParam(value = "图形验证码答案", required = true) @RequestParam("captchaAnswer") String captchaAnswer) {
//校验图形验证码 //校验图形验证码
...@@ -64,9 +68,12 @@ public class AccountController extends AccountBaseController { ...@@ -64,9 +68,12 @@ public class AccountController extends AccountBaseController {
this.checkMobilePhone(mobilePhone); this.checkMobilePhone(mobilePhone);
String authCode = CommonUtil.createValidateCode(); //随机生成验证码 String authCode = CommonUtil.createValidateCode(); //随机生成验证码
String message = "您的验证码是" + authCode + ",在10分钟内有效。如非本人操作,请忽略本短信!"; String message = "您的验证码是" + authCode + ",在10分钟内有效。如非本人操作,请忽略本短信!";
//判断账号是否已经存在 long senderId = 0L;
Account account = accountService.getByMobilePhone(mobilePhone); if (Integer.parseInt(flag) != 7) {
long senderId = account == null ? 0L : account.getId(); //判断账号是否已经存在
Account account = accountService.getByMobilePhone(mobilePhone);
senderId = account == null ? 0L : account.getId();
}
//验证码保存到redis,失效时间10分钟 //验证码保存到redis,失效时间10分钟
redisClient.set(this.getAuthCodeKey(mobilePhone, flag), authCode, 600); redisClient.set(this.getAuthCodeKey(mobilePhone, flag), authCode, 600);
//发送短信 //发送短信
...@@ -212,7 +219,7 @@ public class AccountController extends AccountBaseController { ...@@ -212,7 +219,7 @@ public class AccountController extends AccountBaseController {
redisClient.del(oldToken); redisClient.del(oldToken);
} }
//生成新token //生成新token
int expiredSeconds = 30*24*60*60; //H5 token有效期30天 int expiredSeconds = 30 * 24 * 60 * 60; //H5 token有效期30天
newToken = UUID.randomUUID().toString().replace("-", "").toUpperCase(); newToken = UUID.randomUUID().toString().replace("-", "").toUpperCase();
String tokenKey = "token-" + newToken; String tokenKey = "token-" + newToken;
redisClient.set(tokenKey, tokenValue, expiredSeconds); redisClient.set(tokenKey, tokenValue, expiredSeconds);
...@@ -224,11 +231,14 @@ public class AccountController extends AccountBaseController { ...@@ -224,11 +231,14 @@ public class AccountController extends AccountBaseController {
picaUser.setToken(newToken); picaUser.setToken(newToken);
picaUser.setId(account.getId().intValue()); picaUser.setId(account.getId().intValue());
picaUser.setMobile(account.getMobilePhone()); picaUser.setMobile(account.getMobilePhone());
picaUser.setName(EncryptUtils.decryptContent(account.getMobilePhone(), EncryptConstants.ENCRYPT_TYPE_MOBILE, EncryptConstants.ENCRYPT_DECRYPT_KEY).replaceAll("(\\d{3})\\d{4}(\\w{4})","$1****$2")); picaUser.setName(EncryptUtils.decryptContent(account.getMobilePhone(), EncryptConstants.ENCRYPT_TYPE_MOBILE, EncryptConstants.ENCRYPT_DECRYPT_KEY).replaceAll("(\\d{3})\\d{4}(\\w{4})", "$1****$2"));
picaUser.setCreated_time(account.getCreatTime()); picaUser.setCreated_time(account.getCreatTime());
Map<String, String> data = Object2Map.objectToMapString("yyyy-MM-dd HH:mm:ss", picaUser, new String[0]); Map<String, String> data = Object2Map.objectToMapString("yyyy-MM-dd HH:mm:ss", picaUser, new String[0]);
data.put("sysCode", "h5"); data.put("sysCode", "h5");
data.forEach((key, value) -> {value = value == null ? "" : value; redisClient.hset(tokenValue, key, value);}); data.forEach((key, value) -> {
value = value == null ? "" : value;
redisClient.hset(tokenValue, key, value);
});
} }
} catch (Exception ex) { } catch (Exception ex) {
logger.error("生成H5 token异常:{}" + ex.getMessage(), ex); logger.error("生成H5 token异常:{}" + ex.getMessage(), ex);
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册