InvokeComCenter.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Variables;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using PTMedicalInsurance.Business;
  11. using System.Diagnostics;
  12. using PTMedicalInsurance.Forms;
  13. namespace PTMedicalInsurance.Helper
  14. {
  15. class InvokeComCenter : IInvokeCenter
  16. {
  17. string progID1 = "ybjk.interface";
  18. System.Type YinHaiComType;
  19. object YinHaiComInstance;
  20. //[STAThread]
  21. //static void Main()
  22. //{
  23. // //Application.EnableVisualStyles();
  24. // //Application.SetCompatibleTextRenderingDefault(false);
  25. // // 开始监控窗口
  26. // WindowMonitor.Start();
  27. // // 运行应用程序
  28. // //Application.Run();
  29. //}
  30. public int Business(string infno, ref string input, ref string output)
  31. {
  32. YinHaiComType = System.Type.GetTypeFromProgID(progID1);
  33. JObject jo = new JObject();
  34. jo.Add("transNo", infno);
  35. jo.Add("transType", "passwordCheck");
  36. jo.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmss"));
  37. jo.Add("businessType", Global.pat.card.ecBizType);
  38. jo.Add("data", JObject.Parse(input));
  39. string inpar = jo.ToString();
  40. try
  41. {
  42. //WindowMonitor.Start();
  43. // 创建Com的实例
  44. if (YinHaiComType != null)
  45. {
  46. //创建实例
  47. YinHaiComInstance = Activator.CreateInstance(YinHaiComType);
  48. //设置需要设置的参数值
  49. //设置需要设置的参数值
  50. object[] ParamArray = new object[3];
  51. ParamArray[0] = infno;
  52. ParamArray[1] = inpar;
  53. ParamArray[2] = "";
  54. ParameterModifier[] ParamMods = new ParameterModifier[1];
  55. ParamMods[0] = new ParameterModifier(3); // 初始化为接口参数的个数
  56. //ParamMods[0][0] = false;
  57. //ParamMods[0][1] = false;
  58. ParamMods[0][2] = true;
  59. YinHaiComType.InvokeMember("xjyb_call", // 接口函数名
  60. BindingFlags.Default | BindingFlags.InvokeMethod,
  61. null,
  62. YinHaiComInstance, // 调用的COM组件
  63. ParamArray, // 参数数组
  64. ParamMods, // 指定返回参数的ParameterModifier数组
  65. null,
  66. null);
  67. output = ParamArray[2].ToString();
  68. return 0;
  69. }
  70. else
  71. {
  72. output = "YinHaiComType加载失败!";
  73. return 1;
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. string outMes = ex.Message;
  79. if (ex.InnerException != null)
  80. {
  81. outMes += ex.InnerException.Message;
  82. }
  83. output = outMes;
  84. return -1;
  85. }
  86. finally
  87. {
  88. Global.writeLog("InvokeComCenter.Business", inpar, output);
  89. }
  90. }
  91. public int BusinessExt(string inputData, ref string outputData, ref string pErrMsg)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. public int DownloadFile(string inputData, ref string outputData)
  96. {
  97. throw new NotImplementedException();
  98. }
  99. public int Init(ref string pErrMsg)
  100. {
  101. return 0;
  102. }
  103. public int UploadFile(string inputData, ref string outputData, ref string pErrMsg)
  104. {
  105. throw new NotImplementedException();
  106. }
  107. }
  108. /// <summary>
  109. /// 2026版本控件调用
  110. /// </summary>
  111. class InvokeComCenter2026 : IInvokeCenter
  112. {
  113. string progID1 = "ybjk.interface";
  114. System.Type YinHaiComType;
  115. object YinHaiComInstance;
  116. public int Business(string infno, ref string input, ref string output)
  117. {
  118. try
  119. {
  120. Type comType = Type.GetTypeFromProgID(progID1);
  121. if (comType == null)
  122. {
  123. output = "COM 组件未注册或 progID 错误";
  124. return -1;
  125. }
  126. object comInstance = Activator.CreateInstance(comType);
  127. // 构造输入 JSON(略,你已有)
  128. JObject jo = new JObject();
  129. jo.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmss"));
  130. jo.Add("business_type", Global.pat.card.ecBizType );
  131. jo.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
  132. jo.Add("operator_id", Global.user.ID);
  133. jo.Add("operator_name", Global.user.name);
  134. jo.Add("device_type", ""); // 注意:你之前写成 user.ID,可能错误!
  135. jo.Add("office_id", Global.user.officeID);
  136. jo.Add("office_name", Global.user.officeName);
  137. jo.Add("work_injury_flag", Global.pat.isWorkInjury ? "1" :"0");
  138. jo.Add("data", string.IsNullOrWhiteSpace(input) ? new JObject() : JObject.Parse(input));
  139. string inpar = jo.ToString();
  140. // === 关键:调用 COM 方法 ===
  141. string jysc = ""; // 初始化输出参数(必须是 string 类型!)
  142. // 使用 object[] 传递参数
  143. object[] args = new object[3] { infno, inpar, jysc };
  144. // 告诉 .NET 第3个参数是 ref(可被修改)
  145. ParameterModifier paramMod = new ParameterModifier(3);
  146. paramMod[2] = true; // 索引从0开始,第3个参数是索引2
  147. comType.InvokeMember(
  148. "xjyb_call",
  149. BindingFlags.InvokeMethod,
  150. null,
  151. comInstance,
  152. args,
  153. new ParameterModifier[] { paramMod },
  154. null,
  155. null
  156. );
  157. // 取出被 COM 修改后的输出值
  158. output = args[2]?.ToString() ?? "";
  159. // 可选:记录日志
  160. Global.writeLog($"InvokeComCenter.Business.{infno}", inpar, output);
  161. return 0;
  162. }
  163. catch (Exception ex)
  164. {
  165. output = $"调用 COM 失败: {ex.Message}";
  166. Global.writeLog("InvokeComCenter.Error", "", output);
  167. return -1;
  168. }
  169. }
  170. //public int Business(string infno, ref string input, ref string output)
  171. //{
  172. // YinHaiComType = System.Type.GetTypeFromProgID(progID1);
  173. // JObject jo = new JObject();
  174. // jo.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmss"));
  175. // jo.Add("business_type", Global.pat.card.ecBizType);
  176. // jo.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
  177. // jo.Add("operator_id", Global.user.ID);
  178. // jo.Add("operator_name", Global.user.name);
  179. // jo.Add("device_typ", Global.user.ID);//自助机该字段设为SelfService,其它情况 不用设置
  180. // jo.Add("office_id", Global.user.officeID);
  181. // jo.Add("office_name", Global.user.officeName);
  182. // jo.Add("work_injury_flag", Global.pat.isWorkInjury?1:0);//根据此标志转发人社工伤医疗费用结算子系统,见本文档附件 2《字典表》
  183. // jo.Add("data", JObject.Parse(input));
  184. // string inpar = jo.ToString();
  185. // try
  186. // {
  187. // //WindowMonitor.Start();
  188. // // 创建Com的实例
  189. // if (YinHaiComType != null)
  190. // {
  191. // //创建实例
  192. // YinHaiComInstance = Activator.CreateInstance(YinHaiComType);
  193. // //设置需要设置的参数值
  194. // //设置需要设置的参数值
  195. // object[] ParamArray = new object[3];
  196. // ParamArray[0] = infno;
  197. // ParamArray[1] = inpar;
  198. // ParamArray[2] = "";
  199. // ParameterModifier[] ParamMods = new ParameterModifier[1];
  200. // ParamMods[0] = new ParameterModifier(3); // 初始化为接口参数的个数
  201. // //ParamMods[0][0] = false;
  202. // //ParamMods[0][1] = false;
  203. // ParamMods[0][2] = true;
  204. // YinHaiComType.InvokeMember("xjyb_call", // 接口函数名
  205. // BindingFlags.Default | BindingFlags.InvokeMethod,
  206. // null,
  207. // YinHaiComInstance, // 调用的COM组件
  208. // ParamArray, // 参数数组
  209. // ParamMods, // 指定返回参数的ParameterModifier数组
  210. // null,
  211. // null);
  212. // output = ParamArray[2].ToString();
  213. // return 0;
  214. // }
  215. // else
  216. // {
  217. // output = "YinHaiComType加载失败!";
  218. // return 1;
  219. // }
  220. // }
  221. // catch (Exception ex)
  222. // {
  223. // string outMes = ex.Message;
  224. // if (ex.InnerException != null)
  225. // {
  226. // outMes += ex.InnerException.Message;
  227. // }
  228. // output = outMes;
  229. // return -1;
  230. // }
  231. // finally
  232. // {
  233. // Global.writeLog($"InvokeComCenter.Business{infno}", inpar, output);
  234. // }
  235. //}
  236. public int BusinessExt(string inputData, ref string outputData, ref string pErrMsg)
  237. {
  238. throw new NotImplementedException();
  239. }
  240. public int DownloadFile(string inputData, ref string outputData)
  241. {
  242. throw new NotImplementedException();
  243. }
  244. public int Init(ref string pErrMsg)
  245. {
  246. return 0;
  247. }
  248. public int UploadFile(string inputData, ref string outputData, ref string pErrMsg)
  249. {
  250. throw new NotImplementedException();
  251. }
  252. }
  253. }