提交
This commit is contained in:
122
app/service/BaiduOcrService.php
Normal file
122
app/service/BaiduOcrService.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace app\service;
|
||||
|
||||
use Curl\Curl;
|
||||
|
||||
class BaiduOcrService
|
||||
{
|
||||
private $url = 'https://uniuser.evus.cn/home/upload/';
|
||||
/**
|
||||
*
|
||||
*护照识别
|
||||
* @param string $fileData 图片的二进制数据
|
||||
* @return array
|
||||
*/
|
||||
function passport($fileData)
|
||||
{
|
||||
if ($fileData === false) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '无法读取上传的文件',
|
||||
];
|
||||
}
|
||||
$curl = new Curl();
|
||||
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
|
||||
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, 0);
|
||||
|
||||
$curl->post($this->url.'passport', [
|
||||
'image' => $fileData,
|
||||
]);
|
||||
if ($curl->error) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $curl->errorMessage,
|
||||
];
|
||||
} else {
|
||||
if (!$curl->response->code){
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '解析失败',
|
||||
];
|
||||
}
|
||||
return [
|
||||
'code' => 1,
|
||||
'data' => $curl->response->data,
|
||||
];
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*身份证识别
|
||||
* @param string $fileData 图片的二进制数据
|
||||
* @return array
|
||||
*/
|
||||
function identification($fileData)
|
||||
{
|
||||
if ($fileData === false) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '无法读取上传的文件',
|
||||
];
|
||||
}
|
||||
$curl = new Curl();
|
||||
$curl->post($this->url.'identification', [
|
||||
'image' => $fileData,
|
||||
]);
|
||||
if ($curl->error) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $curl->errorMessage,
|
||||
];
|
||||
} else {
|
||||
if (!$curl->response->code){
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '解析失败',
|
||||
];
|
||||
}
|
||||
return [
|
||||
'code' => 1,
|
||||
'data' => $curl->response->data,
|
||||
];
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*护照识别
|
||||
* @param string $fileData 图片的二进制数据
|
||||
* @return array 包含压缩后图片信息的数组
|
||||
*/
|
||||
function visa($fileData)
|
||||
{
|
||||
if ($fileData === false) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '无法读取上传的文件',
|
||||
];
|
||||
}
|
||||
$curl = new Curl();
|
||||
$curl->post($this->url.'visa', [
|
||||
'image' => $fileData,
|
||||
]);
|
||||
if ($curl->error) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $curl->errorMessage,
|
||||
];
|
||||
} else {
|
||||
if (!$curl->response->code){
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '解析失败',
|
||||
];
|
||||
}
|
||||
return [
|
||||
'code' => 1,
|
||||
'data' => $curl->response->data,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user