ATM实现扫描二维码打印(二)下载文件到根目录,并判断文件是PNG还是PDF

上一步通过扫描二维码获取了一个URL,这里通过这个URL下载文件,下载的文件存在根目录,然后判断文件类型。如果文件是PDF类型,打印文档,如果为png则不存在,转到扫描页。

代码:

复制代码
  //下载PDF
            using (WebClient webClient = new WebClient())
            {
              
                    timer.Stop();
                 
                    webClient.DownloadFile("http://180.166.99.4/print/scanOutReal.htm?outEnterId=677469", $"{System.Environment.CurrentDirectory}/scanOutReal.PDF");//PDF//webClient.DownloadFile("http://180.166.99.4/print/scanOutReal.htm?outEnterId=675767", $"{System.Environment.CurrentDirectory}/scanOutReal.PDF"); //png,无实提单               
                    //根据是否为PNG,判断有无实提单                
                    FileStream fs = new FileStream($"{System.Environment.CurrentDirectory}/scanOutReal.PDF", FileMode.Open, FileAccess.Read);
                    BinaryReader reader = new BinaryReader(fs);
                    string fileClass;
                    byte buffer;
                    byte[] b = new byte[2];
                    buffer = reader.ReadByte();
                    b[0] = buffer;
                    fileClass = buffer.ToString();
                    buffer = reader.ReadByte();
                    b[1] = buffer;
                    fileClass += buffer.ToString();
                    reader.Close();
                    fs.Close();
                    if (fileClass == "13780")//255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar 
                    {
                       
                    }
                    else
                    {
                        
                    }
                
             
              
复制代码

 

posted @   MrKing&  阅读(222)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
点击右上角即可分享
微信分享提示