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

优化极验体验,改进初始化流程,phoneNo降为为非必填项

parent 73189d4d
......@@ -98,6 +98,7 @@ public interface Constants {
// -- Start -- 验证码常量组
int GT_CAPTCHA_VALIDATE_SUCCESS =1;
String GT_UNIQUE_KEY = "uniqueKey";
String FN_GEETEST_CHALLENGE = "geetest_challenge";
String FN_GEETEST_VALIDATE = "geetest_validate";
String FN_GEETEST_SECCODE = "geetest_seccode";
......
......@@ -77,13 +77,14 @@ public class CaptchaNewValidateAdvisor {
* @throws Throwable
*/
private boolean gtValid(HttpServletRequest request) {
String uniqueKey = request.getParameter(Constants.GT_UNIQUE_KEY);
String phoneNo = request.getParameter(Constants.PHONE_NO);
String clientType = request.getParameter(Constants.CLIENT_TYPE);
String challenge = request.getParameter(Constants.FN_GEETEST_CHALLENGE);
String validate = request.getParameter(Constants.FN_GEETEST_VALIDATE);
String seccode = request.getParameter(Constants.FN_GEETEST_SECCODE);
log.info("Geetest - 极验二次校验, phoneNo:{}, clientType:{}, ip:{}, challenge:{}, validate:{}, seccode:{}", phoneNo, clientType, IPUtil.getRemoteIP(request), challenge, validate, seccode);
return geetestCaptchaService.validGeetestCaptcha(PasswordUtil.MD5(phoneNo), IPUtil.getRemoteIP(request), ClientType.valueByName(clientType), challenge, validate, seccode);
log.info("Geetest - 极验二次校验, phoneNo:{}, uniqueKey:{}, clientType:{}, ip:{}, challenge:{}, validate:{}, seccode:{}", phoneNo, uniqueKey, clientType, IPUtil.getRemoteIP(request), challenge, validate, seccode);
return geetestCaptchaService.validGeetestCaptcha(uniqueKey, IPUtil.getRemoteIP(request), ClientType.valueByName(clientType), challenge, validate, seccode);
}
/**
......
......@@ -17,9 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.*;
/**
* @author xufei on 2018/1/30.
......@@ -41,15 +39,20 @@ public class NewCaptchaController {
public JsonResult getCaptcha(String phoneNo, String clientType, HttpServletRequest request) {
String remoteIp = IPUtil.getRemoteIP(request);
log.info("获取验证码, phoneNo:{}, clientType:{}, ip:{}, verifyType-qg:{}", phoneNo, clientType, remoteIp, geetestClose);
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
if (Objects.nonNull(phoneNo) && !ValidationUtil.validatePhoneNo(phoneNo)) {
return JsonResult.buildErrorStateResult("手机号格式错误", null);
}
// 唯一key,用于初始化极验
String key = Optional.ofNullable(phoneNo).orElse(UUID.fromString(Constants.VERIFY_TYPE_GT).toString());
// key指纹
String keyMd5 = PasswordUtil.MD5(key);
log.info("获取验证码, phoneNo:{}, keyMd5:{}, clientType:{}, ip:{}, verifyType-qg:{}", phoneNo, keyMd5, clientType, remoteIp, geetestClose);
// 数据容器
Map<String, String> data = new HashMap<String, String>();
Map<String, String> imgMap = null;
// 优先获取极验
if(!Boolean.valueOf(geetestClose)){
imgMap = geetestCaptchaService.fetchGeetestCaptcha(PasswordUtil.MD5(phoneNo), remoteIp, ClientType.valueByName(clientType));
imgMap = geetestCaptchaService.fetchGeetestCaptcha(keyMd5, remoteIp, ClientType.valueByName(clientType));
data.put(Constants.VERIFY_PARAM, Constants.VERIFY_TYPE_GT);
}
// 备选方案:量化派图形验证码
......@@ -63,6 +66,7 @@ public class NewCaptchaController {
}
// 填充数据并返回
data.putAll(imgMap);
data.put(Constants.GT_UNIQUE_KEY, keyMd5);
return JsonResult.buildSuccessResult("", data);
}
......
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