SDK调用示例

本文介绍在金融级NFC认证方案App接入场景下,如何下载和集成适合不同编程语言的SDK,并调用OpenAPI的示例流程。

服务端需要集成的OpenAPI

说明

在基于阿里云OpenAPI进行二次开发前,您可以通过OpenAPI门户提供的网页或命令行方式,预先验证OpenAPI请求方式,入参和查看OpenAPI的返回结果。当调用出错时,OpenAPI 门户会提示您如何解决,帮助您快速了解OpenAPI功能及使用方法。

步骤一:开通服务

在使用金融级实人认证服务之前,您需要开通服务。具体操作,请参见开通金融级实人认证服务

步骤二:创建RAM用户并授权

在集成SDK前,您需要创建一个用户调用SDK的用户身份,获取身份关联的OpenAPI访问凭据,并授予访问云上资源的访问权限。如何创建和授权RAM用户,以及如何生成用于调用服务的AccessKey,请参见授权RAM用户访问服务

步骤三:添加认证场景

认证场景指您的用户使用金融级实人认证服务完成用户实人认证的不同场景,例如,登录、支付等。您可以添加一个或多个场景,并为不同的场景配置不同的认证方案。调用InitFaceVerify发起认证请求时,需要传输认证场景ID。如何添加认证场景并获取认证场景ID, 请参见添加认证场景

说明

在添加认证场景时,您可以授权阿里云访问指定OSS存储空间,用于存储认证的资料图片。具体操作,请参见授权金融级实人认证访问OSS存储空间

步骤四:集成SDK并编辑写代码

服务接入点

目前支持的接入地域如下表所示。

重要

建议您参考本文示例代码,配置主备地域Endpoint。在主Endpoint发生故障时可以自动切换到备用Endpoint,保证系统的持续可用性。

地域

服务地址

VPC地址

全局接入地址

华东2(上海)

IPv4:cloudauth.cn-shanghai.aliyuncs.com

cloudauth-vpc.cn-shanghai.aliyuncs.com

  • IPv4:cloudauth.aliyuncs.com

  • IPv6:cloudauth-dualstack.aliyuncs.com

IPv6:cloudauth-dualstack.aliyuncs.com

华北2(北京)

IPv4:cloudauth.cn-beijing.aliyuncs.com

cloudauth-vpc.cn-beijing.aliyuncs.com

IPv6:cloudauth-dualstack.cn-beijing.aliyuncs.com

SDK安装与源码下载

您可根据业务实际的技术选型,选择合适的SDK语言进行集成。

支持语言

Github源码地址

SDK下载地址

Java

Alibaba Cloud Green SDK for Java

下载Java SDK

Python

Alibaba Cloud Green SDK for Python

下载Python SDK

Typescript

Alibaba Cloud Green SDK for Typescript

下载TypeScript SDK

Go

Alibaba Cloud Green SDK for Go

下载Go SDK

PHP

Alibaba Cloud Green SDK for PHP

下载PHP SDK

C#

Alibaba Cloud Green SDK for C#

下载C# SDK

C++

Alibaba Cloud Green SDK for C++

下载C++ SDK

编写代码(Java语言示例)

