Commit c942eddb authored by 贷前—徐菲's avatar 贷前—徐菲

review代码

parent adb404b0
......@@ -94,9 +94,10 @@ public interface Constants {
String AES_KEY = "ScnmRBhuQpo9kBdn";
String GT_CAPTCHA_UNUSER = "0";
String GT_CAPTCHA_AVAILABLE = "0";
int GT_CAPTCHA_VALIDATE_SUCCESS =1;
String FN_GEETEST_CHALLENGE = "geetest_challenge";
String FN_GEETEST_VALIDATE = "geetest_validate";
String FN_GEETEST_SECCODE = "geetest_seccode";
String GEETEST_CAPTCHA_STATUS = "success";
String CAPTCHA_OF_QG_OR_GT = "success";
}
......@@ -2,7 +2,7 @@ package cn.quantgroup.xyqb.aspect.captcha;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.captcha.geetest.IGeetestCaptchaService;
import cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService;
import cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService;
import cn.quantgroup.xyqb.util.IPUtil;
import cn.quantgroup.xyqb.util.PasswordUtil;
......@@ -67,21 +67,21 @@ public class CaptchaNewValidateAdvisor {
private Object doCaptchaValidate(ProceedingJoinPoint pjp) throws Throwable {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
if (Constants.GT_CAPTCHA_UNUSER.equals(request.getParameter(Constants.GEETEST_CAPTCHA_STATUS))) {
//极验不可用,用QG
if (isQuantgroupCaptchaValidateSuccess(request)) {
return pjp.proceed();
} else {
return JsonResult.buildErrorStateResult("图形验证码有误", "");
}
} else {
if (Constants.GT_CAPTCHA_AVAILABLE.equals(request.getParameter(Constants.CAPTCHA_OF_QG_OR_GT))) {
String challenge = request.getParameter(Constants.FN_GEETEST_CHALLENGE);
String validate = request.getParameter(Constants.FN_GEETEST_VALIDATE);
String seccode = request.getParameter(Constants.FN_GEETEST_SECCODE);
String phoneNo = request.getParameter("phoneNo");
String clientType = request.getParameter("clientType");
geetestCaptchaService.captchaValidate(clientType, PasswordUtil.MD5(phoneNo), IPUtil.getRemoteIP(request), challenge, validate, seccode);
log.info("使用极验二次验证,phoneNo:{}", phoneNo);
if (!geetestCaptchaService.isCaptchaValidateSuccess(clientType, PasswordUtil.MD5(phoneNo), IPUtil.getRemoteIP(request), challenge, validate, seccode)) {
return JsonResult.buildErrorStateResult("图形验证码有误", "");
}
} else {
//极验不可用,用QG
if (!isQuantgroupCaptchaValidateSuccess(request)) {
return JsonResult.buildErrorStateResult("图形验证码有误", "");
}
}
return pjp.proceed();
}
......
package cn.quantgroup.xyqb.controller.external.captcha;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.aspect.captcha.CaptchaNewValidator;
import cn.quantgroup.xyqb.aspect.logcaller.LogHttpCaller;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.captcha.geetest.IGeetestCaptchaService;
import cn.quantgroup.xyqb.service.captcha.qg.IQuantgroupCaptchaService;
import cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService;
import cn.quantgroup.xyqb.service.captcha.IQuantgroupCaptchaService;
import cn.quantgroup.xyqb.util.IPUtil;
import cn.quantgroup.xyqb.util.PasswordUtil;
import cn.quantgroup.xyqb.util.ValidationUtil;
......@@ -40,16 +39,16 @@ public class NewCaptchaController {
log.info("[newCaptcha]获取验证码,phoneNo:{}", phoneNo);
String geetestCaptcha = geetestCaptchaService.fetchGeetestCaptcha(PasswordUtil.MD5(phoneNo),
IPUtil.getRemoteIP(request), request.getParameter("clientType"));
if (Constants.GT_CAPTCHA_UNUSER.equals(geetestCaptcha)) {
log.info("结果geetestCaptcha:{},phoneNo:{}", geetestCaptcha,phoneNo);
if (null != geetestCaptcha) {
return JsonResult.buildSuccessResult("", geetestCaptcha);
} else {
try {
return JsonResult.buildSuccessResult("", quantgroupCaptchaService.fetchCaptcha(request.getLocale()));
} catch (Exception e) {
log.error("获取验证码失败e:{}", e);
return JsonResult.buildErrorStateResult("", "fail");
}
} else {
log.info("[newCaptcha]极验可用,phoneNo:{}", phoneNo);
return JsonResult.buildSuccessResult("", geetestCaptcha);
}
}
......
......@@ -2,7 +2,7 @@ package cn.quantgroup.xyqb.controller.internal.sms;
import cn.quantgroup.sms.MsgParams;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator;
import cn.quantgroup.xyqb.aspect.captcha.CaptchaNewValidator;
import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.sms.ISmsService;
......@@ -51,14 +51,14 @@ public class SmsController implements IBaseController {
* 短信验证码: for H5
* 使用 @FPLock 注解并加入自定义限制参数, 做针对手机号的发送次数限制
*/
@CaptchaValidator
@CaptchaNewValidator
@RequestMapping("/send_sms_verification_code")
public JsonResult verifyPhoneNoH5(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,@RequestParam(required = false,defaultValue = "")String appName) {
LOGGER.info("注册-发送验证码, phoneNo:{}, registerFrom:{}", phoneNo, registerFrom);
return sendVerificationCode2(phoneNo,appName);
}
@CaptchaValidator
@CaptchaNewValidator
@RequestMapping("/send_reset_code")
public JsonResult resetPasswordH5(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,@RequestParam(required = false,defaultValue = "")String appName) {
LOGGER.info("重置密码-发送验证码, phoneNo:{}, registerFrom:{}", phoneNo, registerFrom);
......@@ -69,7 +69,7 @@ public class SmsController implements IBaseController {
* 短信验证码: for H5
* 使用 @FPLock 注解并加入自定义限制参数, 做针对手机号的发送次数限制
*/
@CaptchaValidator
@CaptchaNewValidator
@RequestMapping("/send_sms_verification_code_voice")
public JsonResult verifyPhoneNoH5New(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,
String usage) {
......@@ -81,7 +81,7 @@ public class SmsController implements IBaseController {
return sendVerificationCode2Voice(phoneNo, usage);
}
@CaptchaValidator
@CaptchaNewValidator
@RequestMapping("/send_reset_code_voice")
public JsonResult resetPasswordH5New(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,
String usage) {
......@@ -96,7 +96,7 @@ public class SmsController implements IBaseController {
/**
* 快速登陆发送验证码
*/
@CaptchaValidator
@CaptchaNewValidator
@RequestMapping("/send_login_code_voice")
public JsonResult sendLoginCodeNew(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,
String usage) {
......@@ -111,7 +111,7 @@ public class SmsController implements IBaseController {
/**
* 快速登陆发送验证码
*/
@CaptchaValidator
@CaptchaNewValidator
@RequestMapping("/send_login_code")
public JsonResult sendLoginCode(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,@RequestParam(required = false,defaultValue = "")String appName) {
LOGGER.info("快速登陆-发送验证码, phoneNo:{}, registerFrom:{}", phoneNo, registerFrom);
......@@ -121,7 +121,7 @@ public class SmsController implements IBaseController {
/**
* 快速注册发送验证码
*/
@CaptchaValidator
@CaptchaNewValidator
@RequestMapping("/send_regist_code")
public JsonResult sendRegistCode(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,@RequestParam(required = false,defaultValue = "")String appName) {
LOGGER.info("快速注册-发送验证码, phoneNo:{}, registerFrom:{}", phoneNo, registerFrom);
......@@ -199,7 +199,7 @@ public class SmsController implements IBaseController {
/**
* 快速登陆发送验证码新版
*/
@CaptchaValidator
@CaptchaNewValidator
@RequestMapping("/send_login_code_voice_new")
public JsonResult sendLoginCodeVoiceNew(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom,
String usage, @RequestParam(required = false) String deviceId) {
......@@ -215,7 +215,7 @@ public class SmsController implements IBaseController {
/**
* 快速登陆发送短信验证码
*/
@CaptchaValidator
@CaptchaNewValidator
@RequestMapping("/send_login_code_new")
public JsonResult sendLoginSmsCodeNew(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom, @RequestParam(required = false) String deviceId,@RequestParam(required = false,defaultValue = "")String appName) {
LOGGER.info("快速登陆-发送验证码, phoneNo:{}, registerFrom:{}", phoneNo, registerFrom);
......@@ -224,7 +224,7 @@ public class SmsController implements IBaseController {
/**
* 快速登陆发送短信验证码
*/
@CaptchaValidator
@CaptchaNewValidator
@RequestMapping("/send_login_code_new_forH5")
public JsonResult sendLoginSmsCodeNewForH5(@RequestParam String phoneNo, @RequestParam(required = false) String registerFrom, @RequestParam(required = false) String deviceId,@RequestParam(required = false,defaultValue = "")String appName) {
LOGGER.info("快速登陆-发送验证码, phoneNo:{}, registerFrom:{}", phoneNo, registerFrom);
......
package cn.quantgroup.xyqb.service.captcha.geetest.sdk;
package cn.quantgroup.xyqb.service.captcha;
import cn.quantgroup.xyqb.Constants;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -15,6 +14,7 @@ import java.util.HashMap;
/**
* Java SDK
*
* @author geetet
*/
public class GeetestLib {
......@@ -46,7 +46,7 @@ public class GeetestLib {
/**
* 返回字符串
*/
private String responseStr = "";
private String responseStr;
/**
* 调试开关,是否输出调试日志
......@@ -60,7 +60,7 @@ public class GeetestLib {
* @param captchaId
* @param privateKey
*/
public GeetestLib(String captchaId, String privateKey, boolean newFailback,String apiUrl) {
public GeetestLib(String captchaId, String privateKey, boolean newFailback, String apiUrl) {
this.captchaId = captchaId;
this.privateKey = privateKey;
......@@ -85,7 +85,7 @@ public class GeetestLib {
* @return
*/
private String getFailPreProcessRes() {
return Constants.GT_CAPTCHA_UNUSER;
return null;
}
/**
......@@ -98,7 +98,7 @@ public class GeetestLib {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("success", 1);
jsonObject.put("success", "0");
jsonObject.put("gt", this.captchaId);
jsonObject.put("challenge", challenge);
......
package cn.quantgroup.xyqb.service.captcha.geetest;
package cn.quantgroup.xyqb.service.captcha;
/**
* @author xufei on 2018/1/30.
......@@ -11,7 +11,7 @@ public interface IGeetestCaptchaService {
* @param markStr 标示
* @param remoteIp
* @param clientType
* @return 获取失败返回"0"服务不可用,成功返回验证码
* @return 获取失败返回null
*/
String fetchGeetestCaptcha(String markStr, String remoteIp, String clientType);
......@@ -20,12 +20,13 @@ public interface IGeetestCaptchaService {
* 二次验证
*
* @param clientType
* @param phoneNo 参数
* @param seccode
* @param validate
* @param phoneNo
* @param remoteIp
* @param challenge
* @return 验证结果, 1表示验证成功0表示验证失败
* @param validate
* @param seccode
* @return
*/
int captchaValidate(String clientType, String phoneNo, String remoteIp, String challenge, String validate, String seccode);
Boolean isCaptchaValidateSuccess(String clientType, String phoneNo, String remoteIp, String challenge, String validate, String seccode);
}
package cn.quantgroup.xyqb.service.captcha.geetest;
package cn.quantgroup.xyqb.service.captcha.impl;
import cn.quantgroup.xyqb.service.captcha.geetest.sdk.GeetestLib;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.service.captcha.GeetestLib;
import cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
......@@ -59,8 +61,8 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService {
}
@Override
public int captchaValidate(String clientType, String markStr, String remoteIp, String challenge, String validate, String seccode) {
public Boolean isCaptchaValidateSuccess(String clientType, String markStr, String remoteIp, String challenge, String validate, String seccode) {
HashMap<String, String> param = getParam(markStr, remoteIp, clientType);
return getGeetestSdk().enhencedValidateRequest(challenge, validate, seccode, param);
return Constants.GT_CAPTCHA_VALIDATE_SUCCESS==getGeetestSdk().enhencedValidateRequest(challenge, validate, seccode, param);
}
}
package cn.quantgroup.xyqb.service.captcha.qg;
package cn.quantgroup.xyqb.service.captcha.impl;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.service.captcha.IQuantgroupCaptchaService;
import cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONObject;
......@@ -43,7 +44,7 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService {
String imageBase64 = Base64.encodeBase64String(jpegOutputStream.toByteArray());
JSONObject jsonObject = new JSONObject();
jsonObject.put("success","0");
jsonObject.put("success","1");
jsonObject.put("imageId", imageId);
jsonObject.put("image", String.format(IMG_BASE64_PATTREN, imageBase64));
return jsonObject.toString();
......
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