提交 788c2c41 编写于 作者: dong.an's avatar dong.an

图形验证码

上级 d6a1528c
流水线 #13079 已失败 于阶段
...@@ -58,7 +58,7 @@ public class AccountController extends AccountBaseController { ...@@ -58,7 +58,7 @@ public class AccountController extends AccountBaseController {
@ApiParam(value = "图形验证码答案", required = true) @RequestParam("captchaAnswer") String captchaAnswer) { @ApiParam(value = "图形验证码答案", required = true) @RequestParam("captchaAnswer") String captchaAnswer) {
//校验图形验证码 //校验图形验证码
if (!captchaService.acknowledge(captchaToken, captchaAnswer)) { if (!captchaService.acknowledge(captchaToken, captchaAnswer)) {
return PicaResponse.toResponse(null, PicaResultCode.PARAM_IS_INVALID.code(), "图形验证码答案错误!"); return PicaResponse.toResponse(null, PicaResultCode.PARAM_IS_INVALID.code(), "图形验证码错误");
} }
this.checkMobilePhone(mobilePhone); this.checkMobilePhone(mobilePhone);
String authCode = CommonUtil.createValidateCode(); //随机生成验证码 String authCode = CommonUtil.createValidateCode(); //随机生成验证码
...@@ -186,16 +186,16 @@ public class AccountController extends AccountBaseController { ...@@ -186,16 +186,16 @@ public class AccountController extends AccountBaseController {
String flag = StringUtils.isBlank(req.getFlag()) ? "0" : req.getFlag(); String flag = StringUtils.isBlank(req.getFlag()) ? "0" : req.getFlag();
if (StringUtils.isBlank(req.getAuthCode())) { if (StringUtils.isBlank(req.getAuthCode())) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的验证码"); throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
} }
String authCodeKey = this.getAuthCodeKey(req.getMobilePhone(), flag); String authCodeKey = this.getAuthCodeKey(req.getMobilePhone(), flag);
String cacheCode = redisClient.get(authCodeKey); //从redis获取验证码 String cacheCode = redisClient.get(authCodeKey); //从redis获取验证码
if (StringUtils.isBlank(cacheCode)) { if (StringUtils.isBlank(cacheCode)) {
throw new PicaException(PicaResultCode.RESULE_DATA_NONE.code(), "验证码已过期,请重新获取"); throw new PicaException(PicaResultCode.RESULE_DATA_NONE.code(), "短信验证码已过期,请重新获取");
} }
if (!StringUtils.equals(req.getAuthCode(), cacheCode)) { if (!StringUtils.equals(req.getAuthCode(), cacheCode)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "请输入正确的验证码"); throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "短信验证码错误");
} }
redisClient.del(authCodeKey); //清除验证码 redisClient.del(authCodeKey); //清除验证码
} }
......
...@@ -29,11 +29,11 @@ public class CaptchaGenerator { ...@@ -29,11 +29,11 @@ public class CaptchaGenerator {
public CaptchaGenerator() throws FontFormatException, IOException { public CaptchaGenerator() throws FontFormatException, IOException {
int h = 40; int h = 40;
ctxs.put(Range.closedOpen(0, h), new CaptchaContext(h * 4, h, (h / 2) * 3, true)); ctxs.put(Range.closedOpen(0, h), new CaptchaContext(h * 4, h, (int) (h * 1.2), true));
h *= 2; h *= 2;
ctxs.put(Range.closedOpen(h / 2, h), new CaptchaContext(h * 4, h, (h / 2) * 3, true)); ctxs.put(Range.closedOpen(h / 2, h), new CaptchaContext(h * 4, h, (int) (h * 1.2), true));
h *= 2; h *= 2;
ctxs.put(Range.closedOpen(h / 2, Integer.MAX_VALUE), new CaptchaContext(h * 4, h, (h / 2) * 3, true)); ctxs.put(Range.closedOpen(h / 2, Integer.MAX_VALUE), new CaptchaContext(h * 4, h, (int) (h * 1.2), true));
gens.add(new NumberLetterGenerator()); gens.add(new NumberLetterGenerator());
} }
......
/**
*
*/
package com.pica.cloud.account.account.server.util.captcha; package com.pica.cloud.account.account.server.util.captcha;
/** /**
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册