Driving license recognition

更新时间:
复制 MD 格式

This guide provides sample code for Driving License Recognition in common programming languages.

Note
  • For live online help, visit Online Consultation.

  • For questions about API access, API usage, or other issues related to the Visual Intelligence API, join the Visual Intelligence API DingTalk group (ID: 23109592) to contact us.

Overview

For a description of the Driving License Recognition feature and its request parameters, see the Recognize Driving License API.

SDK installation

For information about SDK dependencies for common languages, see SDK Overview.

Sample code

Image in OSS (Shanghai region)

/*
Add the dependency
<!-- https://mvnrepository.com/artifact/com.aliyun/ocr20191230 -->
<dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>ocr20191230</artifactId>
      <version>${aliyun.ocr.version}</version>
</dependency>
*/

import com.aliyun.ocr20191230.models.RecognizeDrivingLicenseResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;

public class RecognizeDrivingLicense {

    public static com.aliyun.ocr20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        /*
          Initialize the configuration object com.aliyun.teaopenapi.models.Config.
          This object stores configurations such as AccessKey ID, AccessKey Secret, and endpoint.
         */
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        // The endpoint.
        config.endpoint = "ocr.cn-shanghai.aliyuncs.com";
        return new com.aliyun.ocr20191230.Client(config);
    }

    public static void main(String[] args) throws Exception {
        // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
        // If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // This example reads the AccessKey ID and AccessKey Secret from environment variables.
        String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); 
        com.aliyun.ocr20191230.Client client = RecognizeDrivingLicense.createClient(accessKeyId, accessKeySecret);
        com.aliyun.ocr20191230.models.RecognizeDrivingLicenseRequest recognizeDrivingLicenseRequest = new com.aliyun.ocr20191230.models.RecognizeDrivingLicenseRequest()
                .setImageURL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg")
                .setSide("face");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Print the API response.
            RecognizeDrivingLicenseResponse response = client.recognizeDrivingLicenseWithOptions(recognizeDrivingLicenseRequest, runtime);
            System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(response)));
        } catch (TeaException error) {
            // Get the full error message.
            System.out.println(com.aliyun.teautil.Common.toJSONString(error));
            // Get a specific field.
            System.out.println(error.getCode());
        }
    }
}
# -*- coding: utf-8 -*-
# Install the dependency.
# pip install alibabacloud_ocr20191230

import os
from alibabacloud_ocr20191230.client import Client
from alibabacloud_ocr20191230.models import RecognizeDrivingLicenseRequest
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

config = Config(
  # To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  # If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  # This example reads the AccessKey ID and AccessKey Secret from environment variables.
  access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
  access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
  # The endpoint.
  endpoint='ocr.cn-shanghai.aliyuncs.com',
  # The region ID.
  region_id='cn-shanghai'
)
recognize_driving_license_request = RecognizeDrivingLicenseRequest(
    image_url='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg',
    side='face'
)
runtime = RuntimeOptions()
try:
  # Initialize the client.
  client = Client(config)
  response = client.recognize_driving_license_with_options(recognize_driving_license_request, runtime)
  # Get the full response.
  print(response.body)
except Exception as error:
  # Get the full error message.
  print(error)
  # Get a specific field.
  print(error.code)
<?php

// Install the dependency.
// composer require alibabacloud/ocr-20191230

