| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893 |
-
- 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 System.Reflection;
- using PTMedicalInsurance.Forms;
- using FastReport.Cloud.OAuth;
- using Fizzler;
- using System.Security.Policy;
- using System.IO.Pipes;
- using FastReport.Utils;
- using System.Web;
- namespace PTMedicalInsurance.Helper
- {
- class InvokeHelper
- {
- private string serviceURL;
- private string authorization;
-
-
-
-
- public void Call(string infno, string input, out string output)
- {
- try
- {
- Type YinHaiComType = System.Type.GetTypeFromProgID("YinHai.XJ.Actual.Interface.New");
- if (YinHaiComType != null)
- {
-
- object YinHaiComInstance = System.Activator.CreateInstance(YinHaiComType);
- if (YinHaiComInstance != null)
- {
- Global.writeLog("实例创建成功,准备调用Call服务");
- }
- else
- {
- output = "实例不存在!";
- Global.writeLog("实例不存在");
- return;
- }
-
-
-
- object[] ParamArray = new object[3];
- ParamArray[0] = infno;
- ParamArray[1] = input;
- ParamArray[2] = "";
- ParameterModifier[] ParamMods = new ParameterModifier[1];
- ParamMods[0] = new ParameterModifier(3);
-
-
- ParamMods[0][2] = true;
- YinHaiComType.InvokeMember("gxyb_call",
- BindingFlags.Default | BindingFlags.InvokeMethod,
- null,
- YinHaiComInstance,
- ParamArray,
- ParamMods,
- null,
- null);
- output = ParamArray[2].ToString();
- Global.writeLog("Com输出:" + output);
- }
- else
- {
- output = "COM加载失败!";
- Global.writeLog("COM加载失败!");
- }
- }
- catch (Exception ex)
- {
- output = ex.Message;
- Global.writeLog("COM加载失败!" + output);
- }
- }
-
-
-
-
-
- public JObject invokeIrisService(string data, string serviceDesc)
- {
- string rtn = "", url = "";
- JObject joRtn = new JObject();
- try
- {
-
- url = serviceURL;
- ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
-
- HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
-
- 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();
-
-
- HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
-
- StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
-
- rtn = reader.ReadToEnd();
- 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;
- }
- }
-
-
-
-
-
- public JObject invokeHISService(string data, string serviceDesc)
- {
- JObject joRtn = new JObject();
- try
- {
-
- 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));
- }
- }
-
- public string GetToken(string url,int ifbd )
- {
- string rtn = "";
- JObject joRtn = new JObject();
- url = url + "/auth/oauth/token";
- CardReader_JIL Cardreader= new CardReader_JIL();
- string ClID = "";
- string OutBar = "";
-
-
- string Authorza = "";
- if (ifbd == 1)
- {
- Authorza = @"Basic OTBDQzJDN0ZBQTkzQTc3QzoyMjAxMDQwMg==";
- }
- else
- {
- Authorza = @"Basic QTU4RTcwRjg3MTZDOEM4QzoyMjAxMDQwMg==";
- }
-
-
-
-
- Cardreader.getCid(out OutBar);
- ClID = OutBar;
- string data = "";
- if (ifbd == 1)
- {
- data = "username=ccxyb00004&password=111111&grant_type=password&scope=server";
- }
- else
- {
- data = "username=50004&password=111111&grant_type=password&scope=server";
- }
-
-
-
-
-
-
- joRtn =invokeTokenService(data, Authorza, url);
-
- rtn = JsonHelper.getDestValue(joRtn, "access_token");
- return rtn;
- }
-
- private JObject invokeTokenService(string data, string auto, string url)
- {
- string postContent = "";
- JObject joRtn = new JObject();
- try
- {
-
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
-
- request.Method = "POST";
- request.Headers.Add("Authorization", auto);
-
-
- request.ContentType = "application/x-www-form-urlencoded";
-
- string paraUrlCoded = data;
- byte[] payload;
-
- payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
-
- request.ContentLength = payload.Length;
-
- Stream writer;
- writer = request.GetRequestStream();
-
- writer.Write(payload, 0, payload.Length);
- writer.Close();
-
- 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);
- return joRtn;
- }
- catch (Exception ex)
- {
- postContent = "获取Token异常" + ex.Message;
- joRtn.Add("infcode", -1);
- joRtn.Add("err_msg", "invokeTokenService(1):" + ex.Message);
- return joRtn;
- }
- }
-
-
-
-
-
- public JObject invokeInsuService(string data, string serviceDesc)
- {
- string rtn = "";
- JObject joRtn = new JObject();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- try
- {
-
- serviceURL = string.Format("{0}/{1}", Global.insuConfig.ip, Global.insuConfig.url);
- authorization = Global.insuConfig.authorization;
- joRtn = invokeIrisService(data, serviceDesc);
- rtn = JsonConvert.SerializeObject(joRtn);
- 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);
- }
- }
-
-
-
-
-
- private JObject invokeCenterService(string data)
- {
- string postContent = "";
- JObject joRtn = new JObject();
- try
- {
-
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
-
- request.Method = "POST";
-
-
- string headstr = "";
-
-
-
-
-
-
-
-
-
-
- headstr = @"bearer " + Global.curEvt.token;
-
-
- request.Headers.Add("Authorization", headstr);
-
-
- request.ContentType = "application/json";
-
- string paraUrlCoded = data;
- byte[] payload;
-
- payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
-
- request.ContentLength = payload.Length;
-
- Stream writer;
- writer = request.GetRequestStream();
-
- writer.Write(payload, 0, payload.Length);
- writer.Close();
-
- 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);
- return joRtn;
- }
- catch (Exception ex)
- {
- postContent = "调用中心服务异常" + ex.Message;
- joRtn.Add("infcode", -1);
- joRtn.Add("err_msg", "invokeCenterService(1):" + ex.Message);
- return joRtn;
- }
- }
-
-
-
-
-
- private JObject invokeSCCenterService(string data)
- {
- string postContent = "";
- JObject joRtn = new JObject();
- try
- {
-
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://ddjk.jlhs.gov.cn:20215/mbs/fsi/api/fileupload");
-
- request.Method = "POST";
-
-
- string headstr = "";
-
-
-
-
-
-
-
-
-
-
- headstr = @"bearer " + Global.curEvt.token;
-
-
- request.Headers.Add("Authorization", headstr);
-
-
- request.ContentType = "application/json";
-
- string paraUrlCoded = data;
- byte[] payload;
-
- payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
-
- request.ContentLength = payload.Length;
-
- Stream writer;
- writer = request.GetRequestStream();
-
- writer.Write(payload, 0, payload.Length);
- writer.Close();
-
- 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);
- return joRtn;
- }
- catch (Exception ex)
- {
- postContent = "调用中心服务异常" + ex.Message;
- joRtn.Add("infcode", -1);
- joRtn.Add("err_msg", "invokeCenterService(1):" + ex.Message);
- return joRtn;
- }
- }
-
-
-
-
-
-
- public JObject invokeCenterService(string funNO, JObject data)
- {
- JObject joRtn = new JObject();
- string outPar = "";
- string input = "";
- try
- {
- Global.curEvt.URL = Global.inf.centerURL;
- input = JsonHelper.setCenterInpar(funNO, data.ToString());
- 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), outPar, JsonHelper.Compress(data), outPar);
- }
- }
-
-
-
-
-
-
- public JObject invokeCenterService(string funNO, string data)
- {
- JObject joRtn = new JObject();
- int iInt = 0;
- String outPar = "";
- string input = "";
- try
- {
- Global.curEvt.URL = Global.inf.centerURL ;
-
-
-
- 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), outPar);
-
- this.saveCenterLog(JsonHelper.Compress(data), outPar, JsonHelper.Compress(data), outPar);
- }
- }
-
- public JObject UploadCenterService(string funNO, string data)
- {
- JObject joRtn = new JObject();
- int iInt = 0;
- String outPar = "";
- string input = "";
- try
- {
-
-
-
-
- joRtn = invokeSCCenterService(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), outPar);
-
- this.saveCenterLog(JsonHelper.Compress(data), outPar, JsonHelper.Compress(data), outPar);
- }
- }
-
-
-
-
-
- public JObject DownloadCenterFileByAPI(string data)
- {
- string error = string.Empty; int errorCode = 0;
- string sRtn = "";
- string durl = "http://ddjk.jlhs.gov.cn:20215/mbs/fsi/api/fileupload";
- 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))
- {
- MessageBox.Show("文件存在");
- File.Delete(filePath);
- }
- FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
-
-
-
-
-
-
-
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(durl);
-
- string headstr = @"bearer " + Global.curEvt.token;
-
- request.Headers.Add("Authorization", headstr);
-
-
- request.Method = "POST";
- string timestamp = TimeStamp.get13().ToString();
- string nonce = Guid.NewGuid().ToString();
- string InsuHosID = Global.inf.hospitalNO;
- string CreditID = Global.inf.CreditID;
- string BusinessID = Global.inf.BusinessID;
-
- request.ContentType = "application/json";
- request.Accept = "text/html,application/xhtml+xml, */*";
-
-
-
- string paraUrlCoded = data;
- byte[] payload;
-
- payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
-
- request.ContentLength = payload.Length;
- Stream writer;
- try
- {
- writer = request.GetRequestStream();
- }
- catch (Exception)
- {
- writer = null;
- errorCode = -100;
- error = "连接服务器失败!";
- }
-
- writer.Write(payload, 0, payload.Length);
- writer.Close();
-
-
- HttpWebResponse response = request.GetResponse() as HttpWebResponse;
-
- 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" + "(" + durl + ")", data, sRtn);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- private void saveCenterLog(string inParam, string outParam, string inParamPlain, string outParamPlain)
- {
- dynamic joIris = new JObject();
- string sRtn = "";
- try
- {
-
- 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);
-
- sRtn = invokeInsuService(joIris.ToString(), "保存日志到数据库").ToString();
- }
- catch (Exception ex)
- {
- sRtn = JsonHelper.setExceptionJson(-100, "保存日志异常", ex.Message).ToString();
- Global.writeLog_Iris("保存日志异常:" + sRtn.ToString());
- }
- }
-
- }
- }
|