腾讯云【OCR-行驶证驾驶证识别】PHP - POST请求 Api踩的坑 Demo

本文详细介绍了如何使用腾讯云的OCR接口进行图像识别,包括使用image和url请求包的具体实现步骤,以及常见错误代码的解读和解决方法。

    一,使用 image 的请求包 

       $appid = "9999999";
        $secretId = 'dfghthiUXuEhvQgy1p4Uffffff';
        $secretKey = 'dfgrtyVNPM5yPr9HHnertyuop';
        $bucket = "8";
        $expired = time() + 2592000;
        $onceExpired = 0;
        $current = time();
        $rdm = rand();
        $userid = "0";
        $fileid = "";
        $srcStr = 'a=' . $appid . '&b=' . $bucket . '&k=' . $secretId . '&e=' . $expired . '&t=' . $current . '&r=' . $rdm . '&f=';
        $signStr = base64_encode(hash_hmac('SHA1', $srcStr, $secretKey, true) . $srcStr);
        $images = $this->config['address'] . date('Ym', time()) . '/60502b57f901b1815665380515ce183920190119.jpg';
        $minetype = 'image/jpeg';
        $images = curl_file_create($images, $minetype);
        $params = array(
            'type' => 0,
            'appid' => $appid,
            'image' => $images,
            'bucket' => "8"
        );
     
        $res = $this->tocurl($params, $signStr);
        $result = json_decode($res, true);

 private function tocurl($content, $signStr)
    {
        $curl = curl_init();
        $response = false;
        $head = array(
            'Content-Type:multipart/form-data',
            'Host:recognition.image.myqcloud.com',
            'Authorization:' . $signStr
            // 'Content-Length:' . filesize($content)
        );

  二,使用 url的请求包 

 $images = "http://m.qpic.cn/psb?/V13951Rw205AJa/yXeWsYqJh0*VozfH0I7hgDYIu8NJ2DIYKCCDqwxqzeg";//网络地址 

$params = array(
            'type' => 0,
            'appid' => $appid,
            'url' => $images,
            'bucket' => "8"
        );

$params=json_encode($params);

$res = $this->tocurl($params, $signStr);
 $result = json_decode($res, true);

把官方文档中要我们写的Content-Length去掉。

三,报错及处理

1,腾讯云行驶证驾驶证OCR 返回信息-1102,无法解码?

{"code":-1102,"message":"SDK_IMAGE_DECODE_FAILED","data":{"recognize_warn_msg":[],"recognize_warn_code":[],"items":[],"session_id":"1257423962-2026704825","class":[]}

出现该报错的原因是:采用了这 'Content-Type:multipart/form-data',这种方式传递,但是图片没有正常上传

2,腾讯云行驶证驾驶证ocr识别接口返回-1308?

data:{code:-1308,message:"ERROR_DOWNLOAD_IMAGE_FAILED"}

出现该报错的原因是:采用url的请求包, 但是图片要使用网络地址

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值