InvokeHelper.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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 encData = JsonHelper.getDestValue(joRtn, "encData");
  500. string signData = JsonHelper.getDestValue(joRtn, "signData");
  501. if (!string.IsNullOrEmpty(encData) && !string.IsNullOrEmpty(signData))
  502. {
  503. joRtn.Remove("encData");
  504. joRtn.Remove("signData");
  505. joRtn.Remove("data");
  506. //解密
  507. string decData = encrypt.decrypt(encData);
  508. // 验签
  509. JsonConvert.DefaultSettings = () => new JsonSerializerSettings
  510. {
  511. FloatParseHandling = FloatParseHandling.Decimal
  512. };
  513. joRtn.Add("data", JToken.FromObject(JsonConvert.DeserializeObject(decData)));
  514. bool rtn = encrypt.verify(joRtn, signData);
  515. Global.writeLog("验签结果:" + rtn);
  516. joRtn.Add("output", decData);
  517. }
  518. return joRtn;
  519. }
  520. catch (Exception ex)
  521. {
  522. if (joRtn["infcode"] == null)
  523. { joRtn.Add("infcode", -1); }
  524. if (joRtn["err_msg"] == null)
  525. { joRtn.Add("err_msg", "invokeCenterService(3):" + ex.Message); }
  526. outPar = JsonHelper.Compress(joRtn);
  527. return joRtn;
  528. }
  529. finally
  530. {
  531. Global.writeLog(funNO + "(" + Global.curEvt.URL + ")", joInput.ToString(), joRtn.ToString());
  532. this.saveCenterLog(joInput.ToString(), joRtn.ToString(), joInput.ToString(), joRtn.ToString());
  533. }
  534. }
  535. /// <summary>
  536. /// 设置医保动态库目录
  537. /// </summary>
  538. /// <param name="sPath"></param>
  539. /// <param name="pErrMsg"></param>
  540. /// <returns></returns>
  541. private void invokeSetDirByOCX(ref string pErrMsg)
  542. {
  543. try
  544. {
  545. //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();
  546. //InterfaceBase_Yn.SetDir(IntPath);
  547. }
  548. catch (Exception ex)
  549. {
  550. pErrMsg = "invokeInitByDLL.SetDir 异常:" + ex.Message;
  551. MessageBox.Show(pErrMsg);
  552. }
  553. finally
  554. {
  555. //Global.writeLog("invokeInitByDLL.SetDir设置医保动态库目录(" + IntPath + ")", "", pErrMsg);
  556. }
  557. }
  558. /// <summary>
  559. /// 医保目录txt文件下载
  560. /// </summary>
  561. /// <param name="data"></param>
  562. /// <returns></returns>
  563. public JObject DownloadCenterFile(string data)
  564. {
  565. string error = string.Empty; int errorCode = 0;
  566. string sRtn = "";
  567. try
  568. {
  569. JObject jsonInParam = JObject.Parse(data);
  570. // 去除外wrapper层便于通用
  571. Utils.removeWrapper(jsonInParam);
  572. string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
  573. string filePath = Global.curEvt.path + "\\Download\\" + fileName;
  574. //如果不存在目录,则创建目录
  575. if (!Directory.Exists(Global.curEvt.path + "\\Download"))
  576. {
  577. //创建文件夹
  578. DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\Download");
  579. }
  580. if (File.Exists(filePath))
  581. {
  582. File.Delete(filePath);
  583. }
  584. FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
  585. //创建一个HTTP请求
  586. Global.curEvt.URL = Global.inf.downURL;
  587. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.curEvt.URL);
  588. //Post请求方式
  589. request.Method = "POST";
  590. //string timestamp = TimeStamp.get13().ToString(); //当前时间戳(秒)
  591. //string nonce = Guid.NewGuid().ToString(); //非重复的随机字符串(十分钟内不能重复)
  592. //string InsuHosID = Global.inf.hospitalNO; //医疗机构ID
  593. //string CreditID = Global.inf.CreditID; //服务商统一社会信用代码
  594. //string BusinessID = Global.inf.BusinessID; //服务商ID
  595. //内容类型
  596. request.ContentType = "application/json";
  597. //昆明增加头部信息
  598. //string sTemp = timestamp + BusinessID + nonce;
  599. //Sha256 加密生成的签名 signature = sha256(hsf_timestamp + infosyssign + hsf_nonce)
  600. //string signature = Encrypt.SHA256EncryptStr(sTemp);
  601. //request.Headers.Add("hsf_signature", signature);
  602. //request.Headers.Add("hsf_timestamp", timestamp);
  603. //request.Headers.Add("hsf_nonce", nonce);
  604. //request.Headers.Add("fixmedins_code", InsuHosID);
  605. //request.Headers.Add("infosyscode", CreditID);
  606. //设置参数,并进行URL编码
  607. string paraUrlCoded = JsonHelper.toJsonString(jsonInParam);
  608. byte[] payload;
  609. //将Json字符串转化为字节
  610. payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
  611. //设置请求的ContentLength
  612. request.ContentLength = payload.Length;
  613. Stream writer;
  614. try
  615. {
  616. writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
  617. }
  618. catch (Exception)
  619. {
  620. writer = null;
  621. errorCode = -100;
  622. error = "连接服务器失败!";
  623. }
  624. //将请求参数写入流
  625. writer.Write(payload, 0, payload.Length);
  626. writer.Close();//关闭请求流
  627. // String strValue = "";//strValue为http响应所返回的字符流
  628. //发送请求并获取相应回应数据
  629. HttpWebResponse response = request.GetResponse() as HttpWebResponse;
  630. //直到request.GetResponse()程序才开始向目标网页发送Post请求
  631. Stream responseStream = response.GetResponseStream();
  632. //创建本地文件写入流
  633. byte[] bArr = new byte[1024];
  634. int iTotalSize = 0;
  635. int size = responseStream.Read(bArr, 0, (int)bArr.Length);
  636. while (size > 0)
  637. {
  638. iTotalSize += size;
  639. fs.Write(bArr, 0, size);
  640. size = responseStream.Read(bArr, 0, (int)bArr.Length);
  641. }
  642. fs.Close();
  643. responseStream.Close();
  644. dynamic joReturn = new JObject();
  645. joReturn.errorCode = errorCode;
  646. joReturn.errorMessage = error;
  647. joReturn.filePath = filePath;
  648. sRtn = joReturn.ToString();
  649. return joReturn;
  650. }
  651. catch (Exception ex)
  652. {
  653. errorCode = -100;
  654. error = ex.Message;
  655. dynamic joReturn = new JObject();
  656. joReturn.errorCode = errorCode;
  657. joReturn.errorMessage = error;
  658. sRtn = joReturn.ToString();
  659. return joReturn;
  660. }
  661. finally
  662. {
  663. Global.writeLog("DownloadCenterFile" +"(" + Global.inf.downURL + ")", data, sRtn);
  664. }
  665. }
  666. /// <summary>
  667. /// 调用医保动态库初始化 CM 20220925
  668. /// </summary>
  669. /// <param name="fixmedins_code"></param>
  670. /// <param name="infosyscode"></param>
  671. /// <param name="infosyssign"></param>
  672. /// <param name="url"></param>
  673. /// <param name="pErrMsg"></param>
  674. /// <returns>0或小于0</returns>
  675. private int invokeInitByOCX(string fixmedins_code, string infosyscode, string infosyssign, string url, ref string pErrMsg)
  676. {
  677. //pErrMsg = "";
  678. JObject joRtn = new JObject();
  679. try
  680. {
  681. //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();
  682. //string pRtn = InterfaceBase_Yn.Init(fixmedins_code, infosyscode, infosyssign, url);
  683. //joRtn = JObject.Parse(pRtn);
  684. if (joRtn["infcode"].ToString() != "0")
  685. {
  686. pErrMsg = joRtn["err_msg"].ToString();
  687. return -1;
  688. }
  689. else
  690. {
  691. return 0;
  692. }
  693. }
  694. catch (Exception ex)
  695. {
  696. pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
  697. return -1;
  698. }
  699. finally
  700. {
  701. Global.writeLog("invokeInitByDLL.Init医保动态库初始化(" + url + ")", "", pErrMsg);
  702. }
  703. }
  704. /// <summary>
  705. /// 调用医保动态库通用业务函数 CM 20220925
  706. /// </summary>
  707. /// <param name="fixmedins_code"></param>
  708. /// <param name="infosyscode"></param>
  709. /// <param name="infosyssign"></param>
  710. /// <param name="inputData"></param>
  711. /// <param name="outputData"></param>
  712. /// <param name="pErrMsg"></param>
  713. /// <returns>0或小于0</returns>
  714. private int invokeBusiessByOCX(string fixmedins_code, string infosyscode, string infosyssign, string inputData, ref string outputData, ref string pErrMsg)
  715. {
  716. pErrMsg = "";
  717. outputData = "";
  718. JObject joRtn = new JObject();
  719. try
  720. {
  721. try
  722. {
  723. //chsinterfaceyn.chsdllClass InterfaceBase_Yn1 = new chsinterfaceyn.chsdllClass();
  724. //InterfaceBase_Yn1.SetDir(IntPath);
  725. }
  726. catch (Exception ex)
  727. {
  728. pErrMsg = "invokeInitByDLL.SetDir 异常:" + ex.Message;
  729. MessageBox.Show(pErrMsg);
  730. }
  731. finally
  732. {
  733. //Global.writeLog("invokeInitByDLL.SetDir设置医保动态库目录(" + IntPath + ")", "", pErrMsg);
  734. }
  735. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  736. //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();
  737. //调用业务函数
  738. //string pRtn =InterfaceBase_Yn.BusinessHandleW(fixmedins_code, infosyscode, infosyssign, inputData);
  739. //string pRtn = InterfaceBase_Yn.UploadFile(fixmedins_code, infosyscode, infosyssign, Global.inf.fileName,inputData);
  740. //joRtn = JObject.Parse(pRtn);
  741. if (joRtn["infcode"].ToString() != "0")
  742. {
  743. pErrMsg = joRtn["err_msg"].ToString();
  744. //outputData = pRtn;
  745. return -1;
  746. }
  747. else
  748. {
  749. //outputData = pRtn;
  750. return 0;
  751. }
  752. }
  753. catch (Exception ex)
  754. {
  755. pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
  756. return -1;
  757. }
  758. finally
  759. {
  760. Global.writeLog("invokeInitByDLL.BusinessHandle医保动态库通用业务函数", inputData, outputData);
  761. }
  762. }
  763. /// <summary>
  764. /// 医保动态库下载目录文件
  765. /// </summary>
  766. /// <param name="data"></param>
  767. /// <returns></returns>
  768. public JObject DownloadCenterFileByDll(string data)
  769. {
  770. string error = string.Empty; int errorCode = 0;
  771. string sRtn = "";
  772. try
  773. {
  774. JObject jsonInParam = JObject.Parse(data);
  775. string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
  776. string filePath = Global.curEvt.path + "\\Download\\" + fileName;
  777. //如果不存在目录,则创建目录
  778. if (!Directory.Exists(Global.curEvt.path + "\\Download"))
  779. {
  780. //创建文件夹
  781. DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\Download");
  782. }
  783. if (File.Exists(filePath))
  784. {
  785. File.Delete(filePath);
  786. }
  787. FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
  788. //创建一个HTTP请求
  789. Global.curEvt.URL = Global.inf.centerURL;
  790. int iRes = invokeDownloadFileByDLL(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, data.ToString(),ref sRtn, ref error);
  791. if (iRes == 0)
  792. {
  793. dynamic joReturn = new JObject();
  794. joReturn.errorCode = errorCode;
  795. joReturn.errorMessage = error;
  796. joReturn.filePath = filePath;
  797. sRtn = joReturn.ToString();
  798. return joReturn;
  799. }
  800. else
  801. {
  802. errorCode = -100;
  803. dynamic joReturn = new JObject();
  804. joReturn.errorCode = errorCode;
  805. joReturn.errorMessage = error;
  806. sRtn = joReturn.ToString();
  807. return joReturn;
  808. }
  809. }
  810. catch (Exception ex)
  811. {
  812. errorCode = -100;
  813. error = ex.Message;
  814. dynamic joReturn = new JObject();
  815. joReturn.errorCode = errorCode;
  816. joReturn.errorMessage = error;
  817. sRtn = joReturn.ToString();
  818. return joReturn;
  819. }
  820. finally
  821. {
  822. Global.writeLog("DownloadCenterFile" + "(" + Global.curEvt.URL + ")", data, sRtn);
  823. }
  824. }
  825. /// <summary>
  826. /// 保存中心交易日志到数据库
  827. /// </summary>
  828. /// <param name="inParam"></param>
  829. /// <param name="outParam"></param>
  830. /// <param name="inParamPlain"></param>
  831. /// <param name="outParamPlain"></param>
  832. private void saveCenterLog(string inParam, string outParam, string inParamPlain, string outParamPlain)
  833. {
  834. dynamic joIris = new JObject();
  835. string sRtn = "";
  836. try
  837. {
  838. //解析postContent,插入医保交易日志表
  839. JObject joInParam = new JObject(JObject.Parse(inParam));
  840. //解包
  841. JObject joIn = Utils.removeWrapper(joInParam);
  842. JObject joOut = new JObject(JObject.Parse(outParam));
  843. JObject joInPlain = new JObject(JObject.Parse(inParamPlain));
  844. JObject joOutPlain = new JObject(JObject.Parse(outParamPlain));
  845. JArray jaParams = new JArray();
  846. JObject joParam = new JObject();
  847. joParam.Add("inParam", JObject.FromObject(joIn));
  848. joParam.Add("outParam", JObject.FromObject(joOut));
  849. joParam.Add("inParamPlain", JObject.FromObject(joInPlain));
  850. joParam.Add("outParamPlain", JObject.FromObject(joOutPlain));
  851. joParam.Add("HospitalDr", Global.inf.hospitalDr);
  852. joParam.Add("InterfaceDr", Global.inf.interfaceDr);
  853. joParam.Add("updateUserID", Global.user.ID);
  854. joParam.Add("psn_no", Global.pat.psn_no);
  855. jaParams.Add(joParam);
  856. joIris.code = "09010021";
  857. joIris.Add("params", jaParams);
  858. //InvokeHelper invoker = new InvokeHelper();
  859. sRtn = invokeInsuService(joIris.ToString(), "保存日志到数据库").ToString();
  860. }
  861. catch (Exception ex)
  862. {
  863. sRtn = JsonHelper.setExceptionJson(-100, "保存日志异常", ex.Message).ToString();
  864. Global.writeLog_Iris("保存日志异常:" + sRtn.ToString());
  865. }
  866. }
  867. /**********************************************************调用DLL方式**************************************************************/
  868. public int InvokeInitByDLL(ref string pErrMsg)
  869. {
  870. //string pErrMsg = "";
  871. int pRtn =-1;
  872. JObject joRtn = new JObject();
  873. try
  874. {
  875. StringBuilder outSb = new StringBuilder(40960);
  876. pRtn = Init(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, Global.inf.centerURL, outSb);
  877. if (pRtn != 0)
  878. {
  879. pErrMsg = outSb.ToString();
  880. return -1;
  881. }
  882. else
  883. {
  884. return 0;
  885. }
  886. }
  887. catch (Exception ex)
  888. {
  889. pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
  890. return -1;
  891. }
  892. finally
  893. {
  894. Global.writeLog("InvokeInitByDLL(" + Global.inf.centerURL + ")", Global.inf.CreditID +":" + Global.inf.BusinessID,pRtn.ToString() + pErrMsg);
  895. }
  896. }
  897. private int invokeBusiessByDLL(string inputData, ref string outputData, ref string pErrMsg)
  898. {
  899. pErrMsg = "";
  900. outputData = "";
  901. JObject joRtn = new JObject();
  902. try
  903. {
  904. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  905. StringBuilder errmsgSb = new StringBuilder(4096);
  906. StringBuilder outSb = new StringBuilder(40960);
  907. //调用业务函数
  908. int pRtn = BusinessHandle(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, inputData, outSb, errmsgSb);
  909. if (pRtn != 0)
  910. {
  911. outputData = outSb.ToString();
  912. pErrMsg = errmsgSb.ToString();
  913. return -1;
  914. }
  915. else
  916. {
  917. outputData = outSb.ToString();
  918. return 0;
  919. }
  920. }
  921. catch (Exception ex)
  922. {
  923. pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
  924. return -1;
  925. }
  926. finally
  927. {
  928. Global.writeLog("CreditID11", Global.inf.CreditID, Global.inf.BusinessID);
  929. Global.writeLog("invokeInitByDLL.BusinessHandle医保动态库通用业务函数", inputData, outputData);
  930. }
  931. }
  932. private int invokeBusiessWByDLL(string inputData, ref string outputData, ref string pErrMsg)
  933. {
  934. pErrMsg = "";
  935. outputData = "";
  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. StringBuilder sbHospitalNO = new StringBuilder(Global.inf.hospitalNO);
  943. StringBuilder sbCreditID = new StringBuilder(Global.inf.CreditID);
  944. StringBuilder sbBusinessID = new StringBuilder(Global.inf.BusinessID);
  945. StringBuilder sbInput = new StringBuilder(inputData);
  946. //调用业务函数
  947. int pRtn = BusinessHandleW(sbHospitalNO, sbCreditID, sbBusinessID, sbInput, outSb, errmsgSb);
  948. if (pRtn != 0)
  949. {
  950. outputData = outSb.ToString();
  951. pErrMsg = errmsgSb.ToString();
  952. return -1;
  953. }
  954. else
  955. {
  956. outputData = outSb.ToString();
  957. return 0;
  958. }
  959. }
  960. catch (Exception ex)
  961. {
  962. pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
  963. return -1;
  964. }
  965. finally
  966. {
  967. Global.writeLog("CreditID12", Global.inf.CreditID, Global.inf.BusinessID);
  968. Global.writeLog("invokeInitByDLL.BusinessHandleW医保动态库通用业务函数", inputData, outputData);
  969. }
  970. }
  971. private int invokeUploadFileByDLL(string inputData, ref string outputData, ref string pErrMsg)
  972. {
  973. pErrMsg = "";
  974. outputData = "";
  975. JObject joRtn = new JObject();
  976. try
  977. {
  978. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  979. StringBuilder errmsgSb = new StringBuilder(4096);
  980. StringBuilder outSb = new StringBuilder(40960);
  981. //调用业务函数
  982. int pRtn = UploadFile(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, Global.inf.fileName,inputData, 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 = "invokeUploadFileByDLL.UploadFile 异常:" + ex.Message;
  998. return -1;
  999. }
  1000. finally
  1001. {
  1002. Global.writeLog("invokeUploadFileByDLL.UploadFile医保动态库上传业务函数", inputData, outputData);
  1003. }
  1004. }
  1005. }
  1006. }