提交 9091e460 编写于 作者: Chongwen.jiang's avatar Chongwen.jiang

调用风控接口修改完成

上级 73a19199
流水线 #23396 已失败 于阶段
in 0 second
...@@ -167,7 +167,7 @@ ...@@ -167,7 +167,7 @@
<dependency> <dependency>
<groupId>com.pica.cloud.riskcontrol</groupId> <groupId>com.pica.cloud.riskcontrol</groupId>
<artifactId>pica-cloud-riskcontrol-client</artifactId> <artifactId>pica-cloud-riskcontrol-client</artifactId>
<version>1.0.2</version> <version>1.0.3.1</version>
</dependency> </dependency>
<!-- apple identifyToken校验 --> <!-- apple identifyToken校验 -->
......
...@@ -66,4 +66,10 @@ public class Constants { ...@@ -66,4 +66,10 @@ public class Constants {
/** 注册逻辑幂等处理缓存key */ /** 注册逻辑幂等处理缓存key */
public static final String REPEAT_REGISTER_PREFIX = "repeat-register—"; public static final String REPEAT_REGISTER_PREFIX = "repeat-register—";
/** h5拼图缓存key */
public static final String JIGSAW_CODE_KEY = "jigsaw-code-{mobile}";
/** h5拼图缓存时长*/
public static final int JIGSAW_CODE_EXPIRE_SECONDS = 60 * 10;
} }
...@@ -107,12 +107,13 @@ public class AutoCodeController extends AccountBaseController { ...@@ -107,12 +107,13 @@ public class AutoCodeController extends AccountBaseController {
// 验证码类型 0默认 1注册 2微信登录绑定手机 3修改手机 // 验证码类型 0默认 1注册 2微信登录绑定手机 3修改手机
// 4重置密码 5忘记密码 7患者招募提交问卷(效验) 8Appe登录绑定手机 // 4重置密码 5忘记密码 7患者招募提交问卷(效验) 8Appe登录绑定手机
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class); BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
request.setSourceType(super.getSourceType());
AccountUtils.checkMobilePhone(request.getMobile()); AccountUtils.checkMobilePhone(request.getMobile());
if (request.getBizType() != null && request.getBizType().equals(1)) { if (request.getBizType() != null && request.getBizType().equals(1)) {
logger.info("app-rcValidate-start"); logger.info("app-rcValidate-start");
// 调用风控接口 // 调用风控接口
authCodeService.rcValidate(req, request, super.getDeviceInfo()); authCodeService.rcValidate(req, request, super.getDeviceInfo(), super.getSourceType());
// 发送短信验证码 // 发送短信验证码
processSysCode(request.getMobile(), request.getFlag()); processSysCode(request.getMobile(), request.getFlag());
return PicaResponse.toResponse(); return PicaResponse.toResponse();
...@@ -138,16 +139,19 @@ public class AutoCodeController extends AccountBaseController { ...@@ -138,16 +139,19 @@ public class AutoCodeController extends AccountBaseController {
// 验证码类型 0默认 1注册 2微信登录绑定手机 3修改手机 // 验证码类型 0默认 1注册 2微信登录绑定手机 3修改手机
// 4重置密码 5忘记密码 7患者招募提交问卷(效验) 8Appe登录绑定手机 // 4重置密码 5忘记密码 7患者招募提交问卷(效验) 8Appe登录绑定手机
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class); BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
request.setSourceType(super.getSourceType());
AccountUtils.checkMobilePhone(request.getMobile()); AccountUtils.checkMobilePhone(request.getMobile());
// 拼图验证 // 拼图验证
authCodeService.validateJigsawCode(request.getMobile(), request.getCapCode(), request.getxPos()); Boolean recordData = authCodeService.validateJigsawCode(req, request);
// 发送短信验证码 // 发送短信验证码
processSysCode(request.getMobile(), request.getFlag()); processSysCode(request.getMobile(), request.getFlag());
// TODO 记录风控数据(记录是h5端) if (recordData) {
// 记录风控数据(记录是h5端)
authCodeService.recordRcData(req, request, super.getDeviceInfo("device_ip")); authCodeService.recordRcData(req, request, super.getDeviceInfo("device_ip"));
}
return PicaResponse.toResponse(); return PicaResponse.toResponse();
} }
...@@ -165,6 +169,7 @@ public class AutoCodeController extends AccountBaseController { ...@@ -165,6 +169,7 @@ public class AutoCodeController extends AccountBaseController {
public PicaResponse<String> getAuthCodeWithCaptcha(@RequestBody EncryptEntity entity, public PicaResponse<String> getAuthCodeWithCaptcha(@RequestBody EncryptEntity entity,
HttpServletRequest req) throws Exception { HttpServletRequest req) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class); BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
request.setSourceType(super.getSourceType());
String mobilePhone = request.getMobile(); String mobilePhone = request.getMobile();
String flag = request.getFlag() + ""; String flag = request.getFlag() + "";
String captchaToken = request.getCaptchaToken(); String captchaToken = request.getCaptchaToken();
...@@ -198,7 +203,7 @@ public class AutoCodeController extends AccountBaseController { ...@@ -198,7 +203,7 @@ public class AutoCodeController extends AccountBaseController {
public PicaResponse getJigsawCode(@RequestBody EncryptEntity entity, public PicaResponse getJigsawCode(@RequestBody EncryptEntity entity,
HttpServletRequest req) throws Exception { HttpServletRequest req) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class); BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
return PicaResponse.toResponse(authCodeService.validateJigsawCode(request.getMobile())); return PicaResponse.toResponse(authCodeService.getJigsawCode(req, super.getSourceType(), request.getMobile()));
} }
@ApiOperation("微信获取验证码") @ApiOperation("微信获取验证码")
......
...@@ -16,13 +16,13 @@ import javax.servlet.http.HttpServletRequest; ...@@ -16,13 +16,13 @@ import javax.servlet.http.HttpServletRequest;
*/ */
public interface AuthCodeService { public interface AuthCodeService {
void rcValidate(HttpServletRequest request, BaseRequest baseRequest, String deviceInfoStr); Boolean rcValidate(HttpServletRequest request, BaseRequest baseRequest, String deviceInfoStr, Integer sourceType);
void recordRcData(HttpServletRequest req, BaseRequest baseRequest, String deviceIp); void recordRcData(HttpServletRequest req, BaseRequest baseRequest, String deviceIp);
void validateJigsawCode(String mobile, String capCode, int xPos); Boolean validateJigsawCode(HttpServletRequest request, BaseRequest req);
JigsawCodeModel validateJigsawCode(String mobile); JigsawCodeModel getJigsawCode(HttpServletRequest request, Integer sourceType, String mobile);
} }
...@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.constants.Constants; import com.pica.cloud.account.account.server.constants.Constants;
import com.pica.cloud.account.account.server.enums.AccountExceptionEnum; import com.pica.cloud.account.account.server.enums.AccountExceptionEnum;
import com.pica.cloud.account.account.server.enums.RcRepTypeEnum; import com.pica.cloud.account.account.server.enums.RcRepTypeEnum;
import com.pica.cloud.account.account.server.enums.SourceTypeEnum;
import com.pica.cloud.account.account.server.req.BaseRequest; import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.model.JigsawCodeModel; import com.pica.cloud.account.account.server.model.JigsawCodeModel;
import com.pica.cloud.account.account.server.service.AuthCodeService; import com.pica.cloud.account.account.server.service.AuthCodeService;
...@@ -69,7 +70,8 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -69,7 +70,8 @@ public class AuthCodeServiceImpl implements AuthCodeService {
* @Return com.pica.cloud.account.account.server.resp.UnifiedVerificationResp * @Return com.pica.cloud.account.account.server.resp.UnifiedVerificationResp
*/ */
@Override @Override
public void rcValidate(HttpServletRequest request, BaseRequest baseRequest, String deviceInfoStr) { public Boolean rcValidate(HttpServletRequest request, BaseRequest baseRequest, String deviceInfoStr, Integer sourceType) {
Boolean need = true;
// 调用风控接口 // 调用风控接口
PicaResponse picaResponse = null; PicaResponse picaResponse = null;
try { try {
...@@ -81,6 +83,7 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -81,6 +83,7 @@ public class AuthCodeServiceImpl implements AuthCodeService {
rcReq.setIp(publicIp); rcReq.setIp(publicIp);
rcReq.setDeviceIp(deviceInfo.getDevice_ip()); rcReq.setDeviceIp(deviceInfo.getDevice_ip());
rcReq.setDeviceId(deviceToken); rcReq.setDeviceId(deviceToken);
rcReq.setSourceType(sourceType);
logger.info("rc-checkcodeRisk-req:{}", JSON.toJSONString(rcReq)); logger.info("rc-checkcodeRisk-req:{}", JSON.toJSONString(rcReq));
picaResponse = rcClient.checkcodeRisk(rcReq); picaResponse = rcClient.checkcodeRisk(rcReq);
logger.info("rc-checkcodeRisk-resp:{}", JSON.toJSONString(picaResponse)); logger.info("rc-checkcodeRisk-resp:{}", JSON.toJSONString(picaResponse));
...@@ -104,8 +107,12 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -104,8 +107,12 @@ public class AuthCodeServiceImpl implements AuthCodeService {
throw new PicaWarnException(AccountExceptionEnum.PICA_RC_SEND_FAIL.getCode(), throw new PicaWarnException(AccountExceptionEnum.PICA_RC_SEND_FAIL.getCode(),
AccountExceptionEnum.PICA_RC_SEND_FAIL.getMessage()); AccountExceptionEnum.PICA_RC_SEND_FAIL.getMessage());
} else if (processCode.equals(RcRepTypeEnum.RC_TRIGGER.getCode())) { } else if (processCode.equals(RcRepTypeEnum.RC_TRIGGER.getCode())) {
if(SourceTypeEnum.H5.getCode().equals(sourceType)) {
// h5端需要触发拼图验证,后台去获取拼图数据返给前端
} else {
throw new PicaWarnException(AccountExceptionEnum.PICA_RC_TRIGGER.getCode(), throw new PicaWarnException(AccountExceptionEnum.PICA_RC_TRIGGER.getCode(),
AccountExceptionEnum.PICA_RC_TRIGGER.getMessage()); AccountExceptionEnum.PICA_RC_TRIGGER.getMessage());
}
} else if (processCode.equals(RcRepTypeEnum.RC_BLACKLIST.getCode())) { } else if (processCode.equals(RcRepTypeEnum.RC_BLACKLIST.getCode())) {
throw new PicaWarnException(AccountExceptionEnum.PICA_RC_BLACKLIST.getCode(), throw new PicaWarnException(AccountExceptionEnum.PICA_RC_BLACKLIST.getCode(),
AccountExceptionEnum.PICA_RC_BLACKLIST.getMessage()); AccountExceptionEnum.PICA_RC_BLACKLIST.getMessage());
...@@ -124,15 +131,18 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -124,15 +131,18 @@ public class AuthCodeServiceImpl implements AuthCodeService {
} }
} else { } else {
// 刚好60秒缓存时间过去了,也允许发送短信验证码 // 刚好60秒缓存时间过去了,也允许发送短信验证码
need = false;
} }
} else { } else {
// processCode equals "1" (允许发送短信验证码) // processCode equals "1" (允许发送短信验证码)
need = false;
} }
} }
} }
} }
} }
return need;
} }
/** /**
...@@ -150,6 +160,7 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -150,6 +160,7 @@ public class AuthCodeServiceImpl implements AuthCodeService {
rec.setIp(IPUtil.getIpAdrress(request)); rec.setIp(IPUtil.getIpAdrress(request));
rec.setDeviceIp(deviceIp); rec.setDeviceIp(deviceIp);
rec.setDeviceId(baseRequest.getDevice_token()); rec.setDeviceId(baseRequest.getDevice_token());
rec.setSourceType(baseRequest.getSourceType());
try { try {
threadPoolTaskExecutor.execute(() -> { threadPoolTaskExecutor.execute(() -> {
logger.info("recordRcData-execute-{}", JSON.toJSONString(rec)); logger.info("recordRcData-execute-{}", JSON.toJSONString(rec));
...@@ -170,17 +181,39 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -170,17 +181,39 @@ public class AuthCodeServiceImpl implements AuthCodeService {
* @Return void * @Return void
*/ */
@Override @Override
public void validateJigsawCode(String mobile, String capCode, int xPos) { public Boolean validateJigsawCode(HttpServletRequest request, BaseRequest paramReq) {
// 调用风控服务,是否需要触发拼图验证 Boolean recordData = false;
Boolean need = this.judgeNeedJigsaw(mobile); if(!SourceTypeEnum.H5.getCode().equals(paramReq.getSourceType())) {
Boolean paramValid = StringUtils.isNotEmpty(capCode) && xPos > 0; logger.error("validateJigsawCode-h5 sourceType error");
if (!need && !paramValid) { throw new PicaWarnException(PicaResultCode.PARAM_IS_INVALID.code(), PicaResultCode.PARAM_IS_INVALID.message());
return;
} }
// 调用风控服务,是否需要触发拼图验证
String capCode = paramReq.getCapCode();
int xPos = paramReq.getxPos();
if (!paramValid) { BaseRequest rcReq = new BaseRequest();
throw new PicaWarnException(PicaResultCode.PARAM_IS_INVALID.code(), PicaResultCode.PARAM_IS_INVALID.message()); rcReq.setMobile(paramReq.getMobile());
Boolean need = this.rcValidate(request, rcReq, "{}", paramReq.getSourceType());
if (!need) {
recordData = true;
return recordData;
} }
String key = Constants.JIGSAW_CODE_KEY.replace("{mobile}", paramReq.getMobile());
if (StringUtils.isEmpty(capCode) || xPos <= 0) {
Long count = cacheClient.decr(key);
logger.info("validateJigsawCode-count:{}", count);
if (count.equals(99)) {
// 上一次拼图验证通过时设置的值是100,这一次直接去发送短信验证码
cacheClient.del(key);
recordData = true;
return recordData;
} else {
logger.error("validateJigsawCode-abnormal request, jigsaw code cache not correct");
throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_CODE_ERROR.getCode(),
AccountExceptionEnum.PICA_CAP_CODE_ERROR.getMessage());
}
}
PicaResponse resp = null; PicaResponse resp = null;
try { try {
SliderImageRequest req = new SliderImageRequest(); SliderImageRequest req = new SliderImageRequest();
...@@ -190,16 +223,16 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -190,16 +223,16 @@ public class AuthCodeServiceImpl implements AuthCodeService {
logger.info("validateJigsawCode-resp:{}", JSON.toJSONString(resp)); logger.info("validateJigsawCode-resp:{}", JSON.toJSONString(resp));
} catch (Exception e) { } catch (Exception e) {
logger.error("validateJigsawCode-sliderImageService.checkcapcode invoke exception", e.getMessage()); logger.error("validateJigsawCode-sliderImageService.checkcapcode invoke exception", e.getMessage());
throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_CODE_ERROR.getCode(), /*throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_CODE_ERROR.getCode(),
AccountExceptionEnum.PICA_CAP_CODE_ERROR.getMessage()); AccountExceptionEnum.PICA_CAP_CODE_ERROR.getMessage());*/
} }
String code = "2"; String code = "2";
if (Objects.nonNull(resp)) { if (Objects.nonNull(resp)) {
if (!PicaResultCode.SUCCESS.code().equals(resp.getCode())) { if (!PicaResultCode.SUCCESS.code().equals(resp.getCode())) {
logger.info("validateJigsawCode-code exception"); logger.info("validateJigsawCode-code exception");
throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_CODE_ERROR.getCode(), /*throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_CODE_ERROR.getCode(),
AccountExceptionEnum.PICA_CAP_CODE_ERROR.getMessage()); AccountExceptionEnum.PICA_CAP_CODE_ERROR.getMessage());*/
} }
JSONObject respData = JSON.parseObject(JSON.toJSONString(resp.getData()), JSONObject.class); JSONObject respData = JSON.parseObject(JSON.toJSONString(resp.getData()), JSONObject.class);
if (Objects.nonNull(respData)) { if (Objects.nonNull(respData)) {
...@@ -215,6 +248,9 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -215,6 +248,9 @@ public class AuthCodeServiceImpl implements AuthCodeService {
throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_CODE_ERROR.getCode(), throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_CODE_ERROR.getCode(),
AccountExceptionEnum.PICA_CAP_CODE_ERROR.getMessage()); AccountExceptionEnum.PICA_CAP_CODE_ERROR.getMessage());
} }
// 拼图验证通过
cacheClient.set(key, 100, Constants.JIGSAW_CODE_EXPIRE_SECONDS);
return recordData;
} }
/** /**
...@@ -226,10 +262,16 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -226,10 +262,16 @@ public class AuthCodeServiceImpl implements AuthCodeService {
* @Return com.pica.cloud.account.account.server.model.JigsawCodeModel * @Return com.pica.cloud.account.account.server.model.JigsawCodeModel
*/ */
@Override @Override
public JigsawCodeModel validateJigsawCode(String mobile) { public JigsawCodeModel getJigsawCode(HttpServletRequest request, Integer sourceType, String mobile) {
logger.info("getJigsawCode-mobile:{}", mobile); logger.info("getJigsawCode-mobile:{}, sourceType:{}", mobile, sourceType);
if(!SourceTypeEnum.H5.getCode().equals(sourceType)) {
logger.error("getJigsawCode-h5 sourceType error");
throw new PicaWarnException(PicaResultCode.PARAM_IS_INVALID.code(), PicaResultCode.PARAM_IS_INVALID.message());
}
// 调用风控服务,是否需要触发拼图验证 // 调用风控服务,是否需要触发拼图验证
Boolean need = this.judgeNeedJigsaw(mobile); BaseRequest req = new BaseRequest();
req.setMobile(mobile);
Boolean need = this.rcValidate(request, req, "{}", sourceType);
// 调用proof服务获取拼图数据 // 调用proof服务获取拼图数据
JigsawCodeModel data = new JigsawCodeModel(); JigsawCodeModel data = new JigsawCodeModel();
...@@ -240,14 +282,14 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -240,14 +282,14 @@ public class AuthCodeServiceImpl implements AuthCodeService {
logger.info("getJigsawCode-getPic-code:{}", picResp.getCode()); logger.info("getJigsawCode-getPic-code:{}", picResp.getCode());
} catch (Exception e) { } catch (Exception e) {
logger.error("getJigsawCode-sliderImageService.getPic invoke exception", e.getMessage()); logger.error("getJigsawCode-sliderImageService.getPic invoke exception", e.getMessage());
throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_GET_INVOKE_ERROR.getCode(), /*throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_GET_INVOKE_ERROR.getCode(),
AccountExceptionEnum.PICA_CAP_GET_INVOKE_ERROR.getMessage()); AccountExceptionEnum.PICA_CAP_GET_INVOKE_ERROR.getMessage());*/
} }
if (Objects.nonNull(picResp)) { if (Objects.nonNull(picResp)) {
if (!PicaResultCode.SUCCESS.code().equals(picResp.getCode())) { if (!PicaResultCode.SUCCESS.code().equals(picResp.getCode())) {
logger.info("getJigsawCode-getPic-code exception"); logger.info("getJigsawCode-getPic-code exception");
throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_GET_INVOKE_ERROR.getCode(), /*throw new PicaWarnException(AccountExceptionEnum.PICA_CAP_GET_INVOKE_ERROR.getCode(),
AccountExceptionEnum.PICA_CAP_GET_INVOKE_ERROR.getMessage()); AccountExceptionEnum.PICA_CAP_GET_INVOKE_ERROR.getMessage());*/
} }
JSONObject respData = JSON.parseObject(JSON.toJSONString(picResp.getData()), JSONObject.class); JSONObject respData = JSON.parseObject(JSON.toJSONString(picResp.getData()), JSONObject.class);
if (Objects.nonNull(respData)) { if (Objects.nonNull(respData)) {
...@@ -262,26 +304,5 @@ public class AuthCodeServiceImpl implements AuthCodeService { ...@@ -262,26 +304,5 @@ public class AuthCodeServiceImpl implements AuthCodeService {
return data; return data;
} }
/**
* @Description 调用风控服务,是否需要触发拼图验证
* @Author Chongwen.jiang
* @Date 2020/3/23 16:01
* @ModifyDate 2020/3/23 16:01
* @Params [mobile]
* @Return java.lang.Boolean true:需要触发拼图验证 false:不需要
*/
private Boolean judgeNeedJigsaw(String mobile) {
Boolean need = true;
try {
// TODO 调用风控服务,是否需要触发拼图验证
// rcClient.
} catch (Exception e) {
logger.error("judgeNeedJigsaw-client invoke exception", e.getMessage());
throw new PicaWarnException(PicaResultCode.INTERFACE_INVOKE_ERROR.code(),
PicaResultCode.INTERFACE_INVOKE_ERROR.message());
}
return need;
}
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册