add-comomn-CarInvoiceOCR

This commit is contained in:
lccsw
2022-04-14 17:18:30 +08:00
parent 4db90d0a27
commit c1a211fc74
3 changed files with 82 additions and 4 deletions
+22 -2
View File
@@ -33,6 +33,7 @@ class Orders extends HD_Controller
$this->load->library('receiver/order_datas_entity');
$this->load->library('Ordersv2List');
$this->load->library('qyrobot');
$this->load->library('TcOrc');
}
public function index()
@@ -304,7 +305,6 @@ class Orders extends HD_Controller
return $this->show_json(SYS_CODE_FAIL, '请上传身份证照片');
}
$this->load->library('TcOrc');
$cardidA_src = build_qiniu_image_url($cardidA);
$result = $this->tcorc->IdentityCard($cardidA_src);
if (!$result['code']) {
@@ -511,14 +511,34 @@ class Orders extends HD_Controller
}
$row = $this->order_bills_model->get(['o_id' => $row_order['id']]);
if(!$row){
$jsondata = [];
$this->order_bills_model->add(['c_time'=>time(),'o_id'=>$row_order['id']]);
}else{
$jsondata = json_decode($row['jsondata'],true);
}
//图片识别
$img_url = build_qiniu_image_url($file);
$orc_res = $this->tcorc->CarInvoiceInfos($img_url);
if (!$orc_res['code']) {
return $this->show_json(SYS_CODE_FAIL, $orc_res['msg']);
}
$bill_time = date('Y-m-d H:i:s');
$carinfo = $orc_res['data']['CarInvoiceInfos'];
if(is_array($carinfo)){
foreach($carinfo as $kye=>$val){
if($val['Name']=='开票日期'){
$bill_time = $val['Value'];
break;
}
}
}
$jsondata['infos'] = $carinfo;
$update['file'] = $file;
$update['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
$result = $this->order_bills_model->update($update, ['o_id' => $row_order['id']]);
if ($result) {
//更新开票时间
$this->load->model('items/items_model');
$bill_time = date('Y-m-d H:i:s');
$upd = array('bill_time' => $bill_time);
$where = array('id' => $row_order['item_id']);
$ret = $this->items_model->update($upd, $where);
@@ -653,11 +653,18 @@
});
function upBill(obj) {
var loading = layer.msg('图片识别中..', {
icon: 16
,shade: 0.3
,time: false
});
var value = $(obj).val();
var that = this;
$.post("/receiver/orderv2/orders/edit_bill", {
'id': <?=$info['id']?>,
'value': value,
}, function (data) {
layer.closeAll()
if (data.code) {
layer.msg(data.msg, {time: 2000, icon: 1}, function () {
$.form.reload();
+53 -2
View File
@@ -15,6 +15,7 @@ use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Ocr\V20181119\OcrClient;
use TencentCloud\Ocr\V20181119\Models\IDCardOCRRequest;
use TencentCloud\Ocr\V20181119\Models\BizLicenseOCRRequest;
use TencentCloud\Ocr\V20181119\Models\CarInvoiceOCRRequest;
class TcOrc{
private $accessKeyId;
@@ -77,7 +78,7 @@ class TcOrc{
$resp = $client->IDCardOCR($req);
debug_log($resp->toJsonString(),'success.log',$this->dir);
debug_log("function:".__FUNCTION__.$resp->toJsonString(),'success.log',$this->dir);
$result = json_decode($resp->toJsonString(),true);
if($result['Error']){
return ['code'=>0,'msg'=>$result['Error']['Message']];
@@ -126,7 +127,7 @@ class TcOrc{
$resp = $client->BizLicenseOCR($req);
debug_log($resp->toJsonString(),'success.log',$this->dir);
debug_log("function:".__FUNCTION__.$resp->toJsonString(),'success.log',$this->dir);
$result = json_decode($resp->toJsonString(),true);
if($result['Error']){
return ['code'=>0,'msg'=>$result['Error']['Message']];
@@ -139,4 +140,54 @@ class TcOrc{
return ['code'=>0,'msg'=>'识别失败'];
}
}
/**
* 购车发票识别
* Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/37076
* @param $imageUrl string 营业执照图片url
* @param return array 返回值参考官方文档
*/
public function CarInvoiceInfos($imageUrl){
//dev测试
if($this->is_dev){
$this->ci->load->library('mycurl');
$debug_url = 'http://104.194.86.23:8889/infos.php';
$params = [
'ImageUrl' => $imageUrl,
];
$result = $this->ci->mycurl->httpGet($debug_url,$params);
$result = json_decode($result,true);
return $result;
}
try {
$cred = new Credential($this->accessKeyId, $this->accessKeySecret);
$httpProfile = new HttpProfile();
$httpProfile->setEndpoint("ocr.tencentcloudapi.com");
$clientProfile = new ClientProfile();
$clientProfile->setHttpProfile($httpProfile);
$client = new OcrClient($cred, "ap-guangzhou", $clientProfile);
$req = new CarInvoiceOCRRequest();
$params = array(
"ImageUrl" => $imageUrl,
);
$req->fromJsonString(json_encode($params));
$resp = $client->CarInvoiceOCR($req);
debug_log("function:".__FUNCTION__.$resp->toJsonString(),'success.log',$this->dir);
$result = json_decode($resp->toJsonString(),true);
if($result['Error']){
return ['code'=>0,'msg'=>$result['Error']['Message']];
}else{
return ['code'=>1,'msg'=>'图片识别成功','data'=>$result];
}
}
catch(TencentCloudSDKException $e) {
debug_log($e,$this->log_file,$this->dir);
return ['code'=>0,'msg'=>'图片识别失败'];
}
}
}