手机短信验证码开发流程

    1.//短信验证码:应该是一个四位随机数
            Random x = new Random();
            int ranx = x.Next(1000, 9999);
            string VerifyCode = ranx.ToString();

    2.//缓存帮助类进行数据缓存设置 设置过期时间

  SetCache(cacheName, testVerifyCode, 300);

  public static void SetCache(string cacheKey, object objObject, int timeout = 6000)
        {
            try
            {
                if (objObject == null) return;
                var objCache = HttpRuntime.Cache;
                //相对过期  
                //objCache.Insert(cacheKey, objObject, null, DateTime.MaxValue, timeout, CacheItemPriority.NotRemovable, null);  
                //绝对过期时间  
                objCache.Insert(cacheKey, objObject, null, DateTime.Now.AddSeconds(timeout), TimeSpan.Zero, CacheItemPriority.High, null);
            }
            catch (Exception)
            {
                //throw;  
            }
        }

3.在使用短信接口进行推送

4.获取缓存中的验证码进行验证

var objCache = HttpRuntime.Cache.Get(cacheKey);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值