public static SmsValidateTemplate GetModelByGid(string template_guid)
 {
     if (models.Count == 0)
     {
         Tsms_TemplateCollection daTemplateColl = new Tsms_TemplateCollection();
         daTemplateColl.ListAll();
         foreach (Tsms_Template template in daTemplateColl)
         {
             SmsValidateTemplate model = new SmsValidateTemplate();
             model.Template_Id = template.Template_Id;
             model.Gid         = template.Template_Guid;
             model.TimeSpan    = template.Timespan;
             model.SmsContent  = template.Content;
             model.Scalar      = template.Code_Scalar;
             models.Add(model);
         }
     }
     return(models.Find(it => it.Gid == template_guid));
 }
        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);
        }