123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026 |
- /******************************************************************************
- * 文件名称: InvokeHelper.cs
- * 文件说明: 调用助手,调用方法的封装
- * 当前版本: V1.0
- * 创建日期: 2022-04-12
- *
- * 2020-04-12: 增加 businessDLLInvoke 方法
- * 2020-04-12: 增加 writeLog 方法
- * 2020-04-14: 增加 businessDLLInvoke(重载) 方法
- * 2020-04-14: 增加 irisServiceInvoke 方法
- ******************************************************************************/
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using PTMedicalInsurance.Helper;
- using Newtonsoft.Json;
- using PTMedicalInsurance.Common;
- using PTMedicalInsurance.Variables;
- using System.Runtime.InteropServices;
- using chsinterfaceyn;
- namespace PTMedicalInsurance.Helper
- {
- class InvokeHelper
- {
- private string serviceURL;
- private string authorization;
- //医保动态库
- const string DllPath = @"C:\ProgramData\prykNT\prBrowser\bin\service\plugins\INSUNew\InsuDLL\pack\CHSInterfaceYn.dll";
- const string IntPath = @"C:\ProgramData\prykNT\prBrowser\bin\service\plugins\INSUNew\InsuDLL\pack"; // \\InsuDLL\\pack\\CHSInterfaceYn.dll
- /// <summary>
- /// 初始化函数
- /// </summary>
- /// <param name="fixmedins_code"></param>
- /// <param name="infosyscode"></param>
- /// <param name="infosyssign"></param>
- /// <param name="url"></param>
- /// <param name="pErrMsg"></param>
- /// <returns></returns>
- [DllImport("CHSInterfaceYn.dll", EntryPoint = "Init", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
- static extern int Init(string fixmedins_code, string infosyscode, string infosyssign, string url, StringBuilder pErrMsg);
- /// <summary>
- /// 文件下载函数
- /// </summary>
- /// <param name="fixmedins_code"></param>
- /// <param name="infosyscode"></param>
- /// <param name="infosyssign"></param>
- /// <param name="inputData"></param>
- /// <param name="outputData"></param>
- /// <param name="pErrMsg"></param>
- /// <returns></returns>
- [DllImport("CHSInterfaceYn.dll", EntryPoint = "DownloadFile", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
- static extern int DownloadFile(string fixmedins_code, string infosyscode, string infosyssign, string inputData, StringBuilder outputData, StringBuilder pErrMsg);
- /// <summary>
- /// 文件上传函数
- /// </summary>
- /// <param name="fixmedins_code"></param>
- /// <param name="infosyscode"></param>
- /// <param name="infosyssign"></param>
- /// <param name="inputData"></param>
- /// <param name="outputData"></param>
- /// <param name="pErrMsg"></param>
- /// <returns></returns>
- [DllImport("CHSInterfaceYn.dll", EntryPoint = "UploadFile", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
- static extern int UploadFile(string fixmedins_code, string infosyscode, string infosyssign, string fileName,string inputData, StringBuilder outputData, StringBuilder pErrMsg);
- /// <summary>
- /// 通用业务函数
- /// </summary>
- /// <param name="fixmedins_code"></param>
- /// <param name="infosyscode"></param>
- /// <param name="infosyssign"></param>
- /// <param name="inputData"></param>
- /// <param name="outputData"></param>
- /// <param name="errmsg"></param>
- /// <returns></returns>
- [DllImport("CHSInterfaceYn.dll", EntryPoint = "BusinessHandle", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
- static extern int BusinessHandle(string fixmedins_code, string infosyscode, string infosyssign, string inputData, StringBuilder outputData, StringBuilder errmsg);
- /// <summary>
- /// 通用业务函数
- /// </summary>
- /// <param name="fixmedins_code"></param>
- /// <param name="infosyscode"></param>
- /// <param name="infosyssign"></param>
- /// <param name="inputData"></param>
- /// <param name="outputData"></param>
- /// <param name="errmsg"></param>
- /// <returns></returns>
- [DllImport("CHSInterfaceYn.dll", EntryPoint = "BusinessHandleW", CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
- static extern int BusinessHandleW(StringBuilder fixmedins_code, StringBuilder infosyscode, StringBuilder infosyssign, StringBuilder inputData, StringBuilder outputData, StringBuilder errmsg);
- /// <summary>
- /// iris服务调用的封装
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public JObject invokeIrisService(string data, string serviceDesc)
- {
- string rtn = "", url = "";
- JObject joRtn = new JObject();
- try
- {
- //先根据用户请求的uri构造请求地址
- url = serviceURL;
- ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
- //创建Web访问对象
- HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
- //把用户传过来的数据转成“UTF-8”的字节流
- byte[] buf = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(data);
- //添加头部信息
- myRequest.Method = "POST";
- myRequest.ContentLength = buf.Length;
- myRequest.ContentType = "application/json";
- myRequest.Headers.Add("Authorization", authorization);
- myRequest.MaximumAutomaticRedirections = 1;
- myRequest.AllowAutoRedirect = true;
- //发送请求
- Stream stream = myRequest.GetRequestStream();
- stream.Write(buf, 0, buf.Length);
- stream.Close();
- //获取接口返回值
- //通过Web访问对象获取响应内容
- HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
- //通过响应内容流创建StreamReader对象,因为StreamReader更高级更快
- StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
- //string rtn = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
- rtn = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
- reader.Close();
- myResponse.Close();
- joRtn = JObject.Parse(rtn);
- return joRtn;
- }
- catch (Exception ex)
- {
- joRtn = JsonHelper.setExceptionJson(-1, serviceDesc, ex.Message);
- rtn = JsonConvert.SerializeObject(joRtn);
- return joRtn;
- }
- }
- /// <summary>
- /// HIS服务调用的封装
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public JObject invokeHISService(string data, string serviceDesc)
- {
- JObject joRtn = new JObject();
- try
- {
- //先根据用户请求的uri构造请求地址
- serviceURL = string.Format("{0}/{1}", Global.hisConfig.ip, Global.hisConfig.url);
- authorization = Global.hisConfig.authorization;
- joRtn = invokeIrisService(data, serviceDesc);
- return joRtn;
- }
- catch (Exception ex)
- {
- joRtn = JsonHelper.setExceptionJson(-1, serviceDesc, ex.Message);
- return joRtn;
- }
- finally
- {
- Global.writeLog_Iris(serviceDesc + "(" + serviceURL + ")" + "Authorization:" + (authorization), JsonHelper.Compress(data), JsonHelper.Compress(joRtn));
- }
- }
- /// <summary>
- /// 医保平台服务调用的封装
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public JObject invokeInsuService(string data, string serviceDesc)
- {
- string rtn = "";
- JObject joRtn = new JObject();
- try
- {
- //先根据用户请求的uri构造请求地址
- serviceURL = string.Format("{0}/{1}", Global.insuConfig.ip, Global.insuConfig.url);
- authorization = Global.insuConfig.authorization;
- joRtn = invokeIrisService(data, serviceDesc);
- rtn = JsonConvert.SerializeObject(joRtn);
- //if (serviceDesc == "插入签到信息")
- //{
- // MessageBox.Show("插入签到信息入参:" + data +"|返回值:"+ rtn.ToString()+"|"+ Global.insuConfig.url);
- //}
- return joRtn;
- }
- catch (Exception ex)
- {
- joRtn = JsonHelper.setExceptionJson(-1, serviceDesc, ex.Message);
- rtn = JsonConvert.SerializeObject(joRtn);
- return joRtn;
- }
- finally
- {
- Global.writeLog_Iris(serviceDesc + "(" + serviceURL + ")" + "Authorization:" + (authorization), JsonHelper.Compress(data), rtn);
- }
- }
- /// <summary>
- /// 医保中心Post服务调用封装
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- private JObject invokeCenterService(string data)
- {
- string postContent = "";
- JObject joRtn = new JObject();
- try
- {
- //创建一个HTTP请求
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
- //Post请求方式
- request.Method = "POST";
- string nonce = Guid.NewGuid().ToString(); //非重复的随机字符串(十分钟内不能重复)
- string timestamp = TimeStamp.get13().ToString(); //当前时间戳(秒)
- string BusinessID = Global.inf.BusinessID; //服务商ID
- string InsuHosID = Global.inf.hospitalNO; //医疗机构ID
- string CreditID = Global.inf.CreditID; //服务商统一社会信用代码
- //内容类型
- request.ContentType = "application/json";
- //昆明增加头部信息
- string sTemp = timestamp + BusinessID + nonce;
- //Sha256 加密生成的签名 signature = sha256(hsf_timestamp + infosyssign + hsf_nonce)
- string signature = Encrypt.SHA256EncryptStr(sTemp);
- request.Headers.Add("hsf_signature", signature);
- request.Headers.Add("hsf_timestamp", timestamp);
- request.Headers.Add("hsf_nonce", nonce);
- request.Headers.Add("fixmedins_code", InsuHosID);
- request.Headers.Add("infosyscode", CreditID);
- //设置参数,并进行URL编码
- string paraUrlCoded = data;//System.Web.HttpUtility.UrlEncode(jsonParas);
- byte[] payload;
- //将Json字符串转化为字节
- payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
- //设置请求的ContentLength
- request.ContentLength = payload.Length;
- //发送请求,获得请求流
- Stream writer;
- writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
- //将请求参数写入流
- writer.Write(payload, 0, payload.Length);
- writer.Close();//关闭请求流
- // String strValue = "";//strValue为http响应所返回的字符流
- HttpWebResponse response;
- try
- {
- //获得响应流
- response = (HttpWebResponse)request.GetResponse();
- }
- catch (WebException ex)
- {
- response = ex.Response as HttpWebResponse;
- return JsonHelper.setExceptionJson(-99, "centerServeiceInvok中获得响应流异常", ex.Message);
- }
- Stream s = response.GetResponseStream();
- StreamReader sRead = new StreamReader(s);
- postContent = sRead.ReadToEnd();
- sRead.Close();
- joRtn = JObject.Parse(postContent);//返回Json数据
- return joRtn;
- }
- catch (Exception ex)
- {
- postContent = "调用中心服务异常" + ex.Message;
- joRtn.Add("infcode", -1);
- joRtn.Add("err_msg", "invokeCenterService(1):" + ex.Message);
- return joRtn;
- }
- }
- /// <summary>
- /// 调用医保动态库文件下载函数 CM 20220925
- /// </summary>
- /// <param name="fixmedins_code"></param>
- /// <param name="infosyscode"></param>
- /// <param name="infosyssign"></param>
- /// <param name="inputData"></param>
- /// <param name="outputData"></param>
- /// <param name="pErrMsg"></param>
- /// <returns>0或小于0</returns>
- private int invokeDownloadFileByDLL(string fixmedins_code, string infosyscode, string infosyssign, string inputData, ref string outputData, ref string pErrMsg)
- {
- pErrMsg = "";
- outputData = "";
- try
- {
- StringBuilder errmsgSb = new StringBuilder(4096);
- StringBuilder outSb = new StringBuilder(40960);
- int pRtn = DownloadFile(fixmedins_code, infosyscode, infosyssign, inputData, outSb, errmsgSb);
- if (pRtn < 0)
- {
- pErrMsg = errmsgSb.ToString();
- return -1;
- }
- else
- {
- outputData = outSb.ToString();
- }
- return pRtn;
- }
- catch (Exception ex)
- {
- pErrMsg = "invokeInitByDLL.DownloadFile 异常:" + ex.Message;
- return -1;
- }
- finally
- {
- Global.writeLog("invokeInitByDLL.DownloadFile 医保动态库文件下载函数", inputData, outputData);
- }
- }
- /// <summary>
- /// 这个是调用业务服务的invokeCenterService
- /// </summary>
- /// <param name="funNO"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- public JObject invokeCenterService(string funNO, JObject data)
- {
- JObject joRtn = new JObject();
- string outPar = ""; Boolean bDownLoad = false;
- int iInt = 0;
- try
- {
- Global.curEvt.URL = Global.inf.centerURL;
- if (bDownLoad == false)
- {
- string outData = "", errMsg = "";
- iInt = InvokeInitByDLL(ref errMsg);
- if (iInt == 0)
- {
- iInt = invokeBusiessByDLL(data.ToString(), ref outData, ref errMsg);
- joRtn = JObject.Parse(outData);
- return joRtn;
- }
- else
- {
- joRtn.Add("infcode", -1);
- joRtn.Add("err_msg", "医保动态库初始化失败invokeInitByDLL:" + errMsg);
- outPar = JsonHelper.Compress(joRtn);
- return joRtn;
- }
- }
- else
- {
- joRtn = invokeCenterService(data.ToString());
- outPar = JsonHelper.Compress(joRtn);
- return joRtn;
- }
- }
- catch (Exception ex)
- {
- if (joRtn["infcode"] == null)
- { joRtn.Add("infcode", -1); }
- if (joRtn["err_msg"] == null)
- { joRtn.Add("err_msg", "invokeCenterService(2):" + ex.Message); }
- outPar = JsonHelper.Compress(joRtn);
- return joRtn;
- }
- finally
- {
- Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
- this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
- }
- }
- /// <summary>
- /// 这个是下载目录用的invokeCenterService
- /// </summary>
- /// <param name="funNO"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- public JObject invokeCenterService(string funNO, string data)
- {
- JObject joRtn = new JObject();
- int iInt = 0;
- String outPar = ""; Boolean bDownLoad = false;
- try
- {
- //Global.inf.centerURL = @"http://10.114.177.55:8080/eapdomain/callService";
- Global.curEvt.URL = Global.inf.centerURL ;
- List<string> infList = new List<string> { "6201", "6202", "6203", "6301", "6401" };
- if (infList.Contains(funNO))
- {
- Global.writeLog(Global.curEvt.path + @"\CenterServiceURL.ini");
- IniFile urlIni = new IniFile(Global.curEvt.path + @"\CenterServiceURL.ini");
- Global.curEvt.URL = urlIni.ReadValue("URL", funNO);
- Global.inf.centerURL = Global.curEvt.URL;
- }
- if (funNO != "9101")
- {
- string outData = "", errMsg = "";
- iInt = InvokeInitByDLL(ref errMsg);
- if (iInt == 0)
- {
- iInt = invokeBusiessByDLL(data.ToString(), ref outData, ref errMsg);
- joRtn = JObject.Parse(outData);
- return joRtn;
- }
- else
- {
- joRtn.Add("infcode", -1);
- joRtn.Add("err_msg", "医保动态库初始化失败invokeInitByDLL:" + errMsg);
- outPar = JsonHelper.Compress(joRtn);
- return joRtn;
- }
- }
- else
- {
- joRtn = invokeCenterService(data);
- outPar = JsonHelper.Compress(joRtn);
- return joRtn;
- }
- }
- catch (Exception ex)
- {
- if (joRtn["infcode"] == null)
- { joRtn.Add("infcode", -1); }
- if (joRtn["err_msg"] == null)
- { joRtn.Add("err_msg", "invokeCenterService(3):" + ex.Message); }
- outPar = JsonHelper.Compress(joRtn);
- return joRtn;
- }
- finally
- {
- Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
- this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
- }
- }
- /// <summary>
- /// 移动
- /// </summary>
- /// <param name="funNO"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- public JObject invokeMPService(string funNO, string data)
- {
- JObject joRtn = new JObject();
- int iInt = 0;
- String outPar = ""; Boolean bDownLoad = false;
- try
- {
- Global.curEvt.URL = Global.inf.centerURL;
- List<string> infList = new List<string> { "6201", "6202", "6203", "6301", "6401" };
- if (infList.Contains(funNO))
- {
- IniFile urlIni = new IniFile(Global.curEvt.path + @"\CenterServiceURL.ini");
- Global.curEvt.URL = urlIni.ReadValue("URL", funNO);
- Global.inf.centerURL = Global.curEvt.URL;
- }
- joRtn = invokeCenterService(data);
- outPar = JsonHelper.Compress(joRtn);
- return joRtn;
-
- }
- catch (Exception ex)
- {
- if (joRtn["infcode"] == null)
- { joRtn.Add("infcode", -1); }
- if (joRtn["err_msg"] == null)
- { joRtn.Add("err_msg", "invokeCenterService(3):" + ex.Message); }
- outPar = JsonHelper.Compress(joRtn);
- return joRtn;
- }
- finally
- {
- Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
- this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
- }
- }
- /// <summary>
- /// 设置医保动态库目录
- /// </summary>
- /// <param name="sPath"></param>
- /// <param name="pErrMsg"></param>
- /// <returns></returns>
- private void invokeSetDirByOCX(ref string pErrMsg)
- {
- try
- {
- //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();
- //InterfaceBase_Yn.SetDir(IntPath);
- }
- catch (Exception ex)
- {
- pErrMsg = "invokeInitByDLL.SetDir 异常:" + ex.Message;
- MessageBox.Show(pErrMsg);
- }
- finally
- {
- Global.writeLog("invokeInitByDLL.SetDir设置医保动态库目录(" + IntPath + ")", "", pErrMsg);
- }
- }
- /// <summary>
- /// 医保目录txt文件下载
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public JObject DownloadCenterFile(string data)
- {
- string error = string.Empty; int errorCode = 0;
- string sRtn = "";
- try
- {
- JObject jsonInParam = JObject.Parse(data);
- string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
- string filePath = Global.curEvt.path + "\\Download\\" + fileName;
- //MessageBox.Show("9102下载文件入参:"+jsonInParam.ToString());
- //如果不存在目录,则创建目录
- if (!Directory.Exists(Global.curEvt.path + "\\Download"))
- {
- //创建文件夹
- DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\Download");
- }
- if (File.Exists(filePath))
- {
- File.Delete(filePath);
- }
- FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
- //创建一个HTTP请求
- //Global.curEvt.URL = Global.inf.centerURL + "/hsa-fsi-9102";
- Global.curEvt.URL = Global.inf.centerURL;
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
- //Post请求方式
- request.Method = "POST";
- string timestamp = TimeStamp.get13().ToString(); //当前时间戳(秒)
- string nonce = Guid.NewGuid().ToString(); //非重复的随机字符串(十分钟内不能重复)
- string InsuHosID = Global.inf.hospitalNO; //医疗机构ID
- string CreditID = Global.inf.CreditID; //服务商统一社会信用代码
- string BusinessID = Global.inf.BusinessID; //服务商ID
- //内容类型
- request.ContentType = "application/json";
- //昆明增加头部信息
- string sTemp = timestamp + BusinessID + nonce;
- //Sha256 加密生成的签名 signature = sha256(hsf_timestamp + infosyssign + hsf_nonce)
- string signature = Encrypt.SHA256EncryptStr(sTemp);
- request.Headers.Add("hsf_signature", signature);
- request.Headers.Add("hsf_timestamp", timestamp);
- request.Headers.Add("hsf_nonce", nonce);
- request.Headers.Add("fixmedins_code", InsuHosID);
- request.Headers.Add("infosyscode", CreditID);
- //设置参数,并进行URL编码
- string paraUrlCoded = data;//System.Web.HttpUtility.UrlEncode(jsonParas);
- byte[] payload;
- //将Json字符串转化为字节
- payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
- //设置请求的ContentLength
- request.ContentLength = payload.Length;
- Stream writer;
- try
- {
- writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
- }
- catch (Exception)
- {
- writer = null;
- errorCode = -100;
- error = "连接服务器失败!";
- }
- //将请求参数写入流
- writer.Write(payload, 0, payload.Length);
- writer.Close();//关闭请求流
- // String strValue = "";//strValue为http响应所返回的字符流
- //发送请求并获取相应回应数据
- HttpWebResponse response = request.GetResponse() as HttpWebResponse;
- //直到request.GetResponse()程序才开始向目标网页发送Post请求
- Stream responseStream = response.GetResponseStream();
- //创建本地文件写入流
- byte[] bArr = new byte[1024];
- int iTotalSize = 0;
- int size = responseStream.Read(bArr, 0, (int)bArr.Length);
- while (size > 0)
- {
- iTotalSize += size;
- fs.Write(bArr, 0, size);
- size = responseStream.Read(bArr, 0, (int)bArr.Length);
- }
- fs.Close();
- responseStream.Close();
- dynamic joReturn = new JObject();
- joReturn.errorCode = errorCode;
- joReturn.errorMessage = error;
- joReturn.filePath = filePath;
- sRtn = joReturn.ToString();
- return joReturn;
- }
- catch (Exception ex)
- {
- errorCode = -100;
- error = ex.Message;
- dynamic joReturn = new JObject();
- joReturn.errorCode = errorCode;
- joReturn.errorMessage = error;
- sRtn = joReturn.ToString();
- return joReturn;
- }
- finally
- {
- Global.writeLog("DownloadCenterFile" +"(" + Global.curEvt.URL + ")", data, sRtn);
- }
- }
- /// <summary>
- /// 调用医保动态库初始化 CM 20220925
- /// </summary>
- /// <param name="fixmedins_code"></param>
- /// <param name="infosyscode"></param>
- /// <param name="infosyssign"></param>
- /// <param name="url"></param>
- /// <param name="pErrMsg"></param>
- /// <returns>0或小于0</returns>
- private int invokeInitByOCX(string fixmedins_code, string infosyscode, string infosyssign, string url, ref string pErrMsg)
- {
- //pErrMsg = "";
- JObject joRtn = new JObject();
- try
- {
- //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();
- //string pRtn = InterfaceBase_Yn.Init(fixmedins_code, infosyscode, infosyssign, url);
- //joRtn = JObject.Parse(pRtn);
- if (joRtn["infcode"].ToString() != "0")
- {
- pErrMsg = joRtn["err_msg"].ToString();
- return -1;
- }
- else
- {
- return 0;
- }
- }
- catch (Exception ex)
- {
- pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
- return -1;
- }
- finally
- {
- Global.writeLog("invokeInitByDLL.Init医保动态库初始化(" + url + ")", "", pErrMsg);
- }
- }
- /// <summary>
- /// 调用医保动态库通用业务函数 CM 20220925
- /// </summary>
- /// <param name="fixmedins_code"></param>
- /// <param name="infosyscode"></param>
- /// <param name="infosyssign"></param>
- /// <param name="inputData"></param>
- /// <param name="outputData"></param>
- /// <param name="pErrMsg"></param>
- /// <returns>0或小于0</returns>
- private int invokeBusiessByOCX(string fixmedins_code, string infosyscode, string infosyssign, string inputData, ref string outputData, ref string pErrMsg)
- {
- pErrMsg = "";
- outputData = "";
- JObject joRtn = new JObject();
- try
- {
- try
- {
- //chsinterfaceyn.chsdllClass InterfaceBase_Yn1 = new chsinterfaceyn.chsdllClass();
- //InterfaceBase_Yn1.SetDir(IntPath);
- }
- catch (Exception ex)
- {
- pErrMsg = "invokeInitByDLL.SetDir 异常:" + ex.Message;
- MessageBox.Show(pErrMsg);
- }
- finally
- {
- Global.writeLog("invokeInitByDLL.SetDir设置医保动态库目录(" + IntPath + ")", "", pErrMsg);
- }
- inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
- //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();
- //调用业务函数
- //string pRtn =InterfaceBase_Yn.BusinessHandleW(fixmedins_code, infosyscode, infosyssign, inputData);
- //string pRtn = InterfaceBase_Yn.UploadFile(fixmedins_code, infosyscode, infosyssign, Global.inf.fileName,inputData);
- //joRtn = JObject.Parse(pRtn);
- if (joRtn["infcode"].ToString() != "0")
- {
- pErrMsg = joRtn["err_msg"].ToString();
- //outputData = pRtn;
- return -1;
- }
- else
- {
- //outputData = pRtn;
- return 0;
- }
- }
- catch (Exception ex)
- {
- pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
- return -1;
- }
- finally
- {
- Global.writeLog("invokeInitByDLL.BusinessHandle医保动态库通用业务函数", inputData, outputData);
- }
- }
- /// <summary>
- /// 医保动态库下载目录文件
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public JObject DownloadCenterFileByDll(string data)
- {
- string error = string.Empty; int errorCode = 0;
- string sRtn = "";
- try
- {
- JObject jsonInParam = JObject.Parse(data);
- string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
- string filePath = Global.curEvt.path + "\\Download\\" + fileName;
- //如果不存在目录,则创建目录
- if (!Directory.Exists(Global.curEvt.path + "\\Download"))
- {
- //创建文件夹
- DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\Download");
- }
- if (File.Exists(filePath))
- {
- File.Delete(filePath);
- }
- FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
- //创建一个HTTP请求
- //Global.curEvt.URL = Global.inf.centerURL + "/hsa-fsi-9102";
- Global.curEvt.URL = Global.inf.centerURL;
- int iRes = invokeDownloadFileByDLL(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, data.ToString(),ref sRtn, ref error);
- if (iRes == 0)
- {
- dynamic joReturn = new JObject();
- joReturn.errorCode = errorCode;
- joReturn.errorMessage = error;
- joReturn.filePath = filePath;
- sRtn = joReturn.ToString();
- return joReturn;
- }
- else
- {
- errorCode = -100;
- dynamic joReturn = new JObject();
- joReturn.errorCode = errorCode;
- joReturn.errorMessage = error;
- sRtn = joReturn.ToString();
- return joReturn;
- }
- }
- catch (Exception ex)
- {
- errorCode = -100;
- error = ex.Message;
- dynamic joReturn = new JObject();
- joReturn.errorCode = errorCode;
- joReturn.errorMessage = error;
- sRtn = joReturn.ToString();
- return joReturn;
- }
- finally
- {
- Global.writeLog("DownloadCenterFile" + "(" + Global.curEvt.URL + ")", data, sRtn);
- }
- }
- /// <summary>
- /// 保存中心交易日志到数据库
- /// </summary>
- /// <param name="inParam"></param>
- /// <param name="outParam"></param>
- /// <param name="inParamPlain"></param>
- /// <param name="outParamPlain"></param>
- private void saveCenterLog(string inParam, string outParam, string inParamPlain, string outParamPlain)
- {
- dynamic joIris = new JObject();
- string sRtn = "";
- try
- {
- //解析postContent,插入医保交易日志表
- JObject joIn = new JObject(JObject.Parse(inParam));
- JObject joOut = new JObject(JObject.Parse(outParam));
- JObject joInPlain = new JObject(JObject.Parse(inParamPlain));
- JObject joOutPlain = new JObject(JObject.Parse(outParamPlain));
- JArray jaParams = new JArray();
- JObject joParam = new JObject();
- joParam.Add("inParam", JObject.FromObject(joIn));
- joParam.Add("outParam", JObject.FromObject(joOut));
- joParam.Add("inParamPlain", JObject.FromObject(joInPlain));
- joParam.Add("outParamPlain", JObject.FromObject(joOutPlain));
- joParam.Add("HospitalDr", Global.inf.hospitalDr);
- joParam.Add("InterfaceDr", Global.inf.interfaceDr);
- joParam.Add("updateUserID", Global.user.ID);
- joParam.Add("psn_no", Global.pat.psn_no);
- jaParams.Add(joParam);
- joIris.code = "09010021";
- joIris.Add("params", jaParams);
- //InvokeHelper invoker = new InvokeHelper();
- sRtn = invokeInsuService(joIris.ToString(), "保存日志到数据库").ToString();
- }
- catch (Exception ex)
- {
- sRtn = JsonHelper.setExceptionJson(-100, "保存日志异常", ex.Message).ToString();
- Global.writeLog_Iris("保存日志异常:" + sRtn.ToString());
- }
- }
- /**********************************************************调用DLL方式**************************************************************/
- public int InvokeInitByDLL(ref string pErrMsg)
- {
- //string pErrMsg = "";
- int pRtn =-1;
- JObject joRtn = new JObject();
- try
- {
- StringBuilder outSb = new StringBuilder(40960);
- pRtn = Init(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, Global.inf.centerURL, outSb);
- if (pRtn != 0)
- {
- pErrMsg = outSb.ToString();
- return -1;
- }
- else
- {
- return 0;
- }
- }
- catch (Exception ex)
- {
- pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
- return -1;
- }
- finally
- {
- Global.writeLog("InvokeInitByDLL(" + Global.inf.centerURL + ")", Global.inf.CreditID +":" + Global.inf.BusinessID,pRtn.ToString() + pErrMsg);
- }
- }
- private int invokeBusiessByDLL(string inputData, ref string outputData, ref string pErrMsg)
- {
- pErrMsg = "";
- outputData = "";
- JObject joRtn = new JObject();
- try
- {
- inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
- StringBuilder errmsgSb = new StringBuilder(4096);
- StringBuilder outSb = new StringBuilder(40960);
- //调用业务函数
- int pRtn = BusinessHandle(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, inputData, outSb, errmsgSb);
- if (pRtn != 0)
- {
- outputData = outSb.ToString();
- pErrMsg = errmsgSb.ToString();
- return -1;
- }
- else
- {
- outputData = outSb.ToString();
- return 0;
- }
- }
- catch (Exception ex)
- {
- pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
- return -1;
- }
- finally
- {
- Global.writeLog("CreditID11", Global.inf.CreditID, Global.inf.BusinessID);
- Global.writeLog("invokeInitByDLL.BusinessHandle医保动态库通用业务函数", inputData, outputData);
- }
- }
- private int invokeBusiessWByDLL(string inputData, ref string outputData, ref string pErrMsg)
- {
- pErrMsg = "";
- outputData = "";
- JObject joRtn = new JObject();
- try
- {
- //inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
- StringBuilder errmsgSb = new StringBuilder(4096);
- StringBuilder outSb = new StringBuilder(40960);
- StringBuilder sbHospitalNO = new StringBuilder(Global.inf.hospitalNO);
- StringBuilder sbCreditID = new StringBuilder(Global.inf.CreditID);
- StringBuilder sbBusinessID = new StringBuilder(Global.inf.BusinessID);
- StringBuilder sbInput = new StringBuilder(inputData);
- //调用业务函数
- int pRtn = BusinessHandleW(sbHospitalNO, sbCreditID, sbBusinessID, sbInput, outSb, errmsgSb);
- if (pRtn != 0)
- {
- outputData = outSb.ToString();
- pErrMsg = errmsgSb.ToString();
- return -1;
- }
- else
- {
- outputData = outSb.ToString();
- return 0;
- }
- }
- catch (Exception ex)
- {
- pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
- return -1;
- }
- finally
- {
- Global.writeLog("CreditID12", Global.inf.CreditID, Global.inf.BusinessID);
- Global.writeLog("invokeInitByDLL.BusinessHandleW医保动态库通用业务函数", inputData, outputData);
- }
- }
- private int invokeUploadFileByDLL(string inputData, ref string outputData, ref string pErrMsg)
- {
- pErrMsg = "";
- outputData = "";
- JObject joRtn = new JObject();
- try
- {
- inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
- StringBuilder errmsgSb = new StringBuilder(4096);
- StringBuilder outSb = new StringBuilder(40960);
- //调用业务函数
- int pRtn = UploadFile(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, Global.inf.fileName,inputData, outSb, errmsgSb);
- if (pRtn != 0)
- {
- outputData = outSb.ToString();
- pErrMsg = errmsgSb.ToString();
- return -1;
- }
- else
- {
- outputData = outSb.ToString();
- return 0;
- }
- }
- catch (Exception ex)
- {
- pErrMsg = "invokeUploadFileByDLL.UploadFile 异常:" + ex.Message;
- return -1;
- }
- finally
- {
- Global.writeLog("invokeUploadFileByDLL.UploadFile医保动态库上传业务函数", inputData, outputData);
- }
- }
- }
- }
|