浏览代码

添加营业执照Ocr接口

lcl 4 月之前
父节点
当前提交
1a34eda589
共有 4 个文件被更改,包括 125 次插入1 次删除
  1. 43 0
      Areas/Api/Controllers/PubController.cs
  2. 2 1
      Controllers/HomeController.cs
  3. 1 0
      MySystem.csproj
  4. 79 0
      Util/Aliyun/AliyunOcr.cs

+ 43 - 0
Areas/Api/Controllers/PubController.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Http;
+using System.DrawingCore.Imaging;
+using System.IO;
+using Library;
+using System.Collections;
+using LitJson;
+using System.Globalization;
+using System.Web;
+using System.Security.Cryptography;
+using System.Text;
+using Aliyun.OSS;
+
+namespace MySystem.Areas.Api.Controllers
+{
+    [Area("Api")]
+    [Route("Api/[controller]/[action]")]
+    public class PubController : BaseController
+    {
+        public PubController(IHttpContextAccessor accessor) : base(accessor)
+        {
+        }
+        
+        #region OCR识别-营业执照
+        public JsonResult BusinessLicenseOcr(string value)
+        {
+            value = DesDecrypt(value);
+            Dictionary<string, object> Obj = BusinessLicenseOcrDo(value);
+            return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
+        }
+        public Dictionary<string, object> BusinessLicenseOcrDo(string value)
+        {
+            JsonData data = JsonMapper.ToObject(value);
+            string Url = data["Url"].ToString();
+            Dictionary<string, object> Obj = new Dictionary<string, object>();
+            Obj.Add("OcrData", AliyunOcr.Check(Url));
+            return Obj;
+        }
+        #endregion
+    }
+}

+ 2 - 1
Controllers/HomeController.cs

@@ -31,10 +31,11 @@ namespace MySystem.Controllers
         {
             // string result = HaoDaHelper.Instance.CardInComeRecord("1486641", "2023-10-01", "2023-10-31", "030510606906888", "", "", "1", "10");
             // return result;
-            return AliIotFunction.Instance.IotDeviceQuery("LKB01230900202000002");
+            // return AliIotFunction.Instance.IotDeviceQuery("LKB01230900202000002");
             // return AliIotFunction.Instance.IotUnBind("2088720723136476", "LKBYM2023090700098");
             // return AliIotFunction.Instance.IotTradeVoice("LKBYM2023090700098", "2088720723136476", DateTime.Now.ToString("yyyyMMddHHmmssfff"), a, "OTHER");
             // return AliIotFunction.Instance.IotTradeVoice("01010VO0cD5XkzVNlEVW61HRVe5Jd2sf9u6h4ndoZyS4Gg1rJAeRYJc", "2088720723136476", DateTime.Now.ToString("yyyyMMddHHmmssfff"), a, "OTHER");
+            return AliyunOcr.Check("https://laikeba.oss-cn-chengdu.aliyuncs.com/miniappIncomingData/UnionPay/2024/12/4/380db2e4d913c627.png");
         }
     }
 }

+ 1 - 0
MySystem.csproj

@@ -53,6 +53,7 @@
     </Reference>
   </ItemGroup>
   <ItemGroup>
+    <PackageReference Include="AlibabaCloud.SDK.Ocr-api20210707" Version="3.1.2" />
     <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
     <PackageReference Include="RabbitMQ.Client" Version="6.2.2" />
     <PackageReference Include="System.ServiceModel.Duplex" Version="4.4.*" />

+ 79 - 0
Util/Aliyun/AliyunOcr.cs

@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using Library;
+using Tea;
+using Tea.Utils;
+
+namespace MySystem
+{
+    public class AliyunOcr
+    {
+        private static string AccessKeyID = "LTAI5tBNY8CzWquEUx8HGqUX";
+        private static string AccessKeySecret = "VOGf7ibdydKeKqkb2BfEwp7Nh4gPRJ";
+        
+        /**
+         * 使用AK&SK初始化账号Client
+         * @return Client
+         * @throws Exception
+         */
+        public static AlibabaCloud.SDK.Ocr_api20210707.Client CreateClient()
+        {
+            // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
+            // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378671.html。
+            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
+            {
+                // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
+                AccessKeyId = AccessKeyID,
+                // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
+                AccessKeySecret = AccessKeySecret,
+            };
+            // Endpoint 请参考 https://api.aliyun.com/product/ocr-api
+            config.Endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";
+            return new AlibabaCloud.SDK.Ocr_api20210707.Client(config);
+        }
+
+        public static string Check(string Url)
+        {
+            string result = "";
+            AlibabaCloud.SDK.Ocr_api20210707.Client client = CreateClient();
+            AlibabaCloud.SDK.Ocr_api20210707.Models.RecognizeBusinessLicenseRequest recognizeBusinessLicenseRequest = new AlibabaCloud.SDK.Ocr_api20210707.Models.RecognizeBusinessLicenseRequest
+            {
+                Url = Url,
+            };
+            AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
+            try
+            {
+                // 复制代码运行请自行打印 API 的返回值
+                var res = client.RecognizeBusinessLicenseWithOptions(recognizeBusinessLicenseRequest, runtime);
+                result = res.Body.Data;
+            }
+            catch (TeaException error)
+            {
+                // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+                // 错误 message
+                Console.WriteLine(error.Message);
+                // 诊断地址
+                Console.WriteLine(error.Data["Recommend"]);
+                AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
+            }
+            catch (Exception _error)
+            {
+                TeaException error = new TeaException(new Dictionary<string, object>
+                {
+                    { "message", _error.Message }
+                });
+                // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+                // 错误 message
+                Console.WriteLine(error.Message);
+                // 诊断地址
+                Console.WriteLine(error.Data["Recommend"]);
+                AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
+            }
+            return result;
+        }
+
+        
+    }
+}