CRL.Person.MobileVerifyData.GetCode C# (CSharp) Method

GetCode() public static method

通过模块名称获取验证码
public static GetCode ( string moduleName ) : string
moduleName string
return string
        public static string GetCode(string moduleName)
        {
            CoreHelper.ServerDataCache c = new CoreHelper.ServerDataCache(moduleName);
            if (c["C"] == null)
            {
                return null;
            }
            c["T"] = Convert.ToInt32(c["T"]) + 1;
            return c["C"].ToString();
        }

Usage Example

Example #1
0
        /// <summary>
        /// 检验验证码,成功会清除缓存数据
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="code"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public bool CheckCode(string mobile, string code, out string error)
        {
            error = "";
            if (MobileVerifyData.GetTimes(ModuleName) > 10)
            {
                error = "调用次数超过了限制";
                return(false);
            }
            string code1   = MobileVerifyData.GetCode(ModuleName);
            string mobile1 = MobileVerifyData.GetReceiveMobile(ModuleName);

            if (string.IsNullOrEmpty(code1) || string.IsNullOrEmpty(mobile1))
            {
                error = "请重新发送";
                return(false);
            }
            code  = code.ToLower();
            code1 = code1.ToLower();
            bool a = code == code1 && mobile.Trim() == mobile1.Trim();

            if (a)
            {
                MobileVerifyData.Clear(ModuleName);
            }
            else
            {
                error = "验证码不正确";
            }
            return(a);
        }