资源简介
C#(VS2017)阿里云云市场发票内容识别demo。需要自行购买(或申请)APP CODE。目前的优惠是:可免费500次。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private const String host = “https://ocrapi-invoice.taobao.com“;
private const String path = “/ocrservice/invoice“;
private const String method = “POST“;
private const String appcode = “eb15f9d262474f998880361a1dbea***“;
public string ImageTobase64(string FileName)
{
String img_file = FileName;
FileStream fs = new FileStream(img_file FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] contentBytes = br.ReadBytes(Convert.ToInt32(fs.Length));
String base64 = System.Convert.Tobase64String(contentBytes);
GC.Collect();
return base64;
}
private void button1_Click(object sender EventArgs e)
{
try
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
FileStream fileStream = new FileStream(openFileDialog.FileName FileMode.Open FileAccess.Read);
pictureBox1.Image = Image.FromStream(fileStream);
fileStream.Close();
fileStream.Dispose();
label2.Text = openFileDialog.FileName;
}
string image_base64 = ImageTobase64(this.label2.Text);
String querys = ““;
String bodys = “{\“img\“:\““ + image_base64 + “\“}“;
String url = host + path;
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
if (0 < querys.Length)
{
url = url + “?“ + querys;
}
if (host.Contains(“https://“))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = method;
httpRequest.Headers.Add(“Authorization“ “APPCODE “ + appcode);
//根据API的要求,定义相对应的Content-Type
httpRequest.ContentType = “application/json; charset=UTF-8“;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-04-12 11:39 WindowsFormsApp1\
目录 0 2019-04-12 11:39 WindowsFormsApp1\.vs\
目录 0 2019-04-12 11:39 WindowsFormsApp1\.vs\WindowsFormsApp1\
目录 0 2019-04-12 11:39 WindowsFormsApp1\.vs\WindowsFormsApp1\v15\
文件 19968 2019-04-12 13:27 WindowsFormsApp1\.vs\WindowsFormsApp1\v15\.suo
目录 0 2019-04-12 11:39 WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\
目录 0 2019-04-12 11:39 WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\sqlite3\
文件 0 2019-04-12 11:39 WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\sqlite3\db.lock
文件 4096 2019-04-12 11:39 WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\sqlite3\storage.ide
文件 32768 2019-04-12 11:39 WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\sqlite3\storage.ide-shm
文件 1705712 2019-04-12 13:27 WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\sqlite3\storage.ide-wal
目录 0 2019-04-12 13:26 WindowsFormsApp1\WindowsFormsApp1\
文件 1146 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1.sln
文件 189 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1\App.config
目录 0 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1\bin\
目录 0 2019-04-12 11:48 WindowsFormsApp1\WindowsFormsApp1\bin\Debug\
文件 11776 2019-04-12 12:00 WindowsFormsApp1\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe
文件 189 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe.config
文件 30208 2019-04-12 12:00 WindowsFormsApp1\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.pdb
文件 4443 2019-04-12 13:26 WindowsFormsApp1\WindowsFormsApp1\Form1.cs
文件 4374 2019-04-12 11:44 WindowsFormsApp1\WindowsFormsApp1\Form1.Designer.cs
文件 5817 2019-04-12 11:44 WindowsFormsApp1\WindowsFormsApp1\Form1.resx
目录 0 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1\obj\
目录 0 2019-04-12 11:48 WindowsFormsApp1\WindowsFormsApp1\obj\Debug\
文件 831 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 7276 2019-04-12 11:40 WindowsFormsApp1\WindowsFormsApp1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 0 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
目录 0 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1\obj\Debug\TempPE\
文件 42 2019-04-12 11:39 WindowsFormsApp1\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.csproj.CoreCompileInputs.cache
............此处省略15个文件信息
- 上一篇:C#(VS2017)百度语音识别demo
- 下一篇:基于asp.net的新闻发布网站
评论
共有 条评论