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": ");
}
}?>