Use PHP to call aggregated data identification interface to identify local images

Source: Internet
Author: User
Tags php development environment

Front-facing conditions

Before you begin, please make the following preparations
1. Learn to use PHP to output "Hello world"
2. Go to aggregate data request identification key

Operation Steps

1. Configure the PHP development environment
2. Create a new folder under the corresponding local Web site root directory and name it: Card
3. Please prepare a JPG ID photo (the picture from this example is from the network) and name it 1.jpg, put it in the card directory
4. Make sure PHP has read access to 1.jpg (first Test with fopen (' 1.jpg ', ' R ')
5. Create a new index.php file in the card directory and enter the following:

* Document Recognition Interface Example
* Available in two ways, depending on your PHP version, server environment and other factors to choose the right way
* The first type is recommended (PHP 5 >= 5.5.0)
* Examples of ID card pictures from the network, with a real ID card picture will have better recognition effect
*/header ("Content-type:text/html;charset=utf-8"); $config = Array (' key ' = = ' Replace me with your Application key ', ' url ' = V.juhe.cn/certificates/query.php ',//The URL address of the Aggregation data identification interface
' Cardtype ' = ' 2 ',//type of voucher
' Type ' = ' image/jpg ',//ID picture types);/* The 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 ' = $CFI Le
);
curl_setopt ($ch, curlopt_post,1);
curl_setopt ($ch, Curlopt_postfields, $data);
Curl_exec ($ch);
Curl_close ($ch); echo "";/*/the first way *//* the 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 access http://localhost/card/index.php, normally you should see something like this:

{"Error_code": "X", "Reason": "Operation succeeded", "result": {"Address": "xx xx county xx village xx", "Reserved": "", "Citizenship Number": "420188195408288888", "Born": " 1954-08-28 "," Avatar ":", "name": "XXX", "gender": "Female", "nationality": "Han"}
{"Error_code": "X", "Reason": "Operation succeeded", "result": {"Address": "xx xx county xx village xx", "Reserved": "", "Citizenship Number": "420188195408288888", "Born": " 1954-08-28 "," Avatar ":", "name": "XXX", "gender": "Female", "nationality": "Han"}

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

For PHP < 5.5: return "@ $filename; filename="
. ($postname?: basename ($filename))
. ($mimetype? "; type= $mimetype": ");
}
}?>

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.