阿里云人脸身份证识别

发布时间 2023-11-02 18:49:27作者: 现世中的素人
public function ALiSlyface()
    {
        $host    = "https://slyface.market.alicloudapi.com";
        $path    = "/post/faceidcard/compare";
        $method  = "POST";
        $appcode = "bf3b170a39184dbf9cb268add9d47582";
        $headers = array();
        array_push($headers, "Authorization:APPCODE " . $appcode);
        array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8");
        $url        = Request::param('link');
        $name        = Request::param('name');
        $idcard        = Request::param('idcard');

        $image = urlencode($url);
        $bodys = "idcard=$idcard&name=" . urlencode($name) . "&url=" . $image;
        $url   = $host . $path;

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        //设定返回信息中是否包含响应信息头,启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头
        //如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false
        curl_setopt($curl, CURLOPT_HEADER, false);
        if (1 == strpos("$" . $host, "https://")) {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
        $res = json_decode(curl_exec($curl), true);
        if($res['success'] == true ) {
            return success(Status::SUCCESS, '操作成功', [
                "data" => $res
            ]);
        }else{
            return error(Status::ERROR, '', [
                "data" => $res
            ]);
        }
    }