下面以Java语言为例介绍(要求JDK 1.8及以上版本)。

  1. 在pom.xml中添加如下依赖,即可在Maven工程中使用SDK。

    • Java SDK依赖。以下依赖版本仅供参考,建议在实际配置时获取最新依赖版本

      <dependency>
       <groupId>com.aliyun</groupId>
       <artifactId>cloudauth20190307</artifactId>
       <version>2.1.1</version>
      </dependency>
    • 身份验证依赖。请查看ChangeLog.txt获取所有已发布的版本列表(建议使用最新的版本)。

      <dependency>
         <groupId>com.aliyun</groupId>
         <artifactId>credentials-java</artifactId>
         <version>LATEST</version>
      </dependency>
      说明

      本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见在Linux、macOS和Windows系统配置环境变量

  2. 示例代码。

    • InitFaceVerify接口调用示例

      import java.util.Arrays;
      import java.util.List;
      
      import com.aliyun.cloudauth20190307.Client;
      import com.aliyun.cloudauth20190307.models.*;
      import com.aliyun.teaopenapi.models.Config;
      import com.aliyun.teautil.models.RuntimeOptions;
      
      public class InitFaceVerify {
      
          public static void main(String[] args) throws Exception {
      
              InitFaceVerifyRequest request = new InitFaceVerifyRequest();
              // 请输入场景ID+L。
              request.setSceneId(0L);
              // 设置商户请求的唯一标识。
              request.setOuterOrderNo("xxxx");
              // 认证方案。
              request.setProductCode("NFC_QY");
              request.setCertType("PASSPORT");
              //request.setCertName("张先生");
              //request.setCertNo("xxxx");
              request.setUserId("12345xxxx");
              //request.setBirthday("2011-02-01");
              //request.setValidityDate("2020-02-01");
              request.setReadImg("Y");
              // MetaInfo环境参数。
              request.setMetaInfo("{}");
              //request.setMobile("130xxxxxxxx");
              //request.setIp("114.xxx.xxx.xxx");
              //request.setCallbackUrl("https://www.aliyundoc.com");
              //request.setCallbackToken("xxxxx");
              //request.setMode("3");
              // 如需开启个人信息加密传输。
              //request.setEncryptType("SM2");
              //request.setCertName("BCRD/7ZkNy7Q*****M1BMBezZe8GaYHrLwyJv558w==");
              //request.setCertNo("BMjsstxK3S4b1YH*****Pet8ECObfxmLN92SLsNg==");
      
              // 推荐,支持服务路由。
              InitFaceVerifyResponse response = initFaceVerifyAutoRoute(request);
      
              // 不支持服务自动路由。
              //InitFaceVerifyResponse response = initFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
      
              response.getBody().getRequestId();
              response.getBody().getResultObject().getCertifyId();
              System.out.println(response.getBody().getRequestId());
              System.out.println(response.getBody().getCode());
              System.out.println(response.getBody().getMessage());
              System.out.println(response.getBody().getResultObject() == null ? null
                      : response.getBody().getResultObject().getCertifyId());
          }
      
          private static InitFaceVerifyResponse initFaceVerifyAutoRoute(InitFaceVerifyRequest request) {
              // 第一个为主区域Endpoint,第二个为备区域Endpoint。
              List<String> endpoints = Arrays.asList("cloudauth.cn-shanghai.aliyuncs.com", "cloudauth.cn-beijing.aliyuncs.com");
              InitFaceVerifyResponse lastResponse = null;
              for (int i=0; i<endpoints.size(); i++) {
                  try {
                      InitFaceVerifyResponse response = initFaceVerify(endpoints.get(i), request);
                      lastResponse = response;
      
                      // 服务端错误,切换到下个区域调用。
                      if(response != null){
                          if(500 == response.getStatusCode()){
                              continue;
                          }
                          if(response.getBody() != null){
                              if("500".equals(response.getBody().getCode())){
                                  continue;
                              }
                          }
                      }
      
                      // 正常返回
                      return lastResponse;
                  }catch (Exception e) {
                      e.printStackTrace();
                      if(i == endpoints.size()-1){
                          throw new RuntimeException(e);
                      }
                  }
              }
      
              return lastResponse;
          }
      
          private static InitFaceVerifyResponse initFaceVerify(String endpoint, InitFaceVerifyRequest request)
                  throws Exception {
              // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
              // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
              // 本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。
              com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
              Config config = new Config();
              config.setCredential(credentialClient);
              config.setEndpoint(endpoint);
              // 设置http代理。
              //config.setHttpProxy("http://xx.xx.xx.xx:xxxx");
              // 设置https代理。
              //config.setHttpsProxy("https://xx.xx.xx.xx:xxxx");
              Client client = new Client(config);
      
              // 创建RuntimeObject实例并设置运行参数。
              RuntimeOptions runtime = new RuntimeOptions();
              runtime.readTimeout = 10000;
              runtime.connectTimeout = 10000;
      
              return client.initFaceVerifyWithOptions(request, runtime);
          }
      
      }
    • DescribeFaceVerify接口调用示例

      import java.util.Arrays;
      import java.util.List;
      
      import com.aliyun.cloudauth20190307.Client;
      import com.aliyun.cloudauth20190307.models.DescribeFaceVerifyRequest;
      import com.aliyun.cloudauth20190307.models.DescribeFaceVerifyResponse;
      import com.aliyun.teaopenapi.models.Config;
      import com.aliyun.teautil.models.RuntimeOptions;
      
      public class DescribeFaceVerify {
      
          public static void main(String[] args) throws Exception {
      
              // 通过以下代码创建API请求并设置参数。
              DescribeFaceVerifyRequest request = new DescribeFaceVerifyRequest();
              // 请输入场景ID+L。
              request.setSceneId(0L);
      
              request.setCertifyId("xxxx");
      
              // 推荐,支持服务路由。
              DescribeFaceVerifyResponse response = describeFaceVerifyAutoRoute(request);
      
              // 不支持服务自动路由。
              //DescribeFaceVerifyResponse response = describeFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
      
              System.out.println(response.getBody().getRequestId());
              System.out.println(response.getBody().getCode());
              System.out.println(response.getBody().getMessage());
              System.out.println(
                      response.getBody().getResultObject() == null ? null : response.getBody().getResultObject().getSuccess());
              System.out.println(
                      response.getBody().getResultObject() == null ? null : response.getBody().getResultObject().getSubCode());
              System.out.println(
                      response.getBody().getResultObject() == null ? null
                              : response.getBody().getResultObject().getMaterialInfo());
          }
      
          private static DescribeFaceVerifyResponse describeFaceVerifyAutoRoute(DescribeFaceVerifyRequest request) {
              // 第一个为主区域Endpoint,第二个为备区域Endpoint。
              List<String> endpoints = Arrays.asList("cloudauth.cn-shanghai.aliyuncs.com", "cloudauth.cn-beijing.aliyuncs.com");
              DescribeFaceVerifyResponse lastResponse = null;
              for (int i = 0; i < endpoints.size(); i++) {
                  try {
                      DescribeFaceVerifyResponse response = describeFaceVerify(endpoints.get(i), request);
                      lastResponse = response;
      
                      // 服务端错误,切换到下个区域调用。
                      if (response != null) {
                          if (500 == response.getStatusCode()) {
                              continue;
                          }
                          if (response.getBody() != null) {
                              if ("500".equals(response.getBody().getCode())) {
                                  continue;
                              }
                          }
                      }
      
                      return lastResponse;
                  } catch (Exception e) {
                      if (i == endpoints.size() - 1) {
                          throw new RuntimeException(e);
                      }
                  }
              }
      
              return lastResponse;
          }
      
          private static DescribeFaceVerifyResponse describeFaceVerify(String endpoint, DescribeFaceVerifyRequest request)
                  throws Exception {
              // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
              // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
              // 本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。
              com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
              Config config = new Config();
              config.setCredential(credentialClient);
              config.setEndpoint(endpoint);
              // 设置http代理。
              //config.setHttpProxy("http://xx.xx.xx.xx:xxxx");
              // 设置https代理。
              //config.setHttpsProxy("http://xx.xx.xx.xx:xxxx");
              Client client = new Client(config);
      
              // 创建RuntimeObject实例并设置运行参数。
              RuntimeOptions runtime = new RuntimeOptions();
              runtime.readTimeout = 10000;
              runtime.connectTimeout = 10000;
      
              return client.describeFaceVerifyWithOptions(request, runtime);
          }
      }

