浏览代码

feat(app): 添加人脸识别功能

- 在 AppUserController 中添加 faceRecognition 方法,实现人脸识别接口
- 新增 GetEidToken 类,用于获取 EidToken
- 新增 GetEidResult 类,用于获取人脸识别结果
- 在 pom.xml 中添加腾讯云 SDK 依赖
SheepHy 2 天之前
父节点
当前提交
94175e6430

+ 5 - 0
national-motion-module-system/national-motion-system-biz/pom.xml

@@ -19,6 +19,11 @@
 			<groupId>org.jeecgframework.boot</groupId>
 			<artifactId>hibernate-re</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>com.tencentcloudapi</groupId>
+			<artifactId>tencentcloud-sdk-java-faceid</artifactId>
+			<version>3.1.1112</version>
+		</dependency>
 		<!-- AI大模型管理 -->
 		<dependency>
 			<groupId>org.jeecgframework.boot</groupId>

+ 14 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/controller/AppUserController.java

@@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.annotation.Resource;
 import java.util.List;
 
+import static org.jeecg.modules.app.ezt.GetEidToken.getEidToken;
+
 @Slf4j
 @Tag(name = "App用户相关接口")
 @RestController
@@ -79,4 +81,16 @@ public class AppUserController {
     public Result<List<AppKongfuZone>> queryKongfuZone(){
         return Result.ok(appKongfuZoneService.queryKongfuZone());
     }
+
+    /**
+     * @Author SheepHy
+     * @Description 人脸识别
+     * @Date 15:58 2025/8/25
+     **/
+    @GetMapping("/faceRecognition")
+    @Operation(summary = "人脸识别")
+    public Result<String> faceRecognition(@RequestParam("idCard") @Schema(description = "身份证") String idCard,
+                                          @RequestParam("name") @Schema(description = "姓名")String name) throws Exception {
+        return Result.ok(getEidToken(idCard,name));
+    }
 }

+ 32 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/ezt/GetEidResult.java

@@ -0,0 +1,32 @@
+package org.jeecg.modules.app.ezt;
+
+import com.tencentcloudapi.common.Credential;
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
+import com.tencentcloudapi.faceid.v20180301.FaceidClient;
+import com.tencentcloudapi.faceid.v20180301.models.GetEidResultRequest;
+import com.tencentcloudapi.faceid.v20180301.models.GetEidResultResponse;
+
+public class GetEidResult {
+    private static final String SECRET_ID = "AKIDDIDyWsIZfYIrDOWTLCzkU7bsyrX2LQK2 "; // TODO 您账号的腾讯云密钥
+    private static final String SECRET_KEY = "Yt0vfDZhdNvHPK3ZzEG4f4FCvRlsm073"; // TODO 您账号的腾讯云密钥
+    private static final String REGION = "ap-guangzhou";
+    public static void main(String[] args) {
+        // Step 1. 初始化客户端实例
+        Credential credential = new Credential(SECRET_ID, SECRET_KEY);
+        FaceidClient faceidClient = new FaceidClient(credential, REGION);
+        // Step 2. 使用Tencent Cloud API SDK组装请求体,填充参数
+        // 详细的接口文档请参考:https://cloud.tencent.com/document/product/1007/54090
+        GetEidResultRequest request = new GetEidResultRequest();
+        request.setEidToken(""); // 通过GetEidResult接口获取到的EidToken
+        request.setInfoType("0"); // 指定拉取的结果信息
+        try {
+            // Step 3. 调用接口
+            GetEidResultResponse response = faceidClient.GetEidResult(request);
+            System.out.println("SDK response: " + GetEidResultResponse.toJsonString(response));
+        } catch (TencentCloudSDKException e) {
+            // 调用接口异常在这里处理
+            System.err.println("invoke error, code: " + e.getErrorCode() + "message: " + e.getMessage());
+            e.printStackTrace();
+        }
+    }
+}

+ 38 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/ezt/GetEidToken.java

@@ -0,0 +1,38 @@
+package org.jeecg.modules.app.ezt;
+
+import com.tencentcloudapi.common.Credential;
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
+import com.tencentcloudapi.faceid.v20180301.FaceidClient;
+import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenConfig;
+import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenRequest;
+import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenResponse;
+
+public class GetEidToken {
+    private static final String SECRET_ID = "AKIDDIDyWsIZfYIrDOWTLCzkU7bsyrX2LQK2 "; // TODO 您账号的腾讯云密钥
+    private static final String SECRET_KEY = "Yt0vfDZhdNvHPK3ZzEG4f4FCvRlsm073"; // TODO 您账号的腾讯云密钥
+    private static final String REGION = "ap-guangzhou";
+    public static String getEidToken(String idCard, String name) throws Exception {
+        // Step 1. 初始化客户端实例
+        Credential credential = new Credential(SECRET_ID, SECRET_KEY);
+        FaceidClient faceidClient = new FaceidClient(credential, REGION);
+        // Step 2. 使用Tencent Cloud API SDK组装请求体,填充参数
+        // 详细的接口文档请参考:https://cloud.tencent.com/document/product/1007/54089
+        GetEidTokenRequest request = new GetEidTokenRequest();
+        request.setMerchantId("00EI2508221332333922"); // 商户ID,请在控制台查看已经申请的商户ID
+        GetEidTokenConfig config = new GetEidTokenConfig();
+        config.setInputType("4"); // 指定姓名和身份证号输入方式
+        request.setConfig(config);
+        request.setIdCard(idCard);
+        request.setName(name);
+        try {
+            // Step 3. 调用接口
+            GetEidTokenResponse response = faceidClient.GetEidToken(request);
+            return GetEidTokenResponse.toJsonString(response);
+        } catch (TencentCloudSDKException e) {
+            // 调用接口异常在这里处理
+            System.err.println("invoke error, code: " + e.getErrorCode() + "message: " + e.getMessage());
+            e.printStackTrace();
+        }
+        return null;
+    }
+}