InvokeHelper.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  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.Linq;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Net;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows.Forms;
  21. using PTMedicalInsurance.Helper;
  22. using Newtonsoft.Json;
  23. using PTMedicalInsurance.Common;
  24. using PTMedicalInsurance.Variables;
  25. using System.Runtime.InteropServices;
  26. using AnHuiMI.Forms;
  27. using AnHuiMI.Common;
  28. using static System.Net.WebRequestMethods;
  29. using File = System.IO.File;
  30. using GMCrypto.Lib;
  31. namespace PTMedicalInsurance.Helper
  32. {
  33. public class InvokeHelper
  34. {
  35. private string serviceURL;
  36. private string authorization;
  37. ComputerInfo comp = new ComputerInfo();
  38. /// <summary>
  39. /// 初始化函数
  40. /// </summary>
  41. /// <param name="fixmedins_code"></param>
  42. /// <param name="infosyscode"></param>
  43. /// <param name="infosyssign"></param>
  44. /// <param name="url"></param>
  45. /// <param name="pErrMsg"></param>
  46. /// <returns></returns>
  47. [DllImport("CHSInterface.dll", EntryPoint = "Init", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
  48. static extern int Init(string fixmedins_code, string infosyscode, string infosyssign, string url, StringBuilder pErrMsg);
  49. /// <summary>
  50. /// 文件下载函数
  51. /// </summary>
  52. /// <param name="fixmedins_code"></param>
  53. /// <param name="infosyscode"></param>
  54. /// <param name="infosyssign"></param>
  55. /// <param name="inputData"></param>
  56. /// <param name="outputData"></param>
  57. /// <param name="pErrMsg"></param>
  58. /// <returns></returns>
  59. [DllImport("CHSInterface.dll", EntryPoint = "DownloadFile", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
  60. static extern int DownloadFile(string fixmedins_code, string infosyscode, string infosyssign, string inputData, StringBuilder outputData, StringBuilder pErrMsg);
  61. /// <summary>
  62. /// 文件上传函数
  63. /// </summary>
  64. /// <param name="fixmedins_code"></param>
  65. /// <param name="infosyscode"></param>
  66. /// <param name="infosyssign"></param>
  67. /// <param name="inputData"></param>
  68. /// <param name="outputData"></param>
  69. /// <param name="pErrMsg"></param>
  70. /// <returns></returns>
  71. [DllImport("CHSInterface.dll", EntryPoint = "UploadFile", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
  72. static extern int UploadFile(string fixmedins_code, string infosyscode, string infosyssign, string fileName,string inputData, StringBuilder outputData, StringBuilder pErrMsg);
  73. /// <summary>
  74. /// 通用业务函数
  75. /// </summary>
  76. /// <param name="fixmedins_code"></param>
  77. /// <param name="infosyscode"></param>
  78. /// <param name="infosyssign"></param>
  79. /// <param name="inputData"></param>
  80. /// <param name="outputData"></param>
  81. /// <param name="errmsg"></param>
  82. /// <returns></returns>
  83. [DllImport("CHSInterface.dll", EntryPoint = "BusinessHandle", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
  84. static extern int BusinessHandle(string fixmedins_code, string infosyscode, string infosyssign, string inputData, StringBuilder outputData, StringBuilder errmsg);
  85. /// <summary>
  86. /// 通用业务函数
  87. /// </summary>
  88. /// <param name="fixmedins_code"></param>
  89. /// <param name="infosyscode"></param>
  90. /// <param name="infosyssign"></param>
  91. /// <param name="inputData"></param>
  92. /// <param name="outputData"></param>
  93. /// <param name="errmsg"></param>
  94. /// <returns></returns>
  95. [DllImport("CHSInterface.dll", EntryPoint = "BusinessHandleW", CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] //, ExactSpelling = false, CallingConvention = CallingConvention.StdCall
  96. static extern int BusinessHandleW(StringBuilder fixmedins_code, StringBuilder infosyscode, StringBuilder infosyssign, StringBuilder inputData, StringBuilder outputData, StringBuilder errmsg);
  97. public InvokeHelper()
  98. {
  99. LoadCenterURL(false);
  100. }
  101. private void LoadCenterURL(bool reload)
  102. {
  103. IniFile ini = new IniFile(Global.curEvt.path + @"\CenterServiceURL.ini");
  104. Global.inf.uploadURL = tools.getDestPosStrBySpliter(Global.inf.centerURL2, 1);
  105. Global.inf.downURL = tools.getDestPosStrBySpliter(Global.inf.centerURL2, 2);
  106. Global.inf.ecURL = tools.getDestPosStrBySpliter(Global.inf.centerURL2, 3);
  107. if (reload)
  108. {
  109. Global.inf.mobilePayURL = ini.ReadValue("CENTER", "mobilePay");
  110. Global.inf.ecPrescURL = ini.ReadValue("CENTER", "prescription");
  111. // 移动支付
  112. if (string.IsNullOrEmpty(Global.inf.mobilePayURL))
  113. {
  114. Global.inf.mobilePayURL = "http://10.66.159.55:7080";
  115. }
  116. // 电子处方
  117. if (string.IsNullOrEmpty(Global.inf.ecPrescURL))
  118. {
  119. Global.inf.ecPrescURL = "http://10.123.185.12:8080/epc/api";
  120. }
  121. }
  122. }
  123. #region iris
  124. /// <summary>
  125. /// iris服务调用的封装
  126. /// </summary>
  127. /// <param name="data"></param>
  128. /// <returns></returns>
  129. public JObject invokeIrisService(string data, string serviceDesc)
  130. {
  131. string rtn = "", url = "";
  132. JObject joRtn = new JObject();
  133. try
  134. {
  135. //先根据用户请求的uri构造请求地址
  136. url = serviceURL;
  137. ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
  138. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
  139. //创建Web访问对象
  140. HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
  141. //把用户传过来的数据转成“UTF-8”的字节流
  142. byte[] buf = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(data);
  143. //添加头部信息
  144. myRequest.Method = "POST";
  145. myRequest.ContentLength = buf.Length;
  146. myRequest.ContentType = "application/json";
  147. myRequest.Headers.Add("Authorization", authorization);
  148. myRequest.MaximumAutomaticRedirections = 1;
  149. myRequest.AllowAutoRedirect = true;
  150. //发送请求
  151. Stream stream = myRequest.GetRequestStream();
  152. stream.Write(buf, 0, buf.Length);
  153. stream.Close();
  154. //获取接口返回值
  155. //通过Web访问对象获取响应内容
  156. HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
  157. rtn = getResponseData(myResponse);
  158. joRtn = JObject.Parse(rtn);
  159. return joRtn;
  160. }
  161. catch (Exception ex)
  162. {
  163. joRtn = JsonHelper.setExceptionJson(-1, serviceDesc, ex.Message);
  164. rtn = JsonConvert.SerializeObject(joRtn);
  165. return joRtn;
  166. }
  167. }
  168. /// <summary>
  169. /// HIS服务调用的封装
  170. /// </summary>
  171. /// <param name="data"></param>
  172. /// <returns></returns>
  173. ///
  174. public JObject invokeHISService(string data, string serviceDesc)
  175. {
  176. JObject joRtn = new JObject();
  177. try
  178. {
  179. //先根据用户请求的uri构造请求地址
  180. serviceURL = string.Format("{0}/{1}", Global.hisConfig.ip, Global.hisConfig.url);
  181. authorization = Global.hisConfig.authorization;
  182. joRtn = invokeIrisService(data, serviceDesc);
  183. return joRtn;
  184. }
  185. catch (Exception ex)
  186. {
  187. joRtn = JsonHelper.setExceptionJson(-1, serviceDesc, ex.Message);
  188. return joRtn;
  189. }
  190. finally
  191. {
  192. Global.writeLog_Iris(serviceDesc + "(" + serviceURL + ")" + "Authorization:" + (authorization), JsonHelper.Compress(data), JsonHelper.Compress(joRtn));
  193. }
  194. }
  195. /// <summary>
  196. /// 医保平台服务调用的封装
  197. /// </summary>
  198. /// <param name="data"></param>
  199. /// <returns></returns>
  200. public JObject invokeInsuService(string data, string serviceDesc)
  201. {
  202. string rtn = "";
  203. JObject joRtn = new JObject();
  204. try
  205. {
  206. //先根据用户请求的uri构造请求地址
  207. serviceURL = string.Format("{0}/{1}", Global.insuConfig.ip, Global.insuConfig.url);
  208. authorization = Global.insuConfig.authorization;
  209. joRtn = invokeIrisService(data, serviceDesc);
  210. rtn = JsonConvert.SerializeObject(joRtn);
  211. //if (serviceDesc == "插入签到信息")
  212. //{
  213. // MessageBox.Show("插入签到信息入参:" + data +"|返回值:"+ rtn.ToString()+"|"+ Global.insuConfig.url);
  214. //}
  215. return joRtn;
  216. }
  217. catch (Exception ex)
  218. {
  219. joRtn = JsonHelper.setExceptionJson(-1, serviceDesc, ex.Message);
  220. rtn = JsonConvert.SerializeObject(joRtn);
  221. return joRtn;
  222. }
  223. finally
  224. {
  225. Global.writeLog_Iris(serviceDesc + "(" + serviceURL + ")" + "Authorization:" + (authorization), JsonHelper.Compress(data), rtn);
  226. }
  227. }
  228. #endregion
  229. #region 医保核心业务
  230. /// <summary>
  231. /// 医保中心Post服务调用封装
  232. /// </summary>
  233. /// <param name="data"></param>
  234. /// <returns></returns>
  235. private JObject invokeCenterService(string data)
  236. {
  237. string postContent = "";
  238. JObject joRtn = new JObject();
  239. try
  240. {
  241. //Global.writeLog(string.Format("调用中心{0}接口入参:{1}",data, Global.curEvt.URL));
  242. //创建一个HTTP请求
  243. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
  244. //Post请求方式
  245. request.Method = "POST";
  246. //string nonce = Guid.NewGuid().ToString(); //非重复的随机字符串(十分钟内不能重复)
  247. //string timestamp = TimeStamp.get13().ToString(); //当前时间戳(秒)
  248. //string BusinessID = Global.inf.BusinessID; //服务商ID
  249. //string InsuHosID = Global.inf.hospitalNO; //医疗机构ID
  250. //string CreditID = Global.inf.CreditID; //服务商统一社会信用代码
  251. //内容类型
  252. request.ContentType = "application/json;charset=UTF-8";
  253. //昆明增加头部信息
  254. //string sTemp = timestamp + BusinessID + nonce;
  255. //Sha256 加密生成的签名 signature = sha256(hsf_timestamp + infosyssign + hsf_nonce)
  256. //string signature = Encrypt.SHA256EncryptStr(sTemp);
  257. //request.Headers.Add("hsf_signature", signature);
  258. //request.Headers.Add("hsf_timestamp", timestamp);
  259. //request.Headers.Add("hsf_nonce", nonce);
  260. //request.Headers.Add("fixmedins_code", InsuHosID);
  261. //request.Headers.Add("infosyscode", CreditID);
  262. //设置参数,并进行URL编码
  263. string paraUrlCoded = data;//System.Web.HttpUtility.UrlEncode(jsonParas);
  264. byte[] payload;
  265. //将Json字符串转化为字节
  266. payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
  267. //设置请求的ContentLength
  268. request.ContentLength = payload.Length;
  269. //发送请求,获得请求流
  270. Stream writer;
  271. writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
  272. //将请求参数写入流
  273. writer.Write(payload, 0, payload.Length);
  274. writer.Close();//关闭请求流
  275. // String strValue = "";//strValue为http响应所返回的字符流
  276. HttpWebResponse response = null;
  277. try
  278. {
  279. //获得响应流
  280. response = (HttpWebResponse)request.GetResponse();
  281. }
  282. catch (WebException ex)
  283. {
  284. // return JsonHelper.setExceptionJson(-99, "centerServeiceInvok中获得响应流异常", ex.Message);
  285. HttpWebResponse res = (HttpWebResponse)ex.Response;
  286. Stream myResponseStream = res.GetResponseStream();
  287. StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
  288. string retString = myStreamReader.ReadToEnd();
  289. return JsonHelper.setExceptionJson(-99, "获得响应流异常", retString);
  290. }
  291. postContent = getResponseData(response);
  292. joRtn = JObject.Parse(postContent);//返回Json数据
  293. if (joRtn.ContainsKey("body"))
  294. {
  295. joRtn = (JObject)joRtn.GetValue("body");
  296. }
  297. return joRtn;
  298. }
  299. catch (Exception ex)
  300. {
  301. postContent = "调用中心服务异常" + ex.Message;
  302. joRtn.Add("infcode", -1);
  303. joRtn.Add("err_msg", "invokeCenterService(1):" + ex.Message);
  304. return joRtn;
  305. }
  306. }
  307. /// <summary>
  308. /// 医保中心慢特病Post服务调用封装
  309. /// </summary>
  310. /// <param name="data"></param>
  311. /// <returns></returns>
  312. private JObject invokeCenterServiceMB(string data)
  313. {
  314. string postContent = "";
  315. JObject joRtn = new JObject();
  316. try
  317. {
  318. //Global.writeLog(string.Format("调用中心{0}接口入参:{1}",data, Global.curEvt.URL));
  319. //创建一个HTTP请求
  320. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
  321. //Post请求方式
  322. request.Method = "POST";
  323. //string nonce = Guid.NewGuid().ToString(); //非重复的随机字符串(十分钟内不能重复)
  324. //string timestamp = TimeStamp.get13().ToString(); //当前时间戳(秒)
  325. //string BusinessID = Global.inf.BusinessID; //服务商ID
  326. //string InsuHosID = Global.inf.hospitalNO; //医疗机构ID
  327. //string CreditID = Global.inf.CreditID; //服务商统一社会信用代码
  328. //内容类型
  329. request.ContentType = "application/json;charset=UTF-8";
  330. //昆明增加头部信息
  331. //string sTemp = timestamp + BusinessID + nonce;
  332. //Sha256 加密生成的签名 signature = sha256(hsf_timestamp + infosyssign + hsf_nonce)
  333. //string signature = Encrypt.SHA256EncryptStr(sTemp);
  334. //request.Headers.Add("hsf_signature", signature);
  335. //request.Headers.Add("hsf_timestamp", timestamp);
  336. //request.Headers.Add("hsf_nonce", nonce);
  337. //request.Headers.Add("fixmedins_code", InsuHosID);
  338. //request.Headers.Add("infosyscode", CreditID);
  339. //设置参数,并进行URL编码
  340. string paraUrlCoded = data;//System.Web.HttpUtility.UrlEncode(jsonParas);
  341. byte[] payload;
  342. //将Json字符串转化为字节
  343. payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
  344. //设置请求的ContentLength
  345. request.ContentLength = payload.Length;
  346. //发送请求,获得请求流
  347. Stream writer;
  348. writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
  349. //将请求参数写入流
  350. writer.Write(payload, 0, payload.Length);
  351. writer.Close();//关闭请求流
  352. // String strValue = "";//strValue为http响应所返回的字符流
  353. HttpWebResponse response = null;
  354. try
  355. {
  356. //获得响应流
  357. response = (HttpWebResponse)request.GetResponse();
  358. }
  359. catch (WebException ex)
  360. {
  361. // return JsonHelper.setExceptionJson(-99, "centerServeiceInvok中获得响应流异常", ex.Message);
  362. HttpWebResponse res = (HttpWebResponse)ex.Response;
  363. Stream myResponseStream = res.GetResponseStream();
  364. StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
  365. string retString = myStreamReader.ReadToEnd();
  366. return JsonHelper.setExceptionJson(-99, "获得响应流异常", retString);
  367. }
  368. postContent =SMUtil.AESDecrypt(getResponseData(response), Global.inf.MBkey); //解密后转换Json
  369. joRtn = JObject.Parse(postContent);//返回Json数据
  370. if (joRtn.ContainsKey("body"))
  371. {
  372. joRtn = (JObject)joRtn.GetValue("body");
  373. }
  374. return joRtn;
  375. }
  376. catch (Exception ex)
  377. {
  378. postContent = "调用中心服务异常" + ex.Message;
  379. joRtn.Add("infcode", -1);
  380. joRtn.Add("err_msg", "invokeCenterService(1):" + ex.Message);
  381. return joRtn;
  382. }
  383. }
  384. /// <summary>
  385. /// 这个是调用业务服务的invokeCenterService
  386. /// </summary>
  387. /// <param name="funNO"></param>
  388. /// <param name="data"></param>
  389. /// <returns></returns>
  390. public JObject invokeCenterService(string funNO, JObject data)
  391. {
  392. JObject joRtn = new JObject();
  393. string outPar = "";
  394. try
  395. {
  396. // 动态调试模式
  397. if (Global.curEvt.enabledDebug)
  398. {
  399. CenterResult center = new CenterResult();
  400. center.setTradeNo(funNO);
  401. if (center.ShowDialog() == DialogResult.OK)
  402. {
  403. outPar = center.returnData;
  404. return JObject.Parse(outPar);
  405. }
  406. }
  407. setCenterURL(funNO);
  408. joRtn = invokeCenterService(data.ToString());
  409. outPar = JsonHelper.Compress(joRtn);
  410. return joRtn;
  411. }
  412. catch (Exception ex)
  413. {
  414. if (joRtn["infcode"] == null)
  415. { joRtn.Add("infcode", -1); }
  416. if (joRtn["err_msg"] == null)
  417. { joRtn.Add("err_msg", "invokeCenterService(2):" + ex.Message); }
  418. outPar = JsonHelper.Compress(joRtn);
  419. return joRtn;
  420. }
  421. finally
  422. {
  423. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
  424. this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
  425. }
  426. }
  427. /// <summary>
  428. /// 这个是下载目录用的invokeCenterService
  429. /// </summary>
  430. /// <param name="funNO"></param>
  431. /// <param name="data"></param>
  432. /// <returns></returns>
  433. public JObject invokeCenterService(string funNO, string data)
  434. {
  435. JObject joRtn = new JObject();
  436. try
  437. {
  438. // 动态调试模式
  439. if (Global.curEvt.enabledDebug)
  440. {
  441. CenterResult center = new CenterResult();
  442. center.setTradeNo(funNO);
  443. if (center.ShowDialog() == DialogResult.OK)
  444. {
  445. string outPar = center.returnData;
  446. return JObject.Parse(outPar);
  447. }
  448. }
  449. setCenterURL(funNO);
  450. joRtn = invokeCenterService(data);
  451. return joRtn;
  452. }
  453. catch (Exception ex)
  454. {
  455. if (joRtn["infcode"] == null)
  456. { joRtn.Add("infcode", -1); }
  457. if (joRtn["err_msg"] == null)
  458. { joRtn.Add("err_msg", "invokeCenterService(3):" + ex.Message); }
  459. return joRtn;
  460. }
  461. finally
  462. {
  463. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
  464. this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
  465. }
  466. }
  467. /// <summary>
  468. /// 这个是合肥慢病用药查询用的invokeCenterService
  469. /// </summary>
  470. /// <param name="funNO"></param>
  471. /// <param name="data"></param>
  472. /// <returns></returns>
  473. public JObject invokeMBCenterService(string funNO, string data)
  474. {
  475. JObject joRtn = new JObject();
  476. try
  477. {
  478. // 动态调试模式
  479. if (Global.curEvt.enabledDebug)
  480. {
  481. CenterResult center = new CenterResult();
  482. center.setTradeNo(funNO);
  483. if (center.ShowDialog() == DialogResult.OK)
  484. {
  485. string outPar = center.returnData;
  486. return JObject.Parse(outPar);
  487. }
  488. }
  489. Global.curEvt.URL = "http://10.67.241.148:8080/api/definition/send";
  490. joRtn = invokeCenterServiceMB(data);
  491. return joRtn;
  492. }
  493. catch (Exception ex)
  494. {
  495. if (joRtn["infcode"] == null)
  496. { joRtn.Add("infcode", -1); }
  497. if (joRtn["err_msg"] == null)
  498. { joRtn.Add("err_msg", "invokeCenterService(3):" + ex.Message); }
  499. return joRtn;
  500. }
  501. finally
  502. {
  503. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
  504. this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
  505. }
  506. }
  507. /// <summary>
  508. /// 这个是下载目录用的invokeCenterService
  509. /// </summary>
  510. /// <param name="funNO"></param>
  511. /// <param name="data"></param>
  512. /// <returns></returns>
  513. public JObject invokeCenterServiceF(string funNO, string data)
  514. {
  515. JObject joRtn = new JObject();
  516. try
  517. {
  518. // 动态调试模式
  519. if (Global.curEvt.enabledDebug)
  520. {
  521. CenterResult center = new CenterResult();
  522. center.setTradeNo(funNO);
  523. if (center.ShowDialog() == DialogResult.OK)
  524. {
  525. string outPar = center.returnData;
  526. return JObject.Parse(outPar);
  527. }
  528. }
  529. Global.curEvt.URL = comp.getFunNoInsuURL(funNO);
  530. //setCenterURL(funNO);
  531. joRtn = invokeCenterService(data);
  532. return joRtn;
  533. }
  534. catch (Exception ex)
  535. {
  536. if (joRtn["infcode"] == null)
  537. { joRtn.Add("infcode", -1); }
  538. if (joRtn["err_msg"] == null)
  539. { joRtn.Add("err_msg", "invokeCenterService(3):" + ex.Message); }
  540. return joRtn;
  541. }
  542. finally
  543. {
  544. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
  545. this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
  546. }
  547. }
  548. #endregion
  549. private string getResponseData(HttpWebResponse response) {
  550. string data = "";
  551. if (response != null)
  552. {
  553. Stream s = response.GetResponseStream();
  554. StreamReader sRead = new StreamReader(s);
  555. data = sRead.ReadToEnd();
  556. sRead.Close();
  557. response.Close();
  558. }
  559. return data;
  560. }
  561. /// <summary>
  562. /// 调用医保动态库文件下载函数 CM 20220925
  563. /// </summary>
  564. /// <param name="fixmedins_code"></param>
  565. /// <param name="infosyscode"></param>
  566. /// <param name="infosyssign"></param>
  567. /// <param name="inputData"></param>
  568. /// <param name="outputData"></param>
  569. /// <param name="pErrMsg"></param>
  570. /// <returns>0或小于0</returns>
  571. private int invokeDownloadFileByDLL(string fixmedins_code, string infosyscode, string infosyssign, string inputData, ref string outputData, ref string pErrMsg)
  572. {
  573. pErrMsg = "";
  574. outputData = "";
  575. try
  576. {
  577. StringBuilder errmsgSb = new StringBuilder(4096);
  578. StringBuilder outSb = new StringBuilder(40960);
  579. int pRtn = DownloadFile(fixmedins_code, infosyscode, infosyssign, inputData, outSb, errmsgSb);
  580. if (pRtn < 0)
  581. {
  582. pErrMsg = errmsgSb.ToString();
  583. return -1;
  584. }
  585. else
  586. {
  587. outputData = outSb.ToString();
  588. }
  589. return pRtn;
  590. }
  591. catch (Exception ex)
  592. {
  593. pErrMsg = "invokeInitByDLL.DownloadFile 异常:" + ex.Message;
  594. return -1;
  595. }
  596. finally
  597. {
  598. Global.writeLog("invokeInitByDLL.DownloadFile 医保动态库文件下载函数", inputData, outputData);
  599. }
  600. }
  601. private void setCenterURL(string funNo)
  602. {
  603. string prefix = Global.inf.centerURL;
  604. // 环境
  605. LoadCenterURL(true);
  606. switch (funNo)
  607. {
  608. //case "4101A":
  609. case "3101":
  610. case "3102":
  611. case "3103":
  612. prefix = "http://10.66.155.173:8086/1.0.0/hsa-fsi-";
  613. break;
  614. case "10001":
  615. prefix = "http://10.67.187.46:8000/v1/pb/op/opRiskTips";
  616. break;
  617. default:
  618. prefix = Global.inf.centerURL;
  619. break;
  620. }
  621. //移动支付
  622. if (funNo.StartsWith("62") || funNo.StartsWith("63") || funNo.StartsWith("64"))
  623. {
  624. prefix = Global.inf.mobilePayURL; //测试
  625. }
  626. Global.curEvt.URL = prefix + funNo;
  627. }
  628. #region 移动支付
  629. /// <summary>
  630. /// 移动
  631. /// </summary>
  632. /// <param name="funNO"></param>
  633. /// <param name="data"></param>
  634. /// <returns></returns>
  635. ///
  636. public JObject invokeMPService(string funNO, string data)
  637. {
  638. return invokeMPService(funNO,JObject.Parse(data));
  639. }
  640. public JObject invokeMPService(string funNO, JObject joInput)
  641. {
  642. JObject joRtn = new JObject();
  643. String outPar = "";
  644. try
  645. {
  646. LoadCenterURL(true);
  647. string url = "";
  648. switch (funNO)
  649. {
  650. case "6201":
  651. url = "/org/local/api/hos/uldFeeInfo";
  652. break;
  653. case "6202":
  654. url = "/org/local/api/hos/pay_order";
  655. break;
  656. case "6203":
  657. url = "/org/local/api/hos/refund_Order";
  658. break;
  659. case "6301":
  660. url = "/org/local/api/hos/query_order_info";
  661. break;
  662. case "6401":
  663. url = "/org/local/api/hos/revoke_order";
  664. break;
  665. default:
  666. break;
  667. }
  668. EncryptHelper encrypt = new EncryptHelper();
  669. string data = JsonHelper.setMPCenterInpar(funNO, joInput);
  670. // 移动支付地址
  671. Global.curEvt.URL = Global.inf.mobilePayURL + url;
  672. // 动态调试模式
  673. if (Global.curEvt.enabledDebug)
  674. {
  675. CenterResult center = new CenterResult();
  676. center.setTradeNo(funNO);
  677. if (center.ShowDialog() == DialogResult.OK)
  678. {
  679. outPar = center.returnData;
  680. return JObject.Parse(outPar);
  681. }
  682. }
  683. try
  684. {
  685. joRtn = invokeCenterService(data);
  686. Global.writeLog(funNO + "【密文出参】:\r\n" + joRtn.ToString());
  687. string encData = JsonHelper.getDestValue(joRtn, "encData");
  688. string signData = JsonHelper.getDestValue(joRtn, "signData");
  689. if (!string.IsNullOrEmpty(encData) && !string.IsNullOrEmpty(signData))
  690. {
  691. joRtn.Remove("encData");
  692. joRtn.Remove("signData");
  693. joRtn.Remove("data");
  694. //解密
  695. string decData = encrypt.decrypt(encData);
  696. // 验签
  697. JsonConvert.DefaultSettings = () => new JsonSerializerSettings
  698. {
  699. FloatParseHandling = FloatParseHandling.Decimal
  700. };
  701. joRtn.Add("data", JToken.FromObject(JsonConvert.DeserializeObject(decData)));
  702. bool rtn = encrypt.verify(joRtn, signData);
  703. if (rtn)
  704. {
  705. Global.writeLog("验签通过!");
  706. }
  707. else
  708. {
  709. Global.writeLog("验签失败,请核查!");
  710. }
  711. if (!string.IsNullOrEmpty(decData))
  712. {
  713. Global.writeLog(funNO + "【明文出参】:\r\n" + decData);
  714. joRtn = JObject.Parse(decData);
  715. joRtn.Add("success", "True");
  716. }
  717. }
  718. return joRtn;
  719. }
  720. finally
  721. {
  722. this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
  723. }
  724. }
  725. catch (Exception ex)
  726. {
  727. if (joRtn["infcode"] == null)
  728. { joRtn.Add("infcode", -1); }
  729. if (joRtn["err_msg"] == null)
  730. { joRtn.Add("err_msg", "invokeCenterService(3):" + ex.Message); }
  731. outPar = JsonHelper.Compress(joRtn);
  732. return joRtn;
  733. }
  734. finally
  735. {
  736. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", joInput.ToString(), joRtn.ToString());
  737. this.saveCenterLog(joInput.ToString(), joRtn.ToString(), joInput.ToString(), joRtn.ToString());
  738. }
  739. }
  740. #endregion
  741. #region 处方流转
  742. /// <summary>
  743. /// 医保电子处方流转调用服务
  744. /// </summary>
  745. /// <param name="data"></param>
  746. /// <returns></returns>
  747. private JObject invokeCenterServicePresCir(string data)
  748. {
  749. string postContent = "";
  750. JObject joRtn = new JObject();
  751. try
  752. {
  753. Global.writeLog(string.Format("调用中心{0}接口入参:{1}", data, Global.curEvt.URL));
  754. //创建一个HTTP请求
  755. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
  756. //Post请求方式
  757. request.Method = "POST";
  758. //string nonce = Guid.NewGuid().ToString(); //非重复的随机字符串(十分钟内不能重复)
  759. //string timestamp = TimeStamp.get13().ToString(); //当前时间戳(秒)
  760. //string BusinessID = Global.inf.BusinessID; //服务商ID
  761. //string InsuHosID = Global.inf.hospitalNO; //医疗机构ID
  762. //string CreditID = Global.inf.CreditID; //服务商统一社会信用代码
  763. //内容类型
  764. request.ContentType = "application/json;charset=UTF-8";
  765. //昆明增加头部信息
  766. //string sTemp = timestamp + BusinessID + nonce;
  767. //Sha256 加密生成的签名 signature = sha256(hsf_timestamp + infosyssign + hsf_nonce)
  768. //string signature = Encrypt.SHA256EncryptStr(sTemp);
  769. //request.Headers.Add("hsf_signature", signature);
  770. //request.Headers.Add("hsf_timestamp", timestamp);
  771. //request.Headers.Add("hsf_nonce", nonce);
  772. //request.Headers.Add("fixmedins_code", InsuHosID);
  773. //request.Headers.Add("infosyscode", CreditID);
  774. //设置参数,并进行URL编码
  775. string paraUrlCoded = data;//System.Web.HttpUtility.UrlEncode(jsonParas);
  776. byte[] payload;
  777. //将Json字符串转化为字节
  778. payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
  779. //设置请求的ContentLength
  780. request.ContentLength = payload.Length;
  781. //发送请求,获得请求流
  782. Stream writer;
  783. writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
  784. //将请求参数写入流
  785. writer.Write(payload, 0, payload.Length);
  786. writer.Close();//关闭请求流
  787. // String strValue = "";//strValue为http响应所返回的字符流
  788. HttpWebResponse response = null;
  789. try
  790. {
  791. //获得响应流
  792. response = (HttpWebResponse)request.GetResponse();
  793. }
  794. catch (WebException ex)
  795. {
  796. // return JsonHelper.setExceptionJson(-99, "centerServeiceInvok中获得响应流异常", ex.Message);
  797. HttpWebResponse res = (HttpWebResponse)ex.Response;
  798. Stream myResponseStream = res.GetResponseStream();
  799. StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
  800. string retString = myStreamReader.ReadToEnd();
  801. return JsonHelper.setExceptionJson(-99, "获得响应流异常", retString);
  802. }
  803. postContent = getResponseData(response);
  804. joRtn = JObject.Parse(postContent);//返回Json数据
  805. if (joRtn.ContainsKey("body"))
  806. {
  807. joRtn = (JObject)joRtn.GetValue("body");
  808. }
  809. return joRtn;
  810. }
  811. catch (Exception ex)
  812. {
  813. postContent = "调用中心服务异常" + ex.Message;
  814. joRtn.Add("infcode", -1);
  815. joRtn.Add("err_msg", "invokeCenterService(1):" + ex.Message);
  816. return joRtn;
  817. }
  818. }
  819. /// <summary>
  820. /// 医保电子处方调用中心接口
  821. /// </summary>
  822. /// <param name="funNO"></param>
  823. /// <param name="data"></param>
  824. /// <returns></returns>
  825. public JObject invokeCenterServicePresCir(string funNO, string data)
  826. {
  827. JObject joRtn = new JObject();
  828. string outPar = "";
  829. try
  830. {
  831. if (funNO == "7101")
  832. {
  833. Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/uploadChk";
  834. }
  835. else if (funNO == "7102")
  836. {
  837. Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxFixmedinsSign";
  838. }
  839. else if (funNO == "7103")
  840. {
  841. Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxFileUpld";
  842. }
  843. else if (funNO == "7104")
  844. {
  845. Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxUndo";
  846. }
  847. else if (funNO == "7105")
  848. {
  849. Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/hospRxDetlQuery";
  850. }
  851. else if (funNO == "7106")
  852. {
  853. Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxChkInfoQuery";
  854. }
  855. else if (funNO == "7107")
  856. {
  857. Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxSetlInfoQuery";
  858. }
  859. else if (funNO == "7108")
  860. {
  861. Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxChkInfoCallback";
  862. }
  863. else if (funNO == "7109")
  864. {
  865. Global.curEvt.URL = Global.inf.presCenterURL + "/fixmedins/rxSetlInfoCallback";
  866. }
  867. else
  868. {
  869. Global.curEvt.URL = Global.inf.centerURL;
  870. }
  871. //Global.curEvt.URL = Global.inf.centerURL;
  872. joRtn = invokeCenterServicePresCir(data);
  873. outPar = JsonHelper.Compress(joRtn);
  874. return joRtn;
  875. }
  876. catch (Exception ex)
  877. {
  878. if (joRtn["infcode"] == null)
  879. { joRtn.Add("infcode", -1); }
  880. if (joRtn["err_msg"] == null)
  881. { joRtn.Add("err_msg", "invokeCenterServicePresCir(3):" + ex.Message); }
  882. outPar = JsonHelper.Compress(joRtn);
  883. return joRtn;
  884. }
  885. finally
  886. {
  887. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", JsonHelper.Compress(data), joRtn.ToString());
  888. //this.saveCenterLog(JsonHelper.Compress(data), outPar, JsonHelper.Compress(data), outPar);
  889. }
  890. }
  891. #endregion
  892. /// <summary>
  893. /// 医保目录txt文件下载
  894. /// </summary>
  895. /// <param name="data"></param>
  896. /// <returns></returns>
  897. public JObject DownloadCenterFile(string data)
  898. {
  899. string error = string.Empty; int errorCode = 0;
  900. string sRtn = "";
  901. try
  902. {
  903. JObject jsonInParam = JObject.Parse(data);
  904. // 去除外wrapper层便于通用
  905. Utils.removeWrapper(jsonInParam);
  906. string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
  907. string filePath = Global.curEvt.path + "\\Download\\" + fileName;
  908. //如果不存在目录,则创建目录
  909. if (!Directory.Exists(Global.curEvt.path + "\\Download"))
  910. {
  911. //创建文件夹
  912. DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\Download");
  913. }
  914. if (File.Exists(filePath))
  915. {
  916. File.Delete(filePath);
  917. }
  918. FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
  919. //创建一个HTTP请求
  920. Global.curEvt.URL = Global.inf.downURL;
  921. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
  922. //Post请求方式
  923. request.Method = "POST";
  924. //string timestamp = TimeStamp.get13().ToString(); //当前时间戳(秒)
  925. //string nonce = Guid.NewGuid().ToString(); //非重复的随机字符串(十分钟内不能重复)
  926. //string InsuHosID = Global.inf.hospitalNO; //医疗机构ID
  927. //string CreditID = Global.inf.CreditID; //服务商统一社会信用代码
  928. //string BusinessID = Global.inf.BusinessID; //服务商ID
  929. //内容类型
  930. request.ContentType = "application/json";
  931. //昆明增加头部信息
  932. //string sTemp = timestamp + BusinessID + nonce;
  933. //Sha256 加密生成的签名 signature = sha256(hsf_timestamp + infosyssign + hsf_nonce)
  934. //string signature = Encrypt.SHA256EncryptStr(sTemp);
  935. //request.Headers.Add("hsf_signature", signature);
  936. //request.Headers.Add("hsf_timestamp", timestamp);
  937. //request.Headers.Add("hsf_nonce", nonce);
  938. //request.Headers.Add("fixmedins_code", InsuHosID);
  939. //request.Headers.Add("infosyscode", CreditID);
  940. //设置参数,并进行URL编码
  941. string paraUrlCoded = JsonHelper.toJsonString(jsonInParam);
  942. byte[] payload;
  943. //将Json字符串转化为字节
  944. payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
  945. //设置请求的ContentLength
  946. request.ContentLength = payload.Length;
  947. Stream writer;
  948. try
  949. {
  950. writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
  951. }
  952. catch (Exception)
  953. {
  954. writer = null;
  955. errorCode = -100;
  956. error = "连接服务器失败!";
  957. }
  958. //将请求参数写入流
  959. writer.Write(payload, 0, payload.Length);
  960. writer.Close();//关闭请求流
  961. // String strValue = "";//strValue为http响应所返回的字符流
  962. //发送请求并获取相应回应数据
  963. HttpWebResponse response = request.GetResponse() as HttpWebResponse;
  964. //直到request.GetResponse()程序才开始向目标网页发送Post请求
  965. Stream responseStream = response.GetResponseStream();
  966. //创建本地文件写入流
  967. byte[] bArr = new byte[1024];
  968. int iTotalSize = 0;
  969. int size = responseStream.Read(bArr, 0, (int)bArr.Length);
  970. while (size > 0)
  971. {
  972. iTotalSize += size;
  973. fs.Write(bArr, 0, size);
  974. size = responseStream.Read(bArr, 0, (int)bArr.Length);
  975. }
  976. fs.Close();
  977. responseStream.Close();
  978. dynamic joReturn = new JObject();
  979. joReturn.errorCode = errorCode;
  980. joReturn.errorMessage = error;
  981. joReturn.filePath = filePath;
  982. sRtn = joReturn.ToString();
  983. return joReturn;
  984. }
  985. catch (Exception ex)
  986. {
  987. errorCode = -100;
  988. error = ex.Message;
  989. dynamic joReturn = new JObject();
  990. joReturn.errorCode = errorCode;
  991. joReturn.errorMessage = error;
  992. sRtn = joReturn.ToString();
  993. return joReturn;
  994. }
  995. finally
  996. {
  997. Global.writeLog("DownloadCenterFile" +"(" + Global.inf.downURL + ")", data, sRtn);
  998. }
  999. }
  1000. /// <summary>
  1001. /// 保存中心交易日志到数据库
  1002. /// </summary>
  1003. /// <param name="inParam"></param>
  1004. /// <param name="outParam"></param>
  1005. /// <param name="inParamPlain"></param>
  1006. /// <param name="outParamPlain"></param>
  1007. private void saveCenterLog(string inParam, string outParam, string inParamPlain, string outParamPlain)
  1008. {
  1009. dynamic joIris = new JObject();
  1010. string sRtn = "";
  1011. try
  1012. {
  1013. //解析postContent,插入医保交易日志表
  1014. JObject joInParam = new JObject(JObject.Parse(inParam));
  1015. //解包
  1016. JObject joIn = Utils.removeWrapper(joInParam);
  1017. JObject joOut = new JObject(JObject.Parse(outParam));
  1018. JObject joInPlain = new JObject(JObject.Parse(inParamPlain));
  1019. JObject joOutPlain = new JObject(JObject.Parse(outParamPlain));
  1020. JArray jaParams = new JArray();
  1021. JObject joParam = new JObject();
  1022. joParam.Add("inParam", JObject.FromObject(joIn));
  1023. joParam.Add("outParam", JObject.FromObject(joOut));
  1024. joParam.Add("inParamPlain", JObject.FromObject(joInPlain));
  1025. joParam.Add("outParamPlain", JObject.FromObject(joOutPlain));
  1026. joParam.Add("HospitalDr", Global.inf.hospitalDr);
  1027. joParam.Add("InterfaceDr", Global.inf.interfaceDr);
  1028. joParam.Add("updateUserID", Global.user.ID);
  1029. joParam.Add("psn_no", Global.pat.psn_no);
  1030. jaParams.Add(joParam);
  1031. joIris.code = "09010021";
  1032. joIris.Add("params", jaParams);
  1033. //InvokeHelper invoker = new InvokeHelper();
  1034. sRtn = invokeInsuService(joIris.ToString(), "保存日志到数据库").ToString();
  1035. }
  1036. catch (Exception ex)
  1037. {
  1038. sRtn = JsonHelper.setExceptionJson(-100, "保存日志异常", ex.Message).ToString();
  1039. Global.writeLog_Iris("保存日志异常:" + sRtn.ToString());
  1040. }
  1041. }
  1042. }
  1043. }