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, 61 insertions(+), 23 deletions(-)

diff --git a/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs b/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs
index 49bec7f..dfd7289 100644
--- a/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs
+++ b/FlexJobApi.Core/Utils/BaiduUtils/BaiduOcrUtils.cs
@@ -67,12 +67,12 @@
         }
 
         /// <summary>
-        /// 钀ヤ笟鎵х収OCR
+        /// 韬唤璇佹闈CR
         /// </summary>
         /// <param name="url"></param>
         /// <param name="scene"></param>
         /// <param name="isOssUrl"></param>
-        public static async Task<BaiduOcrIdentityResultModel> OcrIdentity(this string url, string scene = null, bool isOssUrl = true)
+        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);
@@ -82,33 +82,71 @@
             {
                 var downloadUrl = AliyunOSSUtils.GetUrl(url);
                 var buffer = await App.GetRequiredService<IHttpRemoteService>().GetAsByteArrayAsync(downloadUrl);
-                value = ocr.Idcard(buffer, "1");
+                value = ocr.Idcard(buffer, "front");
             }
             else
             {
                 var upload = AliyunOSSUtils.Upload(scene, url);
                 url = upload.Url;
-                //value = ocr.Idcard(upload.Buffer);
+                value = ocr.Idcard(upload.Buffer, "front");
             }
-            //var result = value.ToObject<BaiduOcrIdentityResult>();
-            //result.Url = url;
-            //if (result.ErrorCode.IsNotNull())
-            //{
-            //    return result;
-            //}
-            //result.Model = new BaiduOcrIdentityResultModel
-            //{
-            //    EnterpriseName = result.WordsResult["鍗曚綅鍚嶇О"].Words,
-            //    SocietyCreditCode = result.WordsResult["绀句細淇$敤浠g爜"].Words,
-            //    LegalPerson = result.WordsResult["娉曚汉"].Words,
-            //    EnterpriseType = result.WordsResult["绫诲瀷"].Words,
-            //    RegisteredCapital = result.WordsResult["娉ㄥ唽璧勬湰"].Words,
-            //    EstablishmentDate = result.WordsResult["鎴愮珛鏃ユ湡"].Words,
-            //    Address = result.WordsResult["鍦板潃"].Words,
-            //    MainBusiness = result.WordsResult["缁忚惀鑼冨洿"].Words,
-            //};
-            //return result;
-            throw new Exception();
+            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