Skip to content

Commit

Permalink
Merge pull request #25 from lunasaw/3.1.8-SNAPSHOT
Browse files Browse the repository at this point in the history
3.1.8 snapshot
  • Loading branch information
lunasaw authored Apr 16, 2023
2 parents 677bf99 + d7da63b commit 4df30ef
Show file tree
Hide file tree
Showing 32 changed files with 1,056 additions and 73 deletions.
2 changes: 1 addition & 1 deletion ali-pay-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.lunasaw</groupId>
<artifactId>luna-fans-api</artifactId>
<version>3.1.7</version>
<version>3.1.8</version>
</parent>

<artifactId>ali-pay-spring-boot-starter</artifactId>
Expand Down
1 change: 1 addition & 0 deletions ali-spring-boot-starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

## 日志

- 2023-04-15 增加阿里云sdk,人脸检测,表情识别
- 2023-04-09 拆分项目,增加支付宝Api操作
- 8.19 增加支付宝Api操作
- 8.21 增加阿里Oss存储Api调用
Expand Down
22 changes: 12 additions & 10 deletions ali-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>luna-fans-api</artifactId>
<groupId>io.github.lunasaw</groupId>
<version>3.1.7</version>
<version>3.1.8</version>
</parent>
<artifactId>ali-spring-boot-starter</artifactId>
<version>${luna-fans-api.version}</version>
Expand All @@ -16,10 +16,6 @@
<url>https://lunasaw.github.io/${github.username}/${project.name}</url>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/com.aliyun.oss/aliyun-sdk-oss -->
<dependency>
Expand All @@ -28,12 +24,18 @@
<version>3.16.2</version>
</dependency>

<!-- alipay -->
<!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java -->
<!-- https://mvnrepository.com/artifact/com.aliyun/facebody20191230 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>facebody20191230</artifactId>
<version>3.0.7</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.aliyun/facebody20200910 -->
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.35.101.ALL</version>
<groupId>com.aliyun</groupId>
<artifactId>facebody20200910</artifactId>
<version>3.0.0</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* @author Luna@win10
* @date 2020/5/6 21:09
*/
@ConfigurationProperties(prefix = "spring.ali.oss")
@ConfigurationProperties(prefix = "spring.ali")
@Data
public class AliOssConfigProperties {
public class AliConfigProperties {

private Boolean enable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,44 @@
*/
@Configuration
@ConditionalOnProperty(prefix = "spring.ali", name = "enable", havingValue = "true")
@EnableConfigurationProperties({AliOssConfigProperties.class})
@ComponentScan("com.luna.ali.oss")
@EnableConfigurationProperties({AliConfigProperties.class})
@ComponentScan("com.luna.ali")
public class AliOssAutoConfiguration {

@Autowired
private final AliOssConfigProperties aliOssConfigProperties;
private final AliConfigProperties aliConfigProperties;

public AliOssAutoConfiguration(final AliOssConfigProperties aliOssConfigProperties) {
this.aliOssConfigProperties = aliOssConfigProperties;
public AliOssAutoConfiguration(final AliConfigProperties aliConfigProperties) {
this.aliConfigProperties = aliConfigProperties;
}

@Bean
@ConditionalOnMissingBean
public AliOssUploadApi aliOssUploadApi() {
return new AliOssUploadApi(aliOssConfigProperties.getInstanceClient());
return new AliOssUploadApi(aliConfigProperties.getInstanceClient());
}

@Bean
@ConditionalOnMissingBean
public AliOssDownloadApi aliOssDownloadApi() {
return new AliOssDownloadApi(aliOssConfigProperties.getInstanceClient());
return new AliOssDownloadApi(aliConfigProperties.getInstanceClient());
}

@Bean
@ConditionalOnMissingBean
public AliOssBucketApi aliOssBucketApi() {
return new AliOssBucketApi(aliOssConfigProperties.getInstanceClient());
return new AliOssBucketApi(aliConfigProperties.getInstanceClient());
}

@Bean
@ConditionalOnMissingBean
public AliOssUploadGoOnApi aliOssUploadGoOnApi() {
return new AliOssUploadGoOnApi(aliOssConfigProperties.getInstanceClient());
return new AliOssUploadGoOnApi(aliConfigProperties.getInstanceClient());
}

@Bean
@ConditionalOnMissingBean
public AliOssWebApi aliOssWebApi() {
return new AliOssWebApi(aliOssConfigProperties.getInstanceClient());
return new AliOssWebApi(aliConfigProperties.getInstanceClient());
}
}
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";
}
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());
}
}
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);
}
}
}
Loading

0 comments on commit 4df30ef

Please sign in to comment.