| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442 |
-
- 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;
- using PTMedicalInsurance.APIGATEWAY_SDK;
- 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 (Global.businessType != "M6Confirm")
- if (ifbd == 1)
- {
- Authorza = @"Basic OTBDQzJDN0ZBQTkzQTc3QzoyMjAxMDQwMg==";
- }
- else
- {
- Authorza = @"Basic QTU4RTcwRjg3MTZDOEM4QzoyMjAxMDQwMg==";
- }
- if (Global.inf.interfaceDr == 34)
- {
- Authorza = @"Basic QjczOEY5Mjc2MDVFMTkxMjoxMTExMTE=";
- }
-
-
-
-
- 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";
- }
- if (Global.inf.interfaceDr == 34)
- {
- data = "username=cctest1&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;
- }
- finally
- {
- Global.writeLog($"获取Token({url})", $"data:{data},auth:{auto}", joRtn.ToString());
- }
- }
-
-
-
-
-
- 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";
- Global.writeLog("header", "", request.Headers.ToString());
-
- 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;
- }
- finally
- {
- Global.writeLog("服务调用", data, joRtn.ToString());
- }
- }
-
-
-
-
-
- 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 = "";
- try
- {
- Global.curEvt.URL = Global.inf.centerURL;
- 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))
- {
- 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());
- }
- }
-
- #region 移动支付
-
-
-
-
-
-
-
- public JObject invokeMPService(string funNO, string data)
- {
- return invokeMPService(funNO, JObject.Parse(data));
- }
- public JObject invokeMPService(string funNO, JObject joInput)
- {
- JObject joRtn = new JObject();
- String outPar = "";
- try
- {
- string url = "";
- switch (funNO)
- {
- case "6201":
- url = "/org/local/api/hos/uldFeeInfo";
- break;
- case "6202":
- url = "/org/local/api/hos/pay_order";
- break;
- case "6203":
- url = "/org/local/api/hos/refund_Order";
- break;
- case "6301":
- url = "/org/local/api/hos/query_order_info";
- break;
- case "6401":
- url = "/org/local/api/hos/revoke_order";
- break;
- default:
- break;
- }
- EncryptHelper encrypt = new EncryptHelper(Global.inf.MobilePay.appid, Global.inf.MobilePay.secretKey, Global.inf.MobilePay.privateKey, Global.inf.MobilePay.publicKey);
- string data = JsonHelper.setMPCenterInpar(funNO, joInput);
-
- Global.curEvt.URL = Global.inf.MobilePay.url + url;
- try
- {
- joRtn = invokeCenterService(data);
- Global.writeLog(funNO + "【密文出参】:\r\n" + joRtn.ToString());
- string encData = JsonHelper.getDestValue(joRtn, "encData");
- string signData = JsonHelper.getDestValue(joRtn, "signData");
- if (!string.IsNullOrEmpty(encData) && !string.IsNullOrEmpty(signData))
- {
- joRtn.Remove("encData");
- joRtn.Remove("signData");
- joRtn.Remove("data");
-
- string decData = encrypt.decrypt(encData);
-
- JsonConvert.DefaultSettings = () => new JsonSerializerSettings
- {
- FloatParseHandling = FloatParseHandling.Decimal
- };
- joRtn.Add("data", JToken.FromObject(JsonConvert.DeserializeObject(decData)));
- bool rtn = encrypt.verify(joRtn, signData);
- if (rtn)
- {
- Global.writeLog("验签通过!");
- }
- else
- {
- Global.writeLog("验签失败,请核查!");
- }
- if (!string.IsNullOrEmpty(decData))
- {
- Global.writeLog(funNO + "【明文出参】:\r\n" + decData);
- joRtn = JObject.Parse(decData);
- joRtn.Add("success", "True");
- }
- }
- return joRtn;
- }
- finally
- {
- this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
- }
- }
- 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 + ")", joInput.ToString(), joRtn.ToString());
- this.saveCenterLog(joInput.ToString(), joRtn.ToString(), joInput.ToString(), joRtn.ToString());
- }
- }
- #endregion
- #region 处方流转
-
-
-
-
-
- private JObject invokeCenterServicePresCir(string data)
- {
- string postContent = "";
- JObject joRtn = new JObject();
- try
- {
-
- Signer signer = new Signer();
- signer.Key = Global.inf.privateKey;
- signer.Secret = Global.inf.Secret;
- string timestamp = TimeStamp.get13().ToString();
- string nonce = Guid.NewGuid().ToString();
- HttpRequest Resquest = new HttpRequest("POST", new Uri(Global.curEvt.URL));
- Resquest.headers.Add("charset", "UTF-8");
-
-
-
-
- Resquest.body = data;
- string RtnStr;
- HttpWebRequest req = signer.Sign(Resquest);
- req.ContentType = "application/json;charset=utf8";
- req.Timeout = 5 * 10000;
- try
- {
- var writer = new StreamWriter(req.GetRequestStream());
- writer.Write(Resquest.body);
- writer.Flush();
- HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
- StreamReader reader = new StreamReader(resp.GetResponseStream());
- RtnStr = reader.ReadToEnd();
- joRtn = JObject.Parse(RtnStr);
- return joRtn;
- }
- catch (WebException e)
- {
- HttpWebResponse resp = (HttpWebResponse)e.Response;
- if (resp != null)
- {
- return JsonHelper.setExceptionJson(-99, "centerServeiceInvok中获得响应流异常(a)", new StreamReader(resp.GetResponseStream()).ReadToEnd() + "异常内容:" + e.Message);
- }
- else
- {
- RtnStr = "异常:" + e.Message;
- return JsonHelper.setExceptionJson(-99, "centerServeiceInvok中获得响应流异常(b)", e.Message);
- }
- }
- }
- catch (Exception ex)
- {
- postContent = "调用中心服务异常" + ex.Message;
- joRtn.Add("infcode", -1);
- joRtn.Add("err_msg", "invokeCenterService(Exception_Last):" + ex.Message);
- return joRtn;
- }
- }
-
-
-
-
- public JObject invokeCenterServicePresCir(string funNO, string data)
- {
- JObject joRtn = new JObject();
- string outPar = "";
- try
- {
- if (funNO == "7101")
- {
- Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/uploadChk";
- }
- else if (funNO == "7102")
- {
- Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxFixmedinsSign";
- }
- else if (funNO == "7103")
- {
- Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxFileUpld";
- }
- else if (funNO == "7104")
- {
- Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxUndo";
- }
- else if (funNO == "7105")
- {
- Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/hospRxDetlQuery";
- }
- else if (funNO == "7106")
- {
- Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxChkInfoQuery";
- }
- else if (funNO == "7107")
- {
- Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxSetlInfoQuery";
- }
- else if (funNO == "7108")
- {
- Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxChkInfoCallback";
- }
- else if (funNO == "7109")
- {
- Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxSetlInfoCallback";
- }
- else if (funNO == "7112")
- {
- Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/circDrugQuery";
- }
- else
- {
- Global.curEvt.URL = Global.inf.centerURL;
- }
-
- joRtn = invokeCenterServicePresCir(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", "invokeCenterServicePresCir(3):" + ex.Message); }
- outPar = JsonHelper.Compress(joRtn);
- return joRtn;
- }
- finally
- {
- Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
-
- }
- }
- #endregion
- #region 门户支付
- public JObject invokePortalPayService(string funNO, string data)
- {
- return invokePortalPayService(funNO, JObject.Parse(data));
- }
- public JObject invokePortalPayService(string funNO, JObject joInput)
- {
- JObject joRtn = new JObject();
- String outPar = "";
- try
- {
- string url = "";
- switch (funNO)
- {
- case "AMP_HOS_001":
- url = "/api/amp/hos/pushMsg";
- break;
- case "AMP_HOS_002":
- url = "/api/amp/hos/refund";
- break;
- case "AMP_HOS_003":
- url = "/api/amp/hos/queryRefundResult";
- break;
- case "AMP_HOS_004":
- url = "/api/amp/hos/getTradeFile";
- break;
- case "AMP_HOS_006":
- url = "/api/amp/hos/queryRevsExpRecord";
- break;
- default:
- break;
- }
- EncryptHelper encrypt = new EncryptHelper(Global.inf.PortalAmp.appid, Global.inf.PortalAmp.secretKey, Global.inf.PortalAmp.privateKey, Global.inf.PortalAmp.publicKey);
- string data = JsonHelper.setPortalPayAmpCenterInpar(funNO, joInput);
-
- Global.curEvt.URL = Global.inf.PortalAmp.url + url;
- try
- {
- joRtn = invokeCenterService(data);
- string encData = JsonHelper.getDestValue(joRtn, "encData");
- string signData = JsonHelper.getDestValue(joRtn, "signData");
- if (!string.IsNullOrEmpty(encData) && !string.IsNullOrEmpty(signData))
- {
- joRtn.Remove("encData");
- joRtn.Remove("signData");
- joRtn.Remove("data");
-
- string decData = encrypt.decrypt(encData);
-
- JsonConvert.DefaultSettings = () => new JsonSerializerSettings
- {
- FloatParseHandling = FloatParseHandling.Decimal
- };
- joRtn.Add("data", JToken.FromObject(JsonConvert.DeserializeObject(decData)));
- bool rtn = encrypt.verify(joRtn, signData);
- if (rtn)
- {
- Global.writeLog("验签通过!");
- }
- else
- {
- Global.writeLog("验签失败,请核查!");
- }
- if (!string.IsNullOrEmpty(decData))
- {
- joRtn = JObject.Parse(decData);
- joRtn.Add("success", "True");
- }
- }
- return joRtn;
- }
- finally
- {
- this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
- }
- }
- 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 + ")", joInput.ToString(), joRtn.ToString());
- this.saveCenterLog(joInput.ToString(), joRtn.ToString(), joInput.ToString(), joRtn.ToString());
- }
- }
- #endregion
- #region 兼容新版调用
-
-
-
-
-
-
- public JObject invokeCenterService(TradeEnum trade, JObject joInput)
- {
- string funNo = trade.GetCode();
-
- JObject request = Utils.ConvertRequest<JObject>(trade, joInput);
- string data = JsonHelper.toJsonString(request);
-
- if (trade.GetMode() == ModeEnum.REST)
- {
- data = JsonHelper.setCenterInpar(funNo, request);
- }
- JObject joRtn = new JObject();
-
- if (Global.curEvt.enabledDebug)
- {
- CenterResult center = new CenterResult();
- center.setTradeNo(trade.GetCode(), data);
- if (center.ShowDialog() == DialogResult.OK)
- {
-
- string outPar = center.returnData;
- joRtn = JObject.Parse(outPar);
- }
- }
- else
- {
- prepareCallURI(trade);
- joRtn = invokeCenterService(data, trade.GetMode());
- }
-
- joRtn = Utils.ConvertResponse<JObject>(trade, joRtn);
- return joRtn;
- }
-
-
-
- private void LoadAPIKey(string prefix)
- {
-
- if (prefix == "MOBILE")
- {
- }
- else
- {
- }
- }
-
-
-
- private void LoadCoreAPIKey()
- {
- LoadAPIKey("KEY");
- }
- private JObject invokeCenterService(string data, ModeEnum mode = ModeEnum.REST)
- {
- JObject joRtn = new JObject();
- try
- {
- IInvokeCenter center = new InvokeCenterFactory().create(mode);
- string outputData = "";
- string errMsg = "";
- int iInt = center.Init(ref errMsg);
- if (iInt == 0)
- {
- LoadCoreAPIKey();
- iInt = center.Business(data, ref outputData, ref errMsg);
- if (iInt == 0 && !string.IsNullOrEmpty(outputData))
- {
- try
- {
- joRtn = JObject.Parse(outputData);
- }
- catch (Exception ex)
- {
- joRtn.Add("infcode", iInt);
- joRtn.Add("err_msg", "返回参数异常:" + outputData);
- }
- }
- else
- {
- joRtn.Add("infcode", iInt);
- joRtn.Add("err_msg", outputData);
- return joRtn;
- }
- return joRtn;
- }
- else
- {
- joRtn.Add("infcode", -1);
- joRtn.Add("err_msg", "医保动态库初始化失败invokeInitByDLL:" + errMsg);
- return joRtn;
- }
- }
- finally
- {
- Global.writeLog(Global.curEvt.URL, JsonHelper.Compress(data), joRtn.ToString());
-
- this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
- }
- }
- private void prepareCallURI(TradeEnum trade)
- {
- string funNo = trade.GetCode();
- Global.curEvt.funNo = funNo;
- if (Global.curEvt.testMode)
- {
-
-
- }
- string prefix = Global.inf.centerURL;
- switch (trade)
- {
- case TradeEnum.FileUpload:
- prefix = Global.inf.uploadURL ?? Global.inf.centerURL;
- break;
- case TradeEnum.FileDownload:
- prefix = Global.inf.centerURL;
- break;
- default:
- prefix = Global.inf.centerURL;
- break;
- }
-
-
- }
-
-
-
-
-
- public JObject DownloadCenterFile(string data, ModeEnum mode = ModeEnum.REST)
- {
-
- IInvokeCenter center = new InvokeCenterFactory().create(mode);
- string outputMsg = "";
- JObject joRtn = new JObject();
- prepareCallURI(TradeEnum.FileDownload);
- int rtnCode = center.DownloadFile(data, ref outputMsg);
- if (rtnCode == 0)
- {
- joRtn = JObject.Parse(outputMsg);
- }
- else
- {
-
- joRtn = JObject.Parse(outputMsg);
- }
- return joRtn;
- }
- #endregion
- }
- }
|