Exemplo n.º 1
0
        public static TResponse SendRequest <TRequest, TResponse>(int code, TRequest request)
            where TRequest : RequestBase
            where TResponse : ResponseBase, new()
        {
            PluginEntry.Context.Logger.Info($"调用接口:【{code}】");

            var response = new TResponse();

            try
            {
                if (string.IsNullOrEmpty(request.HospitalCode))
                {
                    throw new Exception("医疗机构编号不能为空!");
                }

                if (!isInit && !PluginEntry.YibaoSetting.IsTest)
                {
                    PluginEntry.Context.Logger.Info($"接口初始化");
                    Init(request.HospitalCode);
                    isInit = true;
                }

                string inputData = MessageSerializer.SerializeRequest(request);

                PluginEntry.Context.Logger.Info($"【{code}】输入: {inputData}");
                StringBuilder retMsg = new StringBuilder(4096);
                waitHandler.WaitOne(3000);
                int result = YibaoApi.f_UserBargaingApply(code, 0, inputData, retMsg, request.HospitalCode);
                waitHandler.Set();
                string value = retMsg.ToString().Trim();
                PluginEntry.Context.Logger.Info($"【{code}】返回值: {result} 输出: {value}");

                if (result == 0)
                {
                    response = MessageSerializer.Deserialize <TResponse>(value);
                }
                else
                {
                    response.IsSuccess     = false;
                    response.ResultMessage = "交易失败";
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess     = false;
                response.ResultMessage = ex.Message;
                PluginEntry.Context.Logger.Error($"【{code}】错误", ex);
            }

            return(response);
        }