diff --git a/src/BootstrapBlazor.Shared/Demos/BaiduOcr/BaiduOcrVerifyVatInvoice.razor b/src/BootstrapBlazor.Shared/Demos/BaiduOcr/BaiduOcrVerifyVatInvoice.razor
new file mode 100644
index 00000000000..514072660ef
--- /dev/null
+++ b/src/BootstrapBlazor.Shared/Demos/BaiduOcr/BaiduOcrVerifyVatInvoice.razor
@@ -0,0 +1,87 @@
+@inject IBaiduOcr OcrService
+@inject ToastService ToastService
+@implements IDisposable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@InvoiceVerifyResult?.VerifyMessage
+
+@code {
+ ///
+ /// 取消请求令牌
+ ///
+ private CancellationTokenSource? TokenSource { get; set; }
+
+ private InvoiceVerifyResult? InvoiceVerifyResult { get; set; }
+
+ private InvoiceForm Model { get; set; } = new() { InvoiceType = "elec_special_vat_invoice", TotalAmount = "0" };
+
+ private async Task Verify(EditContext context)
+ {
+ var result = await OcrService.VerifyInvoiceAsync(Model.InvoiceCode, Model.InvoiceNum, Model.InvoiceDate, Model.InvoiceType, Model.CheckCode, Model.TotalAmount);
+ InvoiceVerifyResult = result.Entity;
+ StateHasChanged();
+ }
+
+ ///
+ /// 关闭网页时调用
+ ///
+ ///
+ ///
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing && TokenSource != null)
+ {
+ TokenSource.Cancel();
+ TokenSource.Dispose();
+ }
+ }
+
+ ///
+ /// 关闭网页时调用
+ ///
+ ///
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private class InvoiceForm
+ {
+ [Required(ErrorMessage = "发票代码不能为空")]
+ [NotNull]
+ public string? InvoiceCode { get; set; }
+
+ [Required(ErrorMessage = "发票号码不能为空")]
+ [NotNull]
+ public string? InvoiceNum { get; set; }
+
+ [Required(ErrorMessage = "开票日期不能为空")]
+ [NotNull]
+ public string? InvoiceDate { get; set; }
+
+ [NotNull]
+ public string? InvoiceType { get; set; }
+
+ [Required(ErrorMessage = "校验码不能为空")]
+ [NotNull]
+ public string? CheckCode { get; set; }
+
+ [NotNull]
+ public string? TotalAmount { get; set; }
+ }
+}
diff --git a/src/BootstrapBlazor.Shared/Samples/BaiduOcr.razor b/src/BootstrapBlazor.Shared/Samples/BaiduOcr.razor
index f85f8e57e1d..0a8e7187976 100644
--- a/src/BootstrapBlazor.Shared/Samples/BaiduOcr.razor
+++ b/src/BootstrapBlazor.Shared/Samples/BaiduOcr.razor
@@ -15,3 +15,5 @@
@((MarkupString)Localizer["BaiduOcrStep2"].Value)
+
+
diff --git a/src/Extensions/Components/BootstrapBlazor.BaiduOcr/Services/BaiduOcr.cs b/src/Extensions/Components/BootstrapBlazor.BaiduOcr/Services/BaiduOcr.cs
index 6643ac950f9..5929dd9b078 100644
--- a/src/Extensions/Components/BootstrapBlazor.BaiduOcr/Services/BaiduOcr.cs
+++ b/src/Extensions/Components/BootstrapBlazor.BaiduOcr/Services/BaiduOcr.cs
@@ -5,6 +5,7 @@
using Baidu.Aip.Ocr;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
+using System.Collections.Generic;
namespace BootstrapBlazor.Components;
@@ -71,11 +72,11 @@ public Task> CheckVatInvoiceAsync(byte[] image, Ca
protected async Task GetAccessToken()
{
var client = HttpClientFactory.CreateClient();
- var para = new Dictionary()
+ var para = new List>()
{
- { "grant_type", "client_credentials" },
- { "client_id", Options.CurrentValue.ApiKey },
- { "client_secret", Options.CurrentValue.Secret }
+ new("grant_type", "client_credentials"),
+ new("client_id", Options.CurrentValue.ApiKey),
+ new("client_secret", Options.CurrentValue.Secret)
};
var resp = await client.PostAsync("https://aip.baidubce.com/oauth/2.0/token", new FormUrlEncodedContent(para));
@@ -102,21 +103,21 @@ public Task> VerifyInvoiceAsync(string invoi
var client = HttpClientFactory.CreateClient();
// 拼装参数
- var para = new Dictionary()
+ var para = new List>()
{
- { "invoice_code", invoiceCode },
- { "invoice_num", invoiceNum },
- { "invoice_date", invoiceDate },
- { "invoice_type", invoiceType },
+ new("invoice_code", invoiceCode),
+ new("invoice_num", invoiceNum),
+ new("invoice_date", invoiceDate),
+ new("invoice_type", invoiceType),
};
if (!string.IsNullOrEmpty(checkCode))
{
- para["check_code"] = checkCode;
+ para.Add(new("check_code", checkCode));
}
if (!string.IsNullOrEmpty(totalAmount))
{
- para["total_amount"] = totalAmount;
+ para.Add(new("total_amount", totalAmount));
}
// 提交数据