行驶证 OCR 识别接口是一种极为强大的工具。其强大之处在于,当用户传入行驶证照片后,它能够以令人惊叹的速度和极高的准确性,快速准确地识别出行驶证上的所有文字信息。识别完成后,它会将这些文字信息以高度结构化的形式进行返回。
以下是行驶证 OCR 识别 API 接口用PHP如何调用的示例代码:
<?php
$appKey = "您的appKey";
$appSecret= "您的appSecret";
$url = "https://api.shuxuntech.com/v1/vehicle/ocr";
$method = "POST";
$timestamp = getUnixTimestamp();
var_dump($timestamp);
$sign = hash('sha256',$appKey . $timestamp . $appSecret);
var_dump($sign);
$headers = array();
array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8");
array_push($headers, "appKey" . ":" . appKey);
array_push($headers, "timestamp" . ":" . timestamp);
array_push($headers, "sign" . ":" . sign);
$image = "";
$imgUrl = "";
$bodys = "image=" . $image . "&imgUrl=" . $imgUrl;
$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_POSTFIELDS, $bodys);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (1 == strpos("$".$url, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
var_dump(curl_exec($curl));
function getUnixTimestamp () {
list($s1, $s2) = explode(' ', microtime());
return sprintf('%.0f',(floatval($s1) + floatval($s2)) * 1000);
}
返回的数据:
(1)正确返回
{
"code": "0",
"msg": "成功",
"isFee": 1,
"seqNo": "q7q3znh36dl0fxugefouneng076l1kpg",
"data": {
"result": 1,
"resultDesc": "识别成功,有数据",
"info": {
"owner": "杭州优行料技有限公司宿迁分公司",
"issuedBy": "江苏省宿迁市公安局交通警察支队",
"side": "front",
"address": "沭阳县蓝天名城19幢A1906室",
"vehicleType": "小型轿车",
"registerDate": "2016-12-28",
"type": 3,
"engineNo": "GB5002243",
"issueDate": "2020-03-27",
"plateNo": "苏HD0083",
"useCharacter": "非营运",
"model": "吉利羡日牌MR7002BEV03",
"vin": "L6T78Y4Y3G680672"
}
}
}
(2)错误返回
{
"code": "1",
"msg": "参数错误",
"isFee": 0,
"seqNo": null,
"data": null
}
需要特别注意的是,在使用行驶证 OCR 识别 API 之前,我们首先需要申请并获取 API Key,不同的平台获取 API Key 的方式可能会有所不同。但是这个 API Key 将作为我们身份验证的凭证,在后续的接口请求中必须携带。
标签:OCR,接口,识别,API,行驶证,Key,PHP From: https://blog.csdn.net/shuxunAPI/article/details/143817025