setEndpoint("ocr.tencentcloudapi.com"); $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); $client = new OcrClient($cred, "ap-beijing", $clientProfile); $req = new IDCardOCRRequest(); $configs=[ "CopyWarn"=>true, "BorderCheckWarn"=>true, "ReshootWarn"=>true, "DetectPsWarn"=>true, "TempIdWarn"=>true, "InvalidDateWarn"=>true, "Quality"=>true, "ReflectWarn"=>true ];//"CropIdCard"=>true,"CropPortrait"=>true, $params = [ 'ImageUrl'=>$img, 'Config' => json_encode($configs) ]; $req->fromJsonString(json_encode($params)); $resp = $client->IDCardOCR($req); return $resp->toJsonString(); } public function AdvancedInfo(){ return [ '-9100'=>'身份证有效日期不合法', '-9101'=>'身份证边框不完整', '-9105'=>'身份证框内遮挡', '-9107'=>'身份证反光' ]; } //活体人脸核身 public function checkFaceId($idCard,$name,$url) { $cred = new Credential(env('TENCENT_SECRETID'), env('TENCENT_SECRETKEY')); $httpProfile = new HttpProfile(); $httpProfile->setEndpoint("faceid.tencentcloudapi.com"); $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); $client = new OcrClient($cred, "ap-beijing", $clientProfile); $req = new IDCardOCRRequest(); $params = [ 'IdCard'=>$idCard, 'Name'=>$name, 'ImageBase64'=>$this->getBase64Encode($url), // 'LivenessType'=>'SILENT',//LIP为数字模式,ACTION为动作模式,SILENT为静默模式 ]; $req->fromJsonString(json_encode($params)); $resp = $client->IDCardOCR($req); return $resp->toJsonString(); } //获取base64 protected function getBase64Encode($url) { return base64_encode(file_get_contents($url)); } }