tcocr add vatinvoice about

This commit is contained in:
qianhy
2023-05-06 14:29:47 +08:00
parent 3b9e0467d1
commit 93ec3288eb
3 changed files with 95 additions and 1 deletions
+33 -1
View File
@@ -934,14 +934,46 @@ class Orders extends HD_Controller
return $this->show_json(2, $orc_res['msg']);
}
$carinfo = $orc_res['data']['CarInvoiceInfos'];
$bill_name = '';
if(is_array($carinfo)){
foreach($carinfo as $kye=>$val){
if($val['Name']=='发票名称'){
$bill_name = $val['Value'];
}
if($val['Name']=='开票日期'){
$bill_time = $val['Value'];
break;
}
}
}
# 发票名称为空, 按增值税发票处理
if (!$bill_name){
$orc_res = $this->tcorc->VatInvoice($img_url);
if (!$orc_res['code']) {
return $this->show_json(3, $orc_res['msg']);
}
$carinfo = $orc_res['data']['VatInvoiceInfos'];
if(is_array($carinfo)){
foreach($carinfo as $kye=>$val){
if($val['Name']=='发票名称'){
$bill_name = $val['Value'];
}
if($val['Name']=='开票日期'){
# 开票日期:2023年04月27日
$tmp_value = $val['Value'];
$tmp_value = str_replace("", "-", $tmp_value);
$tmp_value = str_replace("", "-", $tmp_value);
$tmp_value = str_replace("", "", $tmp_value);
$bill_time = $tmp_value;
}
}
}
# 发票名称为空,可能是保单等图片
if (!$bill_name){
return $this->show_json(4, "识别失败");
}
}
$jsondata['infos'] = $carinfo;
}
$update['file'] = $file;
+11
View File
@@ -598,6 +598,17 @@ class Order extends CI_Controller{
$bill_info['二手车市场'] && $add_data['bill_name'] = $bill_info['二手车市场'];
$bill_info['车价合计(小写)'] && $add_data['bill_price'] = str_replace('¥','',$bill_info['车价合计(小写)']);
}
elseif ($bill_info['发票类型'] == '增值税专用发票'){
$bill_info['销售方名称'] && $add_data['bill_name'] = $bill_info['销售方名称'];
# 开票日期:2023年04月27日
if ($tmp_value = $bill_info['开票日期']){
$tmp_value = str_replace("", "-", $tmp_value);
$tmp_value = str_replace("", "-", $tmp_value);
$tmp_value = str_replace("", "", $tmp_value);
$add_data['bill_time'] = $tmp_value;
};
$bill_info['小写金额'] && $add_data['bill_price'] = str_replace('¥','',$bill_info['小写金额']);
}
$add_data['price'] = $add_data['bill_price'] ? $add_data['bill_price'] : 0; #23-04-04: 这个实际售价可以改成默认开票价,不能默认成指导价
if ($debug){
echo "get bill_info: <br>";
+51
View File
@@ -17,6 +17,7 @@ use TencentCloud\Ocr\V20181119\Models\IDCardOCRRequest;
use TencentCloud\Ocr\V20181119\Models\BizLicenseOCRRequest;
use TencentCloud\Ocr\V20181119\Models\CarInvoiceOCRRequest;
use TencentCloud\Ocr\V20181119\Models\VehicleLicenseOCRRequest;
use TencentCloud\Ocr\V20181119\Models\VatInvoiceOCRRequest;
class TcOrc{
private $accessKeyId;
@@ -240,4 +241,54 @@ class TcOrc{
return ['code'=>0,'msg'=>'图片识别失败'];
}
}
/**
* 增值税发票识别
* Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/36210
* @param $imageUrl string 增值税发票图片url
* @param return array 返回值参考官方文档
*/
public function VatInvoice($imageUrl){
//dev测试
if($this->is_dev){
$this->ci->load->library('mycurl');
$debug_url = 'http://104.194.86.23:8889/vinvoice.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 VatInvoiceOCRRequest();
$params = array(
"ImageUrl" => $imageUrl,
);
$req->fromJsonString(json_encode($params));
$resp = $client->VatInvoiceOCR($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'=>'图片识别失败'];
}
}
}