具体来说,行驶证 OCR 识别接口具备强大的功能,可以准确识别包括所有人、品牌型号、住址、车牌号、发动机号码、车辆识别代号、注册日期、发证日期等多个至关重要的字段信息。在实际应用中,该接口通过对行驶证照片进行全面而深入的智能分析,能够极为精准地提取出上述的这些信息。并且,它会将提取出的信息高效地转化为可编辑、可存储的文本格式,为用户后续的操作和管理提供了极大的便利。
以下是行驶证 OCR 识别 API 接口用C#如何调用的示例代码:
using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
public class ApiDemo {
private const String url = "https://api.shuxuntech.com/v1/vehicle/ocr";
private const String method = "POST";
private const String appKey = "您的appKey";
private const String appSecret = "您的appSecret";
public static void Main(string[] args) {
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
String timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
String sign = SHA256(appKey + timestamp + appSecret);
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
httpRequest = (HttpWebRequest) WebRequest.CreateDefault(new Uri(url));
httpRequest.Method = method;
httpRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
httpRequest.Headers.Add("appKey", appKey);
httpRequest.Headers.Add("timestamp", timestamp);
httpRequest.Headers.Add("sign", sign);
String image = "";
String imgUrl = "";
String params = "image=" + image + "&imgUrl=" + imgUrl;
byte[] data = Encoding.UTF8.GetBytes(params);
using (Stream stream = httpRequest.GetRequestStream()) {
stream.Write(data, 0, data.Length);
}
httpResponse = (HttpWebResponse) httpRequest.GetResponse();
Console.WriteLine(httpResponse.StatusCode);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
}
public static string SHA256(string str) {
byte[] SHA256Data = Encoding.UTF8.GetBytes(str);
SHA256Managed Sha256 = new SHA256Managed();
byte[] by = Sha256.ComputeHash(SHA256Data);
return BitConverter.ToString(by).Replace("-", "").ToLower();
}
}
返回的数据:
(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 将作为我们身份验证的凭证,在后续的接口请求中必须携带。
标签:httpRequest,appKey,String,C#,System,API,using,OCR From: https://blog.csdn.net/shuxunAPI/article/details/143817040