Use PHP to call the aggregate data identification interface to identify local images

Source: Internet
Author: User
Tags php development environment
This article describes how to call the document recognition interface of aggregate data through PHP. prerequisites 1: Before the start, make the following preparations to use PHP to output "HelloWorld" to aggregate data and apply for a dedicated KEY for identification of documents: www. juhe. cndocsapiid153 operation procedure configure the PHP development environment in the corresponding local website root directory... this article describes how to call the document recognition interface of aggregate data through PHP.

Prerequisites

1. make the following preparations before you start

Learn to use PHP to output "Hello World"

KEY: https://www.juhe.cn/docs/api/id/153 for de-aggregate data application document recognition

Procedure

Configure the PHP development environment

Create a folder in the root directory of the local website and name it card.

Please upload a jpg ID card photo (the image in this example is shown on the network and named as 1.jpg, which is placed in the card directory)

Please ensure that PHP has read permission on 1.jpg (use fopen('1.jpg ', 'R' first) to test)

Create an index. php file in the card directory and enter the following content:

Php code

 = 5.5.0) * The ID card image in the example comes from the network, and a Real ID card image will have a better recognition effect */header ("Content-type: text/html; charset = utf-8 "); $ config = array ('key' => 'replace me with your applied key', // URL of the aggregate data identification interface 'URL' => 'http: // v.juhe.cn/certificates/query.php', // ID card type. here, the front of the ID card is 'type' => 'image/jpg ', // the type of the credential Image 'cardtype' => '2',);/* First method */$ ch = curl_init ($ config ['URL']); // $ filename

Path to the file which will be uploaded.

// $ Postname [optional]

Name of the file.

$ Cfile = curl_file_create('filename.jpg ', $ config ['type'], 'postname.jpg'); $ data = array ('cardtype' => $ config ['cardtype'], 'key' => $ config ['key'], 'Pic '=> $ cfile,); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); // The obtained content has not been output yet. if the following line is not added, echo response is not required. // curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_exec ($ ch); curl_close ($ ch ); /*/method 1 * // method 2 */$ data = array ('cardtype' => $ config ['cardtype'], 'key' => $ config ['key'], 'Pic '=> "@1.jpg",); post ($ config ['URL'], $ data ); /*/method 2 */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_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); $ response = curl_exec ($ ch); curl_close ($ ch); echo $ response ;}

6. open the browser and access http: // localhost/card/index. php. normally, you should see something similar to the following:

Php code

{"Error_code": "200", "reason": "Operation successful", "result": {"address": "No. XX, XX county, XX village, XX province ", "Reserved": "", "citizenship number": "420188195408288888", "birth": "", "Avatar": "", "name": "XXX ", "Gender": "female", "ethnicity": "Han nationality" }}{ "error_code": "200", "reason": "Operation successful", "result ": {"address": "No. XX, XX village, XX county, XX province", "reserved": "", "citizenship number": "420188195408288888", "born ": "1954-08-28", "Avatar": "", "name": "XXX", "gender": "female", "ethnicity": "Han "}}

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

Php code

For PHP < 5.5: 
 

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.