InvokeHelper.cs 44 KB

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