Browse Source

fix 人脸

he2802 3 years ago
parent
commit
e63c567e76

+ 41 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/face/FaceController.java

@@ -0,0 +1,41 @@
+package com.zhongzheng.controller.face;
+
+import com.zhongzheng.common.core.controller.BaseController;
+import com.zhongzheng.common.core.domain.AjaxResult;
+import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.framework.web.service.WxTokenService;
+import com.zhongzheng.modules.tencentcloud.service.IFaceService;
+import com.zhongzheng.modules.user.entity.ClientLoginUser;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+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;
+
+/**
+ * 人脸核身Controller
+ *
+ * @author hjl
+ * @date 2021-06-18
+ */
+@Api(value = "人脸核身", tags = {"人脸核身"})
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@RestController
+@RequestMapping("/face")
+public class FaceController extends BaseController {
+
+    private final IFaceService iFaceService;
+
+    private final WxTokenService wxTokenService;
+
+
+    @ApiOperation("人脸匹配")
+    @GetMapping("/certification/CompareFace")
+    public AjaxResult CompareFace() throws Exception {
+        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        iFaceService.CompareFace("",loginUser.getUser().getUserId());
+        return AjaxResult.success();
+    }
+}

+ 0 - 68
zhongzheng-api/src/main/java/com/zhongzheng/controller/face/FaceController.java

@@ -1,68 +0,0 @@
-package com.zhongzheng.controller.face;
-
-import com.zhongzheng.common.core.controller.BaseController;
-import com.zhongzheng.common.core.domain.AjaxResult;
-import com.zhongzheng.common.utils.ServletUtils;
-import com.zhongzheng.framework.web.service.WxTokenService;
-import com.zhongzheng.modules.face.bo.FaceVo;
-import com.zhongzheng.modules.face.service.IFaceService;
-import com.zhongzheng.modules.polyv.service.IPolyvVideoService;
-import com.zhongzheng.modules.user.entity.ClientLoginUser;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import lombok.RequiredArgsConstructor;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.Map;
-
-/**
- * 人脸核身Controller
- *
- * @author hjl
- * @date 2021-06-18
- */
-@Api(value = "人脸核身", tags = {"人脸核身"})
-@RequiredArgsConstructor(onConstructor_ = @Autowired)
-@RestController
-@RequestMapping("/face")
-public class FaceController extends BaseController {
-
-    private final IFaceService iFaceService;
-
-    private final WxTokenService wxTokenService;
-
-    @ApiOperation("获取识别凭证")
-    @GetMapping("/certification/BizToken")
-    public AjaxResult<FaceVo> getBizToken() throws Exception {
-        FaceVo face = iFaceService.getFaceDetectAuth("0");
-        return AjaxResult.success(face);
-    }
-
-    @ApiOperation("获取识别结果")
-    @GetMapping("/certification/DetectInfo/{bizToken}")
-    public AjaxResult getDetectInfo(@PathVariable("bizToken") String bizToken) throws Exception {
-        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
-        iFaceService.getDetectInfo(bizToken,loginUser.getUser().getUserId());
-        return AjaxResult.success();
-    }
-
-    @ApiOperation("获取人照识别凭证")
-    @GetMapping("/certification/PicBizToken")
-    public AjaxResult<FaceVo> getPicBizToken() throws Exception {
-        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
-        FaceVo face = iFaceService.getPicFaceDetectAuth("1",loginUser.getUser().getUserId());
-        return AjaxResult.success(face);
-    }
-
-    @ApiOperation("获取人照识别结果")
-    @GetMapping("/certification/PicDetectInfo/{bizToken}")
-    public AjaxResult<Integer> getPicDetectInfo(@PathVariable("bizToken") String bizToken) throws Exception {
-        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
-        Integer result = iFaceService.getPicDetectInfo(bizToken,loginUser.getUser().getUserId());
-        return AjaxResult.success(result);
-    }
-}

+ 1 - 1
zhongzheng-common/pom.xml

