|
@@ -16,10 +16,22 @@ 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.tencentcloudapi.ocr.v20181119.OcrClient;
|
|
|
+import com.tencentcloudapi.ocr.v20181119.models.IDCardOCRRequest;
|
|
|
+import com.tencentcloudapi.ocr.v20181119.models.IDCardOCRResponse;
|
|
|
+import com.tencentcloudapi.ocr.v20181119.models.VatInvoiceOCRRequest;
|
|
|
+import com.tencentcloudapi.ocr.v20181119.models.VatInvoiceOCRResponse;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.common.utils.file.ImageUtils;
|
|
|
+import com.zhongzheng.modules.alioss.bo.OssRequest;
|
|
|
import com.zhongzheng.modules.alioss.service.OssService;
|
|
|
+import com.zhongzheng.modules.base.bo.UserProfileFit;
|
|
|
+import com.zhongzheng.modules.base.bo.UserProfileQueryBo;
|
|
|
+import com.zhongzheng.modules.base.service.IUserProfileService;
|
|
|
+import com.zhongzheng.modules.base.vo.UserProfileVo;
|
|
|
import com.zhongzheng.modules.tencentcloud.bo.FaceQueryBo;
|
|
|
+import com.zhongzheng.modules.tencentcloud.bo.InvoiceQueryBo;
|
|
|
import com.zhongzheng.modules.tencentcloud.service.IFaceService;
|
|
|
import com.zhongzheng.modules.user.service.IUserOcrService;
|
|
|
import com.zhongzheng.modules.user.service.IUserService;
|
|
@@ -27,7 +39,11 @@ import com.zhongzheng.modules.user.vo.UserVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import springfox.documentation.spring.web.json.Json;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service
|
|
@@ -48,37 +64,109 @@ public class FaceServiceImpl implements IFaceService {
|
|
|
@Autowired
|
|
|
private IUserService iUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IUserProfileService iUserProfileService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Integer CompareFace(FaceQueryBo bo){
|
|
|
try{
|
|
|
- UserVo userVo = iUserService.queryById(bo.getUserId());
|
|
|
+ if(Validator.isEmpty(bo.getOrderGoodsId())){
|
|
|
+ throw new CustomException("缺少参数");
|
|
|
+ }
|
|
|
+ /* UserVo userVo = iUserService.queryById(bo.getUserId());
|
|
|
if(Validator.isEmpty(userVo)){
|
|
|
return 0;
|
|
|
- }
|
|
|
- String oneInchPhotos = userVo.getOneInchPhotos(); //一寸照片
|
|
|
- if(Validator.isEmpty(oneInchPhotos)){
|
|
|
+ }*/
|
|
|
+ UserProfileQueryBo userProfileQueryBo = new UserProfileQueryBo();
|
|
|
+ userProfileQueryBo.setUserId(bo.getUserId());
|
|
|
+ userProfileQueryBo.setOrderGoodsId(bo.getOrderGoodsId());
|
|
|
+ userProfileQueryBo.setTypeStatus(1L);
|
|
|
+ UserProfileVo info = iUserProfileService.getInfo(userProfileQueryBo);
|
|
|
+
|
|
|
+ if(Validator.isEmpty(info)){
|
|
|
//没有无需匹配
|
|
|
return 101;
|
|
|
}
|
|
|
+ Map<String, String> maps = JSONObject.parseObject(info.getKeyValue(),Map.class);
|
|
|
+
|
|
|
+ String oneInchPhotos = JSONObject.parseObject(String.valueOf(maps.get("recent_photos")), UserProfileFit.class).getValue(); //一寸照片
|
|
|
+
|
|
|
oneInchPhotos =ossHost+"/"+oneInchPhotos;
|
|
|
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.setImageA(bo.getImageA());
|
|
|
- faceRequest.setUrlB(oneInchPhotos);
|
|
|
- // 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.setImageA(bo.getImageA()); //学习拍照
|
|
|
+ faceRequest.setUrlB(oneInchPhotos); //一寸近照
|
|
|
faceRequest.setQualityControl(4L);
|
|
|
CompareFaceResponse response = iaiClient.CompareFace(faceRequest);
|
|
|
- System.out.println("结果");
|
|
|
- System.out.println(response.getScore());
|
|
|
return response.getScore().intValue();
|
|
|
}catch (TencentCloudSDKException e){
|
|
|
+ System.out.println("错误"+e.getMessage());
|
|
|
return 0;
|
|
|
- // System.out.println("结果"+e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String,String> IDCardOCR(FaceQueryBo bo) {
|
|
|
+ try{
|
|
|
+ Credential cred = new Credential(SecretId, SecretKey);
|
|
|
+ OcrClient client = new OcrClient(cred, "ap-guangzhou");
|
|
|
+ IDCardOCRRequest req = new IDCardOCRRequest();
|
|
|
+ if(Validator.isNotEmpty(bo.getCardImageUrl())){
|
|
|
+ req.setImageUrl(bo.getCardImageUrl());
|
|
|
+ }else{
|
|
|
+ req.setImageBase64(bo.getCardImageBase64());
|
|
|
+ }
|
|
|
+ if(Validator.isNotEmpty(bo.getCardSide())){
|
|
|
+ if(bo.getCardSide()==1){
|
|
|
+ req.setCardSide("FRONT");
|
|
|
+ }
|
|
|
+ if(bo.getCardSide()==2){
|
|
|
+ req.setCardSide("BACK");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String,String> rs = new HashMap<>();
|
|
|
+ req.setConfig("{\"CropIdCard\":true}");
|
|
|
+ IDCardOCRResponse resp = client.IDCardOCR(req);
|
|
|
+ String IdNum = resp.getIdNum();
|
|
|
+ String AdvancedInfo = resp.getAdvancedInfo();
|
|
|
+ String IdCard = JSONObject.parseObject(AdvancedInfo).getString("IdCard");
|
|
|
+ if(Validator.isEmpty(IdCard)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ OssRequest ossRequest = new OssRequest();
|
|
|
+ ossRequest.setUserId(bo.getUserId());
|
|
|
+ ossRequest.setGradeId(bo.getGradeId());
|
|
|
+ ossRequest.setImageStatus(5);
|
|
|
+ String ossPath = ossService.uploadBase64(IdCard,ossRequest);
|
|
|
+ rs.put("IdNum",IdNum);
|
|
|
+ rs.put("IdImgPath",ossPath);
|
|
|
+ return rs;
|
|
|
+ }catch (TencentCloudSDKException e){
|
|
|
+ System.out.println("错误"+e.getMessage());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, String> VatInvoiceOCR(InvoiceQueryBo bo) {
|
|
|
+ try{
|
|
|
+ if(Validator.isEmpty(bo.getImageUrl())){
|
|
|
+ throw new CustomException("缺少参数");
|
|
|
+ }
|
|
|
+ Credential cred = new Credential(SecretId, SecretKey);
|
|
|
+ OcrClient client = new OcrClient(cred, "ap-guangzhou");
|
|
|
+ VatInvoiceOCRRequest req = new VatInvoiceOCRRequest();
|
|
|
+ req.setIsPdf(true);
|
|
|
+ req.setImageUrl(ossHost+"/"+bo.getImageUrl());
|
|
|
+ VatInvoiceOCRResponse resp = client.VatInvoiceOCR(req);
|
|
|
+ }catch (TencentCloudSDKException e){
|
|
|
+ System.out.println("错误"+e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|