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);
手机短信验证码开发流程
最新推荐文章于 2024-07-05 15:25:24 发布