コード例 #1
0
        /// <summary>
        /// 解析交易返回的fileContent字符串并落地 (解base64,解DEFLATE压缩并落地) 适用:对账文件下载,批量交易状态查询的文件落地
        /// </summary>
        /// <param name="resData"></param>
        /// <param name="savePath"></param>
        public static bool DeCodeFileContent(Dictionary <string, string> resData, string fileDirectory)
        {
            string fileContent = resData["fileContent"];
            string fileName;

            if (resData.ContainsKey("fileName"))
            {
                fileName = resData["fileName"];
            }
            else
            {
                fileName = resData["merId"] + "_" + resData["batchNo"] + "_" + resData["txnTime"] + ".txt";
            }
            try
            {
                //Base64解码
                byte[] dBase64Byte = Convert.FromBase64String(fileContent);
                //解压缩
                byte[] fileByte = SecurityUtil.Inflater(dBase64Byte);

                //保存
                string path             = System.IO.Path.Combine(fileDirectory, fileName);
                System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
                fs.Write(fileByte, 0, fileByte.Length);
                fs.Close();
                fs.Dispose();

                return(true);
            }
            catch (Exception e)
            {
                log.Error("保存fileContent出错:" + e.Message);
                return(false);
            }
        }