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

Source: Internet
Author: User
Tags php development environment
This article is about how to call a credential recognition interface that aggregates data through PHP

Front-facing conditions

1 before you begin, please make the following preparations

Learn to use PHP to output "Hello world"

Go to aggregate data request identification of key:https://www.juhe.cn/docs/api/id/153

Operation Steps

Configure the PHP development environment.

Create a new folder under the appropriate local Web site root directory and name it: Card

Please prepare a photo ID in jpg format (the picture from this example is from the network) and name it 1.jpg, put it in the card directory

Make sure that PHP has read access to 1.jpg (first Test with fopen (' 1.jpg ', ' R ')

Create a new index.php file in the card directory and enter the following:

PHP code

 = 5.5.0) * Example of the identity card image from the network, with a real ID image will have a better recognition effect */Header ("Content-type:text/html;charset=utf-8"); $config = Array (' key ' =& Gt ' Replace me with your Application key ',//The URL address of the aggregated Data id interface ' url ' = ' http://v.juhe.cn/certificates/query.php ',//ID type, here is the ID of the positive ' type ' = ' image/jpg ',//id picture type ' cardtype ' = ' 2 ',); /* The first way */$ch = Curl_init ($config [' url ']);//$filename

Path to the file which'll be uploaded.

$postname [optional]

Name of the file.

$cfile = curl_file_create (' filename.jpg ', $config [' type '], ' postname.jpg '); $data = Array (' cardtype ' = = $config [' Car DType '], ' key ' = $config [' key '], ' pic ' = $cfile, ' curl_setopt ($ch, curlopt_post,1); curl_setopt ($ch, Curlopt_po Stfields, $data);//has obtained the content, has not output, if does not add below this line, then does not need echo response//curl_setopt ($ch, Curlopt_returntransfer, 1); Curl_exec ( $ch); Curl_close ($ch); /*/the first way *////////* $data = Array (' cardtype ' = + $config [' Cardtype '], ' key ' + $config [' key '], ' pic ' = ' @1 . jpg ",);p Ost ($config [' url '], $data);/*/the 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_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 like this:

PHP code

{"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": "$", "reason": "Operation succeeded", "result": {"Address": " xx province 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

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.