YinHaiSafeCtrl.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Helper;
  3. using PTMedicalInsurance.Variables;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace PTMedicalInsurance.Common
  11. {
  12. /// <summary>
  13. /// 银海安全控件
  14. /// </summary>
  15. class YinHaiSafeCtrl
  16. {
  17. string progID = "YinHai.CHS.InterfaceSCS";
  18. System.Type comType;
  19. object comInstance;
  20. /// <summary>
  21. /// 调用银海安全控件
  22. /// </summary>
  23. /// <param name="funNo"></param>
  24. /// <returns></returns>
  25. public int Prepare(string funNo,out string sSafeControlsRtnValue)
  26. {
  27. string pErrMsg = string.Empty;
  28. JObject joInput = JsonHelper.setYinHaiSafe(funNo);
  29. sSafeControlsRtnValue = string.Empty;
  30. Init();
  31. Call(funNo,joInput.ToString(), out sSafeControlsRtnValue);
  32. JObject joRtn = new JObject();
  33. joRtn = JObject.Parse(sSafeControlsRtnValue);
  34. int errorCode = int.Parse(joRtn["code"].ToString());
  35. string errorMessage = joRtn["message"].ToString();
  36. if (errorCode != 1)
  37. {
  38. sSafeControlsRtnValue = errorMessage;
  39. return -1;
  40. }
  41. else
  42. {
  43. JObject jodata = JObject.FromObject(joRtn["data"]);
  44. Global.writeLog("参保地:"+ Global.pat.insuplc_admdvs);
  45. Global.writeLog("读卡返回:" + jodata.ToString());
  46. // 如果存在则不使用读卡返回的信息
  47. if (string.IsNullOrEmpty(Global.pat.insuplc_admdvs))
  48. {
  49. Global.pat.insuplc_admdvs = jodata["insuplc_admdvs"].ToString();
  50. }
  51. Global.pat.mdtrtcertType = jodata["mdtrt_cert_type"].ToString();
  52. Global.pat.mdtrtcertNO = jodata["mdtrt_cert_no"].ToString();
  53. Global.pat.psn_type = jodata["psn_cert_type"].ToString();
  54. Global.pat.certNO = jodata["certno"].ToString();
  55. Global.pat.name = jodata["psn_name"].ToString();
  56. Global.pat.card.SN = jodata["card_sn"].ToString();
  57. Global.pat.card.Cardtoken = jodata["card_token"].ToString();
  58. sSafeControlsRtnValue = jodata.ToString();
  59. }
  60. return 0;
  61. }
  62. /// <summary>
  63. /// 调用银海控件进行打印
  64. /// </summary>
  65. /// <param name="input"></param>
  66. /// <param name="output"></param>
  67. public void YinHaiPrint(string input, out string output)
  68. {
  69. string errMsg = string.Empty;
  70. Init();
  71. Print(input, out output);
  72. }
  73. private int Init()
  74. {
  75. comType = System.Type.GetTypeFromProgID(progID);
  76. // 创建Com的实例
  77. if (comType != null)
  78. {
  79. Global.writeLog("开始COM组件Init");
  80. //创建实例
  81. comInstance = Activator.CreateInstance(comType);
  82. if (comInstance != null)
  83. {
  84. Global.writeLog("Init实例创建成功");
  85. }
  86. //设置需要设置的参数值
  87. object[] ParamArray = new object[2];
  88. ParamArray[0] = 0;
  89. ParamArray[1] = "";
  90. ParameterModifier[] ParamMods = new ParameterModifier[1];
  91. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  92. ParamMods[0][0] = true;
  93. ParamMods[0][1] = true; // 设置第二个参数为返回参数,调用含有ParameterModifier数组的重载函数
  94. comType.InvokeMember("yh_CHS_init", // 接口函数名
  95. BindingFlags.Default | BindingFlags.InvokeMethod,
  96. null,
  97. comInstance, // 调用的COM组件
  98. ParamArray, // 参数数组
  99. ParamMods, // 指定返回参数的ParameterModifier数组
  100. null,
  101. null);
  102. string Msg = "加载成功:" + ParamArray[1].ToString();
  103. Global.writeLog(Msg + "___" + ParamArray[0].ToString());
  104. return (int)ParamArray[0];
  105. }
  106. else
  107. {
  108. string Msg = "YinHaiComType加载失败!";
  109. Global.writeLog(Msg);
  110. return 1;
  111. }
  112. }
  113. private int Call(string infno, string inputData, out string outputData)
  114. {
  115. try
  116. {
  117. if (comType != null)
  118. {
  119. //创建实例,不能再次创建,否则会提示没有初始化
  120. if (comInstance != null)
  121. {
  122. Global.writeLog("实例创建成功,准备调用Call服务");
  123. }
  124. else
  125. {
  126. outputData = "实例不存在!";
  127. Global.writeLog("实例不存在");
  128. return -1;
  129. }
  130. //设置需要设置的参数值
  131. object[] ParamArray = new object[3];
  132. ParamArray[0] = infno;
  133. ParamArray[1] = inputData;
  134. ParamArray[2] = "";
  135. ParameterModifier[] ParamMods = new ParameterModifier[1];
  136. ParamMods[0] = new ParameterModifier(3); // 初始化为接口参数的个数
  137. ParamMods[0][2] = true;
  138. comType.InvokeMember("yh_CHS_call", // 接口函数名
  139. BindingFlags.Default | BindingFlags.InvokeMethod,
  140. null,
  141. comInstance, // 调用的COM组件
  142. ParamArray, // 参数数组
  143. ParamMods, // 指定返回参数的ParameterModifier数组
  144. null,
  145. null);
  146. outputData = ParamArray[2].ToString();
  147. Global.writeLog("Com输出:" + outputData);
  148. return 0;
  149. }
  150. else
  151. {
  152. outputData = "COM加载失败!";
  153. Global.writeLog("COM加载失败!");
  154. }
  155. }
  156. catch (Exception ex)
  157. {
  158. outputData = ex.Message;
  159. Global.writeLog("COM加载失败!" + outputData);
  160. }
  161. return -1;
  162. }
  163. /// <summary>
  164. /// 打印结算清单
  165. /// </summary>
  166. /// <param name="input"></param>
  167. /// <param name="output"></param>
  168. private void Print(string input, out string output)
  169. {
  170. if (comType != null)
  171. {
  172. //创建实例,不能再次创建,否则会提示没有初始化
  173. if (comInstance != null)
  174. {
  175. Global.writeLog("实例创建成功,准备调用Call服务");
  176. }
  177. else
  178. {
  179. output = "实例不存在!";
  180. Global.writeLog("实例不存在");
  181. return;
  182. }
  183. //设置需要设置的参数值
  184. object[] ParamArray = new object[2];
  185. ParamArray[0] = input;
  186. ParamArray[1] = "";
  187. ParameterModifier[] ParamMods = new ParameterModifier[1];
  188. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  189. ParamMods[0][1] = true;
  190. comType.InvokeMember("yh_CHS_print", // 接口函数名
  191. BindingFlags.Default | BindingFlags.InvokeMethod,
  192. null,
  193. comInstance, // 调用的COM组件
  194. ParamArray, // 参数数组
  195. ParamMods, // 指定返回参数的ParameterModifier数组
  196. null,
  197. null);
  198. output = ParamArray[1].ToString();
  199. }
  200. else
  201. {
  202. output = "COM加载失败!";
  203. Global.writeLog("COM加载失败!");
  204. }
  205. }
  206. public void Destroy(out string output)
  207. {
  208. // 创建Com的实例
  209. if (comType != null)
  210. {
  211. //创建实例
  212. comInstance = Activator.CreateInstance(comType);
  213. if (comInstance != null)
  214. {
  215. Global.writeLog("实例创建成功,准备调用Call服务");
  216. }
  217. else
  218. {
  219. output = "实例不存在!";
  220. Global.writeLog("实例不存在");
  221. return;
  222. }
  223. //设置需要设置的参数值
  224. object[] ParamArray = new object[0];
  225. ParameterModifier[] ParamMods = new ParameterModifier[0];
  226. ParamMods[0] = new ParameterModifier(0); // 初始化为接口参数的个数
  227. comType.InvokeMember("yh_CHS_destroy", // 接口函数名
  228. BindingFlags.Default | BindingFlags.InvokeMethod,
  229. null,
  230. comInstance, // 调用的COM组件
  231. ParamArray, // 参数数组
  232. ParamMods, // 指定返回参数的ParameterModifier数组
  233. null,
  234. null);
  235. output = "destroy成功!";
  236. }
  237. else
  238. {
  239. output = "COM加载失败!";
  240. Global.writeLog("COM加载失败!");
  241. }
  242. }
  243. }
  244. }