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 ']);//$filenamePath 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: