本文介绍金融级多因子意愿认证服务端接入的.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.5
  • 使用包管理安装。
    Install-Package AlibabaCloud.SDK.Cloudauth20190307 -Version 2.0.5

调用示例

InitFaceVerify接口调用示例

关于参数的具体描述,请参见InitFaceVerify

using System;

using System.Collections.Generic;
using Tea;


namespace InitFaceVerify
{
    public class Program
    {

        public static AlibabaCloud.SDK.Cloudauth20190307.Client CreateClient(string endpoint)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                // 您的AccessKey ID。
                AccessKeyId = "您的AccessKey ID",
                // 您的AccessKey Secret。
                AccessKeySecret = "您的AccessKey Secret",
                // 设置HTTP代理。
                // HttpProxy = "http://xx.xx.xx.xx:xxxx",
                // 设置HTTPS代理。
                // HttpsProxy = "https://username:password@xxx.xxx.xxx.xxx:9999",
                Endpoint = endpoint,
            };
            return new AlibabaCloud.SDK.Cloudauth20190307.Client(config);
        }

        public static void Main(string[] args)
        {
            AlibabaCloud.SDK.Cloudauth20190307.Models.InitFaceVerifyRequest request = new AlibabaCloud.SDK.Cloudauth20190307.Models.InitFaceVerifyRequest
            {
                // 固定值。
                ProductCode = "MFVC",
                // 请输入场景ID。
                SceneId = xxx,
                // 设置商户请求的唯一标识。
                OuterOrderNo = "xxxxx",
                UserId = "用户ID",
                // 固定值IDENTITY_CARD。
                CertType = "IDENTITY_CARD",
                CertName = "xxx",
                CertNo = "1******************9",
                MetaInfo = "{\"zimVer\":\"3.0.0\",\"appVersion\": \"1\",\"bioMetaInfo\": \"4.1.0:11501568,0\",\"appName\": \"com.aliyun.antcloudauth\",\"deviceType\": \"ios\",\"osVersion\": \"iOS 10.3.2\",\"apdidToken\": \"\",\"deviceModel\": \"iPhone9,1\"}",
                //Mobile = "1390000****",
                //Ip = "114.100.XX.XX",
                //CallbackUrl = "https://www.aliyundoc.com",
                //CallbackToken = "xxxxxxx"
            };
            AlibabaCloud.SDK.Cloudauth20190307.Models.InitFaceVerifyResponse response = InitFaceVerifyAutoRoute(request);
            // 不支持服务自动路由。
            // AlibabaCloud.SDK.Cloudauth20190307.Models.InitFaceVerifyResponse response = InitFaceVerify("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.CertifyId);
        }


        public static AlibabaCloud.SDK.Cloudauth20190307.Models.InitFaceVerifyResponse InitFaceVerifyAutoRoute(AlibabaCloud.SDK.Cloudauth20190307.Models.InitFaceVerifyRequest request)
        {
            List<string> endpoints = new List<string>
            {
                "cloudauth.cn-shanghai.aliyuncs.com",
                "cloudauth.cn-beijing.aliyuncs.com"
            };
            AlibabaCloud.SDK.Cloudauth20190307.Models.InitFaceVerifyResponse lastResponse = null;

            foreach (var endpoint in endpoints)
            {
                try
                {
                    AlibabaCloud.SDK.Cloudauth20190307.Models.InitFaceVerifyResponse response = InitFaceVerify(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.InitFaceVerifyResponse InitFaceVerify(string endpoint, AlibabaCloud.SDK.Cloudauth20190307.Models.InitFaceVerifyRequest 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.InitFaceVerifyWithOptions(request, runtime);
        }
    }
}

DescribeFaceVerify接口调用示例

关于参数的具体描述,请参见DescribeFaceVerify

using System;

using System.Collections.Generic;
using Tea;


namespace DescribeFaceVerify
{
    public class Program
    {

        public static AlibabaCloud.SDK.Cloudauth20190307.Client CreateClient(string endpoint)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                // 您的AccessKey ID。
                AccessKeyId = "您的AccessKey ID",
                // 您的AccessKey Secret。
                AccessKeySecret = "您的AccessKey Secret",
                // 设置HTTP代理。
                // HttpProxy = "http://xx.xx.xx.xx:xxxx",
                // 设置HTTPS代理。
                // HttpsProxy = "https://xx.xx.xx.xx:xxxx",
                Endpoint = endpoint,
            };
            return new AlibabaCloud.SDK.Cloudauth20190307.Client(config);
        }

        public static void Main(string[] args)
        {
            AlibabaCloud.SDK.Cloudauth20190307.Models.DescribeFaceVerifyRequest request = new AlibabaCloud.SDK.Cloudauth20190307.Models.DescribeFaceVerifyRequest
            {
                // 请输入场景ID。
                SceneId = xxx,
                CertifyId = "91707dc296d469ad38e4c5efa6a0xxxx",
            };
            AlibabaCloud.SDK.Cloudauth20190307.Models.DescribeFaceVerifyResponse response = DescribeFaceVerifyAutoRoute(request);
            // 不支持服务自动路由。
            // AlibabaCloud.SDK.Cloudauth20190307.Models.DescribeFaceVerifyResponse response = DescribeFaceVerify("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.SubCode);
            Console.WriteLine(response.Body.ResultObject.MaterialInfo);
            Console.WriteLine(response.Body.ResultObject.IdentityInfo);
            Console.WriteLine(response.Body.ResultObject.DeviceToken);
        }


        public static AlibabaCloud.SDK.Cloudauth20190307.Models.DescribeFaceVerifyResponse DescribeFaceVerifyAutoRoute(AlibabaCloud.SDK.Cloudauth20190307.Models.DescribeFaceVerifyRequest request)
        {
            List<string> endpoints = new List<string>
            {
                "cloudauth.cn-shanghai.aliyuncs.com",
                "cloudauth.cn-beijing.aliyuncs.com"
            };
            AlibabaCloud.SDK.Cloudauth20190307.Models.DescribeFaceVerifyResponse lastResponse = null;

            foreach (var endpoint in endpoints)
            {
                try
                {
                    AlibabaCloud.SDK.Cloudauth20190307.Models.DescribeFaceVerifyResponse response = DescribeFaceVerify(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.DescribeFaceVerifyResponse DescribeFaceVerify(string endpoint, AlibabaCloud.SDK.Cloudauth20190307.Models.DescribeFaceVerifyRequest 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.DescribeFaceVerifyWithOptions(request, runtime);
        }
    }
}