File tree Expand file tree Collapse file tree
src/Extensions/Components/BootstrapBlazor.BaiduOcr Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<Project Sdk =" Microsoft.NET.Sdk.Razor" >
22
33 <PropertyGroup >
4- <Version >7.0.0 </Version >
4+ <Version >7.0.1 </Version >
55 </PropertyGroup >
66
77 <PropertyGroup >
Original file line number Diff line number Diff line change 1+ // Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
2+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+ // Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+ namespace BootstrapBlazor . Components ;
6+
7+ /// <summary>
8+ /// 百度文字识别返回类
9+ /// </summary>
10+ public class BaiduOcrResult < TEntity >
11+ {
12+ /// <summary>
13+ /// 获得/设置 错误码
14+ /// </summary>
15+ public int ErrorCode { get ; set ; }
16+
17+ /// <summary>
18+ /// 获得/设置 错误描述信息
19+ /// </summary>
20+ /// <remarks>https://ai.baidu.com/ai-doc/OCR/dk3h7y5vr</remarks>
21+ public string ? ErrorMessage { get ; set ; }
22+
23+ /// <summary>
24+ /// 获得/设置 返回实例
25+ /// </summary>
26+ public TEntity ? Entity { get ; set ; }
27+ }
Original file line number Diff line number Diff line change @@ -32,11 +32,30 @@ public void Scan(byte[] image)
3232 /// <summary>
3333 /// 识别增值税发票方法
3434 /// </summary>
35- public Task < InvoiceEntity > CheckVatInvoiceAsync ( byte [ ] image ) => Task . Run ( ( ) =>
35+ public Task < string > CheckVatInvoiceJsonAsync ( byte [ ] image ) => Task . Run ( ( ) =>
3636 {
3737 var client = new Ocr ( Options . CurrentValue . ApiKey , Options . CurrentValue . Secret ) ;
3838 var resp = client . VatInvoice ( image ) ;
39- var ret = resp . GetValue ( "words_result" ) . ToObject ( typeof ( InvoiceEntity ) ) as InvoiceEntity ;
40- return ret ?? new InvoiceEntity ( ) { CommodityName = new ( ) , CommodityTaxRate = new ( ) } ;
39+ return resp . ToString ( ) ;
40+ } ) ;
41+
42+ /// <summary>
43+ /// 识别增值税发票方法
44+ /// </summary>
45+ public Task < BaiduOcrResult < InvoiceEntity > > CheckVatInvoiceAsync ( byte [ ] image ) => Task . Run ( ( ) =>
46+ {
47+ var ret = new BaiduOcrResult < InvoiceEntity > ( ) ;
48+ var client = new Ocr ( Options . CurrentValue . ApiKey , Options . CurrentValue . Secret ) ;
49+ var resp = client . VatInvoice ( image ) ;
50+ if ( resp . TryGetValue ( "words_result" , out var value ) )
51+ {
52+ ret . Entity = value . ToObject ( typeof ( InvoiceEntity ) ) as InvoiceEntity ;
53+ }
54+ else
55+ {
56+ ret . ErrorCode = resp . Value < int > ( "error_code" ) ;
57+ ret . ErrorMessage = resp . Value < string > ( "error_msg" ) ;
58+ }
59+ return ret ;
4160 } ) ;
4261}
Original file line number Diff line number Diff line change @@ -13,5 +13,12 @@ public interface IBaiduOcr
1313 /// 增值税发票识别
1414 /// </summary>
1515 /// <param name="image"></param>
16- Task < InvoiceEntity > CheckVatInvoiceAsync ( byte [ ] image ) ;
16+ Task < BaiduOcrResult < InvoiceEntity > > CheckVatInvoiceAsync ( byte [ ] image ) ;
17+
18+ /// <summary>
19+ /// 增值税发票识别
20+ /// </summary>
21+ /// <param name="image"></param>
22+ /// <returns></returns>
23+ Task < string > CheckVatInvoiceJsonAsync ( byte [ ] image ) ;
1724}
You can’t perform that action at this time.
0 commit comments