tp5身份证识别

tp5身份证识别

tp5身份证识别

引入ocr文件夹

写程序baidu.php

<?php

namespace app\huozhu\controller;

use think\Controller;
use think\Request;
require_once('Baidu/AipOcr.php');
class Baidu extends Controller
{

    /**
     * 身份证
     * @param null $url
     * @param string $side
     * @return \Illuminate\Http\JsonResponse
     */
    public function shenfenzheng(Request $request)
    {
        $url = $request->get('url');

        $side = $request->get('side');

        if (!$url)
        {
            return json(['err' => 1, 'msg' => 'error', 'data' => '']);
        }

        if (!$side)
        {
            $side = 'front';
        }

        $image = file_get_contents($url);

        //正反面
        $idCardSide = $side;
        $ak = '2277jjT8QscMHBZfRlcwsYqx';
        $appid = '16864357';
        $sk = 'TcI1m3HzQXIN3GpqClSBGw845Km3NUYU';
        $api = new \AipOcr($appid,$ak,$sk);
        //var_dump($this->baidu);die;
        $res = $api->idcard($image,$idCardSide);
//dump($res);die;
        $arr = [];

        if ($res)
        {
            $arr['shenfenzheng'] = $res['words_result']['公民身份号码']['words'];
            $arr['name'] = $res['words_result']['姓名']['words'];

            return json(['err' => 0, 'msg' => '身份证识别成功', 'data' => $arr]);
        }else{
            return json(['err' => 1, 'msg' => '身份证识别失败,请手动填写', 'data' => '']);
        }


    }
}

 

上一篇:尝试运用普吕克坐标解决三维空间内三角形和线段的相交判断问题


下一篇:不用代码就能实现get与post