其他编程语言调用示例

PHP

InitFaceVerify接口调用示例

<?php
namespace AlibabaCloud\SDK\Sample\Verify\Id;

use AlibabaCloud\Credentials\Credential; 
use AlibabaCloud\SDK\Cloudauth\V20190307\Cloudauth;
use AlibabaCloud\SDK\Cloudauth\V20190307\Models\InitFaceVerifyRequest;
use AlibabaCloud\SDK\Cloudauth\V20190307\Models\InitFaceVerifyResponse;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Exception;

use Darabonba\OpenApi\Models\Config;

class InitFaceVerify
{

    /**
     * createClient
     * @param string $endpoint
     * @return Cloudauth
     */
    public static function createClient(string $endpoint): Cloudauth
    {
        // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        // 本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。
        $credential = new Credential([]);
        $config = new Config([
			  // 使用 credential 配置凭证
    		    "credential" => $credential,
            // 设置HTTP代理。
            // "httpProxy" => "<http://xx.xx.xx.xx:xxxx>",
            // 设置HTTPS代理
            // "httpsProxy" => "<https://xx.xx.xx.xx:xxxx>",
            "endpoint" => $endpoint

        ]);
        return new Cloudauth($config);
    }

    /**
     * main
     * @return void
     * @throws Exception
     */
    public static function main()
    {
        $request = new InitFaceVerifyRequest([
            // 请输入场景ID。
            "sceneId" => 0,
            "outerOrderNo" => "<商户请求的唯一标识>",
            // 要接入的认证方案。
            "productCode" => "NFC_QY",
            // 要进行活体检测的类型。
            "certType" => "PASSPORT",
            //"certName" => "<xxx>",
            //"certNo" => "<xxx>",
            //"birthday" => "<2011-02-01>",
            //"validityDate" => "<2020-02-01>",
            //"readImg" => "<Y>",
            // MetaInfo环境参数,需要通过客户端SDK获取。
            "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" => "<xxx>",
            // "ip" => "<114.xxx.xxx.xxx>",
            "userId" => "<12345xxxx>",
            // "mode" => "<3>",
            // "callbackUrl" => "<https://www.aliyundoc.com>",
            // "callbackToken" => "<xxxxxxx>",
            // 如需开启个人信息加密传输。
            // "encryptType" => "SM2",
            // "certName" => "BCRD/7ZkNy7Q*****M1BMBezZe8GaYHrLwyJv558w==",
            // "certNo" => "BMjsstxK3S4b1YH*****Pet8ECObfxmLN92SLsNg=="
        ]);

        // 推荐,支持服务路由。
        $response = self::initFaceVerifyAutoRoute($request);
        // 不支持服务自动路由。
        // $response = self::initFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", $request);
        var_dump($response->body->requestId);
        var_dump($response->body->code);
        var_dump($response->body->message);
        var_dump($response->body->resultObject->certifyId);
    }

    /**
     * initFaceVerifyAutoRoute
     * @param InitFaceVerifyRequest $request
     * @return InitFaceVerifyResponse|null
     */
    public static function initFaceVerifyAutoRoute(InitFaceVerifyRequest $request): ?InitFaceVerifyResponse
    {
        $endpoints = [
            "cloudauth.cn-shanghai.aliyuncs.com",
            "cloudauth.cn-beijing.aliyuncs.com"
        ];
        foreach ($endpoints as $endpoint) {
            try {
                $response = self::initFaceVerify($endpoint, $request);
                if (Utils::equalNumber(500, $response->statusCode)) {
                    continue;
                }
                if(Utils::equalString("500", $response->body->code)){
                    continue;
                }
                return $response;
            } catch (Exception $err) {
                var_dump($err -> getCode());
                var_dump($err -> getMessage());
            }
        }
        return null;
    }

    /**
     * initFaceVerify
     * @param string $endpoint
     * @param InitFaceVerifyRequest $request
     * @return InitFaceVerifyResponse
     */
    public static function initFaceVerify(string $endpoint, InitFaceVerifyRequest $request): InitFaceVerifyResponse
    {
        $client = self::createClient($endpoint);
        // 创建RuntimeObject实例并设置运行参数。
        $runtime = new RuntimeOptions([]);
        $runtime->readTimeout = 10000;
        $runtime->connectTimeout = 10000;
        return $client->initFaceVerifyWithOptions($request, $runtime);
    }
}

