예제 #1
0
 /// <summary>
 /// 生成请求的token
 /// </summary>
 /// <param name="argsName"></param>
 /// <param name="args"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 protected string CreateAccessToken(ParameterInfo[] argsName, List <object> args, TokenInfo token)
 {
     if (token.IsJwtToken)
     {
         //使用jwt token
         return(token.Token);
     }
     if (token.UseSign && !string.IsNullOrEmpty(token.Token))
     {
         var arry = token.Token.Split('@');
         var sign = SignCheck.CreateSign(arry[1], argsName, args);
         return(string.Format("{0}@{1}", arry[0], sign));
     }
     return(token.Token);
 }
예제 #2
0
        bool CheckSession(string user, string token, ParameterInfo[] argsName, List <object> args, out string error)
        {
            error = "";
            //var exists = sessions.TryGetValue(user, out Tuple<string, object> v);
            var v = sessionManage.GetSession(user);

            if (v == null)
            {
                error = "未找到API登录状态,请重新登录";
                return(false);
            }
            var serverToken = v.Token;

            if (ServerCreater.__CheckSign)//使用简单签名
            {
                serverToken = SignCheck.CreateSign(serverToken, argsName, args);
            }
            if (token != serverToken)
            {
                error = "token验证失败";
                return(false);
            }
            return(true);
        }