Exemplo n.º 1
0
        /// <summary>
        /// 格式化 Key
        /// </summary>
        /// <param name="key"></param>
        /// <param name="cacheGroup"></param>
        /// <returns></returns>
        public static string FormatKey(string key, MCaching.CacheGroup cacheGroup)
        {
            var versionId = MConfigManager.GetAppSettingsValue <string>(
                MConfigManager.FormatKey(cacheGroup + "_Version", MConfigs.ConfigsCategory.Cache), "1.0");

            return(string.Format("{0}.{1}.{2}", cacheGroup, versionId, key));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        private MRedisCache()
        {
            try
            {
                var onlyReadServers = MConfigManager.GetAppSettingsValue <string>(
                    MConfigManager.FormatKey("RedisServers_readOnly", MConfigs.ConfigsCategory.Cache),
                    "").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                var readWriteServers = MConfigManager.GetAppSettingsValue <string>(
                    MConfigManager.FormatKey("RedisServers_readWrite", MConfigs.ConfigsCategory.Cache),
                    "").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                _cachePool = new PooledRedisClientManager(readWriteServers, onlyReadServers,
                                                          new RedisClientManagerConfig
                {
                    AutoStart        = true,
                    MaxReadPoolSize  = onlyReadServers.Length * 5,
                    MaxWritePoolSize = readWriteServers.Length * 5
                });

                //GetClient() = new RedisClient(host, port);
            }
            catch (Exception ex)
            {
                MLogManager.Error(MLogGroup.Other.Redis缓存, null, "初始化 ReidaCache 失败!", ex);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 格式化图片地址
        /// </summary>
        /// <param name="imgUrl"></param>
        /// <returns></returns>
        public static string FormatProductPicUrl(string imgUrl)
        {
            var picHost =
                MConfigManager.GetAppSettingsValue <string>(MConfigManager.FormatKey("Pic",
                                                                                     Core.Enums.MConfigs.
                                                                                     ConfigsCategory.Host));

            return((string.IsNullOrWhiteSpace(imgUrl) || string.IsNullOrWhiteSpace(picHost)) ? "" : picHost + "product/{0}/" + imgUrl.Trim('/'));
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        public AlipayWapPayment()
        {
            NotifyUrl   = MConfigManager.GetAppSettingsValue <string>(MConfigManager.FormatKey("Alipay_NotifyUrl", Enums.MConfigs.ConfigsCategory.Payment));
            MerchantUrl = MConfigManager.GetAppSettingsValue <string>(MConfigManager.FormatKey("Alipay_MerchantUrl", Enums.MConfigs.ConfigsCategory.Payment));
            CallbackUrl = MConfigManager.GetAppSettingsValue <string>(MConfigManager.FormatKey("Alipay_CallbackUrl", Enums.MConfigs.ConfigsCategory.Payment));

            Partner       = MConfigManager.GetAppSettingsValue <string>(MConfigManager.FormatKey("Alipay_Partner", Enums.MConfigs.ConfigsCategory.Payment));       // "2088201564809153";
            Key           = MConfigManager.GetAppSettingsValue <string>(MConfigManager.FormatKey("Alipay_Key", Enums.MConfigs.ConfigsCategory.Payment));           // "zpdjh9ywq433ejjnkrbc5pys7ipkosnz";
            SellerAccount = MConfigManager.GetAppSettingsValue <string>(MConfigManager.FormatKey("Alipay_SellerAccount", Enums.MConfigs.ConfigsCategory.Payment)); // "*****@*****.**";
        }
Exemplo n.º 5
0
 /// <summary>
 /// 构造函数
 /// </summary>
 private MMongoDbManager()
 {
     try
     {
         var host = MConfigManager.GetAppSettingsValue <string>(MConfigManager.FormatKey("MongoDbServer", MConfigs.ConfigsCategory.Cache));
         var port = MConfigManager.GetAppSettingsValue <int>(MConfigManager.FormatKey("MongoDbPort", MConfigs.ConfigsCategory.Cache));
         if (!string.IsNullOrEmpty(host) && port > 0)
         {
             var serverCon = string.Format("mongodb://{0}:{1}", host.Trim(), port);
             _server = MongoServer.Create(serverCon);
             if (_server == null)
             {
                 MLogManager.Error(MLogGroup.Other.MongoDb, null, "初始化 失败!");
             }
         }
     }
     catch (Exception ex)
     {
         MLogManager.Error(MLogGroup.Other.MongoDb, null, "初始化 失败!", ex);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// 获取缓存对象 采用 配置文件配置
 /// </summary>
 /// <returns></returns>
 public static ICache GetCacheObj()
 {
     if (_cacheObj == null)
     {
         if (IsEnable)
         {
             var key       = MConfigManager.FormatKey("Default", MConfigs.ConfigsCategory.Cache);
             var cacheType = MConfigManager.GetAppSettingsValue(key, "");
             if (!string.IsNullOrEmpty(cacheType))
             {
                 if (cacheType.Equals(MCaching.Provider.Redis.ToString(), StringComparison.OrdinalIgnoreCase))
                 {
                     _cacheObj = MRedisCache.GetInstance();
                 }
                 else if (cacheType.Equals(MCaching.Provider.Memcached.ToString(),
                                           StringComparison.OrdinalIgnoreCase))
                 {
                     _cacheObj = MMemcache.GetInstance();
                 }
                 else
                 {
                     MLogManager.Error(MLogGroup.Other.获取缓存对象, "", "缓存方式配置无法识别,节点" + key);
                 }
             }
             else
             {
                 MLogManager.Error(MLogGroup.Other.获取缓存对象, "", "请配置缓存方式,节点" + key);
             }
         }
         else
         {
             _cacheObj = NotCache.GetInstance();
         }
     }
     return(_cacheObj);
 }
Exemplo n.º 7
0
 static MCacheManager()
 {
     IsEnable = MConfigManager.GetAppSettingsValue <bool>(MConfigManager.FormatKey("IsEnable", MConfigs.ConfigsCategory.Cache), false);
 }
Exemplo n.º 8
0
        /// <summary>
        /// 验证数据一致性
        /// </summary>
        /// <returns></returns>
        public MResult VerifyData()
        {
            var result = new MResult();

            var httpContext = HttpContext.Current;
            var md5         = MHttpHelper.GetParam <string>("md5");
            var requestTime = MHttpHelper.GetParam <DateTime>("time", DateTime.MaxValue);
            var systemKey   = MConfigManager.GetAppSettingsValue <string>("SystemKey");

            if (!string.IsNullOrEmpty(md5) && !string.IsNullOrEmpty(systemKey) && requestTime != DateTime.MaxValue)
            {
                var newMd5 = string.Empty;
                var uri    = httpContext.Request.Url;

                //var url = string.Format("{0}://{1}{2}", uri.Scheme, uri.Host, uri.AbsolutePath);

                var url = uri.ToString().Split('?')[0];

                var getData   = new StringBuilder(1000);
                var getParams = httpContext.Request.QueryString;
                foreach (var p in getParams)
                {
                    var key = p.ToString();
                    if (!key.Equals("md5", StringComparison.CurrentCultureIgnoreCase))
                    {
                        var values = getParams.GetValues(key);
                        if (values != null)
                        {
                            foreach (var v in values)
                            {
                                getData.AppendFormat("{0}={1}", p, v);
                            }
                        }
                    }
                }

                var postData   = new StringBuilder(1000);
                var postParams = httpContext.Request.Form;
                foreach (var p in postParams)
                {
                    var key = p.ToString();
                    if (!key.Equals("md5", StringComparison.CurrentCultureIgnoreCase))
                    {
                        var values = postParams.GetValues(key);
                        if (values != null)
                        {
                            foreach (var v in values)
                            {
                                postData.AppendFormat("{0}={1}", p, v);
                            }
                        }
                    }
                }

                newMd5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(string.Format("{0}{1}{2}{3}", url, requestTime, postData, systemKey).ToUpper(), "MD5");

                if (md5.Equals(newMd5, StringComparison.CurrentCultureIgnoreCase))
                {
                    result.status = MResultStatus.Success;
                }
                else
                {
                    result.msg   += "提交的数据验证未通过,是否修改了参数!";
                    result.status = MResultStatus.ParamsError;
                }
            }
            else
            {
                result.msg   += "提交的数据验证未通过,没有验证代码 md5!";
                result.status = MResultStatus.ParamsError;
            }
            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 获取商品详细
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="uid"></param>
        /// <param name="channelId"></param>
        /// <param name="gid"></param>
        /// <returns></returns>
        public static MResult <ItemGoodsDetails> GetGoodsInfo(string sid, string uid, int channelId, int gid)
        {
            var result = new MResult <ItemGoodsDetails>();

            #region 会员等级
            var userLevel = 0;
            try
            {
                if (!string.IsNullOrEmpty(uid) && !uid.Equals("null", StringComparison.CurrentCultureIgnoreCase))
                {
                    var member     = Factory.DALFactory.Member();
                    var memberInfo = member.GetMemberInfo(uid);
                    userLevel = MCvHelper.To(memberInfo.clusterId, 0);
                }
                if (userLevel < 1)
                {
                    userLevel = 1;
                }
            }
            catch (Exception ex)
            {
                result.status = MResultStatus.ExecutionError;
                result.msg    = "查询用户数据错误!";
            }
            #endregion


            var goods = DALFactory.Goods();
            try
            {
                var picHost =
                    MConfigManager.GetAppSettingsValue <string>(MConfigManager.FormatKey("Pic",
                                                                                         Core.Enums.MConfigs.
                                                                                         ConfigsCategory.Host));

                var info = goods.GetGoodsInfo(userLevel, channelId, gid);
                if (info != null && info.intProductID > 0)
                {
                    var attrList = new List <KeyValuePair <string, object> >();
                    #region 处理其他属性

                    var goodsOtherInfo = GoodsBLL.GetGoodsOtherInfo(sid, uid, gid);
                    if (goodsOtherInfo.status == MResultStatus.Success)
                    {
                        if (!string.IsNullOrWhiteSpace(info.vchBrandName))
                        {
                            attrList.Add(new KeyValuePair <string, object>("品牌", info.vchBrandName));
                        }
                        if (!string.IsNullOrWhiteSpace(info.vchProColr))
                        {
                            attrList.Add(new KeyValuePair <string, object>("颜色", info.vchProColr));
                        }
                        if (!string.IsNullOrWhiteSpace(info.vchSpec))
                        {
                            attrList.Add(new KeyValuePair <string, object>("规格", info.vchSpec));
                        }
                        if (!string.IsNullOrWhiteSpace(goodsOtherInfo.info.vchFactory))
                        {
                            attrList.Add(new KeyValuePair <string, object>("产地", goodsOtherInfo.info.vchFactory));
                        }
                        if (!string.IsNullOrWhiteSpace(goodsOtherInfo.info.vchMaterial))
                        {
                            attrList.Add(new KeyValuePair <string, object>("材质", goodsOtherInfo.info.vchMaterial));
                        }
                        if (goodsOtherInfo.info.intSeason != null && goodsOtherInfo.info.intSeason > 0)
                        {
                            var seasonType = MCvHelper.To <SeasonType>(goodsOtherInfo.info.intSeason);
                            attrList.Add(new KeyValuePair <string, object>("季节性", seasonType.ToString()));
                        }
                        if (goodsOtherInfo.info.intPeriod != null && goodsOtherInfo.info.intPeriod > 0)
                        {
                            attrList.Add(new KeyValuePair <string, object>("保修期", goodsOtherInfo.info.intPeriod + "天"));
                        }

                        if (goodsOtherInfo.info.intShelfLift != null && goodsOtherInfo.info.intShelfLift > 0)
                        {
                            attrList.Add(new KeyValuePair <string, object>("保质期", goodsOtherInfo.info.intShelfLift + "月"));
                        }
                    }
                    #endregion

                    result.info = new ItemGoodsDetails()
                    {
                        gid         = info.intProductID,
                        title       = info.vchProductName,
                        productcode = info.vchProductPrinted,
                        desc        = (HttpUtility.HtmlDecode(info.txtWebShowInfo).Replace("/Purchase/img/Description/", picHost + "product/Description/")),
                        marketprice = MCvHelper.To <decimal>(info.numMarketPrice, 0),
                        price       = MCvHelper.To <decimal>(info.numVipPrice, 0),
                        pic_url     = FormatProductPicUrl(info.vchMainPicURL),
                        score       = info.intScore == null ? 0 : (int)info.intScore,
                        stock       = MCvHelper.To <long>(info.intStockQty, 0),
                        attrs       = attrList
                    };
                    result.status = MResultStatus.Success;
                }
            }
            catch (Exception ex)
            {
                result.status = MResultStatus.ExecutionError;
                result.msg    = "查询商品数据错误!";
            }

            return(result);
        }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        public object Invoke(IMethodInvocation invocation)
        {
            var    shopWatch       = new Stopwatch();
            object result          = null;
            var    enableMethodLog = MConfigManager.GetAppSettingsValue <bool>("EnableMethodLog", false);

            try
            {
                shopWatch.Start();

                var resultType = invocation.Method.ReturnType;

                //{sid}/{token}/{guid}/{user_id}/{uid}
                var args = invocation.Arguments;
                for (var i = 0; i < args.Length; i++)
                {
                    args[i] = ValidateUtility.CheckNull(args[i]);
                }
                if (args.Length >= 5)
                {
                    var sid    = MCvHelper.To <string>(args[0]);
                    var token  = MCvHelper.To <string>(args[1]);
                    var guid   = MCvHelper.To <string>(args[2]);
                    var userID = MCvHelper.To <int>(args[3]);
                    var uid    = MCvHelper.To <string>(args[4]);

                    var methodName      = invocation.Method.Name;
                    var methodCacheList = MCacheManager.GetCacheObj().GetValByKey <List <ItemMethodVerify> >("SystemPermission", MCaching.CacheGroup.Pemissions);

                    if (methodCacheList != null && methodCacheList.Any())
                    {
                        var methodCacheInfo = methodCacheList.Find(item => item.MethodName.Equals(methodName, StringComparison.InvariantCultureIgnoreCase));

                        if (methodCacheInfo != null)
                        {
                            var isVerifySystemId    = methodCacheInfo.IsVerifySystemId;
                            var isVerifyToKen       = methodCacheInfo.IsVerifyToken;
                            var isVerifyPermissions = methodCacheInfo.IsVerfiyPemissions;

                            var secureAuth = new SecureAuth
                            {
                                IsVerifySystemId    = isVerifySystemId,
                                IsVerifyToKen       = isVerifyToKen,
                                IsVerifyPermissions = isVerifyPermissions,
                                Sid    = sid,
                                Token  = token,
                                Uid    = uid,
                                UserId = userID
                            };

                            if (secureAuth.Verify().status == MResultStatus.Success)
                            {
                                if (methodCacheInfo.IsEnableCache)
                                {
                                    var cacheKey = string.Format("{0}_{1}", methodName,
                                                                 string.Join("_", invocation.Arguments));



                                    result = MCacheManager.UseCached <dynamic>(cacheKey, MCaching.CacheGroup.Pemissions,
                                                                               () => invocation.Method.Invoke(invocation.This, args));
                                }
                                else
                                {
                                    result = invocation.Method.Invoke(invocation.This, args);
                                }
                            }
                            //result = invocation.Proceed();
                        }
                        else
                        {
                            result = invocation.Method.Invoke(invocation.This, args);
                        }
                    }
                    else
                    {
                        result = invocation.Method.Invoke(invocation.This, args);
                    }
                }
                if (result == null)
                {
                    result = Activator.CreateInstance(resultType);
                }
                return(result);
            }
            catch (Exception ex)
            {
                MLogManager.Error(MLogGroup.AopAdvice.方法拦截, "", "", ex);
            }
            finally
            {
                if (result == null)
                {
                    var resultType = invocation.Method.ReturnType;
                    result = Activator.CreateInstance(resultType);
                }
                if (enableMethodLog)
                {
                    shopWatch.Stop();
                    MLogManager.Info(MLogGroup.AopAdvice.方法拦截, "", "执行用时:{0}毫秒;请求信息:{1};返回信息:{2};",
                                     shopWatch.ElapsedMilliseconds,
                                     invocation.ToString(),
                                     JsonConvert.SerializeObject(result));
                }
            }
            return(result);
        }