use AlibabaCloud\SDK\Ocr\V20191230\Ocr;
use \Exception;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Ocr\V20191230\Models\RecognizeDrivingLicenseRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class RecognizeDrivingLicense {

    /**
     * Initialize the client with an AccessKey ID and AccessKey Secret.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Ocr Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        // Initialize the configuration object Darabonba\OpenApi\Models\Config.
        // This object stores configurations such as AccessKey ID, AccessKey Secret, and endpoint.
        $config = new Config([
            "accessKeyId" => $accessKeyId,
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint.
        $config->endpoint = "ocr.cn-shanghai.aliyuncs.com";
        return new Ocr($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
        // If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // This example reads the AccessKey ID and AccessKey Secret from environment variables.    
        $accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');      
        $accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
        $client = self::createClient($accessKeyId, $accessKeySecret);
        $recognizeDrivingLicenseRequest = new RecognizeDrivingLicenseRequest([
            "imageURL" => "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg",
            "side" => "face"
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            $resp = $client->recognizeDrivingLicenseWithOptions($recognizeDrivingLicenseRequest, $runtime);
            // Get the full response.
            echo Utils::toJSONString($resp->body);
        } catch (Exception $exception) {
            // Get the full error message.
            echo Utils::toJSONString($exception);
            // Get a specific field.
            echo $exception->getCode();
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
// The $argv array handles command-line arguments and can be ignored for this example.
RecognizeDrivingLicense::main(array_slice($argv, 1));
// Install the dependency.
// npm install @alicloud/ocr20191230
const OcrClient = require('@alicloud/ocr20191230');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');

let config = new OpenapiClient.Config({
  // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  // If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // This example reads the AccessKey ID and AccessKey Secret from environment variables. 
  accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,   
  accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The endpoint.
config.endpoint = `ocr.cn-shanghai.aliyuncs.com`;
const client = new OcrClient.default(config);
let recognizeDrivingLicenseRequest = new OcrClient.RecognizeDrivingLicenseRequest({
  side: "face",
  imageURL: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg",
});
let runtime = new TeaUtil.RuntimeOptions({});
client.recognizeDrivingLicenseWithOptions(recognizeDrivingLicenseRequest, runtime)
  .then(function (recognizeDrivingLicenseResponse) {
    // Get the full response.
    console.log(recognizeDrivingLicenseResponse);
    // Get a specific field.
    console.log(recognizeDrivingLicenseResponse.body.data);
  }, function (error) {
    // Get the full error message.
    console.log(error);
    // Get a specific field.
    console.log(error.data.Code);
  })
/**
Depends on github.com/alibabacloud-go/ocr-20191230/v3.
We recommend using `go mod tidy` to install dependencies.
*/
package main

import (
	"fmt"
	"os"
	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	ocr20191230  "github.com/alibabacloud-go/ocr-20191230/v3/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.comcom/alibabacloud-go/tea/tea"
)

func main() { 
  // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  // If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // This example reads the AccessKey ID and AccessKey Secret from environment variables.  
  accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")  
  accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
  // Initialize the configuration object &openapi.Config. This object stores configurations such as AccessKey ID, AccessKey Secret, and endpoint.
  config := &openapi.Config{
    AccessKeyId: tea.String(accessKeyId),
    AccessKeySecret: tea.String(accessKeySecret),
	}
	// The endpoint.
	config.Endpoint = tea.String("ocr.cn-shanghai.aliyuncs.com")
	client, err := ocr20191230.NewClient(config)
	if err != nil {
		fmt.Println(err.Error())
	}

	recognizeDrivingLicenseRequest := &ocr20191230.RecognizeDrivingLicenseRequest{
		ImageURL: tea.String("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg"),
		Side: tea.String("face"),
	}
	runtime := &util.RuntimeOptions{}
	recognizeDrivingLicenseResponse, _err := client.RecognizeDrivingLicenseWithOptions(recognizeDrivingLicenseRequest, runtime)
	if _err != nil {
		// Get the full error message.
		fmt.Println(_err.Error())
	} else {
		// Get the full response.
		fmt.Println(recognizeDrivingLicenseResponse)
		// Get a specific field.
		fmt.Println(recognizeDrivingLicenseResponse.Body.Data)
	}
}
// Install the dependency.
// dotnet add package AlibabaCloud.SDK.Ocr20191230
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using AlibabaCloud.SDK.Ocr20191230.Models;
using Tea;

namespace AlibabaCloud.SDK.Sample
{
    public class Sample
    {
        /**
            * Initialize the client with an AccessKey ID and AccessKey Secret.
            * @param accessKeyId
            * @param accessKeySecret
            * @return Client
            * @throws Exception
        */
        public static AlibabaCloud.SDK.Ocr20191230.Client CreateClient(string accessKeyId, string accessKeySecret)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                AccessKeyId = accessKeyId,
                AccessKeySecret = accessKeySecret,
            };
            // The endpoint.
            config.Endpoint = "ocr.cn-shanghai.aliyuncs.com";
            return new AlibabaCloud.SDK.Ocr20191230.Client(config);
        }
        public static void Main(string[] args)
        {
            // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
            // If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
            // This example reads the AccessKey ID and AccessKey Secret from environment variables.
            AlibabaCloud.SDK.Ocr20191230.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
            AlibabaCloud.SDK.Ocr20191230.Models.RecognizeDrivingLicenseRequest recognizeDrivingLicenseRequest = new AlibabaCloud.SDK.Ocr20191230.Models.RecognizeDrivingLicenseRequest
            {
                Side = "face",
                ImageURL = "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg",
            };
            AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
            try
            {
                AlibabaCloud.SDK.Ocr20191230.Models.RecognizeDrivingLicenseResponse recognizeDrivingLicenseResponse = client.RecognizeDrivingLicenseWithOptions(recognizeDrivingLicenseRequest, runtime);
                // Get the full response.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeDrivingLicenseResponse.Body));
                // Get a specific field.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeDrivingLicenseResponse.Body.Data));
            }
            catch (TeaException error)
            {
                // Get the full error message.
                Console.WriteLine(error.Message);
            }
            catch (Exception _error)
            {
                TeaException error = new TeaException(new Dictionary<string, object>
                {
                    { "message", _error.Message }
                });
                // Get the full error message.
                Console.WriteLine(error.Message);
            }
        }
    }
}

