本文介紹了金融級實人認證純服務端API的.NET SDK調用示例。
SDK使用說明
如果需要其他語言的SDK示例代碼,您可以通過OpenAPI 開發者門戶在線調試工具調試API接口,該工具會自動生成相應API的SDK調用示例代碼。您可以單擊以下接口鏈接進行調試:
前提條件
需要使用的.NET Framework為4.5.0及以上版本或者.NET Standard為2.0及以上版本。
已添加認證場景,并獲取對應的場景ID。具體操作,請參見添加認證場景。
安裝SDK
關于.NET SDK源代碼,請參見.NET SDK包。
SDK有以下兩種安裝方式,請選擇合適的方式安裝:
通過.NET命令行安裝。
dotnet add package AlibabaCloud.SDK.Cloudauth20190307 --version 2.0.3 dotnet add package Aliyun.Credentials
使用包管理安裝。
Install-Package AlibabaCloud.SDK.Cloudauth20190307 -Version 2.0.3 Install-Package Aliyun.Credentials
說明
Credentials工具配置方法,請參見身份驗證配置。
照片實人認證調用示例
關于參數的具體描述,請參見照片實人認證。
using System;
using System.Collections.Generic;
using Tea;
namespace ContrastFaceVerify
{
public class Program
{
public static AlibabaCloud.SDK.Cloudauth20190307.Client CreateClient(string endpoint)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
Credential=new Aliyun.Credentials.Client(null)
};
config.Endpoint = endpoint;
return new AlibabaCloud.SDK.Cloudauth20190307.Client(config);
}
public static void Main(string[] args)
{
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyRequest request = new AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyRequest
{
// 固定值。
ProductCode = "ID_MIN",
// 請輸入場景ID。
SceneId = xxx,
OuterOrderNo = "商戶請求的唯一標識",
Model = "NO_LIVENESS",
// 固定值IDENTITY_CARD。
CertType = "IDENTITY_CARD",
CertName = "張三",
CertNo = "xxx",
//Ip = "用戶IP地址",
//UserId = "用戶ID",
//Mobile = "130xxxxxxxx",
//DeviceToken = "通過設備指紋獲取的deviceToken",
// 請在以下四種方式中選擇其一。
// 1.照片Base64編碼。
// 2.照片OSS Bucket名和文件名。
// 3.照片OSS的URL地址。
// 4.已經實人認證通過的CertifyId。
// 方式一:照片Base64。
//FaceContrastPicture = "人臉照片Base64編碼",
// 方式二:照片OSS Bucket名和文件名。
// OssBucketName = "cn-shanghai-aliyun-cloudauth-xxxxx",
// OssObjectName = "verify/xxxxx/xxxxxx.jpeg",
// 方式三:照片OSS的URL地址,公網可訪問。
FaceContrastPictureUrl = "https://cn-shanghai-aliyun-cloudauth-xxxxxx.oss-cn-shanghai.aliyuncs.com/verify/xxxxx/xxxxx.jpeg",
// 方式四:已經實人認證通過的CertifyId。
// CertifyId = "0bfa7c493f850e5178b9f8613634c9xx",
// 如需開啟個人信息加密傳輸。
// EncryptType = "SM2",
// CertName = "BCRD/7ZkNy7Q*****M1BMBezZe8GaYHrLwyJv558w==",
// CertNo = "BMjsstxK3S4b1YH*****Pet8ECObfxmLN92SLsNg=="
};
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse response = ContrastFaceVerifyAutoRoute(request);
// 不支持服務自動路由。
//AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse response = ContrastFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
Console.WriteLine(response.Body.RequestId);
Console.WriteLine(response.Body.Code);
Console.WriteLine(response.Body.Message);
Console.WriteLine(response.Body.ResultObject.Passed);
Console.WriteLine(response.Body.ResultObject.IdentityInfo);
Console.WriteLine(response.Body.ResultObject.SubCode);
Console.WriteLine(response.Body.ResultObject.MaterialInfo);
Console.WriteLine(response.Body.ResultObject.CertifyId);
}
public static AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse ContrastFaceVerifyAutoRoute(AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyRequest request)
{
List<string> endpoints = new List<string>
{
"cloudauth.cn-shanghai.aliyuncs.com",
"cloudauth.cn-beijing.aliyuncs.com"
};
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse lastResponse = null;
foreach (var endpoint in endpoints)
{
try
{
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse response = ContrastFaceVerify(endpoint, request);
lastResponse = response;
if (response is not null)
{
if (AlibabaCloud.TeaUtil.Common.EqualNumber(500, (int)(response.StatusCode)))
{
continue;
}
if (response.Body is not null)
{
if (AlibabaCloud.TeaUtil.Common.EqualString("500", response.Body.Code))
{
continue;
}
}
}
return response;
}
catch (TeaException err)
{
Console.WriteLine(err);
// 網絡異常,切換到下個區域調用。
if (AlibabaCloud.TeaUtil.Common.EqualString("ServiceUnavailable", err.Code))
{
continue;
}
}
catch (Exception _err)
{
Console.WriteLine(_err);
continue;
}
}
return lastResponse;
}
public static AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse ContrastFaceVerify(string endpoint, AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyRequest request)
{
AlibabaCloud.SDK.Cloudauth20190307.Client client = CreateClient(endpoint);
// 創建RuntimeObject實例并設置運行參數。
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
runtime.ReadTimeout = 10000;
runtime.ConnectTimeout = 10000;
return client.ContrastFaceVerifyWithOptions(request, runtime);
}
}
}
視頻實人認證調用示例
支持OSS對象存儲方式和本地文件兩種方式。關于參數的具體描述,請參見視頻實人認證。
使用本地文件的方式(推薦)
using System;
using System.Collections.Generic;
using Tea;
using System.IO;
namespace ContrastFaceVerify
{
public class Program
{
public static AlibabaCloud.SDK.Cloudauth20190307.Client CreateClient(string endpoint)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
Credential=new Aliyun.Credentials.Client(null)
};
config.Endpoint = endpoint;
return new AlibabaCloud.SDK.Cloudauth20190307.Client(config);
}
public static void Main(string[] args)
{
FileStream fs = new FileStream("本地文件路徑", FileMode.Open);
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyAdvanceRequest request = new AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyAdvanceRequest
{
// 固定值。
ProductCode = "ID_MIN_VIDEO",
// 請輸入場景ID。
SceneId = xxx,
OuterOrderNo = "商戶請求的唯一標識",
Model = "FRONT_CAMERA_LIVENESS",
// 固定值IDENTITY_CARD。
CertType = "IDENTITY_CARD",
CertName = "張三",
CertNo = "xxx",
//Ip = "用戶IP地址",
//UserId = "用戶ID",
//Mobile = "130xxxxxxxx",
//DeviceToken = "通過設備指紋獲取的deviceToken",
FaceContrastFileObject = fs,
// 如需開啟個人信息加密傳輸。
// EncryptType = "SM2",
// CertName = "BCRD/7ZkNy7Q*****M1BMBezZe8GaYHrLwyJv558w==",
// CertNo = "BMjsstxK3S4b1YH*****Pet8ECObfxmLN92SLsNg=="
};
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse response = ContrastFaceVerifyAutoRoute(request);
// 不支持服務自動路由。
//AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse response = ContrastFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
Console.WriteLine(response.Body.RequestId);
Console.WriteLine(response.Body.Code);
Console.WriteLine(response.Body.Message);
Console.WriteLine(response.Body.ResultObject.Passed);
Console.WriteLine(response.Body.ResultObject.IdentityInfo);
Console.WriteLine(response.Body.ResultObject.SubCode);
Console.WriteLine(response.Body.ResultObject.MaterialInfo);
Console.WriteLine(response.Body.ResultObject.CertifyId);
fs.Close();
}
public static AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse ContrastFaceVerifyAutoRoute(AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyAdvanceRequest request)
{
List<string> endpoints = new List<string>
{
"cloudauth.cn-shanghai.aliyuncs.com",
"cloudauth.cn-beijing.aliyuncs.com"
};
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse lastResponse = null;
foreach (var endpoint in endpoints)
{
try
{
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse response = ContrastFaceVerify(endpoint, request);
lastResponse = response;
if (response is not null)
{
if (AlibabaCloud.TeaUtil.Common.EqualNumber(500, (int)(response.StatusCode)))
{
continue;
}
if (response.Body is not null)
{
if (AlibabaCloud.TeaUtil.Common.EqualString("500", response.Body.Code))
{
continue;
}
}
}
return response;
}
catch (TeaException err)
{
Console.WriteLine(err);
// 網絡異常,切換到下個區域調用。
if (AlibabaCloud.TeaUtil.Common.EqualString("ServiceUnavailable", err.Code))
{
continue;
}
}
catch (Exception _err)
{
Console.WriteLine(_err);
continue;
}
}
return lastResponse;
}
public static AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse ContrastFaceVerify(string endpoint, AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyAdvanceRequest request)
{
AlibabaCloud.SDK.Cloudauth20190307.Client client = CreateClient(endpoint);
// 創建RuntimeObject實例并設置運行參數。
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
runtime.ReadTimeout = 10000;
runtime.ConnectTimeout = 10000;
return client.ContrastFaceVerifyAdvance(request, runtime);
}
}
}
使用OSS對象存儲的方式
using System;
using System.Collections.Generic;
using Tea;
namespace ContrastFaceVerify
{
public class Program
{
public static AlibabaCloud.SDK.Cloudauth20190307.Client CreateClient(string endpoint)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
Credential=new Aliyun.Credentials.Client(null)
};
config.Endpoint = endpoint;
return new AlibabaCloud.SDK.Cloudauth20190307.Client(config);
}
public static void Main(string[] args)
{
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyRequest request = new AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyRequest
{
// 固定值。
ProductCode = "ID_MIN_VIDEO",
// 請輸入場景ID。
SceneId = xxx,
OuterOrderNo = "商戶請求的唯一標識",
Model = "FRONT_CAMERA_LIVENESS",
// 固定值IDENTITY_CARD。
CertType = "IDENTITY_CARD",
CertName = "張三",
CertNo = "xxx",
//Ip = "用戶IP地址",
//UserId = "用戶ID",
//Mobile = "130xxxxxxxx",
//DeviceToken = "通過設備指紋獲取的deviceToken",
OssBucketName = "cn-shanghai-aliyun-cloudauth-xxxxx",
OssObjectName = "verify/xxxxx/xxxxxx.mp4",
// 如需開啟個人信息加密傳輸。
// EncryptType = "SM2",
// CertName = "BCRD/7ZkNy7Q*****M1BMBezZe8GaYHrLwyJv558w==",
// CertNo = "BMjsstxK3S4b1YH*****Pet8ECObfxmLN92SLsNg=="
};
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse response = ContrastFaceVerifyAutoRoute(request);
// 不支持服務自動路由。
//AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse response = ContrastFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
Console.WriteLine(response.Body.RequestId);
Console.WriteLine(response.Body.Code);
Console.WriteLine(response.Body.Message);
Console.WriteLine(response.Body.ResultObject.Passed);
Console.WriteLine(response.Body.ResultObject.IdentityInfo);
Console.WriteLine(response.Body.ResultObject.SubCode);
Console.WriteLine(response.Body.ResultObject.MaterialInfo);
Console.WriteLine(response.Body.ResultObject.CertifyId);
}
public static AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse ContrastFaceVerifyAutoRoute(AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyRequest request)
{
List<string> endpoints = new List<string>
{
"cloudauth.cn-shanghai.aliyuncs.com",
"cloudauth.cn-beijing.aliyuncs.com"
};
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse lastResponse = null;
foreach (var endpoint in endpoints)
{
try
{
AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse response = ContrastFaceVerify(endpoint, request);
lastResponse = response;
if (response is not null)
{
if (AlibabaCloud.TeaUtil.Common.EqualNumber(500, (int)(response.StatusCode)))
{
continue;
}
if (response.Body is not null)
{
if (AlibabaCloud.TeaUtil.Common.EqualString("500", response.Body.Code))
{
continue;
}
}
}
return response;
}
catch (TeaException err)
{
Console.WriteLine(err);
// 網絡異常,切換到下個區域調用。
if (AlibabaCloud.TeaUtil.Common.EqualString("ServiceUnavailable", err.Code))
{
continue;
}
}
catch (Exception _err)
{
Console.WriteLine(_err);
continue;
}
}
return lastResponse;
}
public static AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyResponse ContrastFaceVerify(string endpoint, AlibabaCloud.SDK.Cloudauth20190307.Models.ContrastFaceVerifyRequest request)
{
AlibabaCloud.SDK.Cloudauth20190307.Client client = CreateClient(endpoint);
// 創建RuntimeObject實例并設置運行參數。
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
runtime.ReadTimeout = 10000;
runtime.ConnectTimeout = 10000;
return client.ContrastFaceVerifyWithOptions(request, runtime);
}
}
}
文檔內容是否對您有幫助?