-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from lunasaw/3.1.8-SNAPSHOT
3.1.8 snapshot
- Loading branch information
Showing
32 changed files
with
1,056 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
ali-spring-boot-starter/src/main/java/com/luna/ali/constant/AliAccessConstant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.luna.ali.constant; | ||
|
||
/** | ||
* @author luna | ||
* @description | ||
* @date 2023/4/15 | ||
*/ | ||
public class AliAccessConstant { | ||
|
||
public static final String FACE_BODY_HOST = "facebody.cn-shanghai.aliyuncs.com"; | ||
} |
85 changes: 85 additions & 0 deletions
85
ali-spring-boot-starter/src/main/java/com/luna/ali/face/AliFaceBodyClientSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.luna.ali.face; | ||
|
||
import com.aliyun.facebody20191230.Client; | ||
import com.aliyun.teautil.models.RuntimeOptions; | ||
import com.luna.ali.config.AliConfigProperties; | ||
import com.luna.ali.constant.AliAccessConstant; | ||
import com.luna.ali.face.api.AliFaceCheckApi; | ||
import com.luna.ali.face.enums.FaceTypeEnum; | ||
import lombok.Data; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author luna | ||
* @description | ||
* @date 2023/4/15 | ||
*/ | ||
@Component | ||
public class AliFaceBodyClientSupport implements InitializingBean { | ||
|
||
@Autowired | ||
private AliConfigProperties aliConfigProperties; | ||
|
||
private FaceClient faceClient; | ||
|
||
private RuntimeOptions runtimeOptions; | ||
|
||
|
||
public com.aliyun.teaopenapi.Client getClient(FaceTypeEnum faceType) { | ||
if (FaceTypeEnum.FACE_DETECTION.equals(faceType)) { | ||
return faceClient.getFaceBodyClient(); | ||
} else if (FaceTypeEnum.FACE_VERIFICATION.equals(faceType)) { | ||
return faceClient.getFaceBodyClient(); | ||
} | ||
throw new RuntimeException("getClient not found"); | ||
} | ||
|
||
@Data | ||
public static class FaceClient { | ||
|
||
/** | ||
* 人脸检测 | ||
*/ | ||
private com.aliyun.facebody20191230.Client faceCheckClient; | ||
|
||
/** | ||
* 人脸核身 | ||
*/ | ||
private com.aliyun.facebody20200910.Client faceBodyClient; | ||
} | ||
|
||
public RuntimeOptions getRuntimeOptions() { | ||
return runtimeOptions; | ||
} | ||
|
||
public void createClient(String accessKeyId, String accessKeySecret) { | ||
try { | ||
// CLIENT 单例模式创建 | ||
synchronized (AliFaceCheckApi.class) { | ||
|
||
if (faceClient == null) { | ||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config() | ||
.setAccessKeyId(accessKeyId) | ||
.setAccessKeySecret(accessKeySecret) | ||
.setEndpoint(AliAccessConstant.FACE_BODY_HOST); | ||
faceClient = new FaceClient(); | ||
faceClient.setFaceCheckClient(new com.aliyun.facebody20191230.Client(config)); | ||
faceClient.setFaceBodyClient(new com.aliyun.facebody20200910.Client(config)); | ||
} | ||
|
||
if (runtimeOptions == null) { | ||
runtimeOptions = new RuntimeOptions(); | ||
} | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
createClient(aliConfigProperties.getAccessKey(), aliConfigProperties.getSecretKey()); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
ali-spring-boot-starter/src/main/java/com/luna/ali/face/api/AliFaceAuditApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.luna.ali.face.api; | ||
|
||
import com.aliyun.facebody20200910.Client; | ||
import com.aliyun.facebody20200910.models.ExecuteServerSideVerificationRequest; | ||
import com.aliyun.facebody20200910.models.ExecuteServerSideVerificationResponse; | ||
import com.google.common.collect.Maps; | ||
import com.luna.ali.face.enums.FaceTypeEnum; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import com.luna.ali.face.AliFaceBodyClientSupport; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author luna | ||
* @description | ||
* @date 2023/4/16 | ||
*/ | ||
@Component | ||
public class AliFaceAuditApi { | ||
|
||
@Autowired | ||
private AliFaceBodyClientSupport aliFaceBodyClientSupport; | ||
|
||
private Client getClient() { | ||
return (Client)aliFaceBodyClientSupport.getClient(FaceTypeEnum.FACE_VERIFICATION); | ||
} | ||
|
||
/** | ||
* 人脸核身服务端。 | ||
* | ||
* @param certificateName 真实姓名。 | ||
* @param certificateNumber 身份证号。 | ||
* @param facialPictureUrl 待比对的图像URL地址,只支持JPG格式图片。推荐使用上海地域的OSS链接,对于文件在本地或者非上海地域OSS链接的情况,请参见文件URL处理。 | ||
*/ | ||
public ExecuteServerSideVerificationResponse ExecuteServerSideVerificationResponse(String certificateName, String certificateNumber, | ||
String facialPictureUrl) { | ||
return executeServerSideVerificationWithOptions(certificateName, certificateNumber, null, facialPictureUrl, "server"); | ||
} | ||
|
||
/** | ||
* 人脸核身服务端。 | ||
* | ||
* @param certificateName 真实姓名。 | ||
* @param certificateNumber 身份证号。 | ||
* @param facialPictureData | ||
* 待比对的图像,Base64格式,只支持JPG格式图片。必须是"/9j/"开头,如非"/9j/"开头请检查是否为JPG格式图片。文件的Base64编码处理操作,请参见文件Base64处理。 | ||
* @param facialPictureUrl 待比对的图像URL地址,只支持JPG格式图片。推荐使用上海地域的OSS链接,对于文件在本地或者非上海地域OSS链接的情况,请参见文件URL处理。 | ||
* @param sceneType 场景类型,默认为server。目前只支持server。 | ||
*/ | ||
public ExecuteServerSideVerificationResponse executeServerSideVerificationWithOptions(String certificateName, String certificateNumber, | ||
String facialPictureData, String facialPictureUrl, String sceneType) { | ||
ExecuteServerSideVerificationRequest request = new ExecuteServerSideVerificationRequest(); | ||
request.setCertificateName(certificateName); | ||
request.setCertificateNumber(certificateNumber); | ||
request.setFacialPictureData(facialPictureData); | ||
request.setFacialPictureUrl(facialPictureUrl); | ||
request.setSceneType(sceneType); | ||
return executeServerSideVerificationWithOptions(request, Maps.newHashMap()); | ||
} | ||
|
||
public ExecuteServerSideVerificationResponse executeServerSideVerificationWithOptions(ExecuteServerSideVerificationRequest request, | ||
Map<String, String> headers) { | ||
try { | ||
return getClient().executeServerSideVerificationWithOptions(request, headers, aliFaceBodyClientSupport.getRuntimeOptions()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.