Local file or public URL

/*
Add the dependency
<!-- https://mvnrepository.com/artifact/com.aliyun/ocr20191230 -->
<dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>ocr20191230</artifactId>
      <version>${aliyun.ocr.version}</version>
</dependency>
*/

import com.aliyun.ocr20191230.models.RecognizeDrivingLicenseResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;

public class RecognizeDrivingLicenseAdvance {

    public static com.aliyun.ocr20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        /*
          Initialize the configuration object com.aliyun.teaopenapi.models.Config.
          This object stores configurations such as AccessKey ID, AccessKey Secret, and endpoint.
         */
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        // The endpoint.
        config.endpoint = "ocr.cn-shanghai.aliyuncs.com";
        return new com.aliyun.ocr20191230.Client(config);
    }

    public static void main(String[] args) throws Exception {
        // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
        // If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // This example reads the AccessKey ID and AccessKey Secret from environment variables.
        String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); 
        com.aliyun.ocr20191230.Client client = RecognizeDrivingLicenseAdvance.createClient(accessKeyId, accessKeySecret);
        // Scenario 1: Use a local file.
        //InputStream inputStream = new FileInputStream(new File("/tmp/RecognizeDrivingLicense1.jpg"));
        // Scenario 2: Use a public URL.
        URL url = new URL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg");
        InputStream inputStream = url.openConnection().getInputStream();
        com.aliyun.ocr20191230.models.RecognizeDrivingLicenseAdvanceRequest recognizeDrivingLicenseAdvanceRequest = new com.aliyun.ocr20191230.models.RecognizeDrivingLicenseAdvanceRequest()
                .setImageURLObject(inputStream)
                .setSide("face");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Print the API response.
            RecognizeDrivingLicenseResponse response = client.recognizeDrivingLicenseAdvance(recognizeDrivingLicenseAdvanceRequest, runtime);
            System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(response)));
        } catch (TeaException error) {
            // Get the full error message.
            System.out.println(com.aliyun.teautil.Common.toJSONString(error));
            // Get a specific field.
            System.out.println(error.getCode());
        }
    }
}
# -*- coding: utf-8 -*-
# Install the dependency.
# pip install alibabacloud_ocr20191230

import os
import io
from urllib.request import urlopen
from alibabacloud_ocr20191230.client import Client
from alibabacloud_ocr20191230.models import RecognizeDrivingLicenseAdvanceRequest
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

config = Config(
  # To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  # If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  # This example reads the AccessKey ID and AccessKey Secret from environment variables.
  access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
  access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
  # The endpoint.
  endpoint='ocr.cn-shanghai.aliyuncs.com',
  # The region ID.
  region_id='cn-shanghai'
)
# Scenario 1: Use a local file.
#img = open(r'/tmp/xsz1.jpg', 'rb')
# Scenario 2: Use a public URL.
url = 'http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg'
img = io.BytesIO(urlopen(url).read())
recognize_driving_license_request = RecognizeDrivingLicenseAdvanceRequest(
    imageURLObject=img,
    side='face'
)
runtime = RuntimeOptions()
try:
  # Initialize the client.
  client = Client(config)
  response = client.recognize_driving_license_advance(recognize_driving_license_request, runtime)
  # Get the full response.
  print(response.body)
except Exception as error:
  # Get the full error message.
  print(error)
  # Get a specific field.
  print(error.code)
<?php

// Install the dependency.
// composer require alibabacloud/ocr-20191230

use AlibabaCloud\SDK\Ocr\V20191230\Ocr;
use \Exception;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Ocr\V20191230\Models\RecognizeDrivingLicenseAdvanceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use GuzzleHttp\Psr7\Stream;

