提交 0f7347cd 编写于 作者: Chongwen.jiang's avatar Chongwen.jiang

发送短信加入老业务记录风控数据接口

上级 e5e47c5e
流水线 #22157 已失败 于阶段
in 3 second
......@@ -167,7 +167,7 @@
<dependency>
<groupId>com.pica.cloud.riskcontrol</groupId>
<artifactId>pica-cloud-riskcontrol-client</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
<!-- apple identifyToken校验 -->
......
package com.pica.cloud.account.account.server.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @Description ThreadPoolConfig
* @Author Chongwen.jiang
* @Date 2020/2/27 16:37
* @ModifyDate 2020/2/27 16:37
* @Params
* @Return
*/
@Configuration
public class ThreadPoolConfig {
@Bean(name = "accountThreadPool")
public ThreadPoolTaskExecutor getExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(3);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(100);
executor.setKeepAliveSeconds(60);
executor.setThreadNamePrefix("tims_ThreadPool");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
return executor;
}
}
package com.pica.cloud.account.account.server.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.entity.AccountUnionEntity;
import com.pica.cloud.account.account.server.entity.EncryptEntity;
import com.pica.cloud.account.account.server.enums.AccountExceptionEnum;
import com.pica.cloud.account.account.server.enums.AccountTypeEnum;
import com.pica.cloud.account.account.server.enums.BizTypeRespEnum;
import com.pica.cloud.account.account.server.exception.AccountException;
import com.pica.cloud.account.account.server.mapper.AccountInfoDetailMapper;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.resp.UnifiedVerificationResp;
import com.pica.cloud.account.account.server.service.AccountService;
......@@ -31,6 +29,8 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -60,6 +60,10 @@ public class AutoCodeController extends AccountBaseController {
@Autowired
private CheckCodeClient rcClient;
@Autowired
@Qualifier("accountThreadPool")
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@GetMapping("/ip")
public PicaResponse getIp(HttpServletRequest request){
return PicaResponse.toResponse(IPUtil.getIpAdrress(request));
......@@ -72,7 +76,7 @@ public class AutoCodeController extends AccountBaseController {
// 验证码类型 0默认 1注册 2微信登录绑定手机 3修改手机
// 4重置密码 5忘记密码 7患者招募提交问卷(效验) 8Appe登录绑定手机
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
AccountUtils.checkMobilePhone(request.getMobile());
if (request.getBizType() != null && request.getBizType().equals(1)) {
// 调用风控接口
UnifiedVerificationResp rcResp = this.rcValidate(
......@@ -83,13 +87,11 @@ public class AutoCodeController extends AccountBaseController {
request.getDevice_token());
if (rcResp == null) {
// 风控接口调用异常也继续后面的逻辑
processSysCode(request.getMobile(), request.getFlag());
return PicaResponse.toResponse();
return getPicaResponse(request);
} else {
if (null == rcResp.getBizCode()) {
// 风控校验后允许发送短信验证码
processSysCode(request.getMobile(), request.getFlag());
return PicaResponse.toResponse();
return getPicaResponse(request);
} else {
// 风控接口调用正常,并返回业务提示给前端
return PicaResponse.toResponse(rcResp);
......@@ -97,14 +99,26 @@ public class AutoCodeController extends AccountBaseController {
}
} else {
// 老版本业务
AccountUtils.checkMobilePhone(request.getMobile());
processSysCode(request.getMobile(), request.getFlag());
// 记录风控数据
recordRcData(req, request);
return PicaResponse.toResponse();
}
}
private PicaResponse getPicaResponse(BaseRequest request) {
processSysCode(request.getMobile(), request.getFlag());
UnifiedVerificationResp rcResp = new UnifiedVerificationResp();
rcResp.setBizCode(1);
rcResp.setBizMsg("验证码发送成功");
return PicaResponse.toResponse(rcResp);
}
@ApiOperation("获取短信验证码,需要图形验证码,如H5端和PC端;验证码类型 0默认 1注册 2微信登录绑定手机 3修改手机 4重置密码 5忘记密码 7患者招募提交问卷(效验)")
@PostMapping("/account/authCode")
public PicaResponse<String> getAuthCodeWithCaptcha(@RequestBody EncryptEntity entity) throws Exception {
public PicaResponse<String> getAuthCodeWithCaptcha(@RequestBody EncryptEntity entity,
HttpServletRequest req) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
String mobilePhone = request.getMobile();
String flag = request.getFlag() + "";
......@@ -127,9 +141,33 @@ public class AutoCodeController extends AccountBaseController {
logger.info(this.getAuthCodeKey(mobilePhone, flag));
//发送短信
super.sendMobileMessage(mobilePhone, message, senderId);
// 记录风控数据
recordRcData(req, request);
return PicaResponse.toResponse(StringUtils.EMPTY);
}
/**
* @Description 记录风控数据
* @Author Chongwen.jiang
* @Date 2020/2/27 16:53
* @ModifyDate 2020/2/27 16:53
* @Params [req, request]
* @Return void
*/
private void recordRcData(HttpServletRequest req, BaseRequest request) {
threadPoolTaskExecutor.execute(() -> {
CheckcodeRiskReq rec = new CheckcodeRiskReq();
rec.setMobile(request.getMobile());
rec.setIp(IPUtil.getIpAdrress(req));
rec.setDeviceIp(super.getDeviceInfo("device_ip"));
rec.setDeviceId(request.getDevice_token());
PicaResponse resp = rcClient.logSend(rec);
logger.info("thread execute-app-authCode resp-{}", JSON.toJSONString(resp));
});
}
@ApiOperation("微信获取验证码")
@PostMapping(value = "/authCode/wechat")
public PicaResponse getWChatSysCode(@RequestBody EncryptEntity entity) throws Exception {
......
......@@ -662,8 +662,8 @@ public class LoginServiceImpl implements LoginService {
appleResp = HttpClientCloudUtils.getHttpExecute(Constants.APPLE_GET_PUBLIC_KEY_URL);
//logger.info("checkIdentifyToken-appleResp:{}", appleResp);
} catch (Exception e) {
logger.info("checkIdentifyToken-get apple public key fail");
throw new PicaException("get apple public key fail Exception", e.getMessage());
logger.info("checkIdentifyToken-get apple public key fail " + e.getMessage());
throw new PicaException("get apple public key fail Exception", "get apple public key fail");
}
JSONObject jsonObject = JSONObject.parseObject(appleResp);
String keys = jsonObject.getString("keys");
......@@ -677,7 +677,8 @@ public class LoginServiceImpl implements LoginService {
Jwk jwa = Jwk.fromValues(jsonObject1);
publicKey = jwa.getPublicKey();
} catch (Exception e) {
throw new PicaException("checkIdentifyToken-generate publicKey fail", e.getMessage());
logger.info("checkIdentifyToken-generate publicKey fail " + e.getMessage());
throw new PicaException("checkIdentifyToken-generate publicKey fail", "generate publicKey fail");
}
// 分割前台传过来的identifyToken(jwt格式的token)用base64解码使用
if (identifyToken.split("\\.").length > 1) {
......@@ -691,8 +692,8 @@ public class LoginServiceImpl implements LoginService {
// appleUserId从token中解码取出后赋值
request.setAppleUserId(sub);
} catch (Exception e) {
logger.info("checkIdentifyToken-token decode fail" + e.getMessage());
throw new PicaException("checkIdentifyToken-token decode fail Exception", e.getMessage());
logger.info("checkIdentifyToken-token decode fail " + e.getMessage());
throw new PicaException("checkIdentifyToken-token decode fail Exception", "token decode fail");
}
return this.verify(publicKey, identifyToken, aud, sub, request);
}
......@@ -725,11 +726,11 @@ public class LoginServiceImpl implements LoginService {
}
return false;
} catch (ExpiredJwtException e) {
logger.info("checkIdentifyToken-apple token expired" + e.getMessage());
throw new PicaException("apple token expired Exception", e.getMessage());
logger.info("checkIdentifyToken-apple token expired " + e.getMessage());
throw new PicaException("apple token expired Exception", "apple token expired");
} catch (Exception e) {
logger.info("checkIdentifyToken-apple token illegal" + e.getMessage());
throw new PicaException("apple token illegal Exception", e.getMessage());
logger.info("checkIdentifyToken-apple token illegal " + e.getMessage());
throw new PicaException("apple token illegal Exception", "apple token illegal");
}
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册