using NPOI.SS.Formula.Functions;
using RMYY_CallCenter_Api.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace RMYY_CallCenter_Api.Controllers
{
    [AllowAnonymous ]
    public class PortalController : BaseController
    {
        private string url = ConfigHelper.GetValue("PortalURL");
        // GET: Portal
        public ActionResult WiningBrower()
        {
            //Process myProcess = new Process();
            //ProcessStartInfo startInfo = new ProcessStartInfo(@"WiningBrower.exe", "分级诊疗 http://www.baidu.com");
            //myProcess.startInfo = startInfo;
            //myProcess.startInfo.UseShellExecute = false;
            //myProcess.start();
            return View();
        }

        private  static string MD5Hex(string data,string key)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] dataHash = md5.ComputeHash(Encoding.UTF8.GetBytes(data + key));
            StringBuilder sb = new StringBuilder();
            foreach (byte b in dataHash )
            {
                sb.Append(b.ToString("x2").ToLower());
            }
            return sb.ToString();
        }
        /// <summary>
        /// 获取本地ip地址
        /// </summary>
        /// <returns></returns>
        private static IPAddress GetLocalIP()
        {
            IPAddress localip = null;
            try
            {
                String name = Dns.GetHostName();
                IPHostEntry me = Dns.GetHostEntry(name);
                foreach (IPAddress ips in me .AddressList )
                {
                    if (ips .AddressFamily .ToString ()=="InterNetwork")
                    {
                        localip = ips;
                        break;
                    }
                }
            }
            catch(Exception err)
            {
                throw;
            }
            return localip; 
        }

        public ActionResult GetUrl(string userid,string zjh, string jzlb, string bookids
            , string jzlsh="0", string hzyljgdm="0",string djh="0", string mzzyh="0")
        {
            if (string.IsNullOrEmpty(jzlsh))
                jzlsh = "0";
            if (string.IsNullOrEmpty(zjh))
                return Error("请输入身份证号");
            url = url.Replace("userid", userid)
                    .Replace("zjh", zjh)
                    .Replace("jzlsh", jzlsh)
                    .Replace("jzlb", jzlb)
                    .Replace("mzzyh", mzzyh)
                    .Replace("hzyljgdm", hzyljgdm)
                    .Replace("bookids", bookids)
                    .Replace("djh", djh);
            return Success("获取成功", url);
        }
    }
}