accessKeyId = $accessKeyId; $this->accessKeySecret = $accessKeySecret; } else { $this->accessKeyId = 'AKIDMXS7WhbEdlcCWZMs75mDNHuIPHsCF2Yn'; $this->accessKeySecret = 'zh8JDpAF3bOvCCvNYS5RXLs87pGQKxJO'; } $this->ci = &get_instance(); $this->dir = 'tcorc'; } /** * 身份证识别 * Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/33524 * @param $imageUrl string 身份证图片地址 * @param $CardSide string 省份证正反面 (FRONT 正面 BACK 反面) * @param return array 返回值参考官方文档 */ public function IdentityCard($imageUrl, $CardSide = 'FRONT') { 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 IDCardOCRRequest(); $params = array( "ImageUrl" => $imageUrl, "CardSide" => $CardSide ); $req->fromJsonString(json_encode($params)); $resp = $client->IDCardOCR($req); debug_log("function:" . __FUNCTION__ . $resp->toJsonString(), $this->log_success_file, $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' => '识别失败,请重新上传']; } } /** * 营业执照 * Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/36215 * @param $imageUrl string 营业执照图片url * @param return array 返回值参考官方文档 */ public function BizLicense($imageUrl) { 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 BizLicenseOCRRequest(); $params = array( "ImageUrl" => $imageUrl, ); $req->fromJsonString(json_encode($params)); $resp = $client->BizLicenseOCR($req); debug_log("function:" . __FUNCTION__ . $resp->toJsonString(), $this->log_success_file, $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' => '识别失败']; } } /** * 购车发票识别 * Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/37076 * @param $imageUrl string 购车发票图片url * @param return array 返回值参考官方文档 */ public function CarInvoiceInfos($imageUrl) { 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("img:" . $imageUrl, 'success.log', $this->dir); debug_log("function:" . __FUNCTION__ . $resp->toJsonString(), $this->log_success_file, $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->getMessage(), $this->log_file, $this->dir); return ['code' => 0, 'msg' => '图片识别失败']; } } /** * 行驶证识别 * Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/36209 * @param $imageUrl string 行驶证照图片url * @param return array 返回值参考官方文档 */ public function VehicleLicense($imageUrl) { 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 VehicleLicenseOCRRequest(); $params = array( "ImageUrl" => $imageUrl, ); $req->fromJsonString(json_encode($params)); $resp = $client->VehicleLicenseOCR($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' => '图片识别失败']; } } /** * 增值税发票识别 * Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/36210 * @param $imageUrl string 增值税发票图片url * @param return array 返回值参考官方文档 */ public function VatInvoice($imageUrl) { 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' => '图片识别失败']; } } }