@@ -158,7 +158,7 @@
         <dependency>
             <groupId>com.tencentcloudapi</groupId>
             <artifactId>tencentcloud-sdk-java</artifactId>
-            <version>3.1.293</version>
+            <version>3.1.479</version>
         </dependency>
 
         <dependency>

+ 0 - 17
zhongzheng-system/src/main/java/com/zhongzheng/modules/face/bo/FaceVo.java

@@ -1,17 +0,0 @@
-package com.zhongzheng.modules.face.bo;
-
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.experimental.Accessors;
-
-@Data
-@NoArgsConstructor
-@Accessors(chain = true)
-public class FaceVo {
-
-    private String Url;
-
-    private String BizToken;
-
-    private String RequestId;
-}

+ 0 - 17
zhongzheng-system/src/main/java/com/zhongzheng/modules/face/domain/DetectAuth.java

@@ -1,17 +0,0 @@
-package com.zhongzheng.modules.face.domain;
-
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.experimental.Accessors;
-
-@Data
-@NoArgsConstructor
-@Accessors(chain = true)
-public class DetectAuth {
-
-    private String Url;
-
-    private String BizToken;
-
-    private String RequestId;
-}

+ 0 - 16
zhongzheng-system/src/main/java/com/zhongzheng/modules/face/service/IFaceService.java

@@ -1,16 +0,0 @@
-package com.zhongzheng.modules.face.service;
-
-
-import com.zhongzheng.modules.face.bo.FaceVo;
-
-public interface IFaceService {
-
-    FaceVo getFaceDetectAuth(String RuleId);
-
-    void getDetectInfo(String bizToken,Long userId);
-
-    FaceVo getPicFaceDetectAuth(String RuleId,Long userId);
-
-    Integer getPicDetectInfo(String bizToken,Long userId);
-
-}

+ 0 - 211
zhongzheng-system/src/main/java/com/zhongzheng/modules/face/service/impl/FaceServiceImpl.java

