|
@@ -1,15 +1,24 @@
|
|
|
using Aspose.Cells;
|
|
|
+using Aspose.Words;
|
|
|
+using Aspose.Words.Fonts;
|
|
|
+using Microsoft.AspNetCore.Mvc.ViewEngines;
|
|
|
+using NPOI.HPSF;
|
|
|
using OASystem.API.OAMethodLib.File;
|
|
|
//using OASystem.API.OAMethodLib.NPOI;
|
|
|
using OASystem.API.OAMethodLib.TencentCloudAPI;
|
|
|
using OASystem.API.OAMethodLib.YouDaoAPI;
|
|
|
using OASystem.Domain.Dtos.CRM;
|
|
|
+using OASystem.Domain.Dtos.QiYeWeChat;
|
|
|
using OASystem.Domain.Dtos.Tencent;
|
|
|
+using OASystem.Domain.ViewModels.OCR;
|
|
|
+using OASystem.Domain.ViewModels.QiYeWeChat;
|
|
|
using OASystem.Domain.ViewModels.TencentOCR;
|
|
|
using OASystem.Infrastructure.Repositories.CRM;
|
|
|
using Org.BouncyCastle.Crypto;
|
|
|
using Org.BouncyCastle.Utilities.Encoders;
|
|
|
using StackExchange.Redis;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Data;
|
|
|
using System.Net.NetworkInformation;
|
|
|
using TencentCloud.Ocr.V20181119.Models;
|
|
|
using Ubiety.Dns.Core;
|
|
@@ -34,6 +43,7 @@ namespace OASystem.API.Controllers
|
|
|
|
|
|
/// <summary>
|
|
|
/// 通用印刷体
|
|
|
+ /// 文档下载
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
@@ -54,7 +64,7 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView("图片不能大于7M!"));
|
|
|
}
|
|
|
|
|
|
- var gbData = TencentOCRTools.GetOCR((int)TencentOCREnum.GeneralBasic, dto);
|
|
|
+ var gbData = await TencentOCRTools.GetOCR((int)TencentOCREnum.GeneralBasic, dto);
|
|
|
|
|
|
if (gbData.Code != 0)
|
|
|
{
|
|
@@ -66,13 +76,42 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView(gbData.Msg));
|
|
|
}
|
|
|
|
|
|
- return Ok(JsonView(gbData.Data));
|
|
|
+ #region word下载
|
|
|
+
|
|
|
+ GeneralBasicOCRResponse res = gbData.Data as GeneralBasicOCRResponse;
|
|
|
+
|
|
|
+ Document doc = new Document();
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(doc);
|
|
|
+ string fileName = "通用印刷体";
|
|
|
+ string content = $"{fileName}\r\n\r\n";
|
|
|
+ foreach (var view in res.TextDetections)
|
|
|
+ {
|
|
|
+ content += $"Content:{view.DetectedText}\r\n\r\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ builder.Write(content);
|
|
|
+
|
|
|
+ string outputDir = $"{AppSettingsHelper.Get("WordBasePath")}/TencentOCR";
|
|
|
+ string outputFile = $"{fileName}{DateTime.Now.ToString("yyyyMMddHHmmss")}.docx";
|
|
|
+ string outputPath = Path.Combine(outputDir, outputFile);
|
|
|
+
|
|
|
+ if (!Directory.Exists(outputDir))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(outputDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ doc.Save(outputPath);
|
|
|
+ string url = $"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/TencentOCR/{outputFile}";
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ return Ok(JsonView(true, "操作成功", new { dataSource = res, url = url }));
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 身份证识别(国徽面/反面)
|
|
|
- /// 获取身份证返回数据
|
|
|
+ /// 文档下载
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
@@ -93,7 +132,7 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView("图片不能大于7M!"));
|
|
|
}
|
|
|
|
|
|
- var idCardData = TencentOCRTools.GetOCR((int)TencentOCREnum.IDCard, dto);
|
|
|
+ var idCardData =await TencentOCRTools.GetOCR((int)TencentOCREnum.IDCard, dto);
|
|
|
|
|
|
if (idCardData.Code != 0)
|
|
|
{
|
|
@@ -174,7 +213,7 @@ namespace OASystem.API.Controllers
|
|
|
|
|
|
/// <summary>
|
|
|
/// 户口簿识别
|
|
|
- /// 获取户口簿返回数据
|
|
|
+ /// 文档下载 ?
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
@@ -188,7 +227,7 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView("图片不能大于7M!"));
|
|
|
}
|
|
|
|
|
|
- var residenceBookData = TencentOCRTools.GetOCR((int)TencentOCREnum.ResidenceBooklet, dto);
|
|
|
+ var residenceBookData = await TencentOCRTools.GetOCR((int)TencentOCREnum.ResidenceBooklet, dto);
|
|
|
|
|
|
if (residenceBookData.Code != 0)
|
|
|
{
|
|
@@ -200,8 +239,54 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView(residenceBookData.Msg));
|
|
|
}
|
|
|
|
|
|
+ #region Feil Down
|
|
|
|
|
|
- return Ok(JsonView(residenceBookData.Data));
|
|
|
+ BizLicenseOCRResponse res = residenceBookData.Data as BizLicenseOCRResponse;
|
|
|
+
|
|
|
+ Document doc = new Document();
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(doc);
|
|
|
+
|
|
|
+ string fileName = "户口簿识别";
|
|
|
+ string content = $"{fileName}\r\n\r\n";
|
|
|
+
|
|
|
+ if (res != null)
|
|
|
+ {
|
|
|
+ content += $"公司名称:{res.Name}\r\n\r\n";
|
|
|
+ content += $"统一社会信用代码(三合一之前为注册号):{res.RegNum}\r\n\r\n";
|
|
|
+ content += $"注册资本:{res.Capital}\r\n\r\n";
|
|
|
+ content += $"法人代表:{res.Person}\r\n\r\n";
|
|
|
+ content += $"地址:{res.Address}\r\n\r\n";
|
|
|
+ content += $"经营范围:{res.Business}\r\n\r\n";
|
|
|
+ content += $"主题类型:{res.Type}\r\n\r\n";
|
|
|
+ content += $"营业期限:{res.Period}\r\n\r\n";
|
|
|
+ content += $"组成形式:{res.ComposingForm}\r\n\r\n";
|
|
|
+ content += $"成立日期:{res.SetDate}\r\n\r\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ builder.Write(content);
|
|
|
+
|
|
|
+ string outputDir = $"{AppSettingsHelper.Get("WordBasePath")}/TencentOCR";
|
|
|
+ string outputFile = $"{fileName}{DateTime.Now.ToString("yyyyMMddHHmmss")}.docx";
|
|
|
+ string outputPath = Path.Combine(outputDir, outputFile);
|
|
|
+
|
|
|
+ if (!Directory.Exists(outputDir))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(outputDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ doc.Save(outputPath);
|
|
|
+
|
|
|
+ string url = $"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/TencentOCR/{outputFile}";
|
|
|
+
|
|
|
+
|
|
|
+ var data = new {
|
|
|
+ dataSource = residenceBookData.Data,
|
|
|
+ url = url
|
|
|
+ };
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+ return Ok(JsonView(data));
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -220,7 +305,7 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView("图片不能大于7M!"));
|
|
|
}
|
|
|
|
|
|
- var residenceBookData = TencentOCRTools.GetOCR((int)TencentOCREnum.BizLicense, dto);
|
|
|
+ var residenceBookData = await TencentOCRTools.GetOCR((int)TencentOCREnum.BizLicense, dto);
|
|
|
|
|
|
if (residenceBookData.Code != 0)
|
|
|
{
|
|
@@ -252,7 +337,7 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView("图片不能大于7M!"));
|
|
|
}
|
|
|
|
|
|
- var occData = TencentOCRTools.GetOCR((int)TencentOCREnum.OrgCodeCert, dto);
|
|
|
+ var occData = await TencentOCRTools.GetOCR((int)TencentOCREnum.OrgCodeCert, dto);
|
|
|
|
|
|
if (occData.Code != 0)
|
|
|
{
|
|
@@ -269,7 +354,7 @@ namespace OASystem.API.Controllers
|
|
|
|
|
|
/// <summary>
|
|
|
/// 行驶证识别
|
|
|
- /// 获取行驶证返回数据
|
|
|
+ /// 文档下载
|
|
|
/// CardSide=0 主页正面(有红色印章的一面),CardSide=1 行驶证副页正面(有号码号牌的一面),CardSide=2 行驶证主页正面和副页正面。
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
@@ -286,22 +371,119 @@ namespace OASystem.API.Controllers
|
|
|
|
|
|
var vehicleLicenseData = TencentOCRTools.GetOCR((int)TencentOCREnum.VehicleLicense, dto);
|
|
|
|
|
|
- if (vehicleLicenseData.Code != 0)
|
|
|
+ if (vehicleLicenseData.Result.Code != 0)
|
|
|
{
|
|
|
- return Ok(JsonView(vehicleLicenseData.Msg));
|
|
|
+ return Ok(JsonView(vehicleLicenseData.Result.Msg));
|
|
|
}
|
|
|
|
|
|
- if (vehicleLicenseData.Data == null)
|
|
|
+ if (vehicleLicenseData.Result.Data == null)
|
|
|
{
|
|
|
- return Ok(JsonView(vehicleLicenseData.Msg));
|
|
|
+ return Ok(JsonView(vehicleLicenseData.Result.Msg));
|
|
|
}
|
|
|
|
|
|
- return Ok(JsonView(vehicleLicenseData.Data));
|
|
|
+
|
|
|
+ #region word下载
|
|
|
+
|
|
|
+ VehicleLicenseOCRResponse vlData = vehicleLicenseData.Result.Data as VehicleLicenseOCRResponse;
|
|
|
+
|
|
|
+ string url = "";
|
|
|
+ string fileName = "";
|
|
|
+ string content = "";
|
|
|
+ dynamic data = null;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //Aspose.Words.License lic = new Aspose.Words.License();
|
|
|
+ //lic.SetLicense("Aspose.Wrods.lic");//破解版不用设置license
|
|
|
+
|
|
|
+ if (dto.CardSide == 0) // 正面
|
|
|
+ {
|
|
|
+ fileName = "行驶证识别-主页";
|
|
|
+ content = $"{fileName}\r\n\r\n";
|
|
|
+ TextVehicleFront frontInfo = vlData.FrontInfo;
|
|
|
+ Document doc = new Document();
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(doc);
|
|
|
+ if (frontInfo != null)
|
|
|
+ {
|
|
|
+ data = frontInfo;
|
|
|
+ content += $"号牌号码:{frontInfo.PlateNo ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"车辆类型:{frontInfo.VehicleType ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"所有人:{frontInfo.Owner ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"住址:{frontInfo.Address ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"使用性质:{frontInfo.UseCharacter ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"品牌型号:{frontInfo.Model ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"车辆识别代号:{frontInfo.Vin ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"发动机号码:{frontInfo.EngineNo ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"注册日期:{frontInfo.RegisterDate ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"发证日期:{frontInfo.IssueDate ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"印章:{frontInfo.Seal ?? "Unknown"}\r\n\r\n";
|
|
|
+ }
|
|
|
+ builder.Write(content);
|
|
|
+
|
|
|
+ string outputDir = $"{AppSettingsHelper.Get("WordBasePath")}/TencentOCR";
|
|
|
+ string outputFile = $"{fileName}{DateTime.Now.ToString("yyyyMMddHHmmss")}.docx";
|
|
|
+ string outputPath = Path.Combine(outputDir, outputFile);
|
|
|
+
|
|
|
+ if (!Directory.Exists(outputDir))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(outputDir);
|
|
|
+ }
|
|
|
+ //去水印
|
|
|
+ new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
|
|
|
+ doc.Save(outputPath);
|
|
|
+ url = $"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/TencentOCR/{outputFile}";
|
|
|
+ }
|
|
|
+ else if (dto.CardSide == 1) //反面
|
|
|
+ {
|
|
|
+ TextVehicleBack backInfo = vlData.BackInfo;
|
|
|
+ fileName = "行驶证识别-副页";
|
|
|
+ content = $"{fileName}\r\n\r\n";
|
|
|
+ Document doc = new Document();
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(doc);
|
|
|
+ if (backInfo != null)
|
|
|
+ {
|
|
|
+ data = backInfo;
|
|
|
+ content += $"号牌号码:{backInfo.PlateNo ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"档案编号:{backInfo.FileNo ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"核定人数:{backInfo.AllowNum ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"总质量:{backInfo.TotalMass ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"整备质量:{backInfo.CurbWeight ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"核定载质量:{backInfo.LoadQuality ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"外廓尺寸:{backInfo.ExternalSize ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"备注:{backInfo.Marks ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"检验记录:{backInfo.Record ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"准牵引总质量:{backInfo.TotalQuasiMass ?? "Unknown"}\r\n\r\n";
|
|
|
+ }
|
|
|
+ builder.Write(content);
|
|
|
+
|
|
|
+ string outputDir = $"{AppSettingsHelper.Get("WordBasePath")}/TencentOCR";
|
|
|
+ string outputFile = $"{fileName}{DateTime.Now.ToString("yyyyMMddHHmmss")}.docx";
|
|
|
+ string outputPath = Path.Combine(outputDir, outputFile);
|
|
|
+
|
|
|
+ if (!Directory.Exists(outputDir))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(outputDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ doc.Save(outputPath);
|
|
|
+ url = $"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/TencentOCR/{outputFile}";
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ return Ok(JsonView(true, "操作成功", new { dataSource = data, url = url }));
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ return Ok(JsonView(false, $"InnerException:{ex.InnerException?.Message ?? "Unknown"} ErrMsg:{ex.Message}"));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 房产证识别
|
|
|
- /// 获取房产证返回数据
|
|
|
+ /// 房产证识别(腾讯OCR 未找到)
|
|
|
+ /// 返回数据
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
@@ -315,7 +497,7 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView("图片不能大于7M!"));
|
|
|
}
|
|
|
|
|
|
- var pcData = TencentOCRTools.GetOCR((int)TencentOCREnum.PropOwnerCert, dto);
|
|
|
+ var pcData = await TencentOCRTools.GetOCR((int)TencentOCREnum.PropOwnerCert, dto);
|
|
|
|
|
|
if (pcData.Code != 0)
|
|
|
{
|
|
@@ -331,8 +513,8 @@ namespace OASystem.API.Controllers
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 结婚证识别
|
|
|
- /// 获取结婚证返回数据
|
|
|
+ /// 结婚证识别(腾讯OCR 未找到)
|
|
|
+ /// 返回数据
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
@@ -346,7 +528,7 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView("图片不能大于7M!"));
|
|
|
}
|
|
|
|
|
|
- var mlData = TencentOCRTools.GetOCR((int)TencentOCREnum.GeneralBasic, dto);
|
|
|
+ var mlData = await TencentOCRTools.GetOCR((int)TencentOCREnum.GeneralBasic, dto);
|
|
|
|
|
|
if (mlData.Code != 0)
|
|
|
{
|
|
@@ -362,8 +544,8 @@ namespace OASystem.API.Controllers
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 统一信用代码识别
|
|
|
- /// 获取统一信用代码返回数据
|
|
|
+ /// 统一信用代码识别 (腾讯OCR 未找到)
|
|
|
+ /// 返回数据
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
@@ -377,7 +559,7 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView("图片不能大于7M!"));
|
|
|
}
|
|
|
|
|
|
- var gbData = TencentOCRTools.GetOCR((int)TencentOCREnum.GeneralBasic, dto);
|
|
|
+ var gbData = await TencentOCRTools.GetOCR((int)TencentOCREnum.GeneralBasic, dto);
|
|
|
|
|
|
if (gbData.Code != 0)
|
|
|
{
|
|
@@ -408,7 +590,7 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView("图片不能大于7M!"));
|
|
|
}
|
|
|
|
|
|
- var pData = TencentOCRTools.GetOCR((int)TencentOCREnum.Passport, dto);
|
|
|
+ var pData = await TencentOCRTools.GetOCR((int)TencentOCREnum.Passport, dto);
|
|
|
|
|
|
if (pData.Code != 0)
|
|
|
{
|
|
@@ -420,7 +602,49 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView(pData.Msg));
|
|
|
}
|
|
|
|
|
|
- return Ok(JsonView(pData.Data));
|
|
|
+ string url = "";
|
|
|
+ #region 文档下载
|
|
|
+
|
|
|
+ string fileName = "护照识别(中国大陆地区护照)";
|
|
|
+ string content = $"{fileName}\r\n\r\n";
|
|
|
+ PassportOCRResponse pInfo = pData.Data as PassportOCRResponse;
|
|
|
+ Document doc = new Document();
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(doc);
|
|
|
+ if (pInfo != null)
|
|
|
+ {
|
|
|
+ content += $"国家码:{pInfo.Country ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"护照号:{pInfo.PassportNo ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"性别:{pInfo.Sex ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"国籍:{pInfo.Nationality ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"出生日期:{pInfo.BirthDate ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"签发日期:{pInfo.IssueDate ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"签发地点:{pInfo.IssuePlace ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"有效期:{pInfo.ExpiryDate ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"持证人签名:{pInfo.Signature ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"最下方第一行 MRZ Code 序列:{pInfo.CodeSet ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"最下方第二行 MRZ Code 序列:{pInfo.CodeCrc ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"姓名:{pInfo.Name ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"姓:{pInfo.FamilyName ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"名:{pInfo.FirstName ?? "Unknown"}\r\n\r\n";
|
|
|
+ }
|
|
|
+ builder.Write(content);
|
|
|
+
|
|
|
+ string outputDir = $"{AppSettingsHelper.Get("WordBasePath")}/TencentOCR";
|
|
|
+ string outputFile = $"{fileName}{DateTime.Now.ToString("yyyyMMddHHmmss")}.docx";
|
|
|
+ string outputPath = Path.Combine(outputDir, outputFile);
|
|
|
+
|
|
|
+ if (!Directory.Exists(outputDir))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(outputDir);
|
|
|
+ }
|
|
|
+ //去水印
|
|
|
+ new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
|
|
|
+ doc.Save(outputPath);
|
|
|
+ url = $"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/TencentOCR/{outputFile}";
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ return Ok(JsonView(true,"操作成功", new { dataSource = pInfo, url = url }));
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -439,7 +663,7 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView("图片不能大于7M!"));
|
|
|
}
|
|
|
|
|
|
- var mlidpData = TencentOCRTools.GetOCR((int)TencentOCREnum.MLIDPassport, dto);
|
|
|
+ var mlidpData = await TencentOCRTools.GetOCR((int)TencentOCREnum.MLIDPassport, dto);
|
|
|
|
|
|
if (mlidpData.Code != 0)
|
|
|
{
|
|
@@ -451,7 +675,49 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView(mlidpData.Msg));
|
|
|
}
|
|
|
|
|
|
- return Ok(JsonView(mlidpData.Data));
|
|
|
+ string url = "";
|
|
|
+ #region 文档下载
|
|
|
+
|
|
|
+ string fileName = "护照识别(中国大陆地区护照)";
|
|
|
+ string content = $"{fileName}\r\n\r\n";
|
|
|
+ PassportOCRResponse pInfo = mlidpData.Data as PassportOCRResponse;
|
|
|
+ Document doc = new Document();
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(doc);
|
|
|
+ if (pInfo != null)
|
|
|
+ {
|
|
|
+ content += $"国家码:{pInfo.Country ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"护照号:{pInfo.PassportNo ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"性别:{pInfo.Sex ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"国籍:{pInfo.Nationality ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"出生日期:{pInfo.BirthDate ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"签发日期:{pInfo.IssueDate ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"签发地点:{pInfo.IssuePlace ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"有效期:{pInfo.ExpiryDate ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"持证人签名:{pInfo.Signature ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"最下方第一行 MRZ Code 序列:{pInfo.CodeSet ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"最下方第二行 MRZ Code 序列:{pInfo.CodeCrc ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"姓名:{pInfo.Name ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"姓:{pInfo.FamilyName ?? "Unknown"}\r\n\r\n";
|
|
|
+ content += $"名:{pInfo.FirstName ?? "Unknown"}\r\n\r\n";
|
|
|
+ }
|
|
|
+ builder.Write(content);
|
|
|
+
|
|
|
+ string outputDir = $"{AppSettingsHelper.Get("WordBasePath")}/TencentOCR";
|
|
|
+ string outputFile = $"{fileName}{DateTime.Now.ToString("yyyyMMddHHmmss")}.docx";
|
|
|
+ string outputPath = Path.Combine(outputDir, outputFile);
|
|
|
+
|
|
|
+ if (!Directory.Exists(outputDir))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(outputDir);
|
|
|
+ }
|
|
|
+ //去水印
|
|
|
+ new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
|
|
|
+ doc.Save(outputPath);
|
|
|
+ url = $"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/TencentOCR/{outputFile}";
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ return Ok(JsonView(true, "操作成功", new { dataSource = pInfo, url = url }));
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -472,7 +738,7 @@ namespace OASystem.API.Controllers
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- var mlidpData = TencentOCRTools.GetOCR((int)TencentOCREnum.BusinessCard, dto);
|
|
|
+ var mlidpData = await TencentOCRTools.GetOCR((int)TencentOCREnum.BusinessCard, dto);
|
|
|
if (mlidpData.Code != 0)
|
|
|
{
|
|
|
return Ok(JsonView(mlidpData.Msg));
|
|
@@ -491,6 +757,85 @@ namespace OASystem.API.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 智能结构化识别V2
|
|
|
+ /// 获取名片 返回数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
+ public async Task<IActionResult> GetSmartStructuralOCRV2(BusinessCardOCRDto dto)
|
|
|
+ {
|
|
|
+ string[] picBase64Array = dto.picBase64.Split(';');
|
|
|
+ string picFormat = picBase64Array[0].Split('/')[1];
|
|
|
+ if (!TencentOCRTools.ImageType(picFormat))
|
|
|
+ {
|
|
|
+ return Ok(JsonView("图片格式不正确!只支持 PNG、JPG、JPEG、BMP 格式!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ double strSize = 1024 * 1024 * 7;
|
|
|
+ if (dto.picBase64.Length > strSize)
|
|
|
+ {
|
|
|
+ return Ok(JsonView("图片不能大于7M!"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var ssData = await TencentOCRTools.GetOCR((int)TencentOCREnum.SmartStructuralOCRV2, dto);
|
|
|
+ if (ssData.Code != 0)
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, ssData.Msg));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ssData.Data == null)
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, ssData.Msg));
|
|
|
+ }
|
|
|
+
|
|
|
+ //var wordRes = GenerateWord(ssData.Data as List<ocrGeneralView>, "智能结构化识别V2");
|
|
|
+ List<ocrGeneralView>? datas = ssData.Data as List<ocrGeneralView>;
|
|
|
+
|
|
|
+ var data = new {
|
|
|
+ dataSource = ssData.Data,
|
|
|
+ url = GenerateWord(datas, "智能结构化识别V2")
|
|
|
+ };
|
|
|
+ return Ok(JsonView(true, ssData.Msg, data));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 生成 ocr word
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="views"></param>
|
|
|
+ /// <param name="fileName"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private string GenerateWord(List<ocrGeneralView> views, string fileName)
|
|
|
+ {
|
|
|
+ Document doc = new Document();
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(doc);
|
|
|
+
|
|
|
+ string content = $"{fileName}\r\n\r\n";
|
|
|
+ foreach (var view in views)
|
|
|
+ {
|
|
|
+ content += $"TypeName:{view.name}\t\r\nContent:{view.value}\r\n\r\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ builder.Write(content);
|
|
|
+
|
|
|
+ string outputDir = $"{AppSettingsHelper.Get("WordBasePath")}/TencentOCR";
|
|
|
+ string outputFile = $"{fileName}{DateTime.Now.ToString("yyyyMMddHHmmss")}.docx";
|
|
|
+ string outputPath = Path.Combine(outputDir, outputFile);
|
|
|
+
|
|
|
+ if (!Directory.Exists(outputDir))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(outputDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ doc.Save(outputPath);
|
|
|
+
|
|
|
+ return $"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/TencentOCR/{outputFile}";
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region android ios
|