From 5454e326a76e695ba4a51d5994c88ef7ded76efc Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期四, 21 八月 2025 13:24:10 +0800 Subject: [PATCH] feat:开发 --- FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs | 82 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 82 insertions(+), 0 deletions(-) diff --git a/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs b/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs index 51439b2..dfd7289 100644 --- a/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs +++ b/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs @@ -66,5 +66,87 @@ 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