Exemplo n.º 1
0
        /// <summary>
        /// 判断当前节点是否已存在相同的
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int  ExistNum(MobileMessageEntity entity)
        {
            ///id=0,判断总数,ID>0判断除自己之外的总数
            string sql = @"Select count(1) from dbo.[MobileMessage] WITH(NOLOCK) ";

            string where = "where ";
            if (entity.Id == 0)
            {
            }
            else
            {
            }
            sql = sql + where;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            if (entity.Id > 0)
            {
                db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            }
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据主键值读取记录。如果数据库不存在这条数据将返回null
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public MobileMessageEntity GetMobileMessage(int id)
        {
            string    sql = @"SELECT  [Id],[MobilePhone],[MessageContent],[CreateTime],[IpAddress],[IpInt],[Status]
							FROM
							dbo.[MobileMessage] WITH(NOLOCK)	
							WHERE [Id]=@id"                            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, id);
            MobileMessageEntity entity = new MobileMessageEntity();

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    entity.Id             = StringUtils.GetDbInt(reader["Id"]);
                    entity.MobilePhone    = StringUtils.GetDbString(reader["MobilePhone"]);
                    entity.MessageContent = StringUtils.GetDbString(reader["MessageContent"]);
                    entity.CreateTime     = StringUtils.GetDbDateTime(reader["CreateTime"]);
                    entity.IpAddress      = StringUtils.GetDbString(reader["IpAddress"]);
                    entity.IpInt          = StringUtils.GetDbLong(reader["IpInt"]);
                    entity.Status         = StringUtils.GetDbInt(reader["Status"]);
                }
            }
            return(entity);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。
        /// 如果数据库有数据被更新了则返回True,否则返回False
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="mobileMessage">待更新的实体对象</param>
        public int UpdateMobileMessage(MobileMessageEntity entity)
        {
            string    sql = @" UPDATE dbo.[MobileMessage] SET
                       [MobilePhone]=@MobilePhone,[MessageContent]=@MessageContent,[CreateTime]=@CreateTime,[IpAddress]=@IpAddress,[IpInt]=@IpInt,[Status]=@Status
                       WHERE [Id]=@id";
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            db.AddInParameter(cmd, "@MobilePhone", DbType.String, entity.MobilePhone);
            db.AddInParameter(cmd, "@MessageContent", DbType.String, entity.MessageContent);
            db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime);
            db.AddInParameter(cmd, "@IpAddress", DbType.String, entity.IpAddress);
            db.AddInParameter(cmd, "@IpInt", DbType.Int64, entity.IpInt);
            db.AddInParameter(cmd, "@Status", DbType.Int32, entity.Status);
            return(db.ExecuteNonQuery(cmd));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <MobileMessageEntity> GetMobileMessageList(int pagesize, int pageindex, ref int recordCount)
        {
            string sql = @"SELECT   [Id],[MobilePhone],[MessageContent],[CreateTime],[IpAddress],[IpInt],[Status]
						FROM
						(SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER,
						 [Id],[MobilePhone],[MessageContent],[CreateTime],[IpAddress],[IpInt],[Status] from dbo.[MobileMessage] WITH(NOLOCK)	
						WHERE  1=1 ) as temp 
						where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize"                        ;

            string sql2 = @"Select count(1) from dbo.[MobileMessage] with (nolock) ";
            IList <MobileMessageEntity> entityList = new List <MobileMessageEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex);
            db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize);

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    MobileMessageEntity entity = new MobileMessageEntity();
                    entity.Id             = StringUtils.GetDbInt(reader["Id"]);
                    entity.MobilePhone    = StringUtils.GetDbString(reader["MobilePhone"]);
                    entity.MessageContent = StringUtils.GetDbString(reader["MessageContent"]);
                    entity.CreateTime     = StringUtils.GetDbDateTime(reader["CreateTime"]);
                    entity.IpAddress      = StringUtils.GetDbString(reader["IpAddress"]);
                    entity.IpInt          = StringUtils.GetDbLong(reader["IpInt"]);
                    entity.Status         = StringUtils.GetDbInt(reader["Status"]);
                    entityList.Add(entity);
                }
            }
            cmd = db.GetSqlStringCommand(sql2);
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    recordCount = StringUtils.GetDbInt(reader[0]);
                }
                else
                {
                    recordCount = 0;
                }
            }
            return(entityList);
        }
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="sendentity">短信对象</param>
        /// <param name="smstype">通道类型</param>
        /// <returns></returns>
        public MobileMessageEntity SendSms(MobileMessageEntity sendentity, int smstype = 1)
        {
            string mobile  = sendentity.MobilePhone;
            string smsbody = sendentity.MessageContent;

            sendentity.ResultSMS = "";
            IList <ConfigSmsProviderEntity> list = GetConfigSmsProviderAll(smstype, 1);//获取所有有效的短信提供商

            foreach (ConfigSmsProviderEntity entity in list)
            {
                try
                {
                    sendentity.SendProvider = entity.Name;
                    if (entity.Name.ToLower() == SMSProviders.ZhuTongKeJi.ToLower())
                    {
                        sendentity.ResultSMS = ZhuTongKeJiSend(entity.AppId, entity.UserCode, entity.PassWord, entity.Url, mobile, smsbody);
                        if (sendentity.ResultSMS.Contains(","))
                        {
                            string[] temp = sendentity.ResultSMS.Split(',');
                            if (temp[0] == "1")
                            {
                                break;
                            }
                        }
                    }
                    else if (entity.Name.ToLower() == SMSProviders.ChuangShiManDao.ToLower())
                    {
                        sendentity.ResultSMS = ChuangShiManDaoSend(entity.AppId, entity.PassWord, entity.Url, mobile, smsbody);
                        if (StringUtils.GetDbLong(sendentity.ResultSMS) > 0)
                        {
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    sendentity.ResultSMS = ex.Message;
                }
            }
            return(sendentity);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 插入一条记录到表MobileMessage,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="mobileMessage">待插入的实体对象</param>
        public int AddMobileMessage(MobileMessageEntity entity)
        {
            string    sql = @"insert into MobileMessage( [MobilePhone],SendProvider,[MessageContent],[CreateTime],[IpAddress],[IpInt],[Status],ResultSMS)VALUES
			            ( @MobilePhone,@SendProvider,@MessageContent,@CreateTime,@IpAddress,@IpInt,@Status,@ResultSMS);
			SELECT SCOPE_IDENTITY();"            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@MobilePhone", DbType.String, entity.MobilePhone);
            db.AddInParameter(cmd, "@SendProvider", DbType.String, entity.SendProvider);
            db.AddInParameter(cmd, "@MessageContent", DbType.String, entity.MessageContent);
            db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime);
            db.AddInParameter(cmd, "@IpAddress", DbType.String, entity.IpAddress);
            db.AddInParameter(cmd, "@IpInt", DbType.Int64, entity.IpInt);
            db.AddInParameter(cmd, "@Status", DbType.Int32, entity.Status);
            db.AddInParameter(cmd, "@ResultSMS", DbType.String, entity.ResultSMS);
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <MobileMessageEntity> GetMobileMessageAll()
        {
            string sql = @"SELECT    [Id],[MobilePhone],[MessageContent],[CreateTime],[IpAddress],[IpInt],[Status] from dbo.[MobileMessage] WITH(NOLOCK)	";
            IList <MobileMessageEntity> entityList = new List <MobileMessageEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    MobileMessageEntity entity = new MobileMessageEntity();
                    entity.Id             = StringUtils.GetDbInt(reader["Id"]);
                    entity.MobilePhone    = StringUtils.GetDbString(reader["MobilePhone"]);
                    entity.MessageContent = StringUtils.GetDbString(reader["MessageContent"]);
                    entity.CreateTime     = StringUtils.GetDbDateTime(reader["CreateTime"]);
                    entity.IpAddress      = StringUtils.GetDbString(reader["IpAddress"]);
                    entity.IpInt          = StringUtils.GetDbLong(reader["IpInt"]);
                    entity.Status         = StringUtils.GetDbInt(reader["Status"]);
                    entityList.Add(entity);
                }
            }
            return(entityList);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 注册发送手机验证码
        /// </summary>
        /// <returns></returns>
        public string SendRegisterMobileMessage()
        {
            ResultObj           _loginentity = new ResultObj();
            string              mobilestr    = QueryString.SafeQ("mobile");
            long                ip           = IPAddress.DenaryIp;
            MobileMessageEntity _entity      = new MobileMessageEntity();

            _entity.IpInt       = ip;
            _entity.MobilePhone = mobilestr;
            _entity.CreateTime  = DateTime.Now;
            if (MobileMessageBLL.Instance.SendNum(ip) > 30)//当前IP最多一天只能发送30条注册验证短信
            {
                _loginentity.Status = (int)CommonStatus.ExceedDay;
            }

            DateTime?latedate  = MobileMessageBLL.Instance.GetLatelySend(ip);
            bool     sendphone = true;

            if (latedate != null)
            {
                DateTime startTime = Convert.ToDateTime(latedate);
                DateTime endTime   = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                TimeSpan ts        = endTime - startTime;
                if (ts.TotalSeconds <= 60)  //当日次数未起过20次,间隔时间不超过1分钟
                {
                    _loginentity.Status = (int)CommonStatus.LatelyTime;
                    sendphone           = false;
                }
            }
            if (sendphone && StringUtils.IsHandset(mobilestr))
            {
                if (StringUtils.GetDbBool(System.Web.HttpContext.Current.Session[CommonKey.MobileSending]))
                {
                    _loginentity.Status = (int)CommonStatus.PhoneSendGap;
                    sendphone           = false;
                    if (System.Web.HttpContext.Current.Session[CommonKey.MobileSendPreTime] == null)
                    {
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSendPreTime] = DateTime.Now;
                    }
                    else if (StringUtils.GetDbDateTime(System.Web.HttpContext.Current.Session[CommonKey.MobileSendPreTime]) < DateTime.Now.AddSeconds(-10))
                    {
                        sendphone = true;
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSending] = false;
                    }
                }
                if (sendphone)
                {
                    try
                    {
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSending] = true;
                        Random _r          = new Random();
                        string mycode      = _r.Next(100000, 999999).ToString();
                        string datenowstr  = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string _regmsgbody = ConfigCore.Instance.ConfigCommonEntity.MobileRegMsgBody;
                        string msgbody     = string.Format(_regmsgbody, mycode);
                        _entity.MessageContent = msgbody;
                        MobileMessageEntity smsresult = ConfigSmsProviderBLL.Instance.SendSms(_entity);
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSendPreTime] = DateTime.Now;
                        System.Web.HttpContext.Current.Session[CommonKey.MobileYZCode]      = mycode;
                        System.Web.HttpContext.Current.Session[CommonKey.MobileNoRegister]  = mobilestr;

                        MobileMessageBLL.Instance.AddMobileMessage(smsresult);
                        _loginentity.Status = (int)CommonStatus.Success;
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSending] = false;
                        return(JsonJC.ObjectToJson(_loginentity));
                    }
                    catch (Exception ex)
                    {
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSending] = false;
                        LogUtil.Log("注册验证码生成失败", ex.Message);
                        _loginentity.Status = (int)CommonStatus.Fail;
                    }
                }
            }
            return(JsonJC.ObjectToJson(_loginentity));
        }
