zoukankan      html  css  js  c++  java
  • 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
                        {
                            
                        }
                    
                 
                  
  • 相关阅读:
    mybatis中>=和<=的实现方式
    沙盒
    华硕 X201E 拆机
    延迟满足
    文本输入框自适应高度
    Qt实战之酷狗音乐
    协议栈处理中的conntrack HASH查找/Bloom过滤/CACHE查找/大包与小包/分层处理风格
    【processing】小代码3
    【processing】小代码2
    【processing】小代码
  • 原文地址:https://www.cnblogs.com/king10086/p/12911248.html
Copyright © 2011-2022 走看看