예제 #1
0
        /// <summary>
        /// 获取通用接口 -- 返回单个Common集合
        /// </summary>
        /// <param name="key">接口KEY字符串</param>
        /// <param name="skey">接口KEY数字</param>
        /// <returns>结果对象</returns>
        public static object GetCommonApi(string key, short skey = 0)
        {
            string staffNo = "";

            if (HttpContext.Current.Session["StaffNo"] != null)
            {
                staffNo = HttpContext.Current.Session["StaffNo"].ToString();
            }
            string keyCacheCode = key;

            if (key == "Menus")
            {
                keyCacheCode = key + staffNo;
            }
            Cache cache = HttpRuntime.Cache;

            if (cache.Get(keyCacheCode) != null)
            {
                return(cache.Get(keyCacheCode));
            }

            CommonResponse commonResponse = WeChatHelper.CallService <WeChat.ServiceModel.Base.Common, CommonResponse>("",
                                                                                                                       new WeChat.ServiceModel.Base.Common {
                CurrOper = staffNo, RequestType = skey
            }, ConfigurationManager.AppSettings["WeChat_CommonURI"]);

            object returnValue = commonResponse.GetType().GetProperty(key).GetValue(commonResponse, null);

            if (returnValue != null)
            {
                cache.Insert(keyCacheCode, returnValue, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            }
            return(returnValue);
        }
예제 #2
0
        /// <summary>
        /// 调用接口(缓存180分钟)
        /// </summary>
        /// <typeparam name="TRequestDto">请求DTO</typeparam>
        /// <typeparam name="TResponseDto">响应DTO</typeparam>
        /// <param name="key">缓存KEY</param>
        /// <param name="serviceId">接口服务ID</param>
        /// <param name="request">请求DTO实例</param>
        /// <param name="action"></param>
        /// <returns>响应DTO实例</returns>
        public static TResponseDto GetCache <TRequestDto, TResponseDto>(string key, string serviceId,
                                                                        TRequestDto request, Action <TResponseDto> action = null)
            where TRequestDto : BaseRequest
        {
            Cache cache = HttpRuntime.Cache;

            if (cache.Get(key) != null)
            {
                return((TResponseDto)cache.Get(key));
            }
            var returnValue = WeChatHelper.PostService <TRequestDto, TResponseDto>(serviceId, request);

            if (action != null)
            {
                action(returnValue);
            }
            if (returnValue != null)
            {
                cache.Insert(key, returnValue, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            }
            return(returnValue);
        }
예제 #3
0
        /// <summary>
        /// 初始化服务,缓存参数
        /// </summary>
        public static void InitializeCache()
        {
            Cache          cache          = HttpRuntime.Cache;
            CommonResponse commonResponse = WeChatHelper.CallService <WeChat.ServiceModel.Base.Common, CommonResponse>("",
                                                                                                                       new WeChat.ServiceModel.Base.Common {
                RequestType = 0
            }, ConfigurationManager.AppSettings["WeChat_CommonURI"]);

            if (commonResponse.Services.IsEmpty())
            {
                throw new Exception("获取WeChat服务列表失败");
            }
            if (commonResponse.Services != null)
            {
                cache.Insert("Services", commonResponse.Services, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            }
            //if (commonResponse.PaperTypes != null)
            //    cache.Insert("PaperTypes", commonResponse.PaperTypes, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            //if (commonResponse.TradeFees != null)
            //    cache.Insert("TradeFees", commonResponse.TradeFees, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            //if (commonResponse.TradeParameters != null)
            //    cache.Insert("TradeParameters", commonResponse.TradeParameters, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            //if (commonResponse.CardTypes != null)
            //    cache.Insert("CardTypes", commonResponse.CardTypes, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            //if (commonResponse.CardSurfaces != null)
            //    cache.Insert("CardSurfaces", commonResponse.CardSurfaces, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            //if (commonResponse.CardCosTypes != null)
            //    cache.Insert("CardCosTypes", commonResponse.CardCosTypes, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            //if (commonResponse.CardChipTypes != null)
            //    cache.Insert("CardChipTypes", commonResponse.CardChipTypes, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            //if (commonResponse.Manus != null)
            //    cache.Insert("Manus", commonResponse.Manus, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            //if (commonResponse.ReasonTypes != null)
            //    cache.Insert("ReasonTypes", commonResponse.ReasonTypes, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
            //if (commonResponse.TradeTypeShows != null)
            //    cache.Insert("TradeTypeShows", commonResponse.TradeTypeShows, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 180, 0));
        }