$path = __DIR__ . \DIRECTORY_SEPARATOR . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
InitFaceVerify::main();

DescribeFaceVerify接口调用示例

<?php

namespace AlibabaCloud\SDK\Sample\Verify\Id;

use AlibabaCloud\Credentials\Credential; 
use AlibabaCloud\SDK\Cloudauth\V20190307\Cloudauth;
use AlibabaCloud\SDK\Cloudauth\V20190307\Models\DescribeFaceVerifyRequest;
use AlibabaCloud\SDK\Cloudauth\V20190307\Models\DescribeFaceVerifyResponse;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use \Exception;

use Darabonba\OpenApi\Models\Config;

class DescribeFaceVerify {

    /**
     * createClient
     * @param string $endpoint
     * @return Cloudauth
     */
    public static function createClient(string $endpoint): Cloudauth
    {
        // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        // 本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。 
        $credential = new Credential([]);
        $config = new Config([
		  	// 使用 credential 配置凭证
    		    "credential" => $credential,
            // 设置HTTP代理。
            // "httpProxy" => "<http://xx.xx.xx.xx:xxxx>",
            // 设置HTTPS代理
            // "httpsProxy" => "<https://xx.xx.xx.xx:xxxx>",
            "endpoint" => $endpoint

        ]);
        return new Cloudauth($config);
    }

    /**
     * main
     * @return void
     */
    public static function main(){
        $request = new DescribeFaceVerifyRequest();
        // 场景ID。
        $request->sceneId=0;
        // 认证ID。
        $request->certifyId="<xxx>";
        // 推荐,支持服务路由。
        $response = self::describeFaceVerifyAutoRoute($request);
        // 不支持服务自动路由。
        // $response = self::describeFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", $request);
        var_dump($response->body->requestId);
        var_dump($response->body->code);
        var_dump($response->body->message);
        var_dump($response->body->resultObject->success);
        var_dump($response->body->resultObject->subCode);
        var_dump($response->body->resultObject->materialInfo);
    }

    /**
     * describeFaceVerifyAutoRoute
     * @param DescribeFaceVerifyRequest $request
     * @return DescribeFaceVerifyResponse|null
     */
    public static function describeFaceVerifyAutoRoute(DescribeFaceVerifyRequest $request): ?DescribeFaceVerifyResponse
    {
        $endpoints = [
            "cloudauth.cn-shanghai.aliyuncs.com",
            "cloudauth.cn-beijing.aliyuncs.com"
        ];
        foreach($endpoints as $endpoint){
            try {
                $response = self::describeFaceVerify($endpoint, $request);
                if (Utils::equalNumber(500, $response->statusCode)) {
                    continue;
                }
                if(Utils::equalString("500", $response->body->code)){
                    continue;
                }
                return $response;
            }
            catch (Exception $err) {
                var_dump($err -> getCode());
                var_dump($err -> getMessage());
            }
        }
        return null;
    }

    /**
     * describeFaceVerify
     * @param string $endpoint
     * @param DescribeFaceVerifyRequest $request
     * @return DescribeFaceVerifyResponse
     */
    public static function describeFaceVerify(string $endpoint, DescribeFaceVerifyRequest $request): DescribeFaceVerifyResponse
    {
        $client = self::createClient($endpoint);
        // 创建RuntimeObject实例并设置运行参数。
        $runtime = new RuntimeOptions([]);
        $runtime->readTimeout = 10000;
        $runtime->connectTimeout = 10000;
        return $client->describeFaceVerifyWithOptions($request, $runtime);
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
DescribeFaceVerify::main();

Python

InitFaceVerify接口调用示例

from alibabacloud_cloudauth20190307.client import Client as CloudauthClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_cloudauth20190307 import models as cloudauth_models
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_tea_util import models as util_models
from alibabacloud_credentials.client import Client as CredClient

class InitFaceVerify:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
            endpoint: str,
    ) -> CloudauthClient:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。
        cred=CredClient()
        config = open_api_models.Config(
            credential=cred,
            # 设置HTTP代理。
            # http_proxy='http://xx.xx.xx.xx:xxxx',
            # 设置HTTPS代理。
            # https_proxy='https://username:password@xxx.xxx.xxx.xxx:9999',
            endpoint=endpoint
        )
        return CloudauthClient(config)

