
SdkToken, which is used throughout the selfie verification process and to pull the final verification result.
SDKToken, which is used throughout the selfie verification process and used by the API GetFaceIdResultIntl to obtain the liveness comparison result. The merchant server also needs to provide the corresponding endpoint for the merchant client to call. The following sample code with the Golang language is used as an example to show how to call TencentCloud API on the server and obtain the correct response.SDKToken using the API GetFaceIdTokenIntl, you can return other responses required by the client application to the client along with the SDKToken.var FaceIdClient *faceid.Clientfunc init() {// Instantiate a client configuration object. You can specify the timeout period and other configuration itemsprof := profile.NewClientProfile()prof.HttpProfile.ReqTimeout = 60// TODO replace the SecretId and SecretKey string with the API SecretId and SecretKeycredential := cloud.NewCredential("SecretId", "SecretKey")var err error// Instantiate the client object of the requested faceidFaceIdClient, err = faceid.NewClient(credential, "ap-singapore", prof)if nil != err {log.Fatal("FaceIdClient init error: ", err)}}// GetFaceIdToken get tokenfunc GetFaceIdToken(w http.ResponseWriter, r *http.Request) {log.Println("get face id token")// Step 1: ... parse parameters_ = r.ParseForm()var SecureLevel = r.FormValue("SecureLevel")// Step 2: instantiate the request object and provide necessary parametersrequest := faceid.NewGetFaceIdTokenIntlRequest()request.SecureLevel = &SecureLevel// Step 3: call the Tencent Cloud API through FaceIdClientresponse, err := FaceIdClient.GetFaceIdTokenIntl(request)// Step 4: process the Tencent Cloud API response and construct the return objectif nil != err {_, _ = w.Write([]byte("error"))return}SdkToken := response.Response.SdkTokenapiResp := struct {SdkToken *string}{SdkToken: SdkToken}b, _ := json.Marshal(apiResp)// ... more codes are omitted//Step 5: return the service response_, _ = w.Write(b)}// GetFaceIdResult get resultfunc GetFaceIdResult(w http.ResponseWriter, r *http.Request) {// Step 1: ... parse parameters_ = r.ParseForm()SdkToken := r.FormValue("SdkToken")// Step 2: instantiate the request object and provide necessary parametersrequest := faceid.NewGetFaceIdResultIntlRequest()request.SdkToken = &SdkToken// Step 3: call the Tencent Cloud API through FaceIdClientresponse, err := FaceIdClient.GetFaceIdResultIntl(request)// Step 4: process the Tencent Cloud API response and construct the return objectif nil != err {_, _ = w.Write([]byte("error"))return}result := response.Response.ResultapiResp := struct {Result *string}{Result: result}b, _ := json.Marshal(apiResp)// ... more codes are omitted//Step 5: return the service response_, _ = w.Write(b)}func main() {// expose endpointshttp.HandleFunc("/api/v1/get-token", GetFaceIdToken)http.HandleFunc("/api/v1/get-result", GetFaceIdResult)// listening porterr := http.ListenAndServe(":8080", nil)if nil != err {log.Fatal("ListenAndServe error: ", err)}}
SdkToken is returned and access the API (http://ip:port/api/v1/get-result) to check whether the value of the Result field is 0. Through these results, you can determine whether the server integration is successful. For details on responses, see API introduction.
// Set .so architecture filtering in NDK (using armeabi-v7a as an example)ndk {abiFilters 'armeabi-v7a'}dependencies {// Import the FaceID SDKimplementation files("libs/huiyansdk_android_overseas_1.0.9.5_release.aar")// FaceID general algorithm SDKimplementation files("libs/tencent-ai-sdk-youtu-base-1.0.1.32-release.aar")// Common capability componentsimplementation files("libs/tencent-ai-sdk-common-1.1.27-release.aar")implementation files("libs/tencent-ai-sdk-aicamera-1.0.18-release.aar")// Third-Party libraries that the FaceID SDK depends on// gsonimplementation 'com.google.code.gson:gson:2.8.5'}
AndroidManifest.xml file.<!-- Camera permission --><uses-permission android:name="android.permission.CAMERA" /><uses-featureandroid:name="android.hardware.camera"android:required="true" /><uses-feature android:name="android.hardware.camera.autofocus" /><!-- Permissions required by the SDK --><uses-permission android:name="android.permission.INTERNET" /><!-- Optional permissions for the SDK --><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
AndroidManifest.xml file, you need to add the code Dynamically apply for permissions.Application.@Overridepublic void onCreate() {super.onCreate();instance = this;// Initialize the SDK during app initializationHuiYanOsApi.init(getApp());}
// HuiYanOs parametersHuiYanOsConfig huiYanOsConfig = new HuiYanOsConfig();// The license file is placed in `assets`.huiYanOsConfig.setAuthLicense("YTFaceSDK.license");if (compatCheckBox.isChecked()) {huiYanOsConfig.setPageColorStyle(PageColorStyle.Dark);}// Whether to return the best frameif (needBestImageCB.isChecked()) {huiYanOsConfig.setNeedBestImage(true);}// Start liveness verification. `currentToken` is the token distributed by the backend.HuiYanOsApi.startHuiYanAuth(currentToken, huiYanOsConfig, new HuiYanOsAuthCallBack() {@Overridepublic void onSuccess(HuiYanOsAuthResult authResult) {showToast("Liveness verification passed.");if (!TextUtils.isEmpty(authResult.getBestImage())) {CommonUtils.decryptBestImgBase64(authResult.getBestImage(), false);}}@Overridepublic void onFail(int errorCode, String errorMsg, String token) {String msg = "Liveness verification failed " + "code: " + errorCode + " msg: " + errorMsg + " token: " + token;Log.e(TAG, "onFail" + msg);showToast(msg);}});
Assets Folder.
@Overrideprotected void onDestroy() {super.onDestroy();// Release the resources upon exitHuiYanOsApi.release();}
# The following FaceID SDK obfuscation rules should be added:-keep class com.tencent.could.huiyansdk.** {*;}-keep class com.tencent.could.aicamare.** {*;}-keep class com.tencent.could.component.** {*;}-keep class com.tencent.youtu.** {*;}-keep class com.tenpay.utils.SMUtils {*;}
Link Binary With Libraries to add frameworks.├──HuiYanOverseasSDK.framework├──YtSDKKitSilentLiveness.framework├──YtSDKKitReflectLiveness.framework├──YtSDKKitActionLiveness.framework├──YtSDKKitFramework.framework├──tnnliveness.framework├──YTFaceAlignmentTinyLiveness.framework├──YTFaceTrackerLiveness.framework├──YTFaceDetectorLiveness.framework├──YTPoseDetector.framework├──YTCommonLiveness.framework├──TXYCommonDevice.framework├──TXYCommonNetworking.framework├──TXYCommonUtils.framework├──YTCv.framework├──YtSDKKitFrameworkTool.framework├──YTSm.framework└──YTFaceLiveReflect.framework
Link Binary With Libraries to add system frameworks.├── AVFoundation.framework├── libc++.tbd└── Accelerate.framework
Copy Bundle Resources.└── face-tracker-v003.bundle
Copy Bundle Resources.└── HuiYanSDKUI.bundle
CloudHuiYanSDK_FW folder to the directory at the same level as that of the integration project Podfile.Podfile:target 'HuiYanAuthDemo' douse_frameworks!pod 'CloudHuiYanSDK_FW', :path => './CloudHuiYanSDK_FW'end
pod install.Build Phases settingsOther Linker Flags to add -ObjC.ViewController.m and set the extension to .mm (for a Swift project, add the system library libc++.tbd).info.plist of the main project to add the corresponding permission declaration.<key>Privacy - Camera Usage Description</key><string>FaceID requires you to grant the camera permission for face recognition.</string>
#import <HuiYanOverseasSDK/HuiYanOsApi.h>#import <HuiYanOverseasSDK/HuiYanOSKit.h>// Get the tokenNSString *faceToken = self.tokenTextField.text;// Configure the SDKHuiYanOsConfig *config = [[HuiYanOsConfig alloc] init];// Set the licenseconfig.authLicense = [[NSBundle mainBundle] pathForResource:@"xxx.lic" ofType:@""];// Timeout configuration for the preparation stageconfig.prepareTimeoutMs = 20000;// Timeout configuration for the detection stageconfig.authTimeOutMs = 20000;config.isDeleteVideoCache = YES;config.languageType = EN;// config.userLanguageFileName = @"ko";// config.userLanguageBundleName = @"UseLanguageBundle";config.iShowTipsPage = YES;config.isGetBestImg = YES;[[HuiYanOSKit sharedInstance] startHuiYaneKYC:faceToken withConfig:configwitSuccCallback:^(HuiYanOsAuthResult * _Nonnull authResult, id _Nullable reserved) {NSString *bestImg = authResult.bestImage;NSString *token = authResult.faceToken;} withFailCallback:^(int errCode, NSString * _Nonnull errMsg, id _Nullable reserved) {NSString *showMsg = [NSString stringWithFormat:@"err:%d:%@",errCode,errMsg];NSLog(@"err:%@",showMsg);}];
// Release the resources before exit- (void)dealloc {[HuiYanOsApi release];}//[iOS demo](https://github.com/TencentCloud/huiyan-faceid-demo/tree/main/faceid-iOS-example)[Android demo](https://github.com/TencentCloud/huiyan-faceid-demo/tree/main/id-verification-android-example)
Feedback