Ejemplo n.º 1
0
        public static void SendCode(RandomValueVerifier verifier, SystemPlatform plateForm, string uniqueKey, string targetCellphone, string message = null)
        {
            var errorCountKey = verifier.GetErrorCountKey(plateForm, uniqueKey);

            CheckErrorCount(verifier, errorCountKey);

            var code = verifier.SendCode(plateForm, uniqueKey, targetCellphone, message);

            if (string.IsNullOrEmpty(code))
            {
                return;
            }

            var model = new RandomCodeModel
            {
                Code       = code,
                ExpireTime = DateTime.UtcNow.AddMinutes(verifier.GetExpireTime()).ToUnixTime()
            };
            string codeKey = verifier.GetCodeKey(plateForm, uniqueKey);

            RedisHelper.Set(RedisDBIndex, codeKey, model, TimeSpan.FromMinutes(Constant.SMS_CACHE_TIME));
        }
Ejemplo n.º 2
0
        public static void Verify(RandomValueVerifier verifier, SystemPlatform plateForm, string uniqueKey, string code, bool codeCanVerifyAgain = false)
        {
            var  errorCountKey = verifier.GetErrorCountKey(plateForm, uniqueKey);
            int  errorCount    = CheckErrorCount(verifier, errorCountKey);
            var  codeKey       = verifier.GetCodeKey(plateForm, uniqueKey);
            var  codeModel     = RedisHelper.Get <RandomCodeModel>(Constant.REDIS_SMS_DBINDEX, codeKey);
            bool result        = verifier.Verify(plateForm, uniqueKey, code);

            if (result)
            {
                if (errorCount > 0)
                {
                    DeleteErrorCount(errorCountKey);
                }
                if (!codeCanVerifyAgain)
                {
                    InvalidateCode(verifier, plateForm, uniqueKey);
                }
            }
            else
            {
                IncreaseErrorCount(verifier, errorCountKey);
            }
        }
Ejemplo n.º 3
0
 public static void InvalidateCode(RandomValueVerifier verifier, SystemPlatform plateForm, string uniqueKey)
 {
     RedisHelper.KeyDelete(RedisDBIndex, verifier.GetCodeKey(plateForm, uniqueKey));
 }