123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Management;
- using System.Net;
- using System.IO;
- using System.Runtime.InteropServices;
- using Newtonsoft.Json.Linq;
- using MedicalInsurance.Business;
- using System.Windows.Forms;
- using System.Reflection;
- namespace ChengDuMedInsu2
- {
- class Common
- {
- public string GetMAC()
- {
- try
- {
- //获取网卡硬件地址
- string mac = "";
- ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
- ManagementObjectCollection moc = mc.GetInstances();
- foreach (ManagementObject mo in moc)
- {
- if ((bool)mo["IPEnabled"] == true)
- {
- mac = mo["MacAddress"].ToString();
- mo.Dispose();//释放资源
- break;
- }
- }
- moc = null;
- mc = null;
- return mac;
- }
- catch
- {
- return "unknow";
- }
- }
- public string GetIP()
- {
- IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
- //string myip = IpEntry.AddressList[0].ToString();//IP6
- string myip = IpEntry.AddressList[1].ToString();//IP4
- return myip;
- }
- }
- class Log
- {
- public string DirectoryPath { get; set; }
- public string LogName{ get; set; }
- public Log(string DirectoryPath,string LogName)
- {
- this.DirectoryPath = DirectoryPath;
- this.LogName = LogName;
- }
- //创建文件夹
- //参数:path 文件夹路径
- public bool CreateFolder(string path)
- {
- try
- {
- if (Directory.Exists(path))
- {
- return true;
- }
- if (!Directory.Exists(path.Substring(0, path.LastIndexOf("\\"))))
- { //若路径中无“\”则表示路径错误
- return false;
- }
- else
- {
- //创建文件夹
- DirectoryInfo dirInfo = Directory.CreateDirectory(path);
- return true;
- }
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- //创建文件
- //参数:path 文件路径
- public void CreateFile(string path)
- {
- try
- {
- if (CreateFolder(path.Substring(0, path.LastIndexOf("\\"))))
- {
- if (!File.Exists(path))
- {
- FileStream fs = File.Create(path);
- fs.Close();
- }
- }
- }
- catch (Exception ex)
- {
- return;
- }
- }
- //删除文件
- //参数:path 文件夹路径
- public void DeleteFile(string path)
- {
- try
- {
- if (!File.Exists(path))
- {
- return;
- }
- else
- {
- File.Delete(path);
- }
- }
- catch (Exception ex)
- {
- return;
- }
- }
- /// <summary>
- /// 将即时日志保存入日志文件
- /// </summary>
- public void Write(string content)
- {
- if (!Directory.Exists(this.DirectoryPath))
- {
- CreateFolder(this.DirectoryPath);
- }
- try
- {
- //写入新的文件
- string filePath = this.DirectoryPath + "\\" + this.LogName;
- FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write);
- StreamWriter sw = new StreamWriter(fs);
- sw.WriteLine(content);
- sw.Close();
- fs.Close();
- }
- catch (Exception ex)
- {
- }
- }
- }
- class IniFile
- {
- public string FullPath; //INI全路径
- [DllImport("kernel32")]
- private static extern long WritePrivateProfileString(string section, string key,
- string val, string filePath);
- [DllImport("kernel32")]
- private static extern int GetPrivateProfileString(string section, string key, string def,
- StringBuilder retVal, int size, string filePath);
- public IniFile(string path)
- {
- this.FullPath = path;
- }
- //写INI文件
- public void WriteValue(string Section, string Key, string Value)
- {
- WritePrivateProfileString(Section, Key, Value, this.FullPath);
- }
- //读取INI文件指定
- public string ReadValue(string Section, string Key)
- {
- StringBuilder temp = new StringBuilder(255);
- int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.FullPath);
- return temp.ToString();
- }
- }
- public static class GlobalVariables
- {
- #region 全局变量
- //当前路径
- public static String currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- //医院的基本信息
- public static String hospitalID = "";
- public static String hospitalName = "";
- public static int hospitalDr = 0;
- public static string hospitalLevel = "";
- //接口信息
- public static string InterfaceID = "";
- public static int interfaceDr = 0;
- //医保环境信息
- public static String signno = "";
- public static String centerURL = "";
- public static String ecURL = "";
- public static String hospitalNO = "";
- public static String hospitalAreaCode = "";
- public static String patientAreaCode = "";
- public static String recivedSystemCode = "";
- public static String certificationAuthorityInfo = "";
- public static String signatureType = "";
- public static String interfaceVersion = "";
- public static String deviceSafetyInfo = "";
- public static String businessDllName = "";
- public static String businessDllNameSpace = "";
- //IRIS信息
- public static String irisServiceIP = "";
- public static String irisServiceURL = "";
- public static String irisServiceAuthorization = "";
- //登录用户信息
- public static String operatoType = "";
- public static String operatorNO = "";
- public static String operatorName = "";
- //医保患者信息
- public static string insuplc_admdvs = "";
- public static string mdtrt_cert_type = "";
- public static string mdtrt_cert_no = "";
- public static string psn_cert_type = "";
- public static string certno = "";
- public static string psn_name = "";
- public static string card_sn = "";
- public static string psn_no = "";
- public static string card_token = "";
- //
- //public static int errorcode = 0;
- //public static string errormessage = "";
- #endregion
- public static void printGlobalVariablesVlaue()
- {
- var varList = new List<string>();
- string outParam = "";
- varList.Add("currentDirectory =" + currentDirectory);
- varList.Add("hospitalID =" + hospitalID);
- varList.Add("hospitalName =" + hospitalName);
- varList.Add("hospitalDr =" + hospitalDr);
- varList.Add("InterfaceID =" + InterfaceID);
- varList.Add("interfaceDr =" + interfaceDr);
- varList.Add("signno =" + signno);
- varList.Add("centerURL =" + centerURL);
- varList.Add("ecURL =" + ecURL);
- varList.Add("hospitalNO =" + hospitalNO);
- varList.Add("hospitalAreaCode =" + hospitalAreaCode);
- varList.Add("patientAreaCode =" + patientAreaCode);
- varList.Add("recivedSystemCode =" + recivedSystemCode);
- varList.Add("certificationAuthorityInfo =" + certificationAuthorityInfo);
- varList.Add("signatureType =" + signatureType);
- varList.Add("interfaceVersion =" + interfaceVersion);
- varList.Add("deviceSafetyInfo =" + deviceSafetyInfo);
- varList.Add("businessDllName =" + businessDllName);
- varList.Add("businessDllNameSpace =" + businessDllNameSpace);
- varList.Add("irisServiceIP =" + irisServiceIP);
- varList.Add("irisServiceURL =" + irisServiceURL);
- varList.Add("irisServiceAuthorization =" + irisServiceAuthorization);
- varList.Add("operatoType =" + operatoType);
- varList.Add("operatorNO =" + operatorNO);
- varList.Add("operatorName =" + operatorName);
- for (int i = 0; i < varList.Count; i++)
- outParam = outParam + (varList[i] + "\r\n");
- writeLog("printGlobalVariablesVlaue", "", outParam);
- }
- public static int Init(string inParam)
- {
- string exMsg = string.Empty;
- string outParam = "";
- var varList = new List<string>();
- int iResult = -1;
- try
- {
- //获取配置文件里的IRIS服务信息
- IniFile ini = new IniFile(currentDirectory + @"\INSUConfigure.ini");
- irisServiceIP = ini.ReadValue("HIS", "ip");
- varList.Add("irisServiceIP =" + irisServiceIP);
- irisServiceURL = ini.ReadValue("HIS", "url");
- varList.Add("irisServiceURL =" + irisServiceURL);
- irisServiceAuthorization = ini.ReadValue("HIS", "authorization");
- varList.Add("irisServiceAuthorization =" + irisServiceAuthorization);
- businessDllNameSpace = ini.ReadValue("INTERFACEINFO", "businessDllNameSpace");//后面统一为MedicalInsurance
- varList.Add("businessDllNameSpace =" + businessDllNameSpace);
- //获取his(或者说壳程序)传过来的基本信息
- JObject joInParam = JObject.Parse(inParam);
- JArray jaParams = JArray.FromObject(joInParam["params"]);
- JObject joParam = JObject.FromObject(jaParams[0]);
- hospitalDr = (int)joParam["hospitalDr"];
- varList.Add("hospitalDr =" + hospitalDr);
- hospitalName = (string)joParam["hospitalName"];
- varList.Add("hospitalName =" + hospitalName);
- operatorNO = (string)joParam["operatorNO"];
- varList.Add("operatorNO =" + operatorNO);
- operatorName = (string)joParam["operatorName"];
- varList.Add("operatorName =" + operatorName);
- InterfaceID = (string)joParam["InterfaceID"];
- varList.Add("InterfaceID =" + InterfaceID);
- //MessageBox.Show(joParam["InterfaceID"].ToString());
- //if (int.TryParse(joParam["InterfaceDr"].ToString(), out interfaceDr))
- //{ MessageBox.Show("2"); }
- //else
- //{ MessageBox.Show("2"); }
- interfaceDr = (int)joParam["InterfaceDr"];
- operatoType = "3";
- varList.Add("operatoType =" + operatoType);
- //通过irsi服务获取接口信息09010003
- //IrisInterfaceService iris = new IrisInterfaceService();
- //JObject joInterface = iris.getCurrentInterface();
- //centerURL = (string)joInterface["CenterURL"];
- //hospitalAreaCode = (string)joInterface["AreaCode"];
- //businessDllName = (string)joInterface["DLLName"];
- //hospitalNO = (string)joInterface["HospitalNO"];
- centerURL = (string)joParam["centerURL"];
- varList.Add("centerURL =" + centerURL);
- hospitalAreaCode = (string)joParam["areaCode"];
- varList.Add("hospitalAreaCode =" + hospitalAreaCode);
- businessDllName = (string)joParam["dllName"];
- varList.Add("businessDllName =" + businessDllName);
- hospitalNO = (string)joParam["hospitalNO"];
- varList.Add("hospitalNO =" + hospitalNO);
- interfaceVersion = "v1.0";
- varList.Add("interfaceVersion =" + interfaceVersion);
- signatureType = "sm3";
- varList.Add("signatureType =" + signatureType);
- recivedSystemCode = "YBXT";
- varList.Add("recivedSystemCode =" + recivedSystemCode);
- iResult = 0;
-
- for (int i = 0; i < varList.Count; i++)
- outParam = outParam + (varList[i]) + "\r\n";
- writeLog("getInterfaceInfo", inParam, outParam);
- return iResult;
- }
- catch (Exception ex)
- {
- exMsg = "全局变量初始化异常:" + ex.Message;
- return iResult;
- }
- finally
- {
- if (iResult != 0)
- {
- writeLog("全局变量初始化", inParam, "GlobalVariables.Init异常:" + exMsg);
- }
- else
- {
- writeLog("全局变量初始化", inParam, outParam);
- }
-
- }
-
- }
- /// <summary>
- /// 初始化接口信息(包含医院信息),初始化后会那啥
- /// </summary>
- /// <param name="joInterface"></param>
- public static void getInterfaceInfo(JObject joInterface)
- {
- var varList = new List<string>();//获取his(或者说壳程序)传过来的基本信息
- hospitalDr = (int)joInterface["hospitalDr"];
- varList.Add("hospitalDr =" + hospitalDr);
- hospitalName = (string)joInterface["hospitalName"];
- varList.Add("hospitalName =" + hospitalName);
- operatorNO = (string)joInterface["operatorNO"];
- varList.Add("operatorNO =" + operatorNO);
- operatorName = (string)joInterface["operatorName"];
- varList.Add("operatorName =" + operatorName);
- InterfaceID = (string)joInterface["InterfaceID"];
- varList.Add("InterfaceID =" + InterfaceID);
- interfaceDr = (int)joInterface["InterfaceDr"];
- varList.Add("interfaceDr =" + interfaceDr);
- operatoType = "3";
- varList.Add("operatoType =" + operatoType);
- centerURL = (string)joInterface["centerURL"];
- varList.Add("centerURL =" + centerURL);
- hospitalAreaCode = (string)joInterface["areaCode"];
- varList.Add("hospitalAreaCode =" + hospitalAreaCode);
- businessDllName = (string)joInterface["dllName"];
- varList.Add("businessDllName =" + businessDllName);
- hospitalNO = (string)joInterface["hospitalNO"];
- varList.Add("hospitalNO =" + hospitalNO);
- interfaceVersion = "v1.0";
- varList.Add("interfaceVersion =" + interfaceVersion);
- signatureType = "sm3";
- varList.Add("signatureType =" + signatureType);
- recivedSystemCode = "YBXT";
- varList.Add("recivedSystemCode =" + recivedSystemCode);
- string outParam = "";
- for (int i = 0; i < varList.Count; i++)
- outParam = outParam + (varList[i]) + "\r\n";
- writeLog("getInterfaceInfo", joInterface.ToString(), outParam);
- }
- public static void getInterfaceInfoByIris(JObject joInterface)
- {
- var varList = new List<string>();//获取his(或者说壳程序)传过来的基本信息
- interfaceDr = (int)joInterface["ID"];
- varList.Add("interfaceDr =" + interfaceDr);
- InterfaceID = (string)joInterface["InterfaceID"];
- varList.Add("InterfaceID =" + InterfaceID);
- hospitalNO = (string)joInterface["HospitalNO"];
- varList.Add("hospitalNO =" + hospitalNO);
- hospitalDr = (int)joInterface["HospitalDr"];
- varList.Add("hospitalDr =" + hospitalDr);
- hospitalLevel = (string)joInterface["HospitalLevel"];
- varList.Add("hospitalLevel =" + hospitalLevel);
- centerURL = (string)joInterface["CenterURL"];
- varList.Add("centerURL =" + centerURL);
- hospitalAreaCode = (string)joInterface["AreaCode"];
- varList.Add("hospitalAreaCode =" + hospitalAreaCode);
- businessDllName = (string)joInterface["DLLName"];
- varList.Add("businessDllName =" + businessDllName);
-
- operatoType = "3";
- varList.Add("operatoType =" + operatoType);
- interfaceVersion = "v1.0";
- varList.Add("interfaceVersion =" + interfaceVersion);
- signatureType = "sm3";
- varList.Add("signatureType =" + signatureType);
- recivedSystemCode = "YBXT";
- varList.Add("recivedSystemCode =" + recivedSystemCode);
- string outParam = "";
- for (int i = 0; i < varList.Count; i++)
- outParam = outParam + (varList[i]) + "\r\n";
- writeLog("getInterfaceInfoByIris", joInterface.ToString(), outParam);
- }
- public static void getIrisConfig()
- {
- var varList = new List<string>();
- //获取配置文件里的IRIS服务信息
- IniFile ini = new IniFile(currentDirectory + @"\INSUConfigure.ini");
- irisServiceIP = ini.ReadValue("HIS", "ip");
- varList.Add("irisServiceIP =" + irisServiceIP);
- irisServiceURL = ini.ReadValue("HIS", "url");
- varList.Add("irisServiceURL =" + irisServiceURL);
- irisServiceAuthorization = ini.ReadValue("HIS", "authorization");
- varList.Add("irisServiceAuthorization =" + irisServiceAuthorization);
- string outParam = "";
- for (int i = 0; i < varList.Count; i++)
- outParam = outParam + (varList[i]);
- writeLog("getIrisConfig:" + outParam);
- }
- public static void getInterfaceByHISParam(JObject joInParam)
- {
- hospitalDr = int.Parse(joInParam["hospitalDr"].ToString());
- interfaceDr = int.Parse(joInParam["InterfaceDr"].ToString());
- hospitalName = joInParam["hospitalName"].ToString();
- operatorNO = joInParam["hospitalDr"].ToString();
- operatorName = joInParam["hospitalDr"].ToString();
- }
- public static void writeLog(string content)
- {
- string logDir = GlobalVariables.currentDirectory + "\\Log", logName = DateTime.Now.ToString("yyyy-MM-dd") + "_YW.Log";
- if (!Directory.Exists(logDir))
- {
- //创建文件夹
- DirectoryInfo dirInfo = Directory.CreateDirectory(logDir);
- }
- if (!File.Exists(logDir + "\\" + logName))
- {
- FileStream fs1 = File.Create(logDir + "\\" + logName);
- fs1.Close();
- }
- FileStream fs = new FileStream(logDir + "\\" + logName, FileMode.Append, FileAccess.Write);
- StreamWriter sw = new StreamWriter(fs);
- string timeLine = "**********" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff") + "***********" + "\r\n";
- sw.WriteLine(timeLine + content);
- sw.Close();
- fs.Close();
- }
- public static void writeLog(string tradeName, string inParam, string outParam)
- {
- string logDir = GlobalVariables.currentDirectory + "\\Log", logName = DateTime.Now.ToString("yyyy-MM-dd") + "_YW.Log";
- string statrTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff");
- if (!Directory.Exists(logDir))
- {
- //创建文件夹
- DirectoryInfo dirInfo = Directory.CreateDirectory(logDir);
- }
- if (!File.Exists(logDir + "\\" + logName))
- {
- FileStream fs1 = File.Create(logDir + "\\" + logName);
- fs1.Close();
- }
- FileStream fs = new FileStream(logDir + "\\" + logName, FileMode.Append, FileAccess.Write);
- StreamWriter sw = new StreamWriter(fs);
- string content = "****************************交易开始(" + statrTime + ")****************************" + "\r\n";
- content = content + "交易名称:" + tradeName + "\r\n";
- content = content + "交易入参:" + inParam + "\r\n";
- content = content + "交易出参:" + outParam + "\r\n";
- //content = content + "****************************交易结束(" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff") + ")****************************" + "\r\n";
- sw.WriteLine(content);
- sw.Close();
- fs.Close();
- }
- public static string SetJsonParam(string infno, string input)
- {
- dynamic Jo = new JObject();
- Jo.infno = infno;
- Jo.msgid = GlobalVariables.hospitalNO + DateTime.Now.ToString("yyyyMMddHHmmssffff");
- Jo.mdtrtarea_admvs = GlobalVariables.hospitalAreaCode;
- Jo.insuplc_admdvs = GlobalVariables.patientAreaCode;
- Jo.recer_sys_code = GlobalVariables.recivedSystemCode;
- Common common = new Common();
- Jo.dev_no = common.GetMAC();
- Jo.dev_safe_info = GlobalVariables.deviceSafetyInfo;
- Jo.cainfo = GlobalVariables.certificationAuthorityInfo; ;
- Jo.signtype = GlobalVariables.signatureType; ;
- Jo.infver = GlobalVariables.interfaceVersion; ;
- Jo.opter_type = GlobalVariables.operatoType; ;
- Jo.opter = GlobalVariables.operatorNO; ;
- Jo.opter_name = GlobalVariables.operatorName; ;
- Jo.inf_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- Jo.fixmedins_code = GlobalVariables.hospitalNO;
- Jo.fixmedins_name = GlobalVariables.hospitalName;
- Jo.sign_no = GlobalVariables.signno;
- JObject joInput = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(input);
- Jo.Add("input", JObject.FromObject(joInput));
- return Jo.ToString();
- }
- }
- }
|