using OASystem.API.OAMethodLib.File; using OASystem.API.OAMethodLib.NPOI; using OASystem.API.OAMethodLib.TencentCloudAPI; using OASystem.Domain.Dtos.CRM; using OASystem.Domain.Dtos.Tencent; using OASystem.Domain.ViewModels.TencentOCR; using OASystem.Infrastructure.Repositories.CRM; using Org.BouncyCastle.Crypto; using StackExchange.Redis; using System.Net.NetworkInformation; using TencentCloud.Ocr.V20181119.Models; using Ubiety.Dns.Core; namespace OASystem.API.Controllers { /// /// TencentOCR 识别 /// [Route("api/[controller]/[action]")] //[ApiController] public class TencentOCRController : ControllerBase { private readonly VisaDeleClientRepository _visaDeleClientRepository; public TencentOCRController(VisaDeleClientRepository visaDeleClientRepository) { this._visaDeleClientRepository = visaDeleClientRepository; } /// /// 通用印刷体 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetGeneralBasic(GeneralBasicOCRDto 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 gbData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.GeneralBasic, dto); if (gbData.Code != 0) { return Ok(JsonView(gbData.Msg)); } if (gbData.Data == null) { return Ok(JsonView(gbData.Msg)); } return Ok(JsonView(gbData.Data)); } /// /// 身份证识别(国徽面/反面) /// 获取身份证返回数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetIDCard(IDCardOCRDto 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 idCardData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.IDCard, dto); if (idCardData.Code != 0) { return Ok(JsonView(idCardData.Msg)); } if (idCardData.Data == null) { return Ok(JsonView(idCardData.Msg)); } bool cerdStatus = await _visaDeleClientRepository.SetCrmUpdPassIdCardOCR( new SetCrmUpdPassIdCardOCRDto { UserId = dto.UserId, ClientName = idCardData.Data.Name, Sex = idCardData.Data.Sex == "男" ? 0 : 1, CerdNo = idCardData.Data.IdNum, CerdAddress = idCardData.Data.Address, }); IDCardOCRAndDownUrlView iDCardOCRView = new IDCardOCRAndDownUrlView() { Status = cerdStatus, Name = idCardData.Data.Name, Sex = idCardData.Data.Sex, Nation = idCardData.Data.Nation, Birth = idCardData.Data.Birth, Address = idCardData.Data.Address, IdNum = idCardData.Data.IdNum, Authority = idCardData.Data.Authority, ValidDate = idCardData.Data.ValidDate }; #region word生成 返回地址 string tempPath = string.Format("{0}", "C:\\Server\\File\\OA2023\\Office\\Word\\TencentOCR\\Template\\ocr_身份证(人像面).doc"); Dictionary dic = new Dictionary(); dic.Add("Name", iDCardOCRView.Name); dic.Add("Sex", iDCardOCRView.Sex); dic.Add("Nation", iDCardOCRView.Nation); dic.Add("Birth", iDCardOCRView.Birth); dic.Add("Address", iDCardOCRView.Address); dic.Add("IdNum", iDCardOCRView.IdNum); dic.Add("Authority", iDCardOCRView.Authority); dic.Add("ValidDate", iDCardOCRView.ValidDate); string downPath = string.Format("{0}.doc",dic["Name"].ToString() + "身份证(人像面)" + DateTime.Now.ToString("yyyyMMddHHmmss")); string serverPathh = AsposeHelper.ExpertWordToModel(tempPath, downPath, dic, null); iDCardOCRView.DownUrl = serverPathh.Replace("C:", "http:\\132.232.92.186"); #endregion return Ok(JsonView(iDCardOCRView)); } /// /// 户口簿识别 /// 获取户口簿返回数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetResidenceBookletOCR(ResidenceBookletOCRDto dto) { double strSize = 1024 * 1024 * 7; if (dto.picBase64.Length > strSize) { return Ok(JsonView("图片不能大于7M!")); } var residenceBookData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.ResidenceBooklet, dto); if (residenceBookData.Code != 0) { return Ok(JsonView(residenceBookData.Msg)); } if (residenceBookData.Data == null) { return Ok(JsonView(residenceBookData.Msg)); } return Ok(JsonView(residenceBookData.Data)); } /// /// 营业执照识别 /// 获取营业执照返回数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetBizLicenseOCR(BizLicenseOCRDto dto) { double strSize = 1024 * 1024 * 7; if (dto.picBase64.Length > strSize) { return Ok(JsonView("图片不能大于7M!")); } var residenceBookData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.BizLicense, dto); if (residenceBookData.Code != 0) { return Ok(JsonView(residenceBookData.Msg)); } if (residenceBookData.Data == null) { return Ok(JsonView(residenceBookData.Msg)); } return Ok(JsonView(residenceBookData.Data)); } /// /// 营业执照识别 /// 获取营业执照返回数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetOrgCodeCertOCR(OrgCodeCertOCRDto dto) { double strSize = 1024 * 1024 * 7; if (dto.picBase64.Length > strSize) { return Ok(JsonView("图片不能大于7M!")); } var occData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.OrgCodeCert, dto); if (occData.Code != 0) { return Ok(JsonView(occData.Msg)); } if (occData.Data == null) { return Ok(JsonView(occData.Msg)); } return Ok(JsonView(occData.Data)); } /// /// 行驶证识别 /// 获取行驶证返回数据 /// CardSide=0 主页正面(有红色印章的一面),CardSide=1 行驶证副页正面(有号码号牌的一面),CardSide=2 行驶证主页正面和副页正面。 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetVehicleLicense(VehicleLicenseOCRDto dto) { double strSize = 1024 * 1024 * 7; if (dto.picBase64.Length > strSize) { return Ok(JsonView("图片不能大于7M!")); } var vehicleLicenseData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.VehicleLicense, dto); if (vehicleLicenseData.Code != 0) { return Ok(JsonView(vehicleLicenseData.Msg)); } if (vehicleLicenseData.Data == null) { return Ok(JsonView(vehicleLicenseData.Msg)); } return Ok(JsonView(vehicleLicenseData.Data)); } /// /// 房产证识别 /// 获取房产证返回数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetPropOwnerCert(PropOwnerCertOCRDto dto) { double strSize = 1024 * 1024 * 7; if (dto.picBase64.Length > strSize) { return Ok(JsonView("图片不能大于7M!")); } var pcData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.PropOwnerCert, dto); if (pcData.Code != 0) { return Ok(JsonView(pcData.Msg)); } if (pcData.Data == null) { return Ok(JsonView(pcData.Msg)); } return Ok(JsonView(pcData.Data)); } /// /// 结婚证识别 /// 获取结婚证返回数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetMarriageLicense(MarriageLicenseOCRDto dto) { double strSize = 1024 * 1024 * 7; if (dto.picBase64.Length > strSize) { return Ok(JsonView("图片不能大于7M!")); } var mlData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.GeneralBasic, dto); if (mlData.Code != 0) { return Ok(JsonView(mlData.Msg)); } if (mlData.Data == null) { return Ok(JsonView(mlData.Msg)); } return Ok(JsonView(mlData.Data)); } /// /// 统一信用代码识别 /// 获取统一信用代码返回数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetUniformCreditCode(UniformCreditCodeOCRDto dto) { double strSize = 1024 * 1024 * 7; if (dto.picBase64.Length > strSize) { return Ok(JsonView("图片不能大于7M!")); } var gbData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.GeneralBasic, dto); if (gbData.Code != 0) { return Ok(JsonView(gbData.Msg)); } if (gbData.Data == null) { return Ok(JsonView(gbData.Msg)); } return Ok(JsonView(gbData.Data)); } /// /// 护照识别(中国大陆地区护照) /// 获取护照识别(中国大陆地区护照)返回数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetPassport(PassportOCRDto dto) { double strSize = 1024 * 1024 * 7; if (dto.picBase64.Length > strSize) { return Ok(JsonView("图片不能大于7M!")); } var pData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.Passport, dto); if (pData.Code != 0) { return Ok(JsonView(pData.Msg)); } if (pData.Data == null) { return Ok(JsonView(pData.Msg)); } return Ok(JsonView(pData.Data)); } /// /// 护照识别(港澳台地区及境外护照) /// 获取护照识别(港澳台地区及境外护照)返回数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetMLIDPassport(PassportOCRDto dto) { double strSize = 1024 * 1024 * 7; if (dto.picBase64.Length > strSize) { return Ok(JsonView("图片不能大于7M!")); } var mlidpData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.MLIDPassport, dto); if (mlidpData.Code != 0) { return Ok(JsonView(mlidpData.Msg)); } if (mlidpData.Data == null) { return Ok(JsonView(mlidpData.Msg)); } return Ok(JsonView(mlidpData.Data)); } /// /// 名片识别 /// 获取名片 返回数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetBusinessCard(BusinessCardOCRDto dto) { double strSize = 1024 * 1024 * 7; if (dto.picBase64.Length > strSize) { return Ok(JsonView("图片不能大于7M!")); } var mlidpData = TencentOCRTools.GetOCR((int)TencentOCR.TencentOCREnum.BusinessCard, dto); if (mlidpData.Code != 0) { return Ok(JsonView(mlidpData.Msg)); } if (mlidpData.Data == null) { return Ok(JsonView(mlidpData.Msg)); } return Ok(JsonView(mlidpData.Data)); } } }