InvokeComCenter.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. namespace PTMedicalInsurance.Helper
  11. {
  12. class InvokeComCenter : IInvokeCenter
  13. {
  14. string progID1 = "ybjk.interface";
  15. System.Type YinHaiComType;
  16. object YinHaiComInstance;
  17. public int Business(string infno, ref string input, ref string output)
  18. {
  19. YinHaiComType = System.Type.GetTypeFromProgID(progID1);
  20. JObject jo = new JObject();
  21. jo.Add("transNo", infno);
  22. jo.Add("transType", "passwordCheck");
  23. jo.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmss"));
  24. jo.Add("businessType", Global.pat.card.ecBizType);
  25. jo.Add("data", JObject.Parse(input));
  26. string inpar = jo.ToString();
  27. try
  28. {
  29. // 创建Com的实例
  30. if (YinHaiComType != null)
  31. {
  32. //创建实例
  33. YinHaiComInstance = Activator.CreateInstance(YinHaiComType);
  34. //设置需要设置的参数值
  35. //设置需要设置的参数值
  36. object[] ParamArray = new object[3];
  37. ParamArray[0] = infno;
  38. ParamArray[1] = inpar;
  39. ParamArray[2] = "";
  40. ParameterModifier[] ParamMods = new ParameterModifier[1];
  41. ParamMods[0] = new ParameterModifier(3); // 初始化为接口参数的个数
  42. //ParamMods[0][0] = false;
  43. //ParamMods[0][1] = false;
  44. ParamMods[0][2] = true;
  45. YinHaiComType.InvokeMember("xjyb_call", // 接口函数名
  46. BindingFlags.Default | BindingFlags.InvokeMethod,
  47. null,
  48. YinHaiComInstance, // 调用的COM组件
  49. ParamArray, // 参数数组
  50. ParamMods, // 指定返回参数的ParameterModifier数组
  51. null,
  52. null);
  53. output = ParamArray[2].ToString();
  54. return 0;
  55. }
  56. else
  57. {
  58. output = "YinHaiComType加载失败!";
  59. return 1;
  60. }
  61. }
  62. catch (Exception ex)
  63. {
  64. string outMes = ex.Message;
  65. if (ex.InnerException != null)
  66. {
  67. outMes += ex.InnerException.Message;
  68. }
  69. output = outMes;
  70. return -1;
  71. }
  72. finally
  73. {
  74. Global.writeLog("InvokeComCenter.Business", inpar,output);
  75. }
  76. }
  77. public int BusinessExt(string inputData, ref string outputData, ref string pErrMsg)
  78. {
  79. throw new NotImplementedException();
  80. }
  81. public int DownloadFile(string inputData, ref string outputData)
  82. {
  83. throw new NotImplementedException();
  84. }
  85. public int Init(ref string pErrMsg)
  86. {
  87. return 0;
  88. }
  89. public int UploadFile(string inputData, ref string outputData, ref string pErrMsg)
  90. {
  91. throw new NotImplementedException();
  92. }
  93. }
  94. }