|
@@ -1,9 +1,19 @@
|
|
|
package com.leromro.core.controller;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.leromro.common.config.RuoYiConfig;
|
|
|
+import com.leromro.common.core.controller.BaseController;
|
|
|
import com.leromro.common.core.domain.R;
|
|
|
+import com.leromro.common.core.domain.entity.SysUser;
|
|
|
import com.leromro.common.utils.EIDUtil;
|
|
|
+import com.leromro.common.utils.file.ImageUtils;
|
|
|
+import com.leromro.core.service.IVolunteerFaceRecordService;
|
|
|
+import com.leromro.system.service.ISysUserService;
|
|
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
|
import com.tencentcloudapi.common.Credential;
|
|
|
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
|
|
@@ -11,6 +21,9 @@ import com.tencentcloudapi.faceid.v20180301.models.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.x.file.storage.core.FileInfo;
|
|
|
+import org.dromara.x.file.storage.core.FileStorageService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
@@ -22,12 +35,18 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
@RestController
|
|
|
@Api(tags = "腾讯人脸核身")
|
|
|
@RequestMapping({"/face"})
|
|
|
-public class TencentFaceController {
|
|
|
+public class TencentFaceController extends BaseController {
|
|
|
|
|
|
private static final String SECRET_ID = "AKIDkPr57wb6Peiu02zoW3RhmEUXNzOaaNwI"; // TODO 您账号的腾讯云密钥
|
|
|
private static final String SECRET_KEY = "D2d1EE0Zv4zhCTWLyOaYKtELSRDpE2qb"; // TODO 您账号的腾讯云密钥
|
|
|
private static final String REGION = "ap-chongqing";
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FileStorageService fileStorageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService systemUserService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取token
|
|
|
* @return
|
|
@@ -63,6 +82,8 @@ public class TencentFaceController {
|
|
|
@GetMapping("/getEidResult")
|
|
|
@ApiOperation(value = "获取人脸核身结果", notes = "获取人脸核身结果")
|
|
|
public R<String> getEidResult(String eidToken) {
|
|
|
+ // 初始化修改信息
|
|
|
+ LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<SysUser>().eq(SysUser::getUserId, getUserId());
|
|
|
// Step 1. 初始化客户端实例
|
|
|
Credential credential = new Credential(SECRET_ID, SECRET_KEY);
|
|
|
FaceidClient faceidClient = new FaceidClient(credential, REGION);
|
|
@@ -84,16 +105,45 @@ public class TencentFaceController {
|
|
|
// 调用EIDUtil解密用户信息
|
|
|
byte[] b = EIDUtil.decodeUserInfo(PrivateKeyHex, DesKey, UserInfo);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(new String(b));
|
|
|
- String name = jsonObject.getString("name"); // 王文龙
|
|
|
+ String name = jsonObject.getString("name");
|
|
|
String idNum = jsonObject.getString("idnum");
|
|
|
+ if (StrUtil.isBlank(idNum) || StrUtil.isBlank(name)){
|
|
|
+ throw new Exception("身份证姓名信息解析错误");
|
|
|
+ }
|
|
|
+ updateWrapper.set(SysUser::getName, name).set(SysUser::getIdCard, idNum);
|
|
|
+ String OcrFront = RuoYiConfig.getUploadPath()+"/face/"+ IdUtil.getSnowflakeNextIdStr() +".jpg";
|
|
|
+ String OcrBack = RuoYiConfig.getUploadPath()+"/face/"+ IdUtil.getSnowflakeNextIdStr() +".jpg";
|
|
|
+ String facePicture = RuoYiConfig.getUploadPath()+"/face/"+ IdUtil.getSnowflakeNextIdStr() +".jpg";
|
|
|
+ //提取身份证人像面
|
|
|
+ ImageUtils.base64ToImage(response.getIdCardData().getOcrFront(), OcrFront);
|
|
|
+ if (StrUtil.isNotBlank(OcrFront)){
|
|
|
+ FileInfo fileInfo = fileStorageService.of(OcrFront).upload();
|
|
|
+ updateWrapper.set(SysUser::getIdCardPictureFront, fileInfo.getUrl());
|
|
|
+ }
|
|
|
+ //提取身份证国徽面
|
|
|
+ ImageUtils.base64ToImage(response.getIdCardData().getOcrBack(), OcrBack);
|
|
|
+ if (StrUtil.isNotBlank(OcrBack)){
|
|
|
+ FileInfo fileInfo = fileStorageService.of(OcrBack).upload();
|
|
|
+ updateWrapper.set(SysUser::getIdCardPictureBack, fileInfo.getUrl());
|
|
|
+ }
|
|
|
+ //提取人脸照片
|
|
|
+ ImageUtils.base64ToImage(response.getBestFrame().getBestFrame(), facePicture);
|
|
|
+ if (StrUtil.isNotBlank(facePicture)){
|
|
|
+ FileInfo fileInfo = fileStorageService.of(facePicture).upload();
|
|
|
+ updateWrapper.set(SysUser::getFacePicture, fileInfo.getUrl());
|
|
|
+ }
|
|
|
+ //保存
|
|
|
+ updateWrapper.set(SysUser::getIsFaceApprove, 1);
|
|
|
+ systemUserService.update(updateWrapper);
|
|
|
return R.ok("校验成功");
|
|
|
} catch (TencentCloudSDKException e) {
|
|
|
// 调用接口异常在这里处理
|
|
|
System.err.println("invoke error, code: " + e.getErrorCode() + "message: " + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
+ return R.fail("人脸认证失败:"+e.getMessage());
|
|
|
} catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
+ return R.fail("人脸认证失败:"+e.getMessage());
|
|
|
}
|
|
|
- return R.fail("人脸认证失败");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|