예제 #1
0
        /// <summary>
        /// 获取Token信息
        /// </summary>
        /// <param name="inToken">Token入参</param>
        /// <returns></returns>
        public async Task <JsonResult> Index(InToken inToken)
        {
            var dic = new Dictionary <string, string>();

            dic.Add("201609021530300235", "0987654321");
            var result   = new OutResult();
            var dateTime = DateTime.Now;

            if (
                !DateTime.TryParseExact(inToken.SignTime, "yyyyMMddHHmmss",
                                        System.Globalization.CultureInfo.InvariantCulture,
                                        System.Globalization.DateTimeStyles.None, out dateTime))
            {
                result.code = (int)ResultCode.ParameterError;
                result.msg  = "签名时间不正确";
                return(Json(result));
            }

            var nowTime = DateTime.Now;

            if (dateTime > nowTime.AddMinutes(5) || dateTime < nowTime.AddMinutes(-5))
            {
                result.code = (int)ResultCode.SignTimeError;
                result.msg  = "签名时间与服务器时间相差5分钟";
                return(Json(result));
            }

            var sign = EncryHelper.MD5(inToken.AppId + inToken.SignTime + inToken.Random + dic[inToken.AppId]);

            if (sign != inToken.SignCode)
            {
                result.code = (int)ResultCode.SignError;
                result.msg  = "签名错误";
                return(Json(result));
            }

            //生成token
            var token = Guid.NewGuid().ToString().Replace("-", "");

            _logger.LogDebug("token生成:" + token + " appid:" + inToken.AppId);
            //将token存入缓存
            RedisHelper.SetToken(token, inToken.AppId, TimeSpan.FromMinutes(300));

            _logger.LogDebug("token存入Redis:" + token + " appid:" + inToken.AppId);

            return
                (Json(new OutResult
            {
                data = token
            }));
        }
예제 #2
0
 /// <summary>
 /// Visits an InToken
 /// </summary>
 /// <param name="tokenIn">The In token to visit.</param>
 /// <returns>An InNode that's bound to this token</returns>
 public virtual T Visit(InToken tokenIn)
 {
     throw new NotImplementedException();
 }
예제 #3
0
 protected virtual void VisitInToken(InToken token)
 {
     VisitToken(token.Token);
     State.Write(Symbols.IN);
     VisitTokenSetInParenthesis(token.Set);
 }
 public Expression Visit(InToken tokenIn)
 {
     throw new NotImplementedException();
 }
 public bool Visit(InToken tokenIn)
 {
     throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "QueryToken of type '{0}' is not supported.", tokenIn.Kind));
 }