accessKeyId = $accessKeyId; $this->accessKeySecret = $accessKeySecret; }else{ $this->accessKeyId = 'AKIDMXS7WhbEdlcCWZMs75mDNHuIPHsCF2Yn'; $this->accessKeySecret = 'zh8JDpAF3bOvCCvNYS5RXLs87pGQKxJO'; } if (false !== strpos($_SERVER['HTTP_HOST'], 'dev')) {//dev $this->is_dev = true; } $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'){ if($this->is_dev){ $this->ci->load->library('mycurl'); $debug_url = 'http://104.194.86.23:8889/index.php'; $params = [ 'ImageUrl' => $imageUrl, 'CardSide' => $CardSide ]; $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 IDCardOCRRequest(); $params = array( "ImageUrl" => $imageUrl, "CardSide" => $CardSide ); $req->fromJsonString(json_encode($params)); $resp = $client->IDCardOCR($req); debug_log($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/36215 * @param $imageUrl string 营业执照图片url * @param return array 返回值参考官方文档 */ public function BizLicense($imageUrl){ //dev测试 if($this->is_dev){ $this->ci->load->library('mycurl'); $debug_url = 'http://104.194.86.23:8889/biz.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 BizLicenseOCRRequest(); $params = array( "ImageUrl" => $imageUrl, ); $req->fromJsonString(json_encode($params)); $resp = $client->BizLicenseOCR($req); debug_log($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'=>'识别失败']; } } }