setImage($image); if($url!="")$body->setUrl($url); $request->setBody($body); $msg = ''; try { $response = $client->RecognizeBusinessLicense($request); } catch (ConnectionException $e) { $msg = $e->getMessage(); } catch (RequestTimeoutException $e) { $msg = $e->getMessage(); } catch (ServiceResponseException $e) { $msg = $e->getErrorMsg(); } if ($msg) { return ["isResult"=>false,"msg"=>$msg]; } else { return ['isResult'=>true,'msg'=>"获取成功","data"=>json_decode($response->getResult()->__toString(),true)]; } } protected static function OcrInfo() { $config = HttpConfig::getDefaultConfig(); $config->setIgnoreSslVerification(true); $client = OcrClient::newBuilder() ->withHttpConfig($config) ->withEndpoint(self::$endpoint) ->withCredentials(self::$credentials) ->build(); return $client; } /** * Array of property to type mappings. Used for (de)serialization * code 发票代码。发票种类为全电发票时,该参数须为空字符串。 * number 发票号码 * issueDate 发票日期格式YYYY-MM-DD * checkCode 校验码后六位。 - 以下种类发票,参数不可为空 增值税普通发票、增值税电子普通发票、增值税普通发票(卷式)、增值税电子普通发票(通行费)、区块链电子发票。 * - 区块链电子发票需要填写5位校验码。 * subtotalAmount 合计金额。和票据上的金额的有效数字保持一致,例如票据上的金额为88.00,则需要输入字符串为“88.00”,才能验真成功。如果输入“88”或“88.0”可能会产生\"result_code\": \"1010\", \" Parameter error.\"报错。 * 发票种类为全电发票时,该参数须为价税合计金额,其他票种使用不含税合计金额。 - 以下种类发票,参数不可为空 增值税专用发票、增值税电子专用发票、机动车销售统一发票、二手车销售统一发票、区块链电子发票、全电发票。 - 填写发票合计金额(不含税) 增值税专用发票、增值税电子专用发票、机动车销售统一发票、区块链电子发票。 - 二手车发票需要填写发票车价合计金额 * @var string[] */ public static function InvoiceVerification($code='',$number='',$issueDate='',$checkCode='',$subtotalAmount='') { $client = self::OcrInfo(); $request=new RecognizeInvoiceVerificationRequest(); $body = new InvoiceVerificationRequestBody(); $issueDate = date('Y-m-d',strtotime($issueDate)); if($checkCode!=""&&strlen($checkCode)!=6)$checkCode=substr($checkCode,0,6); if($subtotalAmount!="")$subtotalAmount= number_format($subtotalAmount, 2, '.', ''); $body->setCode($code); $body->setNumber($number); $body->setIssueDate($issueDate); $body->setCheckCode($checkCode); $body->setSubtotalAmount($subtotalAmount); $request->setBody($body); $msg = ''; try { $response = $client->RecognizeInvoiceVerification($request); }catch (ConnectionException $e) { $msg = $e->getMessage(); } catch (RequestTimeoutException $e) { $msg = $e->getMessage(); } catch (ServiceResponseException $e) { $msg = $e->getErrorMsg(); } if ($msg) { return ["isResult"=>false,"msg"=>$msg]; } else { return ['isResult'=>true,'msg'=>"获取成功","data"=>json_decode($response,true)]; } } }