Home  >  Article  >  Backend Development  >  Use PHP to call the aggregated data document identification interface to identify local pictures

Use PHP to call the aggregated data document identification interface to identify local pictures

巴扎黑
巴扎黑Original
2016-11-07 17:46:431050browse

Prerequisites

Before you start, please make the following preparations
1. Learn to use PHP to output "Hello World"
2. Go to Aggregate Data to apply for a KEY dedicated to document identification

Operation steps

1. Configure the PHP development environment
2. Create a new folder in the root directory of the corresponding local website and name it: card
3. Please prepare an ID card photo in jpg format (the picture in this example is from the Internet) and name it 1.jpg, Place it in the card directory
4. Please make sure that PHP has read permission for 1.jpg (test it with fopen('1.jpg', 'r') first)
5. Create a new index.php file in the card directory, and Enter the following content:

* ID identification interface example
* Two methods are provided, please choose the appropriate method according to your PHP version, server environment and other factors
* It is recommended to use the first one (PHP 5 >= 5.5.0)
* Identity in the example The ID card picture comes from the Internet, using the real ID card picture will have better recognition effect
*/header("Content-type:text/html;charset=utf-8");$config = array( 'key' => 'Replace me into the KEY you applied for', 'url' => 'http://v.juhe.cn/certificates/query.php', //The URL address of the aggregated data certificate identification interface
'cardType' => '2', //Type of certificate
'type' => 'image/jpg', //Type of certificate image);/*First way*/$ch = curl_init($config['url']);$cfile = curl_file_create('1.jpg', $config['type'], '1.jpg');$data = array( 'cardType' => $config['cardType'], 'key' => $config[' key'], 'pic' => $cfile,
);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
curl_close($ch );echo "";/*/First way*//*Second way*/$data = array( 'cardType' => $config['cardType'], 'key' => $config[' key'], 'pic' => "@1.jpg",
);
post($config['url'], $data);/*/Second way*/function post($url, $ data) {
$ch = curl_init();
curl_setopt( $ch , CURLOPT_POST , true );
@curl_setopt( $ch , CURLOPT_POSTFIELDS , $data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec( $ch);
curl_close($ch);
}

6. Open the browser and visit http://localhost/card/index.php. Under normal circumstances, you should see something similar to the following:

{ "error_code":"200","reason":"Operation successful","result":{"Address":"No. XX Village, XX County, XX Province","Reserved":"","Citizen Identity Number": "420188195408288888","Birth":"1954-08-28","Avatar":"","Name":"XXX","Gender":"Female","Ethnicity":"Han"}}
{ "error_code":"200","reason":"Operation successful","result":{"Address":"No. XX Village, XX County, XX Province","Reserved":"","Citizen Identity Number": "420188195408288888","Birth":"1954-08-28","Avatar":"","Name":"XXX","Gender":"Female","Ethnicity":"Han"}}

7. If the PHP version is lower than 5.5, but you want to use curl_file_create, please refer to the method provided in the official documentation: http://php.net/manual/en/function.curl-file-create.php

For PHP             return "@$filename;filename="
        . ($postname ? : basename($filename))
                           .

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn