腾讯人脸识别H5简单接入

接入说明

必须企业账号才可以接入人脸识别

官方文档

人脸核身 微信浮层 H5(微信浏览器)_腾讯云

官方时序图

步骤一

根据官方文档步骤一创建RuleId

步骤二

项目引入依赖
   <dependency>
            <groupId>com.tencentcloudapi</groupId>
            <artifactId>tencentcloud-sdk-java</artifactId>
            <version>3.1.1000</version>
        </dependency>

调用实名核身鉴权接口文档:人脸核身 实名核身鉴权_腾讯云

JAVA 测试代码
SecretId,SecretKey 需要自己生成,腾讯云企业账户才有权限进行调用人脸识别接口,个人无法地调通

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.DetectAuthRequest;
import com.tencentcloudapi.faceid.v20180301.models.DetectAuthResponse;

public class Test3 {
    public static void main(String[] args) {
        try {
            // 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中,请参考本文凭证管理章节。
            // 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。
            Credential cred = new Credential("SecretId", "SecretKey");
            FaceidClient client = new FaceidClient(cred,null);
            DetectAuthRequest detectAuthRequest = new DetectAuthRequest();
            detectAuthRequest.setRuleId("1");
            detectAuthRequest.setIdCard("xxxx");
            detectAuthRequest.setName("zx");
            detectAuthRequest.setRedirectUrl("xxxx");
            DetectAuthResponse detectAuthResponse = client.DetectAuth(detectAuthRequest);

            System.out.println(DetectAuthResponse.toJsonString(detectAuthResponse));
        } catch (
                TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
    }
}
未开通服务接口响应

若成功接口响应

{
    "Response": {
        "BizToken": "CE661F1A-0F1E-45BD-BE13-34C05CEA7681",
        "Url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx2cca36a86d5035ae&redirect_uri=http%3A%2F%2Fopen.faceid.qq.com%2Fv1%2Fapi%2FgetCode%3FbizRedirect%3Dhttp%253A%252F%252Ffaceid.qq.com%252Fapi%252Fauth%252FgetOpenidAndSaveToken%253Ftoken%253DCE661F1A-0F1E-45BD-BE13-34C05CEA7681&response_type=code&scope=snsapi_base&state=&component_appid=wx9802ee81e68d6dee#wechat_redirect",
        "RequestId": "f904f4cf-75db-4f8f-a5ec-dc4f942c7f7a"
    }
}

步骤三

根据返回的Url通过手机访问进行人脸认证

步骤四

获取人脸识别结果接口:人脸核身 获取实名核身结果信息增强版_腾讯云
java 测试代码

secretId,secertKey 填充自己的企业信息


import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoEnhancedRequest;
import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoEnhancedResponse;

public class Test4 {
    public static void main(String[] args) throws TencentCloudSDKException {
        //GetDetectInfoEnhanced
        Credential cred = new Credential("", "");
        FaceidClient client = new FaceidClient(cred,null);
        GetDetectInfoEnhancedRequest getDetectInfoEnhancedRequest = new GetDetectInfoEnhancedRequest();
        getDetectInfoEnhancedRequest.setBizToken("xxxx");
        getDetectInfoEnhancedRequest.setInfoType("1");
        getDetectInfoEnhancedRequest.setRuleId("1");
        GetDetectInfoEnhancedResponse getDetectInfoEnhancedResponse = client.GetDetectInfoEnhanced(getDetectInfoEnhancedRequest);
        System.out.println(GetDetectInfoEnhancedResponse.toJsonString(getDetectInfoEnhancedResponse));
    }
}
未开通服务接口响应

接口正常响应
{
    "Response": {
        "BestFrame": {
            "BestFrame": "/9j/4AAQSk...JKD2A//9k=",
            "BestFrames": [
                "/9j/4AAQSk...002dgP/9k=",
                "/9j/4AAQSk...vx+YH/2Q==",
                "/9j/4AAQSk...n6fj5Af//Z",
                "/9j/4AAQSk...dzlFFagf/Z"
            ]
        },
        "EncryptedBody": "",
        "Encryption": {
            "Algorithm": "",
            "CiphertextBlob": "",
            "EncryptList": [],
            "Iv": "",
            "TagList": []
        },
        "IdCardData": {
            "Avatar": null,
            "BackWarnInfos": null,
            "OcrBack": null,
            "OcrFront": null,
            "ProcessedBackImage": null,
            "ProcessedFrontImage": null,
            "WarnInfos": null
        },
        "IntentionActionResult": null,
        "IntentionQuestionResult": {
            "AsrResult": [],
            "Audios": [],
            "FinalResultCode": null,
            "FinalResultDetailCode": null,
            "FinalResultMessage": null,
            "ResultCode": [],
            "ScreenShot": [],
            "Video": null
        },
        "IntentionVerifyData": {
            "AsrResult": null,
            "AsrResultSimilarity": null,
            "ErrorCode": null,
            "ErrorMessage": null,
            "IntentionVerifyBestFrame": null,
            "IntentionVerifyVideo": null
        },
        "RequestId": "91173d84-e461-4da4-a270-2b8d48a2e136",
        "Text": {
            "CompareLibType": "权威库",
            "Comparemsg": "成功",
            "Comparestatus": 0,
            "ErrCode": 0,
            "ErrMsg": "成功",
            "Extra": "",
            "IdCard": "11204416541220243X",
            "IdInfoFrom": "其他",
            "LiveMsg": "成功",
            "LiveStatus": 0,
            "LivenessDetail": [
                {
                    "CompareLibType": "权威库",
                    "Comparemsg": "成功",
                    "Comparestatus": 0,
                    "Errcode": 0,
                    "Errmsg": "成功",
                    "Idcard": "11204416541220243X",
                    "IsNeedCharge": true,
                    "Livemsg": "成功",
                    "LivenessMode": 1,
                    "Livestatus": 0,
                    "Name": "韦小宝",
                    "ReqTime": "1730444265275",
                    "Seq": "1f330eea-f5db-4726-a7b4-38cdf1aefb02",
                    "Sim": "95.51"
                }
            ],
            "LivenessInfoTag": null,
            "LivenessMode": 1,
            "Location": null,
            "Mobile": "",
            "NFCBillingCounts": 0,
            "NFCRequestIds": [],
            "Name": "韦小宝",
            "OcrAddress": null,
            "OcrAuthority": null,
            "OcrBirth": null,
            "OcrGender": null,
            "OcrIdCard": "",
            "OcrName": "",
            "OcrNation": null,
            "OcrValidDate": null,
            "PassNo": null,
            "Sim": "95.51",
            "UseIDType": 0,
            "VisaNum": null
        },
        "VideoData": {
            "LivenessVideo": "AAAAGGZ0eX...VyYWxidW0h"
        }
    }
}
可根据自己的需求对代码增强
## 使用前准备​ 1. 前往注册: [腾讯云账号注册](https://cloud.tencent.com/register) (详细指引见 [注册腾讯云](https://cloud.tencent.com/document/product/378/9603)) 2. 取得存储桶名称 **BucketName**: 请前往 [创建存储桶](https://cloud.tencent.com/document/product/460/10637) 3. 取得 **APPID**、**SecretId**、**SecretKey**:请前往 [云API密钥](https://console.cloud.tencent.com/cam/capi) ,点击“新建密钥” ## 快速体验 1. 修改文件 src/main/java/com/qcloud/image/demo/Demo.java 的 main() 方法,填入上述申请到的 **APPID**、**SecretId**、**SecretKey**、**BucketName** 2. 导入到 IDE:工程用 Maven 构建,以 Intellij IDEA 为例,导入方式为:Import Project -> 选择工程目录 -> Import project from external model -> Maven 3. 运行:Demo.java 右键,Run Demo.main() ## 使用简介 ### 初始化 ```java ImageClient imageClient = new ImageClient(APPID, SecretId, SecretKey); ``` ### 设置代理 根据实际网络环境,可能要设置代理,例如: ```java Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress("127.0.0.1", 8080)); imageClient.setProxy(proxy); ``` ### 使用 SDK 提供功能如下: **图像识别**:鉴黄,标签 **文字识别(OCR)**:身份证,名片,通用,驾驶证行驶证,营业执照,银行卡,车牌号 **人脸识别**:人脸检测,五官定位,个体信息管理,人脸验证,人脸对比及人脸检索 **人脸核身**:照片核身(通过照片和身份证信息),获取唇语验证码(用于活体核身),活体核身(通过视频和照片),活体核身(通过视频和身份证信息) ```java // 调用车牌识别API示例 String imageUrl = "http://youtu.qq.com/app/img/experience/char_general/icon_ocr_license_3.jpg"; String result = imageClient.ocrPlate(new OcrPlateRequest("bucketName", imageUrl)); System.out.println(result); ``` 更多例子详情可参见 [Demo.java](https://github.com/tencentyun/image-java-sdk-v2.0/blob/master/src/main/java/com/qcloud/image/demo/Demo.java) 的代码。 ## 集成到你的项目中 ### 获得 SDK jar 文件 1. 直接使用 release/*-with-dependencies.jar 2. 自行编译:在工程根目录下执行命令 `mvn assembly:assembly`,编译结果见 target/*-with-dependencies.jar ### 导入 jar 文件 根据项目具体情况导入 *-with-dependencies.jar
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值