YinHaiSafeCtrl.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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.pat.insuplc_admdvs = jodata["insuplc_admdvs"].ToString();
  45. Global.pat.mdtrtcertType = jodata["mdtrt_cert_type"].ToString();
  46. Global.pat.mdtrtcertNO = jodata["mdtrt_cert_no"].ToString();
  47. Global.pat.psn_type = jodata["psn_cert_type"].ToString();
  48. Global.pat.certNO = jodata["certno"].ToString();
  49. Global.pat.name = jodata["psn_name"].ToString();
  50. Global.pat.card.SN = jodata["card_sn"].ToString();
  51. Global.pat.card.Cardtoken = jodata["card_token"].ToString();
  52. sSafeControlsRtnValue = jodata.ToString();
  53. }
  54. return 0;
  55. }
  56. /// <summary>
  57. /// 调用银海控件进行打印
  58. /// </summary>
  59. /// <param name="input"></param>
  60. /// <param name="output"></param>
  61. public void YinHaiPrint(string input, out string output)
  62. {
  63. string errMsg = string.Empty;
  64. Init();
  65. Print(input, out output);
  66. }
  67. private int Init()
  68. {
  69. comType = System.Type.GetTypeFromProgID(progID);
  70. // 创建Com的实例
  71. if (comType != null)
  72. {
  73. Global.writeLog("开始COM组件Init");
  74. //创建实例
  75. comInstance = Activator.CreateInstance(comType);
  76. if (comInstance != null)
  77. {
  78. Global.writeLog("Init实例创建成功");
  79. }
  80. //设置需要设置的参数值
  81. object[] ParamArray = new object[2];
  82. ParamArray[0] = 0;
  83. ParamArray[1] = "";
  84. ParameterModifier[] ParamMods = new ParameterModifier[1];
  85. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  86. ParamMods[0][0] = true;
  87. ParamMods[0][1] = true; // 设置第二个参数为返回参数,调用含有ParameterModifier数组的重载函数
  88. comType.InvokeMember("yh_CHS_init", // 接口函数名
  89. BindingFlags.Default | BindingFlags.InvokeMethod,
  90. null,
  91. comInstance, // 调用的COM组件
  92. ParamArray, // 参数数组
  93. ParamMods, // 指定返回参数的ParameterModifier数组
  94. null,
  95. null);
  96. string Msg = "加载成功:" + ParamArray[1].ToString();
  97. Global.writeLog(Msg + "___" + ParamArray[0].ToString());
  98. return (int)ParamArray[0];
  99. }
  100. else
  101. {
  102. string Msg = "YinHaiComType加载失败!";
  103. Global.writeLog(Msg);
  104. return 1;
  105. }
  106. }
  107. private int Call(string infno, string inputData, out string outputData)
  108. {
  109. try
  110. {
  111. if (comType != null)
  112. {
  113. //创建实例,不能再次创建,否则会提示没有初始化
  114. if (comInstance != null)
  115. {
  116. Global.writeLog("实例创建成功,准备调用Call服务");
  117. }
  118. else
  119. {
  120. outputData = "实例不存在!";
  121. Global.writeLog("实例不存在");
  122. return -1;
  123. }
  124. //设置需要设置的参数值
  125. object[] ParamArray = new object[3];
  126. ParamArray[0] = infno;
  127. ParamArray[1] = inputData;
  128. ParamArray[2] = "";
  129. ParameterModifier[] ParamMods = new ParameterModifier[1];
  130. ParamMods[0] = new ParameterModifier(3); // 初始化为接口参数的个数
  131. ParamMods[0][2] = true;
  132. comType.InvokeMember("yh_CHS_call", // 接口函数名
  133. BindingFlags.Default | BindingFlags.InvokeMethod,
  134. null,
  135. comInstance, // 调用的COM组件
  136. ParamArray, // 参数数组
  137. ParamMods, // 指定返回参数的ParameterModifier数组
  138. null,
  139. null);
  140. outputData = ParamArray[2].ToString();
  141. Global.writeLog("Com输出:" + outputData);
  142. return 0;
  143. }
  144. else
  145. {
  146. outputData = "COM加载失败!";
  147. Global.writeLog("COM加载失败!");
  148. }
  149. }
  150. catch (Exception ex)
  151. {
  152. outputData = ex.Message;
  153. Global.writeLog("COM加载失败!" + outputData);
  154. }
  155. return -1;
  156. }
  157. /// <summary>
  158. /// 打印结算清单
  159. /// </summary>
  160. /// <param name="input"></param>
  161. /// <param name="output"></param>
  162. private void Print(string input, out string output)
  163. {
  164. if (comType != null)
  165. {
  166. //创建实例,不能再次创建,否则会提示没有初始化
  167. if (comInstance != null)
  168. {
  169. Global.writeLog("实例创建成功,准备调用Call服务");
  170. }
  171. else
  172. {
  173. output = "实例不存在!";
  174. Global.writeLog("实例不存在");
  175. return;
  176. }
  177. //设置需要设置的参数值
  178. object[] ParamArray = new object[2];
  179. ParamArray[0] = input;
  180. ParamArray[1] = "";
  181. ParameterModifier[] ParamMods = new ParameterModifier[1];
  182. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  183. ParamMods[0][1] = true;
  184. comType.InvokeMember("yh_CHS_print", // 接口函数名
  185. BindingFlags.Default | BindingFlags.InvokeMethod,
  186. null,
  187. comInstance, // 调用的COM组件
  188. ParamArray, // 参数数组
  189. ParamMods, // 指定返回参数的ParameterModifier数组
  190. null,
  191. null);
  192. output = ParamArray[1].ToString();
  193. }
  194. else
  195. {
  196. output = "COM加载失败!";
  197. Global.writeLog("COM加载失败!");
  198. }
  199. }
  200. public void Destroy(out string output)
  201. {
  202. // 创建Com的实例
  203. if (comType != null)
  204. {
  205. //创建实例
  206. comInstance = Activator.CreateInstance(comType);
  207. if (comInstance != null)
  208. {
  209. Global.writeLog("实例创建成功,准备调用Call服务");
  210. }
  211. else
  212. {
  213. output = "实例不存在!";
  214. Global.writeLog("实例不存在");
  215. return;
  216. }
  217. //设置需要设置的参数值
  218. object[] ParamArray = new object[0];
  219. ParameterModifier[] ParamMods = new ParameterModifier[0];
  220. ParamMods[0] = new ParameterModifier(0); // 初始化为接口参数的个数
  221. comType.InvokeMember("yh_CHS_destroy", // 接口函数名
  222. BindingFlags.Default | BindingFlags.InvokeMethod,
  223. null,
  224. comInstance, // 调用的COM组件
  225. ParamArray, // 参数数组
  226. ParamMods, // 指定返回参数的ParameterModifier数组
  227. null,
  228. null);
  229. output = "destroy成功!";
  230. }
  231. else
  232. {
  233. output = "COM加载失败!";
  234. Global.writeLog("COM加载失败!");
  235. }
  236. }
  237. }
  238. }