@@ -1,211 +0,0 @@
-package com.zhongzheng.modules.face.service.impl;
-
-
-import cn.hutool.core.bean.BeanUtil;
-import com.alibaba.fastjson.JSONObject;
-import com.tencentcloudapi.common.Credential;
-import com.tencentcloudapi.common.exception.TencentCloudSDKException;
-import com.tencentcloudapi.common.profile.ClientProfile;
-import com.tencentcloudapi.common.profile.HttpProfile;
-import com.tencentcloudapi.faceid.v20180301.FaceidClient;
-import com.tencentcloudapi.faceid.v20180301.models.*;
-import com.zhongzheng.common.utils.DateUtils;
-import com.zhongzheng.common.utils.file.ImageUtils;
-import com.zhongzheng.modules.alioss.service.OssService;
-import com.zhongzheng.modules.course.mapper.CourseMapper;
-import com.zhongzheng.modules.exam.domain.ExamArrangementGuide;
-import com.zhongzheng.modules.face.bo.FaceVo;
-import com.zhongzheng.modules.face.service.IFaceService;
-import com.zhongzheng.modules.user.bo.UserEditBo;
-import com.zhongzheng.modules.user.bo.UserOcrAddBo;
-import com.zhongzheng.modules.user.domain.User;
-import com.zhongzheng.modules.user.domain.UserOcr;
-import com.zhongzheng.modules.user.mapper.UserMapper;
-import com.zhongzheng.modules.user.service.IUserOcrService;
-import com.zhongzheng.modules.user.service.IUserService;
-import io.swagger.models.auth.In;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-import java.util.Map;
-
-@Service
-public class FaceServiceImpl implements IFaceService {
-
-    @Value("${tencent.cloud.SecretId}")
-    private String SecretId;
-
-    @Value("${tencent.cloud.SecretKey}")
-    private String SecretKey;
-
-    @Value("${aliyun.oss.endpoint}")
-    private String ossHost;
-
-    @Autowired
-    private OssService ossService;
-
-    @Autowired
-    private IUserOcrService iUserOcrService;
-
-    @Autowired
-    private UserMapper userMapper;
-
-
-
-    @Override
-    public FaceVo getFaceDetectAuth(String RuleId) {
-        try{
-            Credential cred = new Credential(SecretId, SecretKey);
-
-            HttpProfile httpProfile = new HttpProfile();
-            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
-            ClientProfile clientProfile = new ClientProfile();
-            clientProfile.setHttpProfile(httpProfile);
-            FaceidClient client = new FaceidClient(cred, "", clientProfile);
-            String params = "{\"RuleId\":\""+RuleId+"\"}";
-            DetectAuthRequest req = DetectAuthRequest.fromJsonString(params, DetectAuthRequest.class);
-    //        DetectAuthRequest req = new DetectAuthRequest();
-            DetectAuthResponse resp = client.DetectAuth(req);
-            System.out.println(DetectAuthResponse.toJsonString(resp));
-            FaceVo vo = BeanUtil.toBean(resp, com.zhongzheng.modules.face.bo.FaceVo.class);
-            return vo;
-        } catch (TencentCloudSDKException e) {
-            System.out.println(e.toString());
-        }
-        return null;
-    }
-
-    @Override
-    public void getDetectInfo(String bizToken,Long userId) {
-        try{
-            Credential cred = new Credential(SecretId, SecretKey);
-
-            HttpProfile httpProfile = new HttpProfile();
-            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
-
-            ClientProfile clientProfile = new ClientProfile();
-            clientProfile.setHttpProfile(httpProfile);
-
-            FaceidClient client = new FaceidClient(cred, "", clientProfile);
-
-            GetDetectInfoRequest req = new GetDetectInfoRequest();
-            req.setBizToken(bizToken);
-            req.setRuleId("0");
-            GetDetectInfoResponse resp = client.GetDetectInfo(req);
-            JSONObject resultObject = JSONObject.parseObject(resp.getDetectInfo());
-            if (resultObject.containsKey("Text")){
-                Map entry = (Map)resultObject.get("Text");
-                int ErrCode = ((Integer)entry.get("ErrCode"));
-                if(ErrCode==0){ //0为成功
-                    String IdCard = ((String)entry.get("IdCard"));
-                    String Name = ((String)entry.get("Name"));
-                    //照片
-                    Map IdCardData = (Map)resultObject.get("IdCardData");
-                    String OcrFront = ((String)IdCardData.get("OcrFront"));
-                    String OcrFrontFileName = ossService.uploadBase64(OcrFront);
-                    String OcrBack = ((String)IdCardData.get("OcrBack"));
-                    String OcrBackFileName = ossService.uploadBase64(OcrBack);
-                    //视频最佳帧截图
-                    Map BestFrame = (Map)resultObject.get("BestFrame");
-                    String imgBestFrame = ((String)BestFrame.get("BestFrame"));
-                    String imgBestFrameFileName = ossService.uploadBase64(imgBestFrame);
-
-                    User user = new User();
-                    user.setUserId(userId);
-                    user.setIdCardImg1(OcrFrontFileName);
-                    user.setIdCardImg2(OcrBackFileName);
-                    user.setRealname(Name);
-                    user.setIdCard(IdCard);
-                    user.setCertified(1);
-                    user.setCertifiedTime(DateUtils.getNowTime());
-                    user.setUpdateTime(DateUtils.getNowTime());
-                    userMapper.updateById(user);
-
-                    UserOcrAddBo bo = new UserOcrAddBo();
-                    bo.setBestFrame(imgBestFrameFileName);
-                    bo.setOcrFront(OcrFrontFileName);
-                    bo.setOcrBack(OcrBackFileName);
-                    bo.setUserId(userId);
-                    bo.setOcrInfo(JSONObject.toJSONString(entry));
-                    bo.setStatus(1);
-                    iUserOcrService.insertByAddBo(bo);
-                    ossService.closeClient();
-                }
-            }
-        } catch (TencentCloudSDKException e) {
-            System.out.println(e.toString());
-        }
-    }
-
-    @Override
-    public FaceVo getPicFaceDetectAuth(String RuleId,Long userId) {
-        try{
-            Credential cred = new Credential(SecretId, SecretKey);
-
-            HttpProfile httpProfile = new HttpProfile();
-            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
-            ClientProfile clientProfile = new ClientProfile();
-            clientProfile.setHttpProfile(httpProfile);
-            FaceidClient client = new FaceidClient(cred, "", clientProfile);
-
-
-            User user = userMapper.selectById(userId);
-            if(user.getCertified()==1){
-                String IdCard = user.getIdCard();
-                String Name = user.getRealname();
-                String ImageBase64 = user.getRealname();
-
-                UserOcr ocr = iUserOcrService.queryByUserId(userId);
-                String bestFile = ocr.getBestFrame();
-                String base64 = ImageUtils.encodeImgageToBase64(ossHost+"/"+bestFile);
-              /*  String params = "{\"RuleId\":\""+RuleId+"\",\"IdCard\":\""+IdCard+"\",\"Name\":\""+Name+"\"" +
-                        ",\"ImageBase64\":\""+base64+"\"}";*/
-                String params = "{\"RuleId\":\""+RuleId+"\",\"IdCard\":\""+IdCard+"\",\"Name\":\""+Name+"\"" +
-                        ",\"ImageBase64\":\""+base64+"\"}";
-                DetectAuthRequest req = DetectAuthRequest.fromJsonString(params, DetectAuthRequest.class);
-                //        DetectAuthRequest req = new DetectAuthRequest();
-                DetectAuthResponse resp = client.DetectAuth(req);
-                FaceVo vo = BeanUtil.toBean(resp, com.zhongzheng.modules.face.bo.FaceVo.class);
-                return vo;
-            }
-        } catch (TencentCloudSDKException e) {
-            System.out.println(e.toString());
-        }
-        return null;
-    }
-
-    @Override
-    public Integer getPicDetectInfo(String bizToken, Long userId) {
-        try{
-            Credential cred = new Credential(SecretId, SecretKey);
-
-            HttpProfile httpProfile = new HttpProfile();
-            httpProfile.setEndpoint("faceid.tencentcloudapi.com");
-
-            ClientProfile clientProfile = new ClientProfile();
-            clientProfile.setHttpProfile(httpProfile);
-
-            FaceidClient client = new FaceidClient(cred, "", clientProfile);
-
-            GetDetectInfoRequest req = new GetDetectInfoRequest();
-            req.setBizToken(bizToken);
-            req.setRuleId("1");
-            GetDetectInfoResponse resp = client.GetDetectInfo(req);
-            System.out.println(resp.getDetectInfo());
-            JSONObject resultObject = JSONObject.parseObject(resp.getDetectInfo());
-            Map entry = (Map)resultObject.get("Text");
-            UserOcrAddBo bo = new UserOcrAddBo();
-            bo.setUserId(userId);
-            bo.setOcrInfo(JSONObject.toJSONString(entry));
-            bo.setStatus(1);
-            iUserOcrService.insertByAddBo(bo);
-            int ErrCode = ((Integer)entry.get("ErrCode"));
-            return ErrCode;
-        } catch (TencentCloudSDKException e) {
-        }
-        return -1;
-    }
-
-
-}

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/order/vo/OrderGoodsRefundVo.java