    @staticmethod
    def main() -> None:
        request = cloudauth_models.InitFaceVerifyRequest(
            # 请输入场景ID。
            scene_id=0,
            outer_order_no='商户请求的唯一标识',
            # 要接入的认证方案。
            product_code='NFC_QY',
            cert_type='PASSPORT',
            # cert_name='xxx',
            # cert_no='xxx',
            # birthday='2011-02-01',
            # validity_date='2020-02-01',
            read_img='Y',
            # MetaInfo环境参数,需要通过客户端SDK获取。
            meta_info='{"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='130xxxxxxxx',
            # ip='114.xxx.xxx.xxx',
            user_id='12345xxxx',
            # mode='3',
            # callback_url='https://www.aliyundoc.com',
            # callback_token='xxxxxxx',
            # 如需开启个人信息加密传输。
            # encrypt_type='SM2',
            # cert_name='BCRD/7ZkNy7Q*****M1BMBezZe8GaYHrLwyJv558w==',
            # cert_no='BMjsstxK3S4b1YH*****Pet8ECObfxmLN92SLsNg=='
        )
        response = InitFaceVerify.init_face_verify_auto_route(request)
        # 不支持服务自动路由。
        # response = InitFaceVerify.init_face_verify('cloudauth.cn-shanghai.aliyuncs.com', request)
        print(response.body.request_id)
        print(response.body.code)
        print(response.body.message)
        print(response.body.result_object.certify_id)

    @staticmethod
    def init_face_verify_auto_route(
            request: cloudauth_models.InitFaceVerifyRequest,
    ) -> cloudauth_models.InitFaceVerifyResponse:
        endpoints = [
            'cloudauth.cn-shanghai.aliyuncs.com',
            'cloudauth.cn-beijing.aliyuncs.com'
        ]
        for endpoint in endpoints:
            try:
                response = InitFaceVerify.init_face_verify(endpoint, request)
                if UtilClient.equal_number(500, response.status_code):
                    continue
                if response is not None and response.body is not None:
                    if UtilClient.equal_string("500", response.body.code):
                        continue
                return response
            except Exception as err:
                print(err)
                # 网络异常,切换到下个区域调用。
                continue
        return None

    @staticmethod
    def init_face_verify(
            endpoint: str,
            request: cloudauth_models.InitFaceVerifyRequest,
    ) -> cloudauth_models.InitFaceVerifyResponse:
        client = InitFaceVerify.create_client(endpoint)
        # 创建RuntimeObject实例并设置运行参数。
        runtime = util_models.RuntimeOptions()
        runtime.read_timeout = 10000
        runtime.connect_timeout = 10000
        return client.init_face_verify_with_options(request, runtime)


if __name__ == '__main__':
    InitFaceVerify.main()

DescribeFaceVerify接口调用示例

from alibabacloud_cloudauth20190307.client import Client as CloudauthClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_cloudauth20190307 import models as cloudauth_models
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_tea_util import models as util_models
from alibabacloud_credentials.client import Client as CredClient

class DescribeFaceVerify:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
            endpoint: str,
    ) -> CloudauthClient:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。
        cred=CredClient()
        config = open_api_models.Config(
            credential=cred,
            # 设置HTTP代理。
            # http_proxy='http://xx.xx.xx.xx:xxxx',
            # 设置HTTPS代理。
            # https_proxy='https://username:password@xxx.xxx.xxx.xxx:9999',
            endpoint=endpoint
        )
        return CloudauthClient(config)

    @staticmethod
    def main() -> None:
        request = cloudauth_models.DescribeFaceVerifyRequest(
            # 请输入场景ID。
            scene_id=0,
            certify_id='xxx'
        )
        response = DescribeFaceVerify.describe_face_verify_auto_route(request)
        # 不支持服务自动路由。
        # response = DescribeFaceVerify.describe_face_verify('cloudauth.cn-shanghai.aliyuncs.com', request)
        print(response.body.request_id)
        print(response.body.code)
        print(response.body.message)
        print(response.body.result_object.success)
        print(response.body.result_object.sub_code)
        print(response.body.result_object.material_info)

    @staticmethod
    def describe_face_verify_auto_route(
            request: cloudauth_models.DescribeFaceVerifyRequest,
    ) -> cloudauth_models.DescribeFaceVerifyResponse:
        endpoints = [
            'cloudauth.cn-shanghai.aliyuncs.com',
            'cloudauth.cn-beijing.aliyuncs.com'
        ]
        for endpoint in endpoints:
            try:
                response = DescribeFaceVerify.describe_face_verify(endpoint, request)
                if UtilClient.equal_number(500, response.status_code):
                    continue
                if response is not None and response.body is not None:
                    if UtilClient.equal_string("500", response.body.code):
                        continue
                return response
            except Exception as err:
                print(err)
                continue
        return None

    @staticmethod
    def describe_face_verify(
            endpoint: str,
            request: cloudauth_models.DescribeFaceVerifyRequest,
    ) -> cloudauth_models.DescribeFaceVerifyResponse:
        client = DescribeFaceVerify.create_client(endpoint)
        # 创建RuntimeObject实例并设置运行参数。
        runtime = util_models.RuntimeOptions()
        runtime.read_timeout = 10000
        runtime.connect_timeout = 10000
        return client.describe_face_verify_with_options(request, runtime)


if __name__ == '__main__':
    DescribeFaceVerify.main()

GO

InitFaceVerify接口调用示例

package main


import (
	"fmt"
	cloudauth "github.com/alibabacloud-go/cloudauth-20190307/v3/client"
	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.com/alibabacloud-go/tea/tea"
  "github.com/aliyun/credentials-go/credentials"
)


func CreateClient (endpoint *string) (_result *cloudauth.Client, _err error) {
	//阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
  //强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
  //本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。
  // 初始化Credential。
	credential, _err := credentials.NewCredential(nil)
	if _err != nil {
		panic(_err)
	}
	// 初始化Client。
	config := &openapi.Config{
	// 使用Credential配置凭证。
	Credential: credential,
	Endpoint:   endpoint,
	// 设置HTTP代理。
	// HttpProxy: tea.String("http://xx.xx.xx.xx:xxxx"),
	// 设置HTTPS代理。
	// HttpsProxy: tea.String("https://username:password@xxx.xxx.xxx.xxx:9999"),
	}
	//_result = &cloudauth.Client{}
	_result, _err = cloudauth.NewClient(config)
	return _result, _err
}

func _main () (_err error) {
	request := &cloudauth.InitFaceVerifyRequest{
		// 固定值。
		ProductCode: tea.String("NFC_QY"),
		// 请输入场景ID。
		SceneId: tea.Int64(xxx),
		OuterOrderNo: tea.String("商户请求的唯一标识"),
		// 固定值IDENTITY_CARD。
		CertType: tea.String("PASSPORT"),
		// CertName: tea.String("xxx"),
		// CertNo: tea.String("xxx"),
        // Birthday: tea.String("2011-02-01"),
        // ValidityDate: tea.String("2021-02-01"),
        ReadImg: tea.String("Y"),
        // Mode: tea.String("3"),
		MetaInfo: tea.String("{\"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\"}"),
		// Ip: tea.String("用户IP地址"),
		// UserId: tea.String("用户ID"),
		// Mobile: tea.String("130xxxxxxxx"),
		// CallbackUrl: tea.String("https://www.aliyundoc.com"),
		// CallbackToken: tea.String("xxxxxxx"),
		// 如需开启个人信息加密传输。
		// EncryptType: tea.String("SM2"),
		// CertName: tea.String("BCRD/7ZkNy7Q*****M1BMBezZe8GaYHrLwyJv558w=="),
		// CertNo: tea.String("BMjsstxK3S4b1YH*****Pet8ECObfxmLN92SLsNg==")
	}
	response, _err := InitFaceVerifyAutoRoute(request)
	// 不支持服务自动路由。
	// response, _err := InitFaceVerify(tea.String("cloudauth.cn-shanghai.aliyuncs.com"), request)
	if _err != nil {
		return _err
	}

	fmt.Println(*response.Body.RequestId)
	fmt.Println(*response.Body.Code)
	fmt.Println(*response.Body.Message)
	fmt.Println(*response.Body.RequestId)
	fmt.Println(*response.Body.ResultObject.CertifyId)
	return _err
}

func InitFaceVerifyAutoRoute (request *cloudauth.InitFaceVerifyRequest) (_result *cloudauth.InitFaceVerifyResponse, _err error) {
	endpoints := []*string{tea.String("cloudauth.cn-shanghai.aliyuncs.com"), tea.String("cloudauth.cn-beijing.aliyuncs.com")}
	var lastResponse *cloudauth.InitFaceVerifyResponse
	for _, endpoint := range endpoints {
		response, _err := InitFaceVerify(endpoint, request)
        lastResponse = response
		if _err != nil {
			var err = &tea.SDKError{}
			if _t, ok := _err.(*tea.SDKError); ok {
				err = _t
				// 系统异常,切换到下个地域调用。
				if *err.StatusCode == 500 {
					continue
				}
			}
			return _result, _err
		}

		if *response.StatusCode == 500 {
			continue
		}

		if *response.Body.Code == "500"{
			continue
		}

		_result = response
		return _result, _err
	}
	_result = lastResponse
	return _result, _err
}

func InitFaceVerify (endpoint *string, request *cloudauth.InitFaceVerifyRequest) (_result *cloudauth.InitFaceVerifyResponse, _err error) {
	client, _err := CreateClient(endpoint)
	if _err != nil {
		return _result, _err
	}

	// 创建RuntimeObject实例并设置运行参数。
	runtime := &util.RuntimeOptions{}
	runtime.ReadTimeout = tea.Int(10000)
	runtime.ConnectTimeout = tea.Int(10000)

	_result = &cloudauth.InitFaceVerifyResponse{}
	_body, _err := client.InitFaceVerifyWithOptions(request, runtime)
	if _err != nil {
		return _result, _err
	}
	_result = _body
	return _result, _err
}

func main() {
	err := _main()
	if err != nil {
		panic(err)
	}
}

DescribeFaceVerify接口调用示例

package main

import (
	"fmt"
	cloudauth "github.com/alibabacloud-go/cloudauth-20190307/v3/client"
  openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.com/alibabacloud-go/tea/tea"
  "github.com/aliyun/credentials-go/credentials"
)

func CreateClient(endpoint *string) (_result *cloudauth.Client, _err error) {
	//阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
  //强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
  //本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。
  // 初始化Credential。
	credential, _err := credentials.NewCredential(nil)
	if _err != nil {
		panic(_err)
	}
	// 初始化Client。
	config := &openapi.Config{
	// 使用Credential配置凭证。
	Credential: credential,
	Endpoint:   endpoint,
	// 设置HTTP代理。
	// HttpProxy: tea.String("http://xx.xx.xx.xx:xxxx"),
	// 设置HTTPS代理。
	// HttpsProxy: tea.String("https://username:password@xxx.xxx.xxx.xxx:9999"),
	}
	//_result = &cloudauth.Client{}
	_result, _err = cloudauth.NewClient(config)
	return _result, _err
}

