public bool ValidSmsCode(string mobileno, string gid, string validCode)
        {
            Tsms_Thirdparty dathirdparty;
            string          error;

            if (!SmsUtils.CheckUserCode(_userCode, _userPwd, mobileno, out dathirdparty, out error))
            {
                Alert(error);
                return(false);
            }
            var model       = SmsTemplateFactory.GetModelByGid(gid);
            var daValidCode = new Tsms_Valid_Code();

            if (!daValidCode.SelectByCodeAndBizType(validCode, mobileno, model.Template_Id))
            {
                Alert("验证码不正确");
                return(false);
            }
            if (daValidCode.Status == 1)
            {
                Alert("验证码已被使用");
                return(false);
            }
            if (daValidCode.Expire_Time < DateTime.Now)
            {
                Alert("验证码已过期");
                return(false);
            }
            daValidCode.UpdateStatus(validCode, mobileno, model.Template_Id);
            return(true);
        }
        public bool SendSmsValidCode(string mobileno, string templateGuid, string sourceApp)
        {
            Tsms_Thirdparty dathirdparty;
            string          error;

            if (!SmsUtils.CheckUserCode(_userCode, _userPwd, mobileno, out dathirdparty, out error))
            {
                Alert(error);
                return(false);
            }
            SmsValidateTemplate model = SmsTemplateFactory.GetModelByGid(templateGuid);

            if (model == null)
            {
                Alert(string.Format("找不到GID={0}的验证码配置信息", templateGuid));
                return(false);
            }
            if (!CheckFrequency(mobileno, 10))
            {
                Alert("短信验证码申请过于频繁,请稍后再申请");
                return(false);
            }
            this.Code = GenerateCode(model.Scalar);
            var daValidCode = new Tsms_Valid_Code();

            if (!daValidCode.SelectEffectiveCode(mobileno, model.Template_Id))
            {
                daValidCode.Template_Id   = model.Template_Id;
                daValidCode.Valid_Code    = this.Code;
                daValidCode.Expire_Time   = DateTime.Now.AddMinutes(model.TimeSpan);
                daValidCode.Mobileno      = mobileno;
                daValidCode.Private_Value = sourceApp;
                daValidCode.Status        = 0;
                daValidCode.Send_Times    = 1;
                if (!daValidCode.Insert())
                {
                    Alert("系统繁忙,请稍后重试!");
                    return(false);
                }
            }
            else
            {
                this.Code = daValidCode.Valid_Code;
                daValidCode.Send_Times++;
                daValidCode.Update();
            }
            string smsContent = model.SmsContent
                                .Replace("$APPNAME$", sourceApp)
                                .Replace("$TIMESPAN$", model.TimeSpan.ToString())
                                .Replace("$VALIDCODE$", this.Code)
                                .Replace("$DATE$", DateTime.Now.ToString("yyyy年MM月dd日"));

            var sms = SmsServiceFactory.GetSmsServiceByChannel(dathirdparty.Channel_Id, out error);
            SmsServiceProvider provider = new SmsServiceProvider(sms, dathirdparty.Appid, mobileno, smsContent);
            bool res = provider.Send();

            if (!res)
            {
                Alert(provider.PromptInfo);
                return(false);
            }
            return(true);
        }
        private bool CheckFrequency(string mobileno, int limit)
        {
            var daValidCode = new Tsms_Valid_Code();

            return(daValidCode.GetSendTimes(mobileno) <= limit);
        }