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

review代码

parent 8e6d1e2c
...@@ -94,6 +94,9 @@ public interface Constants { ...@@ -94,6 +94,9 @@ public interface Constants {
String AES_KEY = "ScnmRBhuQpo9kBdn"; String AES_KEY = "ScnmRBhuQpo9kBdn";
String GT_SERVER_STATUS_SESSION_KEY = "gt_server_status"; String GT_CAPTCHA_UNUSER = "0";
String GT_SERVER_STATUS_USABLE = "1"; String FN_GEETEST_CHALLENGE = "geetest_challenge";
String FN_GEETEST_VALIDATE = "geetest_validate";
String FN_GEETEST_SECCODE = "geetest_seccode";
String GEETEST_CAPTCHA_STATUS = "success";
} }
...@@ -3,18 +3,18 @@ package cn.quantgroup.xyqb.aspect.captcha; ...@@ -3,18 +3,18 @@ package cn.quantgroup.xyqb.aspect.captcha;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.captcha.geetest.IGeetestCaptchaService; import cn.quantgroup.xyqb.service.captcha.geetest.IGeetestCaptchaService;
import cn.quantgroup.xyqb.service.captcha.geetest.sdk.GeetestLib;
import cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService; import cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService;
import cn.quantgroup.xyqb.util.IPUtil; import cn.quantgroup.xyqb.util.IPUtil;
import cn.quantgroup.xyqb.util.PasswordUtil;
import com.octo.captcha.service.CaptchaServiceException; import com.octo.captcha.service.CaptchaServiceException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
...@@ -38,10 +38,6 @@ public class CaptchaNewValidateAdvisor { ...@@ -38,10 +38,6 @@ public class CaptchaNewValidateAdvisor {
@Resource @Resource
private IGeetestCaptchaService geetestCaptchaService; private IGeetestCaptchaService geetestCaptchaService;
@Resource
@Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate;
@Resource @Resource
@Qualifier("customCaptchaService") @Qualifier("customCaptchaService")
private AbstractManageableImageCaptchaService imageCaptchaService; private AbstractManageableImageCaptchaService imageCaptchaService;
...@@ -70,58 +66,53 @@ public class CaptchaNewValidateAdvisor { ...@@ -70,58 +66,53 @@ public class CaptchaNewValidateAdvisor {
@Around("needCaptchaValidate()") @Around("needCaptchaValidate()")
private Object doCaptchaValidate(ProceedingJoinPoint pjp) throws Throwable { private Object doCaptchaValidate(ProceedingJoinPoint pjp) throws Throwable {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String registerFrom = Optional.ofNullable(request.getParameter("registerFrom")).orElse("");
String captchaId = Optional.ofNullable(request.getParameter("captchaId")).orElse(""); if (Constants.GT_CAPTCHA_UNUSER.equals(request.getParameter(Constants.GEETEST_CAPTCHA_STATUS))) {
String captchaValue = request.getParameter("captchaValue"); //极验不可用,用QG
//测试环境使用QG图形验证码 if (isQuantgroupCaptchaValidateSuccess(request)) {
if (autoTestCaptchaEnabled) { return pjp.proceed();
return quantgroupCaptchaValidate(pjp, registerFrom, captchaId, captchaValue, IPUtil.getRemoteIP(request)); } else {
} return JsonResult.buildErrorStateResult("图形验证码有误", "");
String phoneNo = Optional.ofNullable(request.getParameter("phoneNo")).orElse(""); }
String captchaKey = Constants.GT_SERVER_STATUS_SESSION_KEY + phoneNo;
if (stringRedisTemplate.hasKey(captchaKey) && Constants.GT_SERVER_STATUS_USABLE.equals(stringRedisTemplate.opsForValue().get(captchaKey))) {
String challenge = request.getParameter(GeetestLib.fn_geetest_challenge);
String validate = request.getParameter(GeetestLib.fn_geetest_validate);
String seccode = request.getParameter(GeetestLib.fn_geetest_seccode);
geetestCaptchaService.verifyLogin(phoneNo, IPUtil.getRemoteIP(request), challenge, validate, seccode);
log.info("使用极验验证码,phoneNo:{}", phoneNo);
return pjp.proceed();
} else { } else {
return quantgroupCaptchaValidate(pjp, registerFrom, captchaId, captchaValue, IPUtil.getRemoteIP(request)); 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);
} }
return pjp.proceed();
} }
private Object quantgroupCaptchaValidate(ProceedingJoinPoint pjp, String registerFrom, String captchaId, String captchaValue, String remoteIp) throws Throwable { private Boolean isQuantgroupCaptchaValidateSuccess(HttpServletRequest request) throws Throwable {
String registerFrom = Optional.ofNullable(request.getParameter("registerFrom")).orElse("");
String captchaId = Optional.ofNullable(request.getParameter("captchaId")).orElse("");
String captchaValue = request.getParameter("captchaValue");
if (isSkipCaptchaValidate(captchaId, captchaValue)) { if (isSkipCaptchaValidate(captchaId, captchaValue)) {
log.info("使用超级图形验证码校验, registerFrom={}, clientIp={}", registerFrom, remoteIp); log.info("使用超级图形验证码校验, registerFrom={}, clientIp={}", registerFrom, IPUtil.getRemoteIP(request));
return pjp.proceed(); return Boolean.TRUE;
} }
return verifyCaptchaOnline(pjp, captchaId, captchaValue);
}
private Object verifyCaptchaOnline(ProceedingJoinPoint pjp, String captchaId, String captchaValue) throws Throwable { Boolean validCaptcha = false;
JsonResult result = JsonResult.buildSuccessResult("图形验证码不正确", ""); if (StringUtils.isNotBlank(captchaValue)) {
result.setBusinessCode("0002");
if (org.apache.commons.lang3.StringUtils.isNotBlank(captchaValue)) {
// 忽略用户输入的大小写 // 忽略用户输入的大小写
String captcha = org.apache.commons.lang3.StringUtils.lowerCase(captchaValue); String captcha = StringUtils.lowerCase(captchaValue);
// 验证码校验 // 验证码校验
Boolean validCaptcha = false;
try { try {
validCaptcha = imageCaptchaService.validateResponseForID(Constants.IMAGE_CAPTCHA_KEY + captchaId, captcha); validCaptcha = imageCaptchaService.validateResponseForID(Constants.IMAGE_CAPTCHA_KEY + captchaId, captcha);
} catch (CaptchaServiceException ex) { } catch (CaptchaServiceException ex) {
log.error("验证码校验异常, {}, {}", ex.getMessage(), ex); log.error("验证码校验异常, {}, {}", ex.getMessage(), ex);
} }
if (validCaptcha) {
return pjp.proceed();
}
} }
return result; return validCaptcha;
} }
private boolean isSkipCaptchaValidate(String captchaId, Object captchaValue) { private boolean isSkipCaptchaValidate(String captchaId, Object captchaValue) {
// 如果启用了超级验证码功能, 检查超级验证码, 超级验证码区分大小写 // 如果启用了超级验证码功能, 检查超级验证码, 超级验证码区分大小写
return autoTestCaptchaEnabled || org.apache.commons.lang3.StringUtils.equals(SUPER_CAPTCHA_ID, String.valueOf(captchaId)) && org.apache.commons.lang3.StringUtils.equals(SUPER_CAPTCHA, String.valueOf(captchaValue)); return autoTestCaptchaEnabled || org.apache.commons.lang3.StringUtils.equals(SUPER_CAPTCHA_ID, String.valueOf(captchaId))
&& org.apache.commons.lang3.StringUtils.equals(SUPER_CAPTCHA, String.valueOf(captchaValue));
} }
} }
...@@ -5,9 +5,9 @@ import cn.quantgroup.xyqb.aspect.captcha.CaptchaNewValidator; ...@@ -5,9 +5,9 @@ import cn.quantgroup.xyqb.aspect.captcha.CaptchaNewValidator;
import cn.quantgroup.xyqb.aspect.logcaller.LogHttpCaller; import cn.quantgroup.xyqb.aspect.logcaller.LogHttpCaller;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.captcha.geetest.IGeetestCaptchaService; import cn.quantgroup.xyqb.service.captcha.geetest.IGeetestCaptchaService;
import cn.quantgroup.xyqb.service.captcha.geetest.sdk.GeetestLib;
import cn.quantgroup.xyqb.service.captcha.qg.IQuantgroupCaptchaService; import cn.quantgroup.xyqb.service.captcha.qg.IQuantgroupCaptchaService;
import cn.quantgroup.xyqb.util.IPUtil; import cn.quantgroup.xyqb.util.IPUtil;
import cn.quantgroup.xyqb.util.PasswordUtil;
import cn.quantgroup.xyqb.util.ValidationUtil; import cn.quantgroup.xyqb.util.ValidationUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -38,18 +38,20 @@ public class NewCaptchaController { ...@@ -38,18 +38,20 @@ public class NewCaptchaController {
} }
log.info("[newCaptcha]获取验证码,phoneNo:{}", phoneNo); log.info("[newCaptcha]获取验证码,phoneNo:{}", phoneNo);
GeetestLib gtSdk = geetestCaptchaService.getGeetestSdk(); String geetestCaptcha = geetestCaptchaService.fetchGeetestCaptcha(PasswordUtil.MD5(phoneNo),
if (geetestCaptchaService.getGeetestServerStatus(phoneNo, IPUtil.getRemoteIP(request), gtSdk) == Integer.parseInt(Constants.GT_SERVER_STATUS_USABLE)) { IPUtil.getRemoteIP(request), request.getParameter("clientType"));
log.info("[newCaptcha]极验可用,phoneNo:{}", phoneNo); if (Constants.GT_CAPTCHA_UNUSER.equals(geetestCaptcha)) {
return JsonResult.buildSuccessResult("", geetestCaptchaService.startCaptcha(gtSdk));
} else {
try { try {
return JsonResult.buildSuccessResult("", quantgroupCaptchaService.fetchCaptcha(request.getLocale())); return JsonResult.buildSuccessResult("", quantgroupCaptchaService.fetchCaptcha(request.getLocale()));
} catch (Exception e) { } catch (Exception e) {
log.error("获取验证码失败e:{}", e); log.error("获取验证码失败e:{}", e);
return JsonResult.buildErrorStateResult("", "fail"); return JsonResult.buildErrorStateResult("", "fail");
} }
} else {
log.info("[newCaptcha]极验可用,phoneNo:{}", phoneNo);
return JsonResult.buildSuccessResult("", geetestCaptcha);
} }
} }
@CaptchaNewValidator @CaptchaNewValidator
......
package cn.quantgroup.xyqb.service.captcha.geetest; package cn.quantgroup.xyqb.service.captcha.geetest;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.service.captcha.geetest.sdk.GeetestLib; import cn.quantgroup.xyqb.service.captcha.geetest.sdk.GeetestLib;
import cn.quantgroup.xyqb.util.PasswordUtil; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
...@@ -10,7 +9,6 @@ import org.springframework.stereotype.Service; ...@@ -10,7 +9,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.TimeUnit;
/** /**
* @author xufei on 2018/1/30. * @author xufei on 2018/1/30.
...@@ -37,40 +35,32 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService { ...@@ -37,40 +35,32 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService {
@Value("${geetest.api.url}") @Value("${geetest.api.url}")
private String apiUrl; private String apiUrl;
@Override private GeetestLib getGeetestSdk() {
public GeetestLib getGeetestSdk() { return new GeetestLib(captchaId, privateKey, newFailback, apiUrl);
return new GeetestLib(captchaId, privateKey, newFailback,apiUrl);
} }
@Override @Override
public int getGeetestServerStatus(String phoneNo, String remoteIp, GeetestLib gtSdk) { public String fetchGeetestCaptcha(String markStr, String remoteIp, String clientType) {
HashMap<String, String> param = getParam(phoneNo, remoteIp); GeetestLib gtSdk = new GeetestLib(captchaId, privateKey, newFailback, apiUrl);
int gtServerStatus = gtSdk.preProcess(param); HashMap<String, String> param = getParam(markStr, remoteIp, clientType);
stringRedisTemplate.opsForValue().set(Constants.GT_SERVER_STATUS_SESSION_KEY + phoneNo,
Integer.toString(gtServerStatus), gtServerStatusExistTime, TimeUnit.MINUTES);
//进行验证预处理 return gtSdk.getResponseStr(param);
return gtServerStatus;
} }
private HashMap<String, String> getParam(String phoneNo, String remoteIp) { private HashMap<String, String> getParam(String markStr, String remoteIp, String clientType) {
HashMap<String, String> param = new HashMap<>(); HashMap<String, String> param = new HashMap<>();
param.put("user_id", PasswordUtil.MD5(phoneNo)); param.put("user_id", markStr);
param.put("client_type", "H5"); if (StringUtils.isBlank(clientType)) {
param.put("client_type", "APP");
}
param.put("client_type", clientType);
param.put("ip_address", remoteIp); param.put("ip_address", remoteIp);
return param; return param;
} }
@Override
public String startCaptcha(GeetestLib gtSdk) {
return gtSdk.getResponseStr();
}
@Override @Override
public int verifyLogin(String phoneNo, String remoteIp, String challenge, String validate, String seccode) { public int captchaValidate(String clientType, String markStr, String remoteIp, String challenge, String validate, String seccode) {
HashMap<String, String> param = getParam(phoneNo, remoteIp); HashMap<String, String> param = getParam(markStr, remoteIp, clientType);
return getGeetestSdk().enhencedValidateRequest(challenge, validate, seccode, param); return getGeetestSdk().enhencedValidateRequest(challenge, validate, seccode, param);
} }
} }
package cn.quantgroup.xyqb.service.captcha.geetest; package cn.quantgroup.xyqb.service.captcha.geetest;
import cn.quantgroup.xyqb.service.captcha.geetest.sdk.GeetestLib;
/** /**
* @author xufei on 2018/1/30. * @author xufei on 2018/1/30.
*/ */
public interface IGeetestCaptchaService { public interface IGeetestCaptchaService {
/** /**
* 获取极验的sdk * 获取极验验证码
*
* @return
*/
GeetestLib getGeetestSdk();
/**
* 获取geetest服务器可用的状态
* *
* @param phoneNo 用户的手机号 * @param markStr 标示
* @param remoteIp ip * @param remoteIp
* @param gtSdk sdk * @param clientType
* @return 成功返回1, 失败返回0 * @return 获取失败返回"0"服务不可用,成功返回验证码
*/ */
int getGeetestServerStatus(String phoneNo, String remoteIp, GeetestLib gtSdk); String fetchGeetestCaptcha(String markStr, String remoteIp, String clientType);
/**
* 获取geetest的验证码
*
* @param gtSdk sdk
* @return
*/
String startCaptcha(GeetestLib gtSdk);
/** /**
* 二次验证 * 二次验证
* *
* @param clientType
* @param phoneNo 参数 * @param phoneNo 参数
* @param seccode * @param seccode
* @param validate * @param validate
* @param challenge * @param challenge
* @return 验证结果, 1表示验证成功0表示验证失败 * @return 验证结果, 1表示验证成功0表示验证失败
*/ */
int verifyLogin(String phoneNo, String remoteIp,String challenge,String validate,String seccode); int captchaValidate(String clientType, String phoneNo, String remoteIp, String challenge, String validate, String seccode);
} }
package cn.quantgroup.xyqb.service.captcha.geetest.sdk; package cn.quantgroup.xyqb.service.captcha.geetest.sdk;
import cn.quantgroup.xyqb.Constants;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -19,7 +20,6 @@ import java.util.HashMap; ...@@ -19,7 +20,6 @@ import java.util.HashMap;
public class GeetestLib { public class GeetestLib {
protected final String verName = "4.0"; protected final String verName = "4.0";
protected final String sdkLang = "java";
private String apiUrl; private String apiUrl;
...@@ -28,21 +28,6 @@ public class GeetestLib { ...@@ -28,21 +28,6 @@ public class GeetestLib {
protected final String json_format = "1"; protected final String json_format = "1";
/**
* 极验验证二次验证表单数据 chllenge
*/
public static final String fn_geetest_challenge = "geetest_challenge";
/**
* 极验验证二次验证表单数据 validate
*/
public static final String fn_geetest_validate = "geetest_validate";
/**
* 极验验证二次验证表单数据 seccode
*/
public static final String fn_geetest_seccode = "geetest_seccode";
/** /**
* 公钥 * 公钥
*/ */
...@@ -68,10 +53,6 @@ public class GeetestLib { ...@@ -68,10 +53,6 @@ public class GeetestLib {
*/ */
public boolean debugCode = true; public boolean debugCode = true;
/**
* 极验验证API服务状态Session Key
*/
public String gtServerStatusSessionKey = "gt_server_status";
/** /**
* 带参数构造函数 * 带参数构造函数
...@@ -92,17 +73,11 @@ public class GeetestLib { ...@@ -92,17 +73,11 @@ public class GeetestLib {
* *
* @return 初始化结果 * @return 初始化结果
*/ */
public String getResponseStr() { public String getResponseStr(HashMap<String, String> param) {
preProcess(param);
return responseStr; return responseStr;
} }
public String getVersionInfo() {
return verName;
}
/** /**
* 预处理失败后的返回格式串 * 预处理失败后的返回格式串
...@@ -110,29 +85,7 @@ public class GeetestLib { ...@@ -110,29 +85,7 @@ public class GeetestLib {
* @return * @return
*/ */
private String getFailPreProcessRes() { private String getFailPreProcessRes() {
return Constants.GT_CAPTCHA_UNUSER;
Long rnd1 = Math.round(Math.random() * 100);
Long rnd2 = Math.round(Math.random() * 100);
String md5Str1 = md5Encode(rnd1 + "");
String md5Str2 = md5Encode(rnd2 + "");
String challenge = md5Str1 + md5Str2.substring(0, 2);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("success", 0);
jsonObject.put("gt", this.captchaId);
jsonObject.put("challenge", challenge);
jsonObject.put("new_captcha", this.newFailback);
} catch (JSONException e) {
gtlog("json dumps error");
}
return jsonObject.toString();
} }
/** /**
......
package cn.quantgroup.xyqb.service.captcha.qg; package cn.quantgroup.xyqb.service.captcha.qg;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
/** /**
* @author xufei on 2018/1/30. * @author xufei on 2018/1/30.
...@@ -11,8 +10,8 @@ public interface IQuantgroupCaptchaService { ...@@ -11,8 +10,8 @@ public interface IQuantgroupCaptchaService {
* QG获取验证码 * QG获取验证码
* *
* @param locale * @param locale
* @return map * @return
* @throws Exception EX * @throws Exception EX
*/ */
Map<String, String> fetchCaptcha(Locale locale) throws Exception; String fetchCaptcha(Locale locale) throws Exception;
} }
...@@ -3,6 +3,7 @@ package cn.quantgroup.xyqb.service.captcha.qg; ...@@ -3,6 +3,7 @@ package cn.quantgroup.xyqb.service.captcha.qg;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService; import cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.json.JSONObject;
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.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -11,9 +12,7 @@ import org.springframework.stereotype.Service; ...@@ -11,9 +12,7 @@ import org.springframework.stereotype.Service;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
/** /**
...@@ -35,7 +34,7 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService { ...@@ -35,7 +34,7 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService {
private AbstractManageableImageCaptchaService imageCaptchaService; private AbstractManageableImageCaptchaService imageCaptchaService;
@Override @Override
public Map<String, String> fetchCaptcha(Locale locale) throws Exception { public String fetchCaptcha(Locale locale) throws Exception {
String imageId = UUID.randomUUID().toString(); String imageId = UUID.randomUUID().toString();
BufferedImage challenge = imageCaptchaService.getImageChallengeForID(Constants.IMAGE_CAPTCHA_KEY + imageId, locale); BufferedImage challenge = imageCaptchaService.getImageChallengeForID(Constants.IMAGE_CAPTCHA_KEY + imageId, locale);
ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
...@@ -43,9 +42,10 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService { ...@@ -43,9 +42,10 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService {
String imageBase64 = Base64.encodeBase64String(jpegOutputStream.toByteArray()); String imageBase64 = Base64.encodeBase64String(jpegOutputStream.toByteArray());
Map<String, String> data = new HashMap<>(); JSONObject jsonObject = new JSONObject();
data.put("imageId", imageId); jsonObject.put("success","0");
data.put("image", String.format(IMG_BASE64_PATTREN, imageBase64)); jsonObject.put("imageId", imageId);
return data; 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