12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace App\Handlers;
- use GuzzleHttp\Client;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Log;
- use TencentCloud\Common\Credential;
- use TencentCloud\Common\Profile\ClientProfile;
- use TencentCloud\Common\Profile\HttpProfile;
- use TencentCloud\Ocr\V20181119\Models\IDCardOCRRequest;
- use TencentCloud\Ocr\V20181119\OcrClient;
- class TencentHandler {
- protected static $secretId;
- protected static $secretKey;
- //初始化
- public function __construct(){
- self::$secretId=env('TENCENT_SECRETID');
- self::$secretKey=env('TENCENT_SECRETKEY');
- }
- //获取证件信息
- public function getCertInfo($img)
- {
- $cred = new Credential(env('TENCENT_SECRETID'), env('TENCENT_SECRETKEY'));
- $httpProfile = new HttpProfile();
- $httpProfile->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));
- }
- }
|