Example #1
0
        private T DoExecute <T>(IVenusRequest <T> request, string action, string postData) where T : VenusClientResponse
        {
            DateTime timestamp = DateTime.Now;

            //  提前检查业务参数
            try
            {
                request.Validate();
            }
            catch (VenusException e)
            {
                return(CreateErrorResponse <T>(e.ErrorCode, e.ErrorMsg));
            }
            try
            {
                //  postData内插入基础数据、时间戳
                postData = postData.Insert(1, string.Format("{0}, \"timestamp\":{1},", Config.JXServiceConfig.ServiceBody, Utils.ConvertDataTimeHelper.ConvertDataTimeLong(timestamp)));

                //  生成签名
                string sign = SignUtil.SignVenusRequest(postData, appSecret).Replace("+", "%2B");

                //  发起请求
                string body = webUtils.DoPost(string.Format("{0}{1}?signature={2}", this.serverUrl, action, sign), postData);

                // 解释响应结果
                T rsp;


                IVenusParser <T> tp = new VenusJsonParser <T>();
                rsp = tp.Parse(body);

                // 追踪错误的请求
                if (rsp.IsError)
                {
                    log.Warn(string.Format("参数:{0},结果:{1}", postData, rsp.Body));
                }
                log.Info(string.Format("method-{0}|start-{1}|end-{2}|result-{3}", action, timestamp.ToLongTimeString(), DateTime.Now.ToLongTimeString(), rsp.ErrCode));
                return(rsp);
            }
            catch (Exception e)
            {
                log.Error(string.Format("参数:{0},结果:{1}", postData, e.Message));
                return(CreateErrorResponse <T>("1000", e.Message));
            }
        }