Beispiel #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);
        }
Beispiel #2
0
        /// <summary>
        /// 发送自定义格式短信
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="content">不为空时为自定义短信,验证码域请用{0}表示</param>
        /// <param name="error"></param>
        /// <returns></returns>
        public bool SendCode(string mobile, string content, out string error)
        {
            error = "";
            if (string.IsNullOrEmpty(mobile))
            {
                error = "发送失败,没有传入手机号";
                return(false);
            }
            if (!mobile.IsCellPhone())
            {
                error = "手机号格式不正确";
                return(false);
            }
            string chkCode = MakeRandomCode();

            if (string.IsNullOrEmpty(content))
            {
                content = "您本次操作的验证码为 " + chkCode + ",切勿将此验证码泄露给他人,如非本人操作请忽略";
            }
            else
            {
                content = string.Format(content, chkCode);
            }
            double n = MobileVerifyData.GetSendTimeDiff(ModuleName);

            if (n < NextSendSencond)
            {
                error = "发送失败,验证码距上次发送不足" + NextSendSencond + "秒,请稍后再试";
                return(false);
            }
            int totalSend = MobileVerifyData.GetTotalSendTimes(ModuleName);

            if (totalSend > 5)
            {
                error = "发送失败,请求超过了限制,请稍后再试";
                return(false);
            }
            //bool a = CoreHelper.SMSMessage.Send(mobile, content, out error); //老短信接口
            CurrentCode = chkCode;
            bool a = SendSms(mobile, content, out error);

            if (a)
            {
                MobileVerifyData.SetCode(ModuleName, chkCode, mobile.Trim());
                string str = string.Format("时间:{0} 验证码:{1} 模块:{2} \r\n", DateTime.Now.ToString("yy-MM-dd HH:mm:ss fffff"), chkCode, ModuleName);
                SmsSendRecordManage.Instance.Add(new SmsSendRecord()
                {
                    Mobile = mobile, Code = chkCode, ModuleName = ModuleName
                });
            }
            return(a);
        }