Exemplo n.º 9
0
 /// <summary>
 /// 更新一条MobileMessage记录。
 /// 该方法提供给界面等UI层调用
 /// </summary>
 /// <param name="mobileMessage">待更新的实体对象</param>
 /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param>
 public int UpdateMobileMessage(MobileMessageEntity mobileMessage)
 {
     return(MobileMessageDA.Instance.UpdateMobileMessage(mobileMessage));
 }
Exemplo n.º 10
0
 /// <summary>
 /// 插入一条记录到表MobileMessage,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。
 /// 该方法提供给界面等UI层调用
 /// </summary>
 /// <param name="mobileMessage">要添加的MobileMessage数据实体对象</param>
 public int AddMobileMessage(MobileMessageEntity mobileMessage)
 {
     return(MobileMessageDA.Instance.AddMobileMessage(mobileMessage));
 }
Exemplo n.º 11
0
 /// <summary>
 /// 判断对象是否存在
 /// </summary>
 /// <param name="dicEnum"></param>
 /// <returns></returns>
 public bool IsExist(MobileMessageEntity mobileMessage)
 {
     return(MobileMessageDA.Instance.ExistNum(mobileMessage) > 0);
 }
Exemplo n.º 12
0
        public string SendMobileMessage()
        {
            ResultObj           _loginentity = new ResultObj();
            string              mobilestr    = QueryString.SafeQ("mobile");
            long                ip           = IPAddress.DenaryIp;
            MobileMessageEntity _entity      = new MobileMessageEntity();

            _entity.IpInt       = ip;
            _entity.MobilePhone = mobilestr;
            _entity.CreateTime  = DateTime.Now;
            if (MobileMessageBLL.Instance.SendNum(ip) > 20)
            {
                _loginentity.Status = (int)CommonStatus.ExceedDay;
            }

            DateTime?latedate  = MobileMessageBLL.Instance.GetLatelySend(ip);
            bool     sendphone = true;

            if (latedate != null)
            {
                DateTime startTime = Convert.ToDateTime(latedate);
                DateTime endTime   = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                TimeSpan ts        = endTime - startTime;
                if (ts.TotalSeconds <= 60)  //当日次数未起过20次,间隔时间不超过1分钟
                {
                    _loginentity.Status = (int)CommonStatus.LatelyTime;
                    sendphone           = false;
                }
            }
            if (sendphone && StringUtils.IsHandset(mobilestr))
            {
                if (StringUtils.GetDbBool(System.Web.HttpContext.Current.Session[CommonKey.MobileSending]))
                {
                    _loginentity.Status = (int)CommonStatus.PhoneSendGap;
                    sendphone           = false;
                    if (System.Web.HttpContext.Current.Session[CommonKey.MobileSendPreTime] == null)
                    {
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSendPreTime] = DateTime.Now;
                    }
                    else if (StringUtils.GetDbDateTime(System.Web.HttpContext.Current.Session[CommonKey.MobileSendPreTime]) < DateTime.Now.AddSeconds(-10))
                    {
                        sendphone = true;
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSending] = false;
                    }
                }
                if (sendphone)
                {
                    try
                    {
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSending] = true;
                        Random _r          = new Random();
                        string mycode      = _r.Next(100000, 999999).ToString();
                        string datenowstr  = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string _regMsgBody = ConfigCore.Instance.ConfigCommonEntity.MobileRegMsgBody;
                        string msgbody     = string.Format(_regMsgBody, mycode);
                        _entity.MessageContent = msgbody;
                        MobileMessageEntity smsresult = ConfigSmsProviderBLL.Instance.SendSms(_entity);



                        //Hashtable _Pars = new Hashtable();
                        //_Pars.Add("username", _config.UserCode);
                        //_Pars.Add("password", CryptMD5.Encrypt(CryptMD5.Encrypt(_config.PassWord.Trim()).ToLower() + datenowstr).ToLower());
                        //_Pars.Add("mobile", mobilestr);
                        //_Pars.Add("content", msgbody);
                        //_Pars.Add("tkey", datenowstr);
                        //_Pars.Add("productid", _config.AppId);
                        //_Pars.Add("xh", "");

                        //WebServiceClient.QueryPostWebService(_config.Url, _Pars);
                        //System.Web.HttpContext.Current.Response.Cookies.Add(new HttpCookie(CommonKey.MobileYZCode, mycode));
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSendPreTime] = DateTime.Now;
                        System.Web.HttpContext.Current.Session[CommonKey.MobileYZCode]      = mycode;
                        System.Web.HttpContext.Current.Session[CommonKey.MobileNo]          = mobilestr;
                        MobileMessageBLL.Instance.AddMobileMessage(smsresult);
                        _loginentity.Status = (int)CommonStatus.Success;
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSending] = false;
                        return(JsonJC.ObjectToJson(_loginentity));
                    }
                    catch (Exception ex)
                    {
                        System.Web.HttpContext.Current.Session[CommonKey.MobileSending] = false;
                        LogUtil.Log("注册验证码生成失败", ex.Message);
                        _loginentity.Status = (int)CommonStatus.Fail;
                    }
                }
            }
            return(JsonJC.ObjectToJson(_loginentity));
        }