Exemplo n.º 1
0
 public FuncResult Handler(string userCode, string userPwd, string mobileno, string smsContent)
 {
     try
     {
         Tsms_Thirdparty daThirdparty = null;
         string          error;
         if (!SmsUtils.CheckUserCode(userCode, userPwd, mobileno, out daThirdparty, out error))
         {
             return(FuncResult.FailResult(error));
         }
         ISmsProvider sms = SmsServiceFactory.GetSmsServiceByChannel(daThirdparty.Channel_Id, out error);
         if (sms == null)
         {
             return(FuncResult.FailResult(error));
         }
         SmsServiceProvider provider = new SmsServiceProvider(sms, daThirdparty.Appid, mobileno, smsContent);
         if (!provider.Send())
         {
             return(FuncResult.FailResult(provider.PromptInfo.CustomMessage));
         }
         return(FuncResult.SuccessResult());
     }
     catch (Exception ex)
     {
         Log.Error("handler异常", ex);
         return(FuncResult.FailResult(ex.Message));
     }
 }
        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);
        }