From d9cc4b2a25ca241eec1bb7c82b1cca5f3fee9e0b Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期五, 22 八月 2025 14:45:13 +0800 Subject: [PATCH] feat:开发 --- FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs | 86 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 84 insertions(+), 2 deletions(-) diff --git a/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs b/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs index 2ee89c4..dfd7289 100644 --- a/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs +++ b/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs @@ -28,7 +28,7 @@ /// <param name="url"></param> /// <param name="scene"></param> /// <param name="isOssUrl"></param> - public static async Task<BaiduOcrBusinessLicenseResult> OcrBusinessLicense(this string url, string scene, bool isOssUrl = true) + public static async Task<BaiduOcrBusinessLicenseResult> OcrBusinessLicense(this string url, string scene = null, bool isOssUrl = true) { var options = App.GetOptions<BaiduOptions>(); var ocr = new Ocr(options.Ocr.Key, options.Ocr.Secret); @@ -61,10 +61,92 @@ RegisteredCapital = result.WordsResult["娉ㄥ唽璧勬湰"].Words, EstablishmentDate = result.WordsResult["鎴愮珛鏃ユ湡"].Words, Address = result.WordsResult["鍦板潃"].Words, - BusinessScope = result.WordsResult["缁忚惀鑼冨洿"].Words, + MainBusiness = result.WordsResult["缁忚惀鑼冨洿"].Words, }; return result; } + /// <summary> + /// 韬唤璇佹闈CR + /// </summary> + /// <param name="url"></param> + /// <param name="scene"></param> + /// <param name="isOssUrl"></param> + public static async Task<BaiduOcrIdentityFrontResult> OcrIdentityFront(this string url, string scene = null, bool isOssUrl = true) + { + var options = App.GetOptions<BaiduOptions>(); + var ocr = new Ocr(options.Ocr.Key, options.Ocr.Secret); + ocr.Timeout = 60000; + JObject value; + if (isOssUrl) + { + var downloadUrl = AliyunOSSUtils.GetUrl(url); + var buffer = await App.GetRequiredService<IHttpRemoteService>().GetAsByteArrayAsync(downloadUrl); + value = ocr.Idcard(buffer, "front"); + } + else + { + var upload = AliyunOSSUtils.Upload(scene, url); + url = upload.Url; + value = ocr.Idcard(upload.Buffer, "front"); + } + var result = value.ToObject<BaiduOcrIdentityFrontResult>(); + result.Url = url; + if (result.ErrorCode.IsNotNull()) + { + return result; + } + + result.Model = new BaiduOcrIdentityFrontResultModel + { + Address = result.WordsResult["浣忓潃"].Words, + Identity = result.WordsResult["鍏皯韬唤鍙风爜"].Words, + BirthdayText = result.WordsResult["鍑虹敓"].Words, + Name = result.WordsResult["濮撳悕"].Words, + GenderText = result.WordsResult["鎬у埆"].Words, + Nation = result.WordsResult["姘戞棌"].Words, + }; + return result; + } + + /// <summary> + /// 韬唤璇佽儗闈CR + /// </summary> + /// <param name="url"></param> + /// <param name="scene"></param> + /// <param name="isOssUrl"></param> + public static async Task<BaiduOcrIdentityBackResult> OcrIdentityBack(this string url, string scene = null, bool isOssUrl = true) + { + var options = App.GetOptions<BaiduOptions>(); + var ocr = new Ocr(options.Ocr.Key, options.Ocr.Secret); + ocr.Timeout = 60000; + JObject value; + if (isOssUrl) + { + var downloadUrl = AliyunOSSUtils.GetUrl(url); + var buffer = await App.GetRequiredService<IHttpRemoteService>().GetAsByteArrayAsync(downloadUrl); + value = ocr.Idcard(buffer, "back"); + } + else + { + var upload = AliyunOSSUtils.Upload(scene, url); + url = upload.Url; + value = ocr.Idcard(upload.Buffer, "back"); + } + var result = value.ToObject<BaiduOcrIdentityBackResult>(); + result.Url = url; + if (result.ErrorCode.IsNotNull()) + { + return result; + } + + result.Model = new BaiduOcrIdentityBackResultModel + { + ExpiryDateText = result.WordsResult["澶辨晥鏃ユ湡"].Words, + IssueAuthority = result.WordsResult["绛惧彂鏈哄叧"].Words, + IssueDateText = result.WordsResult["绛惧彂鏃ユ湡"].Words, + }; + return result; + } } } -- Gitblit v1.9.1