DEMO: Factor/ocr_idcard - 身份證OCR識(shí)別
<?php
/*****************
* 示例代碼
******************/
//appid參數(shù) appkey參數(shù)在 身份認(rèn)證-創(chuàng)建/管理AppID中獲取
$appid = '6***3'; //appid參數(shù)
$appkey = '5d****************************58'; //appkey參數(shù)
$timestamp = time(); //獲取當(dāng)前時(shí)間戳
$file_type = 'file'; //圖片的格式(file | base64),選擇 file 那邊 base64 參數(shù)就可為空,反之亦然
$file = curl_file_create('***/***/***.png'); //圖片文件 支持 png、jpeg、jpg
$base64 = 'data:image/......'; //圖片的base64編碼
$ocr_type = 1 ; //身份證正反面 0正面 1反面
$temp_data = array(
'appkey' => $appkey ,
'timestamp' => $timestamp,
);
//生成簽名
ksort($temp_data);
reset($temp_data);
$signature = hash('sha256', http_build_query($temp_data));
$post_data = array(
'appid' => $appid,
'timestamp' => $timestamp,
'signature' => $signature,
'file_type' => $file_type,
'file' => $file,
'base64' => $base64,
'ocr_type' => $ocr_type,
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://tpa.mysubmail.com/factor/ocr_idcard",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $post_data,
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}