本文介绍身份二要素核验API接口。
接口信息
接口名:id2MetaVerify。
服务地址:cloudauth.aliyuncs.com(IPv4)或cloudauth-dualstack.aliyuncs.com(IPv6)。
请求方法:POST和GET。
传输协议:HTTPS。
接口说明:传入姓名和身份证号,通过权威数据源验证其真实性和一致性。
请求参数
名称 | 类型 | 是否必选 | 描述 | 示例值 |
ParamType | String | 是 | 参数类型。 normal:原始值(明文)。 说明 由于权威数据源限制,身份二要素核验不支持MD5加密方式。 | normal |
IdentifyNum | String | 是 | 身份证号。 | 429001********8211 |
UserName | String | 是 | 姓名。 | 张三 |
响应参数
名称 | 类型 | 描述 | 示例值 | |
RequestId | String | 请求ID。 | 130A2C10-B9EE-4D84-88E3-5384FF039795 | |
Message | String | 接口调用返回信息。 重要 此参数仅表示接口是否异常。 | success | |
Code | String | 返回码: 200表示成功,其他均为失败。 重要
| 200 | |
ResultObject | Object | 无。 | 无 | |
BizCode | String | 身份核验结果:
| 1 |
SDK调用示例
以下为您介绍不同语言SDK的调用示例。
Java
在pom.xml中添加如下依赖,即可在Maven工程中使用SDK。
Java SDK依赖。以下依赖版本仅供参考,建议在实际配置时获取最新依赖版本。
<dependency> <groupId>com.aliyun</groupId> <artifactId>cloudauth20190307</artifactId> <version>2.1.0</version> </dependency>
身份验证依赖。如何配置环境变量,请参见管理访问凭据。
<dependency> <groupId>com.aliyun</groupId> <artifactId>credentials-java</artifactId> <version>LATEST</version> </dependency>
示例:
import com.aliyun.cloudauth20190307.Client;
import com.aliyun.cloudauth20190307.models.Id2MetaVerifyRequest;
import com.aliyun.cloudauth20190307.models.Id2MetaVerifyResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
import java.util.Arrays;
import java.util.List;
public class Id2MetaVerify {
public static void main(String[] args) throws Exception {
// 通过以下代码创建API请求并设置参数。
Id2MetaVerifyRequest request = new Id2MetaVerifyRequest();
request.setParamType("normal");
request.setUserName("姓名张先生");
request.setIdentifyNum("18位身份证号");
// 推荐,支持服务路由。
Id2MetaVerifyResponse response = id2MetaVerifyAutoRoute(request);
// 不支持服务自动路由。
//Id2MetaVerifyResponse response = id2MetaVerify("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().getBizCode());
}
private static Id2MetaVerifyResponse id2MetaVerifyAutoRoute(Id2MetaVerifyRequest request) {
// 第一个为主区域Endpoint,第二个为备区域Endpoint。
List<String> endpoints = Arrays.asList("cloudauth.cn-shanghai.aliyuncs.com", "cloudauth.cn-beijing.aliyuncs.com");
Id2MetaVerifyResponse lastResponse = null;
for (int i=0; i<endpoints.size(); i++) {
try {
Id2MetaVerifyResponse response = id2MetaVerify(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 response;
} catch (Exception e) {
e.printStackTrace();
if(i == endpoints.size()-1){
throw new RuntimeException(e);
}
}
}
return lastResponse;
}
private static Id2MetaVerifyResponse id2MetaVerify(String endpoint, Id2MetaVerifyRequest 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 = 5000;
runtime.connectTimeout = 5000;
return client.id2MetaVerifyWithOptions(request, runtime);
}
PHP
关于PHP SDK源代码,请参见PHP SDK包。
通过Composer来管理项目依赖(推荐)
composer require alibabacloud/cloudauth-20190307 2.1.0
使用composer.json文件
{ "require": { "alibabacloud/cloudauth-20190307": "2.1.0" } }
示例:
<?php
namespace AlibabaCloud\SDK\Sample\Verify\Id;
use AlibabaCloud\Credentials\Credential;
use AlibabaCloud\SDK\Cloudauth\V20190307\Cloudauth;
use AlibabaCloud\SDK\Cloudauth\V20190307\Models\Id2MetaVerifyRequest;
use AlibabaCloud\SDK\Cloudauth\V20190307\Models\Id2MetaVerifyResponse;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Exception;
class Id2MetaVerify
{
/**
* 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);
}
/**
* @return void
*/
public static function main(){
$request = new Id2MetaVerifyRequest([
"paramType" => "normal",
"userName" => "张*",
"identifyNum" => "411***************",
]);
// 推荐,支持服务路由。
$response = self::id2MetaVerifyAutoRoute($request);
// 不支持服务自动路由。
// $response = self::id2MetaVerify("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->bizCode);
}
/**
* id2MetaVerifyAutoRoute
* @param Id2MetaVerifyRequest $request
* @return Id2MetaVerifyResponse|null
*/
public static function id2MetaVerifyAutoRoute(Id2MetaVerifyRequest $request): ?Id2MetaVerifyResponse
{
$endpoints = [
"cloudauth.cn-shanghai.aliyuncs.com",
"cloudauth.cn-beijing.aliyuncs.com"
];
foreach($endpoints as $endpoint){
try {
$response = self::id2MetaVerify($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;
}
/**
* id2MetaVerify
* @param string $endpoint
* @param Id2MetaVerifyRequest $request
* @return Id2MetaVerifyResponse
*/
public static function id2MetaVerify(string $endpoint, Id2MetaVerifyRequest $request): Id2MetaVerifyResponse
{
$client = self::createClient($endpoint);
// 创建RuntimeObject实例并设置运行参数。
$runtime = new RuntimeOptions([]);
$runtime->readTimeout = 5000;
$runtime->connectTimeout = 5000;
return $client->id2MetaVerifyWithOptions($request, $runtime);
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Id2MetaVerify::main();
Credentials工具配置方法,请参见身份验证配置。
Python
关于Python SDK源代码,请参见Python SDK包。
引入依赖并安装SDK:
pip install alibabacloud_tea_openapi==0.2.5
pip install alibabacloud_credentials==0.3.2
pip install alibabacloud_cloudauth20190307==2.1.0
Credentials工具配置方法,请参见身份验证配置。
示例:
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 Id2MetaVerify:
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.Id2MetaVerifyRequest(
param_type='normal',
user_name='张x',
identify_num='411***************'
)
response = Id2MetaVerify.id_2_meta_verify_auto_route(request)
# 不支持服务自动路由。
# response = Id2MetaVerify.id_2_meta_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.biz_code)
@staticmethod
def id_2_meta_verify_auto_route(
request: cloudauth_models.Id2MetaVerifyRequest,
) -> cloudauth_models.Id2MetaVerifyResponse:
endpoints = [
'cloudauth.cn-shanghai.aliyuncs.com',
'cloudauth.cn-beijing.aliyuncs.com'
]
for endpoint in endpoints:
try:
response = Id2MetaVerify.id_2_meta_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 id_2_meta_verify(
endpoint: str,
request: cloudauth_models.Id2MetaVerifyRequest,
) -> cloudauth_models.Id2MetaVerifyResponse:
client = Id2MetaVerify.create_client(endpoint)
# 创建RuntimeObject实例并设置运行参数。
runtime = util_models.RuntimeOptions()
runtime.read_timeout = 5000
runtime.connect_timeout = 5000
return client.id_2_meta_verify_with_options(request, runtime)
if __name__ == '__main__':
Id2MetaVerify.main()
Go
引入Credentials工具并安装SDK:
go get -u github.com/aliyun/credentials-go
go get github.com/alibabacloud-go/cloudauth-20190307/v3
Credentials工具配置方法,请参见管理访问凭证。
示例:
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.Id2MetaVerifyRequest{
ParamType: tea.String("normal"),
UserName: tea.String("张*"),
IdentifyNum: tea.String("411***************")
}
response, _err := Id2MetaVerifyAutoRoute(request)
// 不支持服务自动路由。
// response, _err := Id2MetaVerify(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.ResultObject.BizCode)
return _err
}
func Id2MetaVerifyAutoRoute (request *cloudauth.Id2MetaVerifyRequest) (_result *cloudauth.Id2MetaVerifyResponse, _err error) {
endpoints := []*string{tea.String("cloudauth.cn-shanghai.aliyuncs.com"), tea.String("cloudauth.cn-beijing.aliyuncs.com")}
var lastResponse *cloudauth.Id2MetaVerifyResponse
for _, endpoint := range endpoints {
response, _err := Id2MetaVerify(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 Id2MetaVerify (endpoint *string, request *cloudauth.Id2MetaVerifyRequest) (_result *cloudauth.Id2MetaVerifyResponse, _err error) {
client, _err := CreateClient(endpoint)
if _err != nil {
return _result, _err
}
// 创建RuntimeObject实例并设置运行参数。
runtime := &util.RuntimeOptions{}
runtime.ReadTimeout = tea.Int(5000)
runtime.ConnectTimeout = tea.Int(5000)
_result = &cloudauth.Id2MetaVerifyResponse{}
_body, _err := client.Id2MetaVerifyWithOptions(request, runtime)
if _err != nil {
return _result, _err
}
_result = _body
return _result, _err
}
func main() {
err := _main()
if err != nil {
panic(err)
}
}
.NET
引入依赖并安装SDK:
方式一:通过.NET命令行安装。
dotnet add package AlibabaCloud.SDK.Cloudauth20190307 --version 2.1.0 dotnet add package Aliyun.Credentials
方式二:使用包管理安装。
Install-Package AlibabaCloud.SDK.Cloudauth20190307 -Version 2.1.0 Install-Package Aliyun.Credentials
Credentials工具配置方法,请参见管理访问凭证。
示例:
using System;
using System.Collections.Generic;
using Tea;
namespace Id2MetaVerify
{
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.Id2MetaVerifyRequest request = new AlibabaCloud.SDK.Cloudauth20190307.Models.Id2MetaVerifyRequest
{
ParamType = "normal",
UserName = "张*",
IdentifyNum = "411***************"
};
AlibabaCloud.SDK.Cloudauth20190307.Models.Id2MetaVerifyResponse response = Id2MetaVerifyAutoRoute(request);
// 不支持服务自动路由。
//AlibabaCloud.SDK.Cloudauth20190307.Models.Id2MetaVerifyResponse response = Id2MetaVerify("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.BizCode);
}
public static AlibabaCloud.SDK.Cloudauth20190307.Models.Id2MetaVerifyResponse Id2MetaVerifyAutoRoute(AlibabaCloud.SDK.Cloudauth20190307.Models.Id2MetaVerifyRequest request)
{
List<string> endpoints = new List<string>
{
"cloudauth.cn-shanghai.aliyuncs.com",
"cloudauth.cn-beijing.aliyuncs.com"
};
AlibabaCloud.SDK.Cloudauth20190307.Models.Id2MetaVerifyResponse lastResponse = null;
foreach (var endpoint in endpoints)
{
try
{
AlibabaCloud.SDK.Cloudauth20190307.Models.Id2MetaVerifyResponse response = Id2MetaVerify(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.Id2MetaVerifyResponse Id2MetaVerify(string endpoint, AlibabaCloud.SDK.Cloudauth20190307.Models.Id2MetaVerifyRequest request)
{
AlibabaCloud.SDK.Cloudauth20190307.Client client = CreateClient(endpoint);
// 创建RuntimeObject实例并设置运行参数。
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
runtime.ReadTimeout = 5000;
runtime.ConnectTimeout = 5000;
return client.Id2MetaVerifyWithOptions(request, runtime);
}
}
}
Node.js
引入依赖并安装SDK:
npm install @alicloud/tea-util
npm install @alicloud/openapi-client
npm install @alicloud/cloudauth20190307@2.1.0
npm install @alicloud/credentials
Credentials工具配置方法,请参见管理访问凭证。
示例:
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 id2MetaVerify(endpoint, request) {
const client = createClient(endpoint);
// 创建RuntimeObject实例并设置运行参数。
const runtime = new RuntimeOptions([]);
runtime.readTimeout=5000;
runtime.connectTimeout=5000;
return await client.id2MetaVerifyWithOptions(request, runtime);
}
async function id2MetaVerifyAutoRoute(request) {
const endpoints = [
"cloudauth.cn-shanghai.aliyuncs.com",
"cloudauth.cn-beijing.aliyuncs.com"
];
for (const endpoint of endpoints) {
try {
const response = await id2MetaVerify(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.Id2MetaVerifyRequest({
// 固定值。
paramType: "normal",
identifyNum: "411***************",
userName: "张*",
});
// 推荐,支持服务路由。
const response = await id2MetaVerifyAutoRoute(request);
// 不支持服务自动路由。
// const response = await id2MetaVerify("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.bizCode);
}
}
main().then(function (response) {});