From b15ba0723040b5e9a348662a09af824f2d5ae9e6 Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期三, 20 八月 2025 17:28:38 +0800
Subject: [PATCH] feat:开发

---
 FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs |   84 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 1 deletions(-)

diff --git a/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs b/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs
index 9e890c9..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);
@@ -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