class RecognizeDrivingLicenseAdvance {

    /**
     * Initialize the client with an AccessKey ID and AccessKey Secret.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Ocr Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        // Initialize the configuration object Darabonba\OpenApi\Models\Config.
        // This object stores configurations such as AccessKey ID, AccessKey Secret, and endpoint.
    $config = new Config([
            "accessKeyId" => $accessKeyId,
            "accessKeySecret" => $accessKeySecret
             ]);
        // The endpoint.
        $config->endpoint = "ocr.cn-shanghai.aliyuncs.com";
        return new Ocr($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
        // If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // This example reads the AccessKey ID and AccessKey Secret from environment variables.    
        $accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');      
        $accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
        $client = self::createClient($accessKeyId, $accessKeySecret);
        // Scenario 1: Use a local file.
        //$file = fopen('/tmp/xsz1.jpg', 'rb');
        //$stream = new Stream($file);
        // Scenario 2: Use a public URL.
        $file = fopen('http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg', 'rb');
        $stream = new Stream($file);
        $recognizeDrivingLicenseAdvanceRequest = new RecognizeDrivingLicenseAdvanceRequest([
            "imageURLObject" => $stream,
            "side" => "face"
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            $resp = $client->recognizeDrivingLicenseAdvance($recognizeDrivingLicenseAdvanceRequest, $runtime);
            // Get the full response.
            echo Utils::toJSONString($resp->body);
        } catch (Exception $exception) {
            // Get the full error message.
            echo Utils::toJSONString($exception);
            // Get a specific field.
            echo $exception->getCode();
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
// The $argv array handles command-line arguments and can be ignored for this example.
RecognizeDrivingLicenseAdvance::main(array_slice($argv, 1));
// Install the dependency.
// npm install @alicloud/ocr20191230
const OcrClient = require('@alicloud/ocr20191230');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');
const fs = require('fs');
const http = require('http');
const https = require('https');
const { URL } = require('url');

let config = new OpenapiClient.Config({
  // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  // If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // This example reads the AccessKey ID and AccessKey Secret from environment variables. 
  accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,   
  accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The endpoint.
config.endpoint = `ocr.cn-shanghai.aliyuncs.com`;
const client = new OcrClient.default(config);
const getResponse = function (httpClient, url) {
  return new Promise((resolve, reject) => {
    httpClient.get(url, function (response) {
      resolve(response);
    })
  })
}
const request = async function () {
  try {
    const client = new OcrClient.default(config);
    let recognizeDrivingLicenseAdvanceRequest = new OcrClient.RecognizeDrivingLicenseAdvanceRequest();
    // Scenario 1: Use a local file.
    // const fileStream = fs.createReadStream('/tmp/xsz1.jpg');
    // recognizeDrivingLicenseAdvanceRequest.imageURLObject = fileStream;
    // recognizeDrivingLicenseAdvanceRequest.side = "face";
    // Scenario 2: Use a public URL.
    const url = new URL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg");
    const httpClient = (url.protocol == "https:") ? https : http;
    recognizeDrivingLicenseAdvanceRequest.imageURLObject = await getResponse(httpClient, url);
    recognizeDrivingLicenseAdvanceRequest.side = "face";
    let runtime = new TeaUtil.RuntimeOptions({ });
    client.recognizeDrivingLicenseAdvance(recognizeDrivingLicenseAdvanceRequest, runtime)
      .then(function(recognizeDrivingLicenseResponse) {
        // Get the full response.
        console.log(recognizeDrivingLicenseResponse);
        // Get a specific field.
        console.log(recognizeDrivingLicenseResponse.body.data);
      }, function(error) {
        // Get the full error message.
        console.log(error);
        // Get a specific field.
        console.log(error.data.Code);
      })
  } catch (error) {
    console.log(error);
  }
}();
/**
Depends on github.com/alibabacloud-go/ocr-20191230/v3.
We recommend using `go mod tidy` to install dependencies.
*/
package main

import (
	"fmt"
	"os"
	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	ocr20191230 "github.com/alibabacloud-go/ocr-20191230/v3/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.com/alibabacloud-go/tea/tea"
	"net/http"
)

func main() {  
  // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  // If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // This example reads the AccessKey ID and AccessKey Secret from environment variables.  
  accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")  
  accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
  // Initialize the configuration object &openapi.Config. This object stores configurations such as AccessKey ID, AccessKey Secret, and endpoint.
  config := &openapi.Config{
    AccessKeyId: tea.String(accessKeyId),
    AccessKeySecret: tea.String(accessKeySecret),
	}
	// The endpoint.
	config.Endpoint = tea.String("ocr.cn-shanghai.aliyuncs.com")
	client, err := ocr20191230.NewClient(config)
	if err != nil {
		fmt.Println(err.Error())
	}
	// Scenario 1: Use a local file.
	//file, err := os.Open("/tmp/RecognizeDrivingLicense1.jpg")
	//if err != nil {
	//	fmt.Println("can not open file", err)
	//}
	//recognizeDrivingLicenseAdvanceRequest := &ocr20191230.RecognizeDrivingLicenseAdvanceRequest{
	//	ImageURLObject: file,
	//	Side: tea.String("face"),
	//}
	// Scenario 2: Use a public URL.
	httpClient := http.Client{}
	file1, _ := httpClient.Get("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg")
	recognizeDrivingLicenseAdvanceRequest := &ocr20191230.RecognizeDrivingLicenseAdvanceRequest{
		ImageURLObject: file1.Body,
		Side: tea.String("face"),
	}
	runtime := &util.RuntimeOptions{}
	recognizeDrivingLicenseResponse, _err := client.RecognizeDrivingLicenseAdvance(recognizeDrivingLicenseAdvanceRequest, runtime)
	if _err != nil {
		// Get the full error message.
		fmt.Println(_err.Error())
	} else {
		// Get the full response.
		fmt.Println(recognizeDrivingLicenseResponse)
		// Get a specific field.
		fmt.Println(recognizeDrivingLicenseResponse.Body.Data)
	}
}
// Install the dependency.
// dotnet add package AlibabaCloud.SDK.Ocr20191230
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using AlibabaCloud.SDK.Ocr20191230.Models;
using Tea;

namespace AlibabaCloud.SDK.Sample
{
    public class Sample
    {
        /**
            * Initialize the client with an AccessKey ID and AccessKey Secret.
            * @param accessKeyId
            * @param accessKeySecret
            * @return Client
            * @throws Exception
        */
        public static AlibabaCloud.SDK.Ocr20191230.Client CreateClient(string accessKeyId, string accessKeySecret)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                AccessKeyId = accessKeyId,
                AccessKeySecret = accessKeySecret,
            };
            // The endpoint.
            config.Endpoint = "ocr.cn-shanghai.aliyuncs.com";
            return new AlibabaCloud.SDK.Ocr20191230.Client(config);
        }
        public static void Main(string[] args)
        {
            // To create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
            // If you are using the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
            // This example reads the AccessKey ID and AccessKey Secret from environment variables.
            AlibabaCloud.SDK.Ocr20191230.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
            AlibabaCloud.SDK.Ocr20191230.Models.RecognizeDrivingLicenseAdvanceRequest recognizeDrivingLicenseAdvanceRequest = new AlibabaCloud.SDK.Ocr20191230.Models.RecognizeDrivingLicenseAdvanceRequest();
            // Scenario 1: Use a local file.
            // System.IO.StreamReader file = new System.IO.StreamReader(@"/tmp/xsz1.jpg");
            // recognizeDrivingLicenseAdvanceRequest.ImageURLObject = file.BaseStream;
            // recognizeDrivingLicenseAdvanceRequest.Side = "face";
            // Scenario 2: Use a public URL.
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeDrivingLicense/xsz1.jpg");
            WebResponse response = request.GetResponse();
            Stream stream = response.GetResponseStream();
            recognizeDrivingLicenseAdvanceRequest.ImageURLObject = stream;
            recognizeDrivingLicenseAdvanceRequest.Side = "face";
            AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
            try
            {
                AlibabaCloud.SDK.Ocr20191230.Models.RecognizeDrivingLicenseResponse recognizeDrivingLicenseResponse = client.RecognizeDrivingLicenseAdvance(recognizeDrivingLicenseAdvanceRequest, runtime);
                // Get the full response.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeDrivingLicenseResponse.Body));
                // Get a specific field.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeDrivingLicenseResponse.Body.Data));
            }
            catch (TeaException error)
            {
                // Get the full error message.
                Console.WriteLine(error.Message);
            }
            catch (Exception _error)
            {
                TeaException error = new TeaException(new Dictionary<string, object>
                {
                    { "message", _error.Message }
                });
                // Get the full error message.
                Console.WriteLine(error.Message);
            }
        }
    }
}