using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using com.unionpay.acp.sdk;
/**
 * 仅供UPOP联机对账文件下载使用
 * */
namespace upacp_demo_identification.demo.api_99_identification
{
    public class DemoUtil
    {
        /// <summary>
        /// 得到用于打印页面的html
        /// </summary>
        /// <param name="url"></param>
        /// <param name="req"></param>
        /// <param name="resp"></param>
        public static string GetPrintResult(string url, Dictionary<string, string> req, Dictionary<string, string> resp)
        {
            string result = "=============<br>\n";
            result = result + "地址：" + url + "<br>\n";
            result = result + "请求：" + System.Web.HttpContext.Current.Server.HtmlEncode(SDKUtil.CreateLinkString(req, false, true, System.Text.Encoding.UTF8)).Replace("\n", "<br>\n") + "<br>\n";
            result = result + "应答：" + System.Web.HttpContext.Current.Server.HtmlEncode(SDKUtil.CreateLinkString(resp, false, false, System.Text.Encoding.UTF8)).Replace("\n", "<br>\n") + "<br>\n";
            result = result + "=============<br>\n";
            return result;
        }

        /// <summary>
        /// 功能：对图片进行base64编码（综合认证平台使用）<br>
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="encoding"></param>
        public static string EnImgContent(string filePath, Encoding encoding)
        {

            string fileContent;
            if (File.Exists(filePath))
            {
                FileStream fs = new FileStream(filePath, FileMode.Open);
                //获取文件大小
                long size = fs.Length;
                byte[] array = new byte[size];
                //将文件读到byte数组中
                fs.Read(array, 0, array.Length);
                fileContent = Convert.ToBase64String(array);
                fs.Close();
                return fileContent;
            }
            else
            {
                return null;
            }
        }
    }
}