Ejemplo 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);
        }
Ejemplo n.º 2
0
        public static void RemoveUserToken(string userTokenStr)
        {
            var CacheKey_API_usertoken            = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.API_usertoken, userTokenStr);
            var CacheKey_MAP_GetUserIDByUserToken = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.User_Ticket, userTokenStr);

            CacheKey_MAP_GetUserIDByUserToken.RemoveCache();
            CacheKey_API_usertoken.RemoveCache();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 记录本次请求的随机数
        /// </summary>
        /// <param name="nonceStr"></param>
        /// <param name="tokenStr"></param>
        public static void SetNonceStr(string nonceStr, string tokenStr)
        {
            if (!string.IsNullOrWhiteSpace(nonceStr) && !string.IsNullOrWhiteSpace(tokenStr))
            {
                var CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.api_noncestr, $"{tokenStr}:{nonceStr}");

                "1".ToCache(CacheKey, TimeSpan.FromMinutes(5));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取用户的通信唯一标识
        /// </summary>
        /// <param name="doctorIDList"></param>
        /// <returns></returns>
        public int GetUserIMUid(string UserID)
        {
            var cacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.MAP_GetIMUidByUserID, UserID);
            int?uid      = cacheKey.FromCache <int?>();

            if (uid == null || !uid.HasValue || uid.Value == 0)
            {
                uid = GetUserIMUids(UserID).FirstOrDefault();
                uid.ToCache(cacheKey);
            }
            return(uid.Value);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///设置登录用户的相对过期
        /// </summary>
        public static void SetUserTokenExpire(string userToken)
        {
            if (!string.IsNullOrEmpty(userToken))
            {
                //设置过期时间
                var expireMinute       = _GetUserTokenExpireMinute();
                var userTokenCacheKey  = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.API_usertoken, userToken);
                var userTicketCacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.User_Ticket, userToken);

                userTokenCacheKey.ExpireEntryAt(TimeSpan.FromMinutes(expireMinute));
                userTicketCacheKey.ExpireEntryAt(TimeSpan.FromMinutes(expireMinute));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 验证随机数(在指定时间内随机数不能重复)
        /// </summary>
        /// <param name="nonceStr"></param>
        /// <param name="tokenStr"></param>
        /// <returns></returns>
        public static bool CheckNonceStr(string nonceStr, string tokenStr)
        {
            if (string.IsNullOrEmpty(nonceStr) || nonceStr.Length < 10 || nonceStr.Length > 40)
            {
                return(false);
            }

            var CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.api_noncestr, $"{tokenStr}:{nonceStr}");

            string cacheNonceStr = CacheKey.FromCache <string>();

            if (cacheNonceStr == "1")
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 7
0
        public static string GetPublicKey(uint SdkAppid)
        {
            var cacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.KEY_IM_PublicKey, SdkAppid.ToString());
            var key      = cacheKey.FromCache <string>();

            if (string.IsNullOrEmpty(key))
            {
                var          basedir      = System.AppDomain.CurrentDomain.BaseDirectory;
                var          pri_key_path = System.IO.Path.Combine(basedir, "App_Data/Key/IM", SdkAppid.ToString(), "public_key");
                FileStream   f            = new FileStream(pri_key_path, FileMode.Open, FileAccess.Read);
                BinaryReader reader       = new BinaryReader(f);
                byte[]       b            = new byte[f.Length];
                reader.Read(b, 0, b.Length);
                key = Encoding.Default.GetString(b);
                key.ToCache(cacheKey);
            }

            return(key);
        }
Ejemplo n.º 8
0
        // GET: VerifyCodes
        public async Task <HttpResponseMessage> Index(string apptoken)
        {
            return(await Task.Run <HttpResponseMessage>(() =>
            {
                if (string.IsNullOrEmpty(apptoken))
                {
                    return new HttpResponseMessage(HttpStatusCode.OK);
                }
                else
                {
                    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

                    //生成验证码
                    var v = new XuHos.Common.Utility.VerifyCode();
                    var code = v.CreateVerifyCode(4);
                    var VerifyCodeCacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.VerifyCode, apptoken);
                    code.ToCache(VerifyCodeCacheKey, TimeSpan.FromMinutes(10));
                    result.Content = new ByteArrayContent(v.GetVerifyCodeImage(code));
                    result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
                    return result;
                }
            }));
        }