コード例 #1
0
        public GetAccessTokenResult GetAccessToken(string appId, string appSecret)
        {
            var cacheKey = appId;

            if (IGetAccessTokenCache != null)
            {
                var cacheObj = IGetAccessTokenCache.Get(cacheKey);
                if (ToolFactory.CreateIValidatorTool().IsNotEmpty(cacheObj))
                {
                    return(cacheObj);
                }
            }
            string url    = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appId, appSecret);
            var    client = ToolFactory.Ioc.Get <IHttpClient>();
            var    result = client.DownloadToString(url);

            if (WeiXinHelper.IsFailureInvokeWeiXinAPI(result))
            {
                throw new Exception(result);
            }
            var iJson       = ToolFactory.CreateIJsonSerializeTool();
            var accessToken = iJson.DeserializeFromString <GetAccessTokenResult>(result);

            if (IGetAccessTokenCache != null)
            {
                IGetAccessTokenCache.Set(cacheKey, accessToken);
            }
            return(accessToken);
        }
コード例 #2
0
        /// <summary>
        /// 获取jsapi_ticket
        /// jsapi_ticket是公众号用于调用微信JS接口的临时票据。
        /// 正常情况下,jsapi_ticket的有效期为7200秒,通过access_token来获取。
        /// 由于获取jsapi_ticket的api调用次数非常有限,频繁刷新jsapi_ticket会导致api调用受限,影响自身业务,开发者必须在自己的服务全局缓存jsapi_ticket 。
        /// </summary>
        /// <param name="accessToken">微信全局access_token</param>
        /// <returns></returns>
        public GenericExecResult <string> GetJsTickect(string accessToken)
        {
            var cacheJsTickect = _ICache.Get <string>(CacheJsTickectId);

            if (ToolFactory.CreateIValidatorTool().IsNotEmpty(cacheJsTickect))
            {
                return(new GenericExecResult <string>()
                {
                    Success = true,
                    Data = cacheJsTickect
                });
            }
            ;
            var url            = string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", accessToken);
            var downloadResult = WeiXinHelper.DownloadToString(url);

            if (WeiXinHelper.IsFailureInvokeWeiXinAPI(downloadResult))
            {
                return(WeiXinHelper.FromDownloadResultToErrorGenericExecResult(downloadResult));
            }
            var jsTicket = WeiXinHelper.ToGetJsTickectResultDto(downloadResult.Data).ticket;

            _ICache.Set(CacheJsTickectId, jsTicket, DateTime.Now.AddSeconds(CacheJsTickectExpireTimeoutSecond));
            return(new GenericExecResult <string>()
            {
                Success = true,
                Data = jsTicket
            });
        }
コード例 #3
0
ファイル: CollectionFilter.cs プロジェクト: sdBruLi/Csharp
 public void AddFilter(IEnumerable <AbstractFilter> filters)
 {
     if (ToolFactory.CreateIValidatorTool().IsEmpty(this.Filters))
     {
         this.Filters = new List <AbstractFilter>();
     }
     this.Filters.AddRange(filters);
 }
コード例 #4
0
        public T FirstOrDefault <T>(IWhereGetter where, IOrderByGetter orderByGetter = null) where T : class
        {
            var list = this.FindByProperties <T>(where, orderByGetter);

            if (ToolFactory.CreateIValidatorTool().IsEmpty(list))
            {
                return(null);
            }
            return(list[0]);
        }
コード例 #5
0
 public static ICriteria AddOrder(ICriteria iCriteria, IEnumerable <OrderBy> orderBys)
 {
     if (ToolFactory.CreateIValidatorTool().IsEmpty(orderBys))
     {
         return(iCriteria);
     }
     foreach (var orderBy in orderBys)
     {
         iCriteria.AddOrder(ToOrder(orderBy));
     }
     return(iCriteria);
 }
コード例 #6
0
ファイル: Lt.cs プロジェクト: sdBruLi/Csharp
        public override bool Valid(object pObject)
        {
            var tIValidatorTool = ToolFactory.CreateIValidatorTool();
            var tIProgramTool   = ToolFactory.CreateIProgramTool();

            if (tIProgramTool.IsStringType(pObject))
            {
                if (tIValidatorTool.IsEmpty(pObject))
                {
                    return(true);
                }
                else
                {
                    var objString = pObject.ToString();
                    var decMax    = Convert.ToDecimal(Max);
                    if (objString.Length < decMax)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            if (tIProgramTool.IsNumericType(pObject))
            {
                decimal decObj = Convert.ToDecimal(pObject);
                var     decMax = Convert.ToDecimal(Max);
                return(decObj < decMax);
            }
            if (tIProgramTool.IsDateTimeType(pObject))
            {
                if (Max == null)
                {
                    return(true);
                }
                if (pObject == null)
                {
                    return(false);
                }
                DateTime dObj = Convert.ToDateTime(pObject);
                DateTime dMax = Convert.ToDateTime(Max);

                return(dObj < dMax);
            }
            throw new Exception("无法自动检测比较类型");
        }
コード例 #7
0
        public static T RequestParam <T>(string parameterName, T defaultValue = default(T))
        {
            IValidatorTool validator       = ToolFactory.CreateIValidatorTool();
            var            srcRequestValue = Request[parameterName];

            if (validator.IsEmpty(srcRequestValue))
            {
                return(default(T));
            }
            T value = ToolFactory.CreateIProgramTool().ChanageType <T>(srcRequestValue);

            if (value == null && defaultValue != null)
            {
                return(defaultValue);
            }
            return(value);
        }
コード例 #8
0
        public void TestNVCollectionValidator()
        {
            var tNameValueCollection = new NameValueCollection();

            tNameValueCollection.Add("Name", "Name");
            tNameValueCollection.Add("BeginTime", DateTime.Now.ToString("yyyy-MM-dd"));
            tNameValueCollection.Add("EndTime", null);
            tNameValueCollection.Add("Count", "0");

            var tNVValidator = ToolFactory.CreateIValidatorTool().CreateNVValidator(tNameValueCollection);

            tNVValidator.SetField("Name", typeof(string), "名称")
            .NotEmpty()
            .Ge(6)
            .Le(5);

            var r = tNVValidator.IsValid();

            Debug.WriteLine(r.Message);
        }