InvokeHelper.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. /******************************************************************************
  2. * 文件名称: InvokeHelper.cs
  3. * 文件说明: 调用助手,调用方法的封装
  4. * 当前版本: V1.0
  5. * 创建日期: 2022-04-12
  6. *
  7. * 2020-04-12: 增加 businessDLLInvoke 方法
  8. * 2020-04-12: 增加 writeLog 方法
  9. * 2020-04-14: 增加 businessDLLInvoke(重载) 方法
  10. * 2020-04-14: 增加 irisServiceInvoke 方法
  11. ******************************************************************************/
  12. using Newtonsoft.Json;
  13. using Newtonsoft.Json.Linq;
  14. using PTMedicalInsurance.Common;
  15. using PTMedicalInsurance.Forms;
  16. using PTMedicalInsurance.Helper;
  17. using PTMedicalInsurance.Variables;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.IO;
  21. using System.Linq;
  22. using System.Net;
  23. using System.Runtime.InteropServices;
  24. using System.Security.Policy;
  25. using System.Text;
  26. using System.Threading.Tasks;
  27. using System.Windows.Forms;
  28. namespace PTMedicalInsurance.Helper
  29. {
  30. class InvokeHelper
  31. {
  32. private string serviceURL;
  33. private string authorization;
  34. //医保动态库
  35. const string DllPath = @"C:\ProgramData\prykNT\prBrowser\bin\service\plugins\INSUNew\InsuDLL\pack\CHSInterfaceYn.dll";
  36. const string IntPath = @"C:\ProgramData\prykNT\prBrowser\bin\service\plugins\INSUNew\InsuDLL\pack"; // \\InsuDLL\\pack\\CHSInterfaceYn.dll
  37. /// <summary>
  38. /// 初始化函数
  39. /// </summary>
  40. /// <param name="fixmedins_code"></param>
  41. /// <param name="infosyscode"></param>
  42. /// <param name="infosyssign"></param>
  43. /// <param name="url"></param>
  44. /// <param name="pErrMsg"></param>
  45. /// <returns></returns>
  46. [DllImport("CHSInterfaceYn.dll", EntryPoint = "Init", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
  47. static extern int Init(string fixmedins_code, string infosyscode, string infosyssign, string url, StringBuilder pErrMsg);
  48. /// <summary>
  49. /// 文件下载函数
  50. /// </summary>
  51. /// <param name="fixmedins_code"></param>
  52. /// <param name="infosyscode"></param>
  53. /// <param name="infosyssign"></param>
  54. /// <param name="inputData"></param>
  55. /// <param name="outputData"></param>
  56. /// <param name="pErrMsg"></param>
  57. /// <returns></returns>
  58. [DllImport("CHSInterfaceYn.dll", EntryPoint = "DownloadFile", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
  59. static extern int DownloadFile(string fixmedins_code, string infosyscode, string infosyssign, string inputData, StringBuilder outputData, StringBuilder pErrMsg);
  60. /// <summary>
  61. /// 文件上传函数
  62. /// </summary>
  63. /// <param name="fixmedins_code"></param>
  64. /// <param name="infosyscode"></param>
  65. /// <param name="infosyssign"></param>
  66. /// <param name="inputData"></param>
  67. /// <param name="outputData"></param>
  68. /// <param name="pErrMsg"></param>
  69. /// <returns></returns>
  70. [DllImport("CHSInterfaceYn.dll", EntryPoint = "UploadFile", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
  71. static extern int UploadFile(string fixmedins_code, string infosyscode, string infosyssign, string fileName,string inputData, StringBuilder outputData, StringBuilder pErrMsg);
  72. /// <summary>
  73. /// 通用业务函数
  74. /// </summary>
  75. /// <param name="fixmedins_code"></param>
  76. /// <param name="infosyscode"></param>
  77. /// <param name="infosyssign"></param>
  78. /// <param name="inputData"></param>
  79. /// <param name="outputData"></param>
  80. /// <param name="errmsg"></param>
  81. /// <returns></returns>
  82. [DllImport("CHSInterfaceYn.dll", EntryPoint = "BusinessHandle", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
  83. static extern int BusinessHandle(string fixmedins_code, string infosyscode, string infosyssign, string inputData, StringBuilder outputData, StringBuilder errmsg);
  84. /// <summary>
  85. /// 通用业务函数
  86. /// </summary>
  87. /// <param name="fixmedins_code"></param>
  88. /// <param name="infosyscode"></param>
  89. /// <param name="infosyssign"></param>
  90. /// <param name="inputData"></param>
  91. /// <param name="outputData"></param>
  92. /// <param name="errmsg"></param>
  93. /// <returns></returns>
  94. [DllImport("CHSInterfaceYn.dll", EntryPoint = "BusinessHandleW", CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
  95. static extern int BusinessHandleW(StringBuilder fixmedins_code, StringBuilder infosyscode, StringBuilder infosyssign, StringBuilder inputData, StringBuilder outputData, StringBuilder errmsg);
  96. /// <summary>
  97. /// iris服务调用的封装
  98. /// </summary>
  99. /// <param name="data"></param>
  100. /// <returns></returns>
  101. public JObject invokeIrisService(string data, string serviceDesc)
  102. {
  103. string rtn = "", url = "";
  104. JObject joRtn = new JObject();
  105. try
  106. {
  107. //先根据用户请求的uri构造请求地址
  108. url = serviceURL;
  109. ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
  110. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
  111. //创建Web访问对象
  112. HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
  113. //把用户传过来的数据转成“UTF-8”的字节流
  114. byte[] buf = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(data);
  115. //添加头部信息
  116. myRequest.Method = "POST";
  117. myRequest.ContentLength = buf.Length;
  118. myRequest.ContentType = "application/json";
  119. myRequest.Headers.Add("Authorization", authorization);
  120. myRequest.MaximumAutomaticRedirections = 1;
  121. myRequest.AllowAutoRedirect = true;
  122. //发送请求
  123. Stream stream = myRequest.GetRequestStream();
  124. stream.Write(buf, 0, buf.Length);
  125. stream.Close();
  126. //获取接口返回值
  127. //通过Web访问对象获取响应内容
  128. HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
  129. //通过响应内容流创建StreamReader对象,因为StreamReader更高级更快
  130. StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
  131. //string rtn = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
  132. rtn = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
  133. reader.Close();
  134. myResponse.Close();
  135. joRtn = JObject.Parse(rtn);
  136. return joRtn;
  137. }
  138. catch (Exception ex)
  139. {
  140. joRtn = JsonHelper.setExceptionJson(-1, serviceDesc, ex.Message);
  141. rtn = JsonConvert.SerializeObject(joRtn);
  142. return joRtn;
  143. }
  144. }
  145. /// <summary>
  146. /// HIS服务调用的封装
  147. /// </summary>
  148. /// <param name="data"></param>
  149. /// <returns></returns>
  150. public JObject invokeHISService(string data, string serviceDesc)
  151. {
  152. JObject joRtn = new JObject();
  153. try
  154. {
  155. //先根据用户请求的uri构造请求地址
  156. serviceURL = string.Format("{0}/{1}", Global.hisConfig.ip, Global.hisConfig.url);
  157. authorization = Global.hisConfig.authorization;
  158. joRtn = invokeIrisService(data, serviceDesc);
  159. return joRtn;
  160. }
  161. catch (Exception ex)
  162. {
  163. joRtn = JsonHelper.setExceptionJson(-1, serviceDesc, ex.Message);
  164. return joRtn;
  165. }
  166. finally
  167. {
  168. Global.writeLog_Iris(serviceDesc + "(" + serviceURL + ")" + "Authorization:" + (authorization), JsonHelper.Compress(data), JsonHelper.Compress(joRtn));
  169. }
  170. }
  171. /// <summary>
  172. /// 医保平台服务调用的封装
  173. /// </summary>
  174. /// <param name="data"></param>
  175. /// <returns></returns>
  176. public JObject invokeInsuService(string data, string serviceDesc)
  177. {
  178. string rtn = "";
  179. JObject joRtn = new JObject();
  180. try
  181. {
  182. //先根据用户请求的uri构造请求地址
  183. serviceURL = string.Format("{0}/{1}", Global.insuConfig.ip, Global.insuConfig.url);
  184. authorization = Global.insuConfig.authorization;
  185. joRtn = invokeIrisService(data, serviceDesc);
  186. rtn = JsonConvert.SerializeObject(joRtn);
  187. //if (serviceDesc == "插入签到信息")
  188. //{
  189. // MessageBox.Show("插入签到信息入参:" + data +"|返回值:"+ rtn.ToString()+"|"+ Global.insuConfig.url);
  190. //}
  191. return joRtn;
  192. }
  193. catch (Exception ex)
  194. {
  195. joRtn = JsonHelper.setExceptionJson(-1, serviceDesc, ex.Message);
  196. rtn = JsonConvert.SerializeObject(joRtn);
  197. return joRtn;
  198. }
  199. finally
  200. {
  201. Global.writeLog_Iris(serviceDesc + "(" + serviceURL + ")" + "Authorization:" + (authorization), JsonHelper.Compress(data), rtn);
  202. }
  203. }
  204. /// <summary>
  205. /// 医保中心Post服务调用封装
  206. /// </summary>
  207. /// <param name="data"></param>
  208. /// <returns></returns>
  209. private JObject invokeCenterService(string data)
  210. {
  211. string postContent = "";
  212. JObject joRtn = new JObject();
  213. try
  214. {
  215. //创建一个HTTP请求
  216. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
  217. //Post请求方式
  218. request.Method = "POST";
  219. string nonce = Guid.NewGuid().ToString(); //非重复的随机字符串(十分钟内不能重复)
  220. string timestamp = TimeStamp.get13().ToString(); //当前时间戳(秒)
  221. string BusinessID = Global.inf.BusinessID; //服务商ID
  222. string InsuHosID = Global.inf.hospitalNO; //医疗机构ID
  223. string CreditID = Global.inf.CreditID; //服务商统一社会信用代码
  224. //内容类型
  225. request.ContentType = "application/json";
  226. //昆明增加头部信息
  227. string sTemp = timestamp + BusinessID + nonce;
  228. //Sha256 加密生成的签名 signature = sha256(hsf_timestamp + infosyssign + hsf_nonce)
  229. string signature = Encrypt.SHA256EncryptStr(sTemp);
  230. request.Headers.Add("hsf_signature", signature);
  231. request.Headers.Add("hsf_timestamp", timestamp);
  232. request.Headers.Add("hsf_nonce", nonce);
  233. request.Headers.Add("fixmedins_code", InsuHosID);
  234. request.Headers.Add("infosyscode", CreditID);
  235. //设置参数,并进行URL编码
  236. string paraUrlCoded = data;//System.Web.HttpUtility.UrlEncode(jsonParas);
  237. byte[] payload;
  238. //将Json字符串转化为字节
  239. payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
  240. //设置请求的ContentLength
  241. request.ContentLength = payload.Length;
  242. //发送请求,获得请求流
  243. Stream writer;
  244. writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
  245. //将请求参数写入流
  246. writer.Write(payload, 0, payload.Length);
  247. writer.Close();//关闭请求流
  248. // String strValue = "";//strValue为http响应所返回的字符流
  249. HttpWebResponse response;
  250. try
  251. {
  252. //获得响应流
  253. response = (HttpWebResponse)request.GetResponse();
  254. }
  255. catch (WebException ex)
  256. {
  257. response = ex.Response as HttpWebResponse;
  258. return JsonHelper.setExceptionJson(-99, "centerServeiceInvok中获得响应流异常", ex.Message);
  259. }
  260. Stream s = response.GetResponseStream();
  261. StreamReader sRead = new StreamReader(s);
  262. postContent = sRead.ReadToEnd();
  263. sRead.Close();
  264. Global.writeLog($"postContent:{postContent}");
  265. joRtn = JObject.Parse(postContent);//返回Json数据
  266. return joRtn;
  267. }
  268. catch (Exception ex)
  269. {
  270. postContent = "调用中心服务异常" + ex.Message;
  271. joRtn.Add("infcode", -1);
  272. joRtn.Add("err_msg", "invokeCenterService(1):" + ex.Message);
  273. return joRtn;
  274. }
  275. }
  276. /// <summary>
  277. /// 调用医保动态库文件下载函数 CM 20220925
  278. /// </summary>
  279. /// <param name="fixmedins_code"></param>
  280. /// <param name="infosyscode"></param>
  281. /// <param name="infosyssign"></param>
  282. /// <param name="inputData"></param>
  283. /// <param name="outputData"></param>
  284. /// <param name="pErrMsg"></param>
  285. /// <returns>0或小于0</returns>
  286. private int invokeDownloadFileByDLL(string fixmedins_code, string infosyscode, string infosyssign, string inputData, ref string outputData, ref string pErrMsg)
  287. {
  288. pErrMsg = "";
  289. outputData = "";
  290. try
  291. {
  292. StringBuilder errmsgSb = new StringBuilder(4096);
  293. StringBuilder outSb = new StringBuilder(40960);
  294. int pRtn = DownloadFile(fixmedins_code, infosyscode, infosyssign, inputData, outSb, errmsgSb);
  295. if (pRtn < 0)
  296. {
  297. pErrMsg = errmsgSb.ToString();
  298. return -1;
  299. }
  300. else
  301. {
  302. outputData = outSb.ToString();
  303. }
  304. return pRtn;
  305. }
  306. catch (Exception ex)
  307. {
  308. pErrMsg = "invokeInitByDLL.DownloadFile 异常:" + ex.Message;
  309. return -1;
  310. }
  311. finally
  312. {
  313. Global.writeLog("invokeInitByDLL.DownloadFile 医保动态库文件下载函数", inputData, outputData);
  314. }
  315. }
  316. /// <summary>
  317. /// 这个是调用业务服务的invokeCenterService
  318. /// </summary>
  319. /// <param name="funNO"></param>
  320. /// <param name="data"></param>
  321. /// <returns></returns>
  322. public JObject invokeCenterService(string funNO, JObject data)
  323. {
  324. JObject joRtn = new JObject();
  325. string outPar = ""; Boolean bDownLoad = false;
  326. int iInt = 0;
  327. try
  328. {
  329. Global.curEvt.URL = Global.inf.centerURL;
  330. if (bDownLoad == false)
  331. {
  332. string outData = "", errMsg = "";
  333. iInt = InvokeInitByDLL(ref errMsg);
  334. if (iInt == 0)
  335. {
  336. iInt = invokeBusiessByDLL(data.ToString(), ref outData, ref errMsg);
  337. joRtn = JObject.Parse(outData);
  338. return joRtn;
  339. }
  340. else
  341. {
  342. joRtn.Add("infcode", -1);
  343. joRtn.Add("err_msg", "医保动态库初始化失败invokeInitByDLL:" + errMsg);
  344. outPar = JsonHelper.Compress(joRtn);
  345. return joRtn;
  346. }
  347. }
  348. else
  349. {
  350. joRtn = invokeCenterService(data.ToString());
  351. outPar = JsonHelper.Compress(joRtn);
  352. return joRtn;
  353. }
  354. }
  355. catch (Exception ex)
  356. {
  357. if (joRtn["infcode"] == null)
  358. { joRtn.Add("infcode", -1); }
  359. if (joRtn["err_msg"] == null)
  360. { joRtn.Add("err_msg", "invokeCenterService(2):" + ex.Message); }
  361. outPar = JsonHelper.Compress(joRtn);
  362. return joRtn;
  363. }
  364. finally
  365. {
  366. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
  367. this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
  368. }
  369. }
  370. public JObject invokeCenterService(TradeEnum trade, JObject joInput)
  371. {
  372. string funNo = trade.GetCode();
  373. // 入参统一转换
  374. JObject request = Utils.ConvertRequest<JObject>(trade, joInput);
  375. string data = JsonHelper.toJsonString(request);
  376. // 统一封装请求头
  377. if (trade.GetMode() == ModeEnum.REST)
  378. {
  379. data = JsonHelper.setCenterInpar(funNo, request);
  380. }
  381. JObject joRtn = new JObject();
  382. // 调试模式
  383. if (Global.curEvt.enabledDebug)
  384. {
  385. CenterResult center = new CenterResult();
  386. center.setTradeNo(trade.GetCode(), data);
  387. if (center.ShowDialog() == DialogResult.OK)
  388. {
  389. // 接口实际返回数据
  390. string outPar = center.returnData;
  391. joRtn = JObject.Parse(outPar);
  392. }
  393. }
  394. else
  395. {
  396. prepareCallURI(trade);
  397. joRtn = invokeCenterService(funNo,data);
  398. }
  399. // 返回结果统一转换
  400. joRtn = Utils.ConvertResponse<JObject>(trade, joRtn);
  401. return joRtn;
  402. }
  403. /// <summary>
  404. /// 这个是下载目录用的invokeCenterService
  405. /// </summary>
  406. /// <param name="funNO"></param>
  407. /// <param name="data"></param>
  408. /// <returns></returns>
  409. public JObject invokeCenterService(string funNO, string data)
  410. {
  411. JObject joRtn = new JObject();
  412. int iInt = 0;
  413. String outPar = ""; Boolean bDownLoad = false;
  414. try
  415. {
  416. Global.curEvt.URL = Global.inf.centerURL ;
  417. List<string> infList = new List<string> { "6201", "6202", "6203", "6301", "6401" };
  418. if (infList.Contains(funNO))
  419. {
  420. Global.writeLog(Global.curEvt.path + @"\CenterServiceURL.ini");
  421. IniFile urlIni = new IniFile(Global.curEvt.path + @"\CenterServiceURL.ini");
  422. Global.curEvt.URL = urlIni.ReadValue("URL", funNO);
  423. Global.inf.centerURL = Global.curEvt.URL;
  424. }
  425. if (funNO != "9101")
  426. {
  427. string outData = "", errMsg = "";
  428. iInt = InvokeInitByDLL(ref errMsg);
  429. if (iInt == 0)
  430. {
  431. int iBusResult = invokeBusiessByDLL(data.ToString(), ref outData, ref errMsg);
  432. if (iBusResult == 0)
  433. {
  434. joRtn = JObject.Parse(outData);
  435. }
  436. else
  437. {
  438. joRtn.Add("infcode", -1);
  439. joRtn.Add("err_msg", errMsg);
  440. }
  441. return joRtn;
  442. }
  443. else
  444. {
  445. joRtn.Add("infcode", -1);
  446. joRtn.Add("err_msg", "医保动态库初始化失败invokeInitByDLL:" + errMsg);
  447. outPar = JsonHelper.Compress(joRtn);
  448. return joRtn;
  449. }
  450. }
  451. else
  452. {
  453. joRtn = invokeCenterService(data);
  454. outPar = JsonHelper.Compress(joRtn);
  455. return joRtn;
  456. }
  457. }
  458. catch (Exception ex)
  459. {
  460. if (joRtn["infcode"] == null)
  461. { joRtn.Add("infcode", -1); }
  462. if (joRtn["err_msg"] == null)
  463. { joRtn.Add("err_msg", "invokeCenterService(3):" + ex.Message); }
  464. outPar = JsonHelper.Compress(joRtn);
  465. return joRtn;
  466. }
  467. finally
  468. {
  469. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
  470. this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
  471. }
  472. }
  473. /// <summary>
  474. /// 移动
  475. /// </summary>
  476. /// <param name="funNO"></param>
  477. /// <param name="data"></param>
  478. /// <returns></returns>
  479. public JObject invokeMPService(string funNO, string data)
  480. {
  481. JObject joRtn = new JObject();
  482. int iInt = 0;
  483. String outPar = ""; Boolean bDownLoad = false;
  484. try
  485. {
  486. //Global.curEvt.URL = Global.inf.centerURL;
  487. //List<string> infList = new List<string> { "6201", "6202", "6203", "6301", "6401" };
  488. //if (infList.Contains(funNO))
  489. //{
  490. // IniFile urlIni = new IniFile(Global.curEvt.path + @"\CenterServiceURL.ini");
  491. // Global.curEvt.URL = urlIni.ReadValue("URL", funNO);
  492. // Global.inf.centerURL = Global.curEvt.URL;
  493. //}
  494. string url = "";
  495. switch (funNO)
  496. {
  497. case "6201":
  498. url = "/org/local/api/hos/uldFeeInfo";
  499. break;
  500. case "6202":
  501. url = "/org/local/api/hos/pay_order";
  502. break;
  503. case "6203":
  504. url = "/org/local/api/hos/refund_Order";
  505. break;
  506. case "6301":
  507. url = "/org/local/api/hos/query_order_info";
  508. break;
  509. case "6401":
  510. url = "/org/local/api/hos/revoke_order";
  511. break;
  512. default:
  513. break;
  514. }
  515. /*
  516. *
  517. * 6201=http://ldjk.yn.hsip.gov.cn/eapdomain/org/local/api/hos/uldFeeInfo
  518. 6202=http://ldjk.yn.hsip.gov.cn/eapdomain/org/local/api/hos/pay_order
  519. 6203=http://ldjk.yn.hsip.gov.cn/eapdomain/org/local/api/hos/refund_Order
  520. 6301=http://ldjk.yn.hsip.gov.cn/eapdomain/org/local/api/hos/query_order_info
  521. 6401=http://ldjk.yn.hsip.gov.cn/eapdomain/org/local/api/hos/revoke_order
  522. */
  523. // 移动支付地址
  524. Global.curEvt.URL = Global.inf.MobilePay.url + url;
  525. Global.inf.centerURL = Global.curEvt.URL;
  526. joRtn = invokeCenterService(data);
  527. outPar = JsonHelper.Compress(joRtn);
  528. return joRtn;
  529. }
  530. catch (Exception ex)
  531. {
  532. if (joRtn["infcode"] == null)
  533. { joRtn.Add("infcode", -1); }
  534. if (joRtn["err_msg"] == null)
  535. { joRtn.Add("err_msg", "invokeCenterService(3):" + ex.Message); }
  536. outPar = JsonHelper.Compress(joRtn);
  537. return joRtn;
  538. }
  539. finally
  540. {
  541. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
  542. this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
  543. }
  544. }
  545. /// <summary>
  546. /// 设置医保动态库目录
  547. /// </summary>
  548. /// <param name="sPath"></param>
  549. /// <param name="pErrMsg"></param>
  550. /// <returns></returns>
  551. private void invokeSetDirByOCX(ref string pErrMsg)
  552. {
  553. try
  554. {
  555. //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();
  556. //InterfaceBase_Yn.SetDir(IntPath);
  557. }
  558. catch (Exception ex)
  559. {
  560. pErrMsg = "invokeInitByDLL.SetDir 异常:" + ex.Message;
  561. MessageBox.Show(pErrMsg);
  562. }
  563. finally
  564. {
  565. Global.writeLog("invokeInitByDLL.SetDir设置医保动态库目录(" + IntPath + ")", "", pErrMsg);
  566. }
  567. }
  568. /// <summary>
  569. /// 医保目录txt文件下载
  570. /// </summary>
  571. /// <param name="data"></param>
  572. /// <returns></returns>
  573. public JObject DownloadCenterFile(string data)
  574. {
  575. string error = string.Empty; int errorCode = 0;
  576. string sRtn = "";
  577. try
  578. {
  579. JObject jsonInParam = JObject.Parse(data);
  580. string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
  581. string filePath = Global.curEvt.path + "\\Download\\" + fileName;
  582. //MessageBox.Show("9102下载文件入参:"+jsonInParam.ToString());
  583. //如果不存在目录,则创建目录
  584. if (!Directory.Exists(Global.curEvt.path + "\\Download"))
  585. {
  586. //创建文件夹
  587. DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\Download");
  588. }
  589. if (File.Exists(filePath))
  590. {
  591. File.Delete(filePath);
  592. }
  593. FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
  594. //创建一个HTTP请求
  595. //Global.curEvt.URL = Global.inf.centerURL + "/hsa-fsi-9102";
  596. Global.curEvt.URL = Global.inf.centerURL;
  597. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
  598. //Post请求方式
  599. request.Method = "POST";
  600. string timestamp = TimeStamp.get13().ToString(); //当前时间戳(秒)
  601. string nonce = Guid.NewGuid().ToString(); //非重复的随机字符串(十分钟内不能重复)
  602. string InsuHosID = Global.inf.hospitalNO; //医疗机构ID
  603. string CreditID = Global.inf.CreditID; //服务商统一社会信用代码
  604. string BusinessID = Global.inf.BusinessID; //服务商ID
  605. //内容类型
  606. request.ContentType = "application/json";
  607. //昆明增加头部信息
  608. string sTemp = timestamp + BusinessID + nonce;
  609. //Sha256 加密生成的签名 signature = sha256(hsf_timestamp + infosyssign + hsf_nonce)
  610. string signature = Encrypt.SHA256EncryptStr(sTemp);
  611. request.Headers.Add("hsf_signature", signature);
  612. request.Headers.Add("hsf_timestamp", timestamp);
  613. request.Headers.Add("hsf_nonce", nonce);
  614. request.Headers.Add("fixmedins_code", InsuHosID);
  615. request.Headers.Add("infosyscode", CreditID);
  616. //设置参数,并进行URL编码
  617. string paraUrlCoded = data;//System.Web.HttpUtility.UrlEncode(jsonParas);
  618. byte[] payload;
  619. //将Json字符串转化为字节
  620. payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
  621. //设置请求的ContentLength
  622. request.ContentLength = payload.Length;
  623. Stream writer;
  624. try
  625. {
  626. writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
  627. }
  628. catch (Exception)
  629. {
  630. writer = null;
  631. errorCode = -100;
  632. error = "连接服务器失败!";
  633. }
  634. //将请求参数写入流
  635. writer.Write(payload, 0, payload.Length);
  636. writer.Close();//关闭请求流
  637. // String strValue = "";//strValue为http响应所返回的字符流
  638. //发送请求并获取相应回应数据
  639. HttpWebResponse response = request.GetResponse() as HttpWebResponse;
  640. //直到request.GetResponse()程序才开始向目标网页发送Post请求
  641. Stream responseStream = response.GetResponseStream();
  642. //创建本地文件写入流
  643. byte[] bArr = new byte[1024];
  644. int iTotalSize = 0;
  645. int size = responseStream.Read(bArr, 0, (int)bArr.Length);
  646. while (size > 0)
  647. {
  648. iTotalSize += size;
  649. fs.Write(bArr, 0, size);
  650. size = responseStream.Read(bArr, 0, (int)bArr.Length);
  651. }
  652. fs.Close();
  653. responseStream.Close();
  654. dynamic joReturn = new JObject();
  655. joReturn.errorCode = errorCode;
  656. joReturn.errorMessage = error;
  657. joReturn.filePath = filePath;
  658. sRtn = joReturn.ToString();
  659. return joReturn;
  660. }
  661. catch (Exception ex)
  662. {
  663. errorCode = -100;
  664. error = ex.Message;
  665. dynamic joReturn = new JObject();
  666. joReturn.errorCode = errorCode;
  667. joReturn.errorMessage = error;
  668. sRtn = joReturn.ToString();
  669. return joReturn;
  670. }
  671. finally
  672. {
  673. Global.writeLog("DownloadCenterFile" +"(" + Global.curEvt.URL + ")", data, sRtn);
  674. }
  675. }
  676. private void prepareCallURI(TradeEnum trade)
  677. {
  678. string funNo = trade.GetCode();
  679. //Global.curEvt.funNo = funNo;
  680. if (Global.curEvt.testMode)
  681. {
  682. // 医保测试环境
  683. //LoadCenterURL(true);
  684. }
  685. string prefix = Global.inf.centerURL;
  686. switch (trade)
  687. {
  688. case TradeEnum.FileUpload:
  689. prefix = Global.inf.uploadURL ?? Global.inf.centerURL;
  690. break;
  691. case TradeEnum.FileDownload:
  692. prefix = Global.inf.centerURL;
  693. break;
  694. default:
  695. prefix = Global.inf.centerURL;
  696. break;
  697. }
  698. // 根据情况确实是否需要加funNo
  699. Global.curEvt.URL = prefix + funNo;
  700. }
  701. /// <summary>
  702. /// 调用医保动态库初始化 CM 20220925
  703. /// </summary>
  704. /// <param name="fixmedins_code"></param>
  705. /// <param name="infosyscode"></param>
  706. /// <param name="infosyssign"></param>
  707. /// <param name="url"></param>
  708. /// <param name="pErrMsg"></param>
  709. /// <returns>0或小于0</returns>
  710. private int invokeInitByOCX(string fixmedins_code, string infosyscode, string infosyssign, string url, ref string pErrMsg)
  711. {
  712. //pErrMsg = "";
  713. JObject joRtn = new JObject();
  714. try
  715. {
  716. //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();
  717. //string pRtn = InterfaceBase_Yn.Init(fixmedins_code, infosyscode, infosyssign, url);
  718. //joRtn = JObject.Parse(pRtn);
  719. if (joRtn["infcode"].ToString() != "0")
  720. {
  721. pErrMsg = joRtn["err_msg"].ToString();
  722. return -1;
  723. }
  724. else
  725. {
  726. return 0;
  727. }
  728. }
  729. catch (Exception ex)
  730. {
  731. pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
  732. return -1;
  733. }
  734. finally
  735. {
  736. Global.writeLog("invokeInitByDLL.Init医保动态库初始化(" + url + ")", "", pErrMsg);
  737. }
  738. }
  739. /// <summary>
  740. /// 调用医保动态库通用业务函数 CM 20220925
  741. /// </summary>
  742. /// <param name="fixmedins_code"></param>
  743. /// <param name="infosyscode"></param>
  744. /// <param name="infosyssign"></param>
  745. /// <param name="inputData"></param>
  746. /// <param name="outputData"></param>
  747. /// <param name="pErrMsg"></param>
  748. /// <returns>0或小于0</returns>
  749. private int invokeBusiessByOCX(string fixmedins_code, string infosyscode, string infosyssign, string inputData, ref string outputData, ref string pErrMsg)
  750. {
  751. pErrMsg = "";
  752. outputData = "";
  753. JObject joRtn = new JObject();
  754. try
  755. {
  756. try
  757. {
  758. //chsinterfaceyn.chsdllClass InterfaceBase_Yn1 = new chsinterfaceyn.chsdllClass();
  759. //InterfaceBase_Yn1.SetDir(IntPath);
  760. }
  761. catch (Exception ex)
  762. {
  763. pErrMsg = "invokeInitByDLL.SetDir 异常:" + ex.Message;
  764. MessageBox.Show(pErrMsg);
  765. }
  766. finally
  767. {
  768. Global.writeLog("invokeInitByDLL.SetDir设置医保动态库目录(" + IntPath + ")", "", pErrMsg);
  769. }
  770. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  771. //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();
  772. //调用业务函数
  773. //string pRtn =InterfaceBase_Yn.BusinessHandleW(fixmedins_code, infosyscode, infosyssign, inputData);
  774. //string pRtn = InterfaceBase_Yn.UploadFile(fixmedins_code, infosyscode, infosyssign, Global.inf.fileName,inputData);
  775. //joRtn = JObject.Parse(pRtn);
  776. if (joRtn["infcode"].ToString() != "0")
  777. {
  778. pErrMsg = joRtn["err_msg"].ToString();
  779. //outputData = pRtn;
  780. return -1;
  781. }
  782. else
  783. {
  784. //outputData = pRtn;
  785. return 0;
  786. }
  787. }
  788. catch (Exception ex)
  789. {
  790. pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
  791. return -1;
  792. }
  793. finally
  794. {
  795. Global.writeLog("invokeInitByDLL.BusinessHandle医保动态库通用业务函数", inputData, outputData);
  796. }
  797. }
  798. /// <summary>
  799. /// 医保动态库下载目录文件
  800. /// </summary>
  801. /// <param name="data"></param>
  802. /// <returns></returns>
  803. public JObject DownloadCenterFileByDll(string data)
  804. {
  805. string error = string.Empty; int errorCode = 0;
  806. string sRtn = "";
  807. try
  808. {
  809. JObject jsonInParam = JObject.Parse(data);
  810. string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
  811. string filePath = Global.curEvt.path + "\\Download\\" + fileName;
  812. //如果不存在目录,则创建目录
  813. if (!Directory.Exists(Global.curEvt.path + "\\Download"))
  814. {
  815. //创建文件夹
  816. DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\Download");
  817. }
  818. if (File.Exists(filePath))
  819. {
  820. File.Delete(filePath);
  821. }
  822. FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
  823. //创建一个HTTP请求
  824. //Global.curEvt.URL = Global.inf.centerURL + "/hsa-fsi-9102";
  825. Global.curEvt.URL = Global.inf.centerURL;
  826. int iRes = invokeDownloadFileByDLL(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, data.ToString(),ref sRtn, ref error);
  827. if (iRes == 0)
  828. {
  829. dynamic joReturn = new JObject();
  830. joReturn.errorCode = errorCode;
  831. joReturn.errorMessage = error;
  832. joReturn.filePath = filePath;
  833. sRtn = joReturn.ToString();
  834. return joReturn;
  835. }
  836. else
  837. {
  838. errorCode = -100;
  839. dynamic joReturn = new JObject();
  840. joReturn.errorCode = errorCode;
  841. joReturn.errorMessage = error;
  842. sRtn = joReturn.ToString();
  843. return joReturn;
  844. }
  845. }
  846. catch (Exception ex)
  847. {
  848. errorCode = -100;
  849. error = ex.Message;
  850. dynamic joReturn = new JObject();
  851. joReturn.errorCode = errorCode;
  852. joReturn.errorMessage = error;
  853. sRtn = joReturn.ToString();
  854. return joReturn;
  855. }
  856. finally
  857. {
  858. Global.writeLog("DownloadCenterFile" + "(" + Global.curEvt.URL + ")", data, sRtn);
  859. }
  860. }
  861. /// <summary>
  862. /// 保存中心交易日志到数据库
  863. /// </summary>
  864. /// <param name="inParam"></param>
  865. /// <param name="outParam"></param>
  866. /// <param name="inParamPlain"></param>
  867. /// <param name="outParamPlain"></param>
  868. private void saveCenterLog(string inParam, string outParam, string inParamPlain, string outParamPlain)
  869. {
  870. dynamic joIris = new JObject();
  871. string sRtn = "";
  872. try
  873. {
  874. //解析postContent,插入医保交易日志表
  875. JObject joIn = new JObject(JObject.Parse(inParam));
  876. JObject joOut = new JObject(JObject.Parse(outParam));
  877. JObject joInPlain = new JObject(JObject.Parse(inParamPlain));
  878. JObject joOutPlain = new JObject(JObject.Parse(outParamPlain));
  879. JArray jaParams = new JArray();
  880. JObject joParam = new JObject();
  881. joParam.Add("inParam", JObject.FromObject(joIn));
  882. joParam.Add("outParam", JObject.FromObject(joOut));
  883. joParam.Add("inParamPlain", JObject.FromObject(joInPlain));
  884. joParam.Add("outParamPlain", JObject.FromObject(joOutPlain));
  885. joParam.Add("HospitalDr", Global.inf.hospitalDr);
  886. joParam.Add("InterfaceDr", Global.inf.interfaceDr);
  887. joParam.Add("updateUserID", Global.user.ID);
  888. joParam.Add("psn_no", Global.pat.psn_no);
  889. jaParams.Add(joParam);
  890. joIris.code = "09010021";
  891. joIris.Add("params", jaParams);
  892. //InvokeHelper invoker = new InvokeHelper();
  893. sRtn = invokeInsuService(joIris.ToString(), "保存日志到数据库").ToString();
  894. }
  895. catch (Exception ex)
  896. {
  897. sRtn = JsonHelper.setExceptionJson(-100, "保存日志异常", ex.Message).ToString();
  898. Global.writeLog_Iris("保存日志异常:" + sRtn.ToString());
  899. }
  900. }
  901. /**********************************************************调用DLL方式**************************************************************/
  902. public int InvokeInitByDLL(ref string pErrMsg)
  903. {
  904. //string pErrMsg = "";
  905. int pRtn =-1;
  906. JObject joRtn = new JObject();
  907. try
  908. {
  909. StringBuilder outSb = new StringBuilder(40960);
  910. pRtn = Init(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, Global.inf.centerURL, outSb);
  911. if (pRtn != 0)
  912. {
  913. pErrMsg = outSb.ToString();
  914. return -1;
  915. }
  916. else
  917. {
  918. return 0;
  919. }
  920. }
  921. catch (Exception ex)
  922. {
  923. pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
  924. return -1;
  925. }
  926. finally
  927. {
  928. Global.writeLog("InvokeInitByDLL(" + Global.inf.centerURL + ")", Global.inf.CreditID +":" + Global.inf.BusinessID,pRtn.ToString() + pErrMsg);
  929. }
  930. }
  931. private int invokeBusiessByDLL(string inputData, ref string outputData, ref string pErrMsg)
  932. {
  933. pErrMsg = "";
  934. outputData = "";
  935. int pRtn = -1;
  936. JObject joRtn = new JObject();
  937. try
  938. {
  939. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  940. StringBuilder errmsgSb = new StringBuilder(4096);
  941. StringBuilder outSb = new StringBuilder(40960);
  942. //调用业务函数
  943. pRtn = BusinessHandle(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, inputData, outSb, errmsgSb);
  944. if (pRtn != 0)
  945. {
  946. outputData = outSb.ToString();
  947. pErrMsg = errmsgSb.ToString();
  948. return -1;
  949. }
  950. else
  951. {
  952. outputData = outSb.ToString();
  953. return 0;
  954. }
  955. }
  956. catch (Exception ex)
  957. {
  958. pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
  959. return -1;
  960. }
  961. finally
  962. {
  963. Global.writeLog("CreditID11", Global.inf.CreditID, Global.inf.BusinessID);
  964. Global.writeLog($"invokeInitByDLL.BusinessHandle医保动态库通用业务函数({pRtn})", inputData, outputData + "------华丽分割线-------" + pErrMsg);
  965. }
  966. }
  967. private int invokeBusiessWByDLL(string inputData, ref string outputData, ref string pErrMsg)
  968. {
  969. pErrMsg = "";
  970. outputData = "";
  971. JObject joRtn = new JObject();
  972. try
  973. {
  974. //inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  975. StringBuilder errmsgSb = new StringBuilder(4096);
  976. StringBuilder outSb = new StringBuilder(40960);
  977. StringBuilder sbHospitalNO = new StringBuilder(Global.inf.hospitalNO);
  978. StringBuilder sbCreditID = new StringBuilder(Global.inf.CreditID);
  979. StringBuilder sbBusinessID = new StringBuilder(Global.inf.BusinessID);
  980. StringBuilder sbInput = new StringBuilder(inputData);
  981. //调用业务函数
  982. int pRtn = BusinessHandleW(sbHospitalNO, sbCreditID, sbBusinessID, sbInput, outSb, errmsgSb);
  983. if (pRtn != 0)
  984. {
  985. outputData = outSb.ToString();
  986. pErrMsg = errmsgSb.ToString();
  987. return -1;
  988. }
  989. else
  990. {
  991. outputData = outSb.ToString();
  992. return 0;
  993. }
  994. }
  995. catch (Exception ex)
  996. {
  997. pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
  998. return -1;
  999. }
  1000. finally
  1001. {
  1002. Global.writeLog("CreditID12", Global.inf.CreditID, Global.inf.BusinessID);
  1003. Global.writeLog("invokeInitByDLL.BusinessHandleW医保动态库通用业务函数", inputData, outputData);
  1004. }
  1005. }
  1006. private int invokeUploadFileByDLL(string inputData, ref string outputData, ref string pErrMsg)
  1007. {
  1008. pErrMsg = "";
  1009. outputData = "";
  1010. JObject joRtn = new JObject();
  1011. try
  1012. {
  1013. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  1014. StringBuilder errmsgSb = new StringBuilder(4096);
  1015. StringBuilder outSb = new StringBuilder(40960);
  1016. //调用业务函数
  1017. int pRtn = UploadFile(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, Global.inf.fileName,inputData, outSb, errmsgSb);
  1018. if (pRtn != 0)
  1019. {
  1020. outputData = outSb.ToString();
  1021. pErrMsg = errmsgSb.ToString();
  1022. return -1;
  1023. }
  1024. else
  1025. {
  1026. outputData = outSb.ToString();
  1027. return 0;
  1028. }
  1029. }
  1030. catch (Exception ex)
  1031. {
  1032. pErrMsg = "invokeUploadFileByDLL.UploadFile 异常:" + ex.Message;
  1033. return -1;
  1034. }
  1035. finally
  1036. {
  1037. Global.writeLog("invokeUploadFileByDLL.UploadFile医保动态库上传业务函数", inputData, outputData);
  1038. }
  1039. }
  1040. #region 电子处方
  1041. /// </summary>
  1042. /// <param name="funNO"></param>
  1043. /// <param name="data"></param>
  1044. /// <returns></returns>
  1045. public JObject invokeEPCenterService(string funNO, string data)
  1046. {
  1047. JObject joRtn = new JObject();
  1048. string outPar = "";
  1049. try
  1050. {
  1051. Global.curEvt.URL = Global.inf.ecPrescURL;
  1052. switch (funNO)
  1053. {
  1054. case "7101":
  1055. {
  1056. Global.curEvt.URL = Global.curEvt.URL + "/fixmedins/uploadChk";
  1057. break;
  1058. }
  1059. case "7102":
  1060. {
  1061. Global.curEvt.URL = Global.curEvt.URL + "/fixmedins/rxFixmedinsSign";
  1062. break;
  1063. }
  1064. case "7103":
  1065. {
  1066. Global.curEvt.URL = Global.curEvt.URL + "/fixmedins/rxFileUpld";
  1067. break;
  1068. }
  1069. case "7104":
  1070. {
  1071. Global.curEvt.URL = Global.curEvt.URL + "/fixmedins/rxUndo";
  1072. break;
  1073. }
  1074. case "7105":
  1075. {
  1076. Global.curEvt.URL = Global.curEvt.URL + "/fixmedins/hospRxDetlQuery";
  1077. break;
  1078. }
  1079. case "7106":
  1080. {
  1081. Global.curEvt.URL = Global.curEvt.URL + "/fixmedins/rxChkInfoQuery";
  1082. break;
  1083. }
  1084. case "7107":
  1085. {
  1086. Global.curEvt.URL = Global.curEvt.URL + "/fixmedins/rxSetlInfoQuery";
  1087. break;
  1088. }
  1089. case "7108":
  1090. {
  1091. Global.curEvt.URL = Global.curEvt.URL + "/fixmedins/rxChkInfoCallback";
  1092. break;
  1093. }
  1094. case "7109":
  1095. {
  1096. Global.curEvt.URL = Global.curEvt.URL + "/fixmedins/rxSetlInfoCallback";
  1097. break;
  1098. }
  1099. }
  1100. //Global.curEvt.URL = Global.inf.centerURL;
  1101. joRtn = invokeEPCenterService(data);
  1102. outPar = JsonHelper.Compress(joRtn);
  1103. return joRtn;
  1104. }
  1105. catch (Exception ex)
  1106. {
  1107. if (joRtn["infcode"] == null)
  1108. { joRtn.Add("infcode", -1); }
  1109. if (joRtn["err_msg"] == null)
  1110. { joRtn.Add("err_msg", "invokeCenterServicePresCir(3):" + ex.Message); }
  1111. outPar = JsonHelper.Compress(joRtn);
  1112. return joRtn;
  1113. }
  1114. finally
  1115. {
  1116. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
  1117. //this.saveCenterLog(JsonHelper.Compress(data), outPar, JsonHelper.Compress(data), outPar);
  1118. }
  1119. }
  1120. /// <summary>
  1121. /// 医保电子处方流转调用服务
  1122. /// </summary>
  1123. /// <param name="data"></param>
  1124. /// <returns></returns>
  1125. private JObject invokeEPCenterService(string data)
  1126. {
  1127. string postContent = "";
  1128. JObject joRtn = new JObject();
  1129. try
  1130. {
  1131. string timestamp = TimeStamp.get13().ToString(); //当前时间戳(秒)
  1132. string nonce = Guid.NewGuid().ToString(); //非重复的随机字符串(十分钟内不能重复)
  1133. //内容类型
  1134. //Signer signer = new Signer();
  1135. //signer.Key = Global.inf.privateKey; //应用编码
  1136. //signer.Secret = Global.inf.secretKey; //secretKey 私钥
  1137. //HttpRequest Resquest = new HttpRequest("POST", new Uri(Global.curEvt.URL));
  1138. //Resquest.headers.Add("charset", "UTF-8");
  1139. //Resquest.headers.Add("x-hw-id", signer.Key);
  1140. //Resquest.headers.Add("x-tif-timestamp", timestamp);
  1141. //Resquest.headers.Add("x-tif-passid", signer.Key);
  1142. //Resquest.headers.Add("x-tif-nonce", nonce);
  1143. //Resquest.body = signData;
  1144. //HttpWebRequest req = signer.Sign(Resquest);
  1145. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
  1146. req.Method = "POST";
  1147. req.ContentType = "application/json;charset=utf8";
  1148. req.Timeout = 5 * 10000;
  1149. try
  1150. {
  1151. var writer = new StreamWriter(req.GetRequestStream());
  1152. writer.Write(data);
  1153. writer.Flush();
  1154. HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
  1155. StreamReader reader = new StreamReader(resp.GetResponseStream());
  1156. string RtnStr = reader.ReadToEnd();
  1157. joRtn = JObject.Parse(RtnStr);
  1158. // 解密返回值
  1159. EncryptHelper encrypt = new EncryptHelper(Global.inf.appId, Global.inf.secretKey, Global.inf.publicKey, Global.inf.privateKey);
  1160. string encData = JsonHelper.getDestValue(joRtn, "encData");
  1161. string signData = JsonHelper.getDestValue(joRtn, "signData");
  1162. Global.writeLog("【密文出参】:\r\n" + RtnStr);
  1163. if (!string.IsNullOrEmpty(encData) && !string.IsNullOrEmpty(signData))
  1164. {
  1165. joRtn.Remove("encData");
  1166. joRtn.Remove("signData");
  1167. joRtn.Remove("data");
  1168. //解密
  1169. string decData = encrypt.decrypt(encData);
  1170. // 验签
  1171. JsonConvert.DefaultSettings = () => new JsonSerializerSettings
  1172. {
  1173. FloatParseHandling = FloatParseHandling.Decimal
  1174. };
  1175. joRtn.Add("data", JToken.FromObject(JsonConvert.DeserializeObject(decData)));
  1176. bool rtn = encrypt.verify(joRtn, signData);
  1177. if (rtn)
  1178. {
  1179. Global.writeLog("【明文出参】:\r\n" + decData);
  1180. joRtn = JObject.Parse(decData);
  1181. joRtn.Add("code", 0);
  1182. joRtn.Add("message", "成功");
  1183. }
  1184. else
  1185. {
  1186. Global.writeLog("验签失败,请核查!");
  1187. }
  1188. }
  1189. return joRtn;
  1190. }
  1191. catch (WebException e)
  1192. {
  1193. HttpWebResponse resp = (HttpWebResponse)e.Response;
  1194. if (resp != null)
  1195. {
  1196. return JsonHelper.setExceptionJson(-99, "centerServeiceInvok中获得响应流异常(a)", new StreamReader(resp.GetResponseStream()).ReadToEnd() + "异常内容:" + e.Message);
  1197. }
  1198. else
  1199. {
  1200. return JsonHelper.setExceptionJson(-99, "centerServeiceInvok中获得响应流异常(b)", e.Message);
  1201. }
  1202. }
  1203. }
  1204. catch (Exception ex)
  1205. {
  1206. postContent = "调用中心服务异常" + ex.Message;
  1207. joRtn.Add("infcode", -1);
  1208. joRtn.Add("err_msg", "invokeCenterService(Exception_Last):" + ex.Message);
  1209. return joRtn;
  1210. }
  1211. }
  1212. #endregion
  1213. }
  1214. }