Esempio n. 1
0
        /// <summary>
        /// 保存token
        /// </summary>
        /// <param name="tokenStr"></param>
        /// <param name="appId"></param>
        public static void SetAppToken(string tokenStr, SysAccessAccountDTO account)
        {
            var CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.API_apptoken, tokenStr);
            var token    = CreateAppToken(tokenStr, account);

            token.ToCache(CacheKey, token.ExpireDate);
        }
Esempio n. 2
0
        /// <summary>
        /// app接入端是否合法
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="appSecret"></param>
        /// <returns></returns>
        public static bool CheckAppAccessAccount(string appId, string appSecret, out SysAccessAccountDTO account)
        {
            account = new SysAccessAccountDTO();

            if (string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(appSecret))
            {
                return(false);
            }

            //检查id,secret是否有效
            account = GetAppAccessAccountByAppID(appId);

            if (account != null && account.AppSecret == appSecret)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        public ApiMessageResult get(string appId, string appSecret)
        {
            var result  = new TokenResult();
            var account = new SysAccessAccountDTO();

            if (BLL.Sys.Implements.ApiSecurityService.CheckAppAccessAccount(appId, appSecret, out account) == false)
            {
                return(new ApiMessageResult {
                    Status = EnumApiStatus.BizError, Msg = "验证失败"
                });
            }

            result.Token = Guid.NewGuid().ToString("N");

            //保存token
            BLL.Sys.Implements.ApiSecurityService.SetAppToken(result.Token, account);

            return(new ApiResult(result)
            {
                Data = result
            });
        }
Esempio n. 4
0
        /// <summary>
        /// 创建AppToken
        /// </summary>
        /// <param name="tokenStr"></param>
        /// <param name="account"></param>
        /// <returns></returns>
        public static XuHos.BLL.Common.DTOs.Response.ResponseToken CreateAppToken(string tokenStr, SysAccessAccountDTO account)
        {
            var expireMinute = _GetAppTokenExpireMinute();
            var nowTime      = DateTime.Now;
            var token        = new XuHos.BLL.Common.DTOs.Response.ResponseToken()
            {
                Token      = tokenStr,
                AppId      = account.AppId,
                SourceType = account.SourceType,
                Time       = nowTime,
                ExpireDate = TimeSpan.FromMinutes(expireMinute),
                OrgID      = account.OrgID
            };

            return(token);
        }