|
|
@@ -3,11 +3,14 @@ package com.cyksj.service.user.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.EnvCommonService;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.common.snowflake.Sequence;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.mapper.UserCertRecordMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
+import com.cyksj.model.dto.UserWxIndentDto;
|
|
|
import com.cyksj.model.entity.User;
|
|
|
import com.cyksj.model.entity.UserCertRecord;
|
|
|
import com.cyksj.model.request.UserBindInfoReq;
|
|
|
@@ -48,12 +51,18 @@ public class UserIdentCertServiceImpl implements UserIdentCertService {
|
|
|
|
|
|
private final RedisService redisService;
|
|
|
|
|
|
+ private final EnvCommonService envCommonService;
|
|
|
+
|
|
|
+ private final static Sequence SEQUENCE = new Sequence(0);
|
|
|
+
|
|
|
private static final String TENCENT_SECRET_ID = "AKIDBB3jEqR0Y95zpfTix1vd6fMqAIahc4Ka";
|
|
|
|
|
|
private static final String TENCENT_SECRET_KEY = "c6YtNm63rcQ1QdiGmEbmEPSTPF3e4KQK";
|
|
|
|
|
|
private static final String ruleId = "1";
|
|
|
|
|
|
+ private static final String REDIRECT_URL = "applets/user/cert/auth/result/";
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean checkCertRecord(long userId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
@@ -130,7 +139,8 @@ public class UserIdentCertServiceImpl implements UserIdentCertService {
|
|
|
// 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
DetectAuthRequest req = new DetectAuthRequest();
|
|
|
req.setRuleId(ruleId);
|
|
|
- req.setRedirectUrl(redirectUrl);
|
|
|
+ Long mappingId = SEQUENCE.nextId();
|
|
|
+ req.setRedirectUrl(envCommonService.getHost() + REDIRECT_URL + mappingId);
|
|
|
// 返回的resp是一个DetectAuthResponse的实例,与请求对象对应
|
|
|
DetectAuthResponse resp = client.DetectAuth(req);
|
|
|
|
|
|
@@ -138,11 +148,18 @@ public class UserIdentCertServiceImpl implements UserIdentCertService {
|
|
|
|
|
|
WxCertAuthTokenResp tokenResp = new WxCertAuthTokenResp();
|
|
|
BeanUtil.copyProperties(resp, tokenResp);
|
|
|
+
|
|
|
+ UserWxIndentDto userWxIndentDto = new UserWxIndentDto();
|
|
|
+ userWxIndentDto.setUserId(userId);
|
|
|
+ userWxIndentDto.setRedirectUrl(redirectUrl);
|
|
|
+ userWxIndentDto.setBizToken(tokenResp.getBizToken());
|
|
|
+ redisService.set(mappingId.toString(), Jsons.toJson(userWxIndentDto), 60 * 60 * 24L);
|
|
|
return tokenResp;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean wxH5IndentCertResult(Long userId, String bizToken) throws Exception {
|
|
|
+ public void wxH5IndentCertResult(UserWxIndentDto userWxIndentDto) throws Exception {
|
|
|
+ Long userId = userWxIndentDto.getUserId();
|
|
|
Credential cred = new Credential(TENCENT_SECRET_ID, TENCENT_SECRET_KEY);
|
|
|
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
HttpProfile httpProfile = new HttpProfile();
|
|
|
@@ -154,19 +171,17 @@ public class UserIdentCertServiceImpl implements UserIdentCertService {
|
|
|
FaceidClient client = new FaceidClient(cred, "", clientProfile);
|
|
|
// 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
GetDetectInfoEnhancedRequest req = new GetDetectInfoEnhancedRequest();
|
|
|
- req.setBizToken(bizToken);
|
|
|
+ req.setBizToken(userWxIndentDto.getBizToken());
|
|
|
req.setRuleId(ruleId);
|
|
|
// 返回的resp是一个GetDetectInfoEnhancedResponse的实例,与请求对象对应
|
|
|
GetDetectInfoEnhancedResponse resp = client.GetDetectInfoEnhanced(req);
|
|
|
DetectInfoText text = resp.getText();
|
|
|
- Boolean flag = false;
|
|
|
if (text.getErrCode() == 0) {
|
|
|
UserCertRecord certRecord = new UserCertRecord();
|
|
|
String ocrIdCard = text.getOcrIdCard();
|
|
|
Integer count = userCertRecordMapper.selectCount(Wrappers.lambdaQuery(UserCertRecord.class)
|
|
|
.eq(UserCertRecord::getIdent, ocrIdCard));
|
|
|
if (count == 0) {
|
|
|
- flag = true;
|
|
|
certRecord.setIdent(text.getOcrIdCard());
|
|
|
certRecord.setName(text.getOcrName());
|
|
|
certRecord.setSex(text.getOcrGender());
|
|
|
@@ -175,6 +190,5 @@ public class UserIdentCertServiceImpl implements UserIdentCertService {
|
|
|
userCertRecordMapper.insert(certRecord);
|
|
|
}
|
|
|
}
|
|
|
- return flag;
|
|
|
}
|
|
|
}
|