一,使用 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的请求包, 但是图片要使用网络地址