|
|
@@ -14,14 +14,18 @@ import org.dromara.backstage.payment.domain.vo.PtFaceFeatureVo;
|
|
|
import org.dromara.backstage.payment.domain.vo.PtUserAccountVo;
|
|
|
import org.dromara.backstage.payment.service.IPtFaceFeatureService;
|
|
|
import org.dromara.backstage.payment.service.IPtUserAccountService;
|
|
|
+import org.dromara.common.core.config.DefaultConfig;
|
|
|
+import org.dromara.common.core.constant.DefaultConstants;
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.utils.SpringUtils;
|
|
|
import org.dromara.common.core.utils.file.FileUtils;
|
|
|
+import org.dromara.common.core.utils.file.PicCompressor;
|
|
|
import org.dromara.common.face.IFaceAlgorithm;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.nio.charset.Charset;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
@@ -40,6 +44,7 @@ import java.util.Map;
|
|
|
public class UserFaceBusiness {
|
|
|
private final IPtUserAccountService userAccountService;
|
|
|
private final IPtFaceFeatureService faceFeatureService;
|
|
|
+ private final DefaultConfig defaultConfig;
|
|
|
// 应用的人脸算法
|
|
|
@Value("${face-algorithm}")
|
|
|
String justFaceAlgorithm;
|
|
|
@@ -223,7 +228,34 @@ public class UserFaceBusiness {
|
|
|
return R.fail(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 处理用户人脸数据。
|
|
|
+ * <p>
|
|
|
+ * 处理时如果图片大于>200k,需要压缩到200k以内后再进行特征码提取
|
|
|
+ *
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @param imageData 人脸图像数据
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
|
|
|
+ public R<Void> dealUserFace(Long userId, String imageData) {
|
|
|
+ String imgData ;
|
|
|
+ byte[] sBytes = Base64.decode(imageData);
|
|
|
+ if(sBytes.length > 200*1024){
|
|
|
+ // 如果图片大于200k,压缩至200k以内
|
|
|
+ byte[] compressed = PicCompressor.compressPicForScale(sBytes, 200);
|
|
|
+ imgData = Base64.encode(compressed);
|
|
|
+ } else {
|
|
|
+ imgData = Base64.encode(sBytes);
|
|
|
+ }
|
|
|
+ String locationFlag = defaultConfig.getLocationFlag();
|
|
|
+ // 如果是本地部署
|
|
|
+ if (ObjectUtil.equals(locationFlag, DefaultConstants.LOCAL_FLAG)) {
|
|
|
+ return this.extractUserFaces(userId, imgData);
|
|
|
+ } else {
|
|
|
+ return this.extractUserFacesForCloud(userId, imgData);
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 人员验证以及根据人员已有的照片地址获取提取人脸特征的图片数据
|
|
|
*
|