@@ -57,4 +57,6 @@ public class OrderGoodsRefundVo {
 	private String goodsName;
 	@ApiModelProperty("商品图片")
 	private String coverUrl;
+	@ApiModelProperty("创建时间")
+	private Long createTime;
 }

+ 11 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/tencentcloud/service/IFaceService.java

@@ -0,0 +1,11 @@
+package com.zhongzheng.modules.tencentcloud.service;
+
+
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
+
+public interface IFaceService {
+
+
+    Integer CompareFace(String ImageA,Long userId) throws TencentCloudSDKException;
+
+}

+ 69 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/tencentcloud/service/impl/FaceServiceImpl.java

@@ -0,0 +1,69 @@
+package com.zhongzheng.modules.tencentcloud.service.impl;
+
+
+import cn.hutool.core.bean.BeanUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.tencentcloudapi.common.Credential;
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
+import com.tencentcloudapi.common.profile.ClientProfile;
+import com.tencentcloudapi.common.profile.HttpProfile;
+import com.tencentcloudapi.faceid.v20180301.FaceidClient;
+import com.tencentcloudapi.faceid.v20180301.models.DetectAuthRequest;
+import com.tencentcloudapi.faceid.v20180301.models.DetectAuthResponse;
+import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoRequest;
+import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoResponse;
+import com.tencentcloudapi.iai.v20200303.IaiClient;
+import com.tencentcloudapi.iai.v20200303.models.CompareFaceRequest;
+import com.tencentcloudapi.iai.v20200303.models.CompareFaceResponse;
+import com.zhongzheng.common.utils.DateUtils;
+import com.zhongzheng.common.utils.file.ImageUtils;
+import com.zhongzheng.modules.alioss.service.OssService;
+import com.zhongzheng.modules.tencentcloud.service.IFaceService;
+import com.zhongzheng.modules.user.service.IUserOcrService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.Map;
+
+@Service
+public class FaceServiceImpl implements IFaceService {
+
+    @Value("${tencent.cloud.SecretId}")
+    private String SecretId;
+
+    @Value("${tencent.cloud.SecretKey}")
+    private String SecretKey;
+
+    @Value("${aliyun.oss.endpoint}")
+    private String ossHost;
+
+    @Autowired
+    private OssService ossService;
+
+    @Autowired
+    private IUserOcrService iUserOcrService;
+
+
+
+
+    @Override
+    public Integer CompareFace(String ImageA, Long userId){
+        try{
+            Credential cred = new Credential(SecretId, SecretKey);
+            ClientProfile clientProfile = new ClientProfile();
+            clientProfile.setSignMethod(clientProfile.SIGN_TC3_256);
+            IaiClient iaiClient = new IaiClient(cred,"ap-guangzhou");
+            CompareFaceRequest faceRequest = new CompareFaceRequest();
+            faceRequest.setUrlA("https://file-dev.xyyxt.net/oss/images/avatar/20220303/1646295379430_725448525");
+            faceRequest.setUrlB("https://file-dev.xyyxt.net/oss/images/avatar/20220303/1646295301022_1332431765");
+            faceRequest.setQualityControl(4L);
+            CompareFaceResponse response = iaiClient.CompareFace(faceRequest);
+            System.out.println("结果");
+            System.out.println(response.getScore());
+        }catch (TencentCloudSDKException e){
+
+        }
+        return null;
+    }
+}

+ 0 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserStudyRecordServiceImpl.java

@@ -18,7 +18,6 @@ import com.zhongzheng.modules.course.service.ICoursePhotoLogService;
 import com.zhongzheng.modules.course.service.ICourseSectionService;
 import com.zhongzheng.modules.course.vo.CourseChapterSectionVo;
 import com.zhongzheng.modules.course.vo.CourseSectionVo;
-import com.zhongzheng.modules.face.service.IFaceService;
 import com.zhongzheng.modules.goods.service.IGoodsService;
 import com.zhongzheng.modules.goods.vo.GoodsUserVo;
 import com.zhongzheng.modules.goods.vo.GoodsVo;

+ 0 - 1
zhongzheng-system/src/main/resources/mapper/modules/order/OrderGoodsRefundMapper.xml

@@ -25,7 +25,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="goodsId" column="goods_id"/>
         <result property="refundFee" column="refund_fee"/>
         <result property="createTime" column="create_time"/>
-        <result property="updateTime" column="update_time"/>
         <result property="status" column="status"/>
         <result property="wxpayRefundId" column="wxpay_refund_id"/>
         <result property="goodsName" column="goods_name"/>