func _main() (_err error) {
	request := &cloudauth.DescribeFaceVerifyRequest{
		// 请输入场景ID。
		SceneId:   tea.Int64(xxx),
		CertifyId: tea.String("91707dc296d469ad38e4c5efa6a0xxxx"),
	}
	response, _err := DescribeFaceVerifyAutoRoute(request)

	// 不支持服务自动路由。
	// response, _err := DescribeFaceVerify(tea.String("cloudauth.cn-shanghai.aliyuncs.com"), request)

	if _err != nil {
		return _err
	}

	if response != nil {
		fmt.Println(*response.Body.RequestId)
		fmt.Println(*response.Body.Code)
		fmt.Println(*response.Body.Message)
		fmt.Println(*response.Body.RequestId)
		fmt.Println(*response.Body.ResultObject.Success)
		fmt.Println(*response.Body.ResultObject.SubCode)
		fmt.Println(*response.Body.ResultObject.MaterialInfo)
	}

	return _err
}

func DescribeFaceVerifyAutoRoute(request *cloudauth.DescribeFaceVerifyRequest) (_result *cloudauth.DescribeFaceVerifyResponse, _err error) {
	endpoints := []*string{tea.String("cloudauth.cn-shanghai.aliyuncs.com"), tea.String("cloudauth.cn-beijing.aliyuncs.com")}
	var lastResponse *cloudauth.DescribeFaceVerifyResponse
	for _, endpoint := range endpoints {
		response, _err := DescribeFaceVerify(endpoint, request)
		lastResponse = response
		if _err != nil {
			var err = &tea.SDKError{}
			if _t, ok := _err.(*tea.SDKError); ok {
				err = _t
				// 系统异常,切换到下个地域调用。
				if *err.StatusCode == 500 {
					continue
				}
			}
			return _result, _err
		}

		if *response.StatusCode == 500 {
			continue
		}

		if *response.Body.Code == "500"{
			continue
		}

		_result = response
		return _result, _err

	}
	_result = lastResponse
	return _result, _err
}

func DescribeFaceVerify(endpoint *string, request *cloudauth.DescribeFaceVerifyRequest) (_result *cloudauth.DescribeFaceVerifyResponse, _err error) {
	client, _err := CreateClient(endpoint)
	if _err != nil {
		return _result, _err
	}

	// 创建RuntimeObject实例并设置运行参数。
	runtime := &util.RuntimeOptions{}
	runtime.ReadTimeout = tea.Int(10000)
	runtime.ConnectTimeout = tea.Int(10000)

	_body, _err := client.DescribeFaceVerifyWithOptions(request, runtime)
	if _err != nil {
		return _result, _err
	}
	_result = _body
	return _result, _err
}

func main() {
	err := _main()
	if err != nil {
		panic(err)
	}
}

.NET

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
            {
               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.InitFaceVerifyRequest request = new AlibabaCloud.SDK.Cloudauth20190307.Models.InitFaceVerifyRequest
            {
                // 固定值。
                ProductCode = "NFC_QY",
                // 请输入场景ID。
                SceneId = xxx,
                // 设置商户请求的唯一标识。
                OuterOrderNo = "xxxxx",
                CertType = "PASSPORT",
                //CertName = "xxx",
                //CertNo = "xxx",
                //Mode = "3",
                //Birthday = "2011-02-01",
                //ValidityDate = 2020-02-03",
                ReadImg = "Y",
                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 = "130xxxxxxxx",
                //Ip = "114.xxx.xxx.xxx",
                UserId = "用户ID",
                //CallbackUrl = "https://www.aliyundoc.com",
                //CallbackToken = "xxxxxxx",
                // 如需开启个人信息加密传输。
                // EncryptType = "SM2",
                // CertName = "BCRD/7ZkNy7Q*****M1BMBezZe8GaYHrLwyJv558w==",
                // CertNo = "BMjsstxK3S4b1YH*****Pet8ECObfxmLN92SLsNg=="
            };
            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接口调用示例

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
            {
               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.DescribeFaceVerifyRequest request = new AlibabaCloud.SDK.Cloudauth20190307.Models.DescribeFaceVerifyRequest
            {
                // 请输入场景ID。
                SceneId = xxxx,
                CertifyId = "91707dxxxx4c5efa6a0xxxx",
            };
            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.Success);
            Console.WriteLine(response.Body.ResultObject.SubCode);
            Console.WriteLine(response.Body.ResultObject.MaterialInfo);
        }


        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);
        }
    }
}

Node.js

InitFaceVerify接口调用示例

const Config = require("@alicloud/openapi-client");
const CloudAuth = require("@alicloud/cloudauth20190307");
const CloudAuthClient = CloudAuth.default;
const {RuntimeOptions} = require("@alicloud/tea-util");
const { default: Credential } = require('@alicloud/credentials');

function createClient(endpoint) {
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
   // 本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。
    const cred = new Credential();
    const config = new Config.Config({
    credential: cred,
    // 设置Endpoint。
    endpoint: endpoint,
    // 设置HTTP代理。
    // httpProxy: "http://xxx.xxx.xxx.xxx:9999",
    // 设置HTTPS代理。
    // httpsProxy: "https://username:password@xxx.xxx.xxx.xxx:9999",
  });
    return new CloudAuthClient(config)
}

async function initFaceVerify(endpoint, request) {
    const client = createClient(endpoint);
    // 创建RuntimeObject实例并设置运行参数。
    const runtime = new RuntimeOptions([]);
    runtime.readTimeout=10000;
    runtime.connectTimeout=10000;
    return await client.initFaceVerifyWithOptions(request, runtime);
}

async function initFaceVerifyAutoRoute(request) {
    const endpoints = [
        "cloudauth.cn-shanghai.aliyuncs.com",
        "cloudauth.cn-beijing.aliyuncs.com"
    ];

    for (const endpoint of endpoints) {
        try {
            const response = await initFaceVerify(endpoint, request);
            if (response.statusCode === 500) {
                continue;
            }
            if(response.body !== null){
                if(response.body.code === "500"){
                    continue;
                }
            }
            return response;
        } catch (err) {
            console.log(err);
            continue;
        }
    }
    return null;
}

async function main(){
    // 通过以下代码创建API请求并设置参数。
    const request = new CloudAuth.InitFaceVerifyRequest({
        // 请输入场景ID。
        sceneId: xxx,
        // 设置商户请求的唯一标识。
        outerOrderNo: "xxx",
        // 要接入的认证方案。
        productCode: "NFC_QY",
        certType: "PASSPORT",
        // certName: "张三",
        // certNo: "xxx",
        // birthday: "2011-02-01",
        // validityDate: "2021-02-01",
        // mode : "3",
        readImg : "N",
        metaInfo: "{\"zimVer\":\"3.0.0\",\"appVersion\": \"1\",\"bioMetaInfo\": \"4.1.0:11501568,0\",\n" +
            "        \"appName\": \"com.aliyun.antcloudauth\",\"deviceType\": \"ios\",\"osVersion\": \"iOS 10.3.2\",\"apdidToken\": \"\",\"deviceModel\": \"iPhone9,1\"}",
        // mobile: "130xxxxxxxx",
        // ip: "114.xxx.xxx.xxx",
        // userId: "12345xxxx",
        // callbackUrl: "https://www.aliyundoc.com",
        // callbackToken: "xxxxxxx",
        // 如需开启个人信息加密传输。
        // encryptType: "SM2",
        // certName: "BCRD/7ZkNy7Q*****M1BMBezZe8GaYHrLwyJv558w==",
        // certNo: "BMjsstxK3S4b1YH*****Pet8ECObfxmLN92SLsNg=="
    });

    // 推荐,支持服务路由。
    const response = await initFaceVerifyAutoRoute(request);
    // 不支持服务自动路由。
    // const response = await initFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
    if (response){
    console.log(response);
    console.log(response.body.requestId);
    console.log(response.body.code);
    console.log(response.body.message);
    console.log(response.body.resultObject.certifyId);
}
}
main().then(function (response) {});

DescribeFaceVerify接口调用示例

const Config = require("@alicloud/openapi-client");
const CloudAuth = require("@alicloud/cloudauth20190307");
const CloudAuthClient = CloudAuth.default;
const {RuntimeOptions} = require("@alicloud/tea-util");
const { default: Credential } = require('@alicloud/credentials');

function createClient(endpoint) {
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。
    const cred = new Credential();
    const config = new Config.Config({
    credential: cred,
    // 设置Endpoint。
    endpoint: endpoint,
    // 设置HTTP代理。
    // httpProxy: "http://xxx.xxx.xxx.xxx:9999",
    // 设置HTTPS代理。
    // httpsProxy: "https://username:password@xxx.xxx.xxx.xxx:9999",
  });
    return new CloudAuthClient(config)
}

async function describeFaceVerify(endpoint, request) {
    const client = createClient(endpoint);
    // 创建RuntimeObject实例并设置运行参数。
    const runtime = new RuntimeOptions([]);
    runtime.readTimeout=10000;
    runtime.connectTimeout=10000;
    return await client.describeFaceVerifyWithOptions(request, runtime);
}

async function describeFaceVerifyAutoRoute(request) {
    const endpoints = [
        "cloudauth.cn-shanghai.aliyuncs.com",
        "cloudauth.cn-beijing.aliyuncs.com"
    ];

    for (const endpoint of endpoints) {
        try {
            const response = await describeFaceVerify(endpoint, request);
            if (response.statusCode === 500) {
                continue;
            }
            if(response.body !== null){
                if(response.body.code === "500"){
                    continue;
                }
            }
            return response;
        } catch (err) {
            console.log(err);
            continue;
        }
    }
    return null;
}

async function main(){
    // 通过以下代码创建API请求并设置参数。
    const request = new CloudAuth.DescribeFaceVerifyRequest({
        sceneId: xxx,
        certifyId: "xxx"
    });

    // 推荐,支持服务路由。
    const response = await describeFaceVerifyAutoRoute(request);
    // 不支持服务自动路由。
    //  const response = await describeFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
    if (response){
    console.log(response.body.requestId);
    console.log(response.body.code);
    console.log(response.body.message);
    console.log(response.body.resultObject.success);
    console.log(response.body.resultObject.materialInfo);
}
}
main().then(function (response) {});
说明

本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见在Linux、macOS和Windows系统配置环境变量