Example #1
0
        /// <summary>
        /// 执行处理
        /// </summary>
        public XmlDocument Execute()
        {
            XmlDocument result;
            Guid?       organization     = null;
            var         organizationName = string.Empty;

            try
            {
                organization     = Company.CompanyId;
                organizationName = Company.AbbreviateName;

                validateSign();
                InvokeStatistic.Instance.Save(Context);
                validatePermission();
                //存储请求接口的域名
                ChinaPay.B3B.Service.LogService.SaveTextLog("客户端信息:IP " + System.Web.HttpContext.Current.Request.UserHostAddress + " 域名 " + System.Web.HttpContext.Current.Request.UserHostName);
                var execResult = ExecuteCore();
                result = Responser.Format(execResult);
            }
            catch (InterfaceInvokeException iie)
            {
                result = Responser.Format(iie);
            }
            catch (CustomException ex)
            {
                result = Responser.Format(ex);
            }
            catch (Exception ex)
            {
                Service.LogService.SaveExceptionLog(ex, "调用接口" + Context.Service);
                result = Responser.Format(ex);
            }
            // 记录访问日志
            var invokeLog = new Service.Log.Domain.InterfaceInvokeLog
            {
                InterfaceName    = Context.Service,
                UserName         = Context.UserName,
                Organization     = organization,
                OrganizationName = organizationName,
                IPAddress        = Context.ClientIP,
                Request          = Context.Original,
                Response         = result.InnerXml,
                Time             = DateTime.Now
            };

            Service.LogService.SaveInterfaceInvokeLog(invokeLog);
            return(result);
        }
Example #2
0
        public XmlDocument Execute()
        {
            XmlDocument result;
            var         interfaceName    = GetType().Name;
            var         remoteIP         = AddressLocator.IPAddressLocator.GetRequestIP(_context.Request).ToString();
            Guid?       organization     = null;
            var         organizationName = "";

            try
            {
                organization     = Company.CompanyId;
                organizationName = Company.AbbreviateName;
                // 控制访问频率
                InvokeStatistic.Instance.Save(interfaceName, _userName, remoteIP);
                var externalInterface = ExternalInterfaceService.Query(Company.CompanyId);
                // 是否有权限访问
                if (externalInterface.BindIP != remoteIP)
                {
                    throw new InterfaceInvokeException("10");
                }
                if (externalInterface.InterfaceInvokeMethod == null || !externalInterface.InterfaceInvokeMethod.Any())
                {
                    throw new InterfaceInvokeException("10");
                }
                if (!externalInterface.InterfaceInvokeMethod.Contains(interfaceName))
                {
                    throw new InterfaceInvokeException("10");
                }
                // 验证签名
                ValidateSign();
                // 验证业务参数
                ValidateBusinessParameters();
                //存储请求接口的域名
                ChinaPay.B3B.Service.LogService.SaveTextLog("客户端信息:IP " + _context.Request.UserHostAddress + " 域名 " + _context.Request.UserHostName);
                // 执行接口处理
                result = FormatInvokeResult("0", string.Empty, ExecuteCore());
            }
            catch (InterfaceInvokeException iie)
            {
                result = FormatInvokeResult(iie.Code, iie.Parameter, string.Empty);
            }
            catch (CustomException ex)
            {
                result = FormatInvokeResult("9", ex.Message, string.Empty);
            }
            catch (Exception ex)
            {
                Service.LogService.SaveExceptionLog(ex, "调用接口" + interfaceName);
                result = FormatInvokeResult("99", string.Empty, string.Empty);
            }
            var businessParametersText = new StringBuilder();
            var businessParameters     = GetBusinessParameterCollection();

            foreach (var key in businessParameters.AllKeys)
            {
                businessParametersText.AppendFormat("&{0}={1}", key, businessParameters.Get(key));
            }
            // 记录访问日志
            var invokeLog = new Service.Log.Domain.InterfaceInvokeLog
            {
                InterfaceName    = interfaceName,
                UserName         = _userName,
                Organization     = organization,
                OrganizationName = organizationName,
                IPAddress        = remoteIP,
                Request          = string.Format("userName={0}&sign={1}{2}", _userName, _sign, businessParametersText.ToString()),
                Response         = result.InnerXml,
                Time             = DateTime.Now
            };

            Service.LogService.SaveInterfaceInvokeLog(invokeLog);
            return(result);
        }