liuyexing/aliyun-contrast-face-verify

阿里云金融级实人认证

1.0.1 2024-12-23 05:51 UTC

This package is not auto-updated.

Last update: 2025-04-01 03:06:46 UTC


README

阿里云金融级实人认证

使用示例:
use AliyunFinancialGradeIdVerification\ContrastFaceVerify;
class Test{
    private $accessKeyId = '';//阿里云key
    private $accessKeySecret = '';//阿里云秘钥
    private $sceneId = ''; //认证场景ID
    
    /**
     * 初始化
     */
    public function __construct($config=[])
    {
        $this->accessKeyId=$config['accessKeyId'];
        $this->accessKeySecret=$config['accessKeySecret'];
        $this->sceneId=$config['sceneId'];
        $this->callbackUrl=$config['callbackUrl'];
    }

    /**
     * 获取CertifyId参数
     */
    public function getCertifyId()
    {
        try{
           $config=[
                'accessKeyId'=>self::$accessKeyId,
                'accessKeySecret'=>self::$accessKeySecret,
                'sceneId'=>self::$sceneId,
                'callbackUrl'=>'https://www.xxx.com/test/callback'
            ];
            $aliyun=new ContrastFaceVerify($config);
            $realname='真实姓名';
            $idcard='身份证号';
            $certifyId=$aliyun->getCertifyId($param['meta_info'],$realname,$idcard);
        }catch(\Exception){
            die($e->getMessage());
        }
        return $certifyId;
    }
    
    /**
     * 处理验证回调
     */
    public function callback()
    {
         $param = $this->request->param();
         $certifyId = $param['certifyId'];
        try{
            $config=[
                'accessKeyId'=>self::$accessKeyId,
                'accessKeySecret'=>self::$accessKeySecret,
                'sceneId'=>self::$sceneId,
                'callbackUrl'=>$this->request->domain().'/api/Alibaba/callback'
            ];
            $aliyun=new ContrastFaceVerify($config);
            $res=$aliyun->callbackVerify($certifyId);
            if($res){
               //处理成功逻辑
            }else{
                //处理失败逻辑
            }
        }catch(\Exception){
            die($e->getMessage());
        }
    }

}