예제 #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        private static int Add(TB_SMSCode model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into TB_SMSCode(");
            strSql.Append("fld_type,fld_phone,fld_code,fld_state,fld_time)");
            strSql.Append(" values (");
            strSql.Append("@fld_type,@fld_phone,@fld_code,@fld_state,@fld_time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@fld_type",  SqlDbType.VarChar, 50),
                new SqlParameter("@fld_phone", SqlDbType.VarChar, 20),
                new SqlParameter("@fld_code",  SqlDbType.VarChar, 10),
                new SqlParameter("@fld_state", SqlDbType.Int,      4),
                new SqlParameter("@fld_time",  SqlDbType.DateTime)
            };
            parameters[0].Value = model.fld_type;
            parameters[1].Value = model.fld_phone;
            parameters[2].Value = model.fld_code;
            parameters[3].Value = model.fld_state;
            parameters[4].Value = model.fld_time;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #2
0
        /// <summary>
        /// 发送手机验证码
        /// </summary>
        /// <param name="type">验证类型(1)</param>
        /// <param name="phone">电话号码</param>
        /// <param name="vcode">验证码</param>
        /// <param name="error">错误信息</param>
        /// <returns></returns>
        public static bool Send(string type, string phone, ref string vcode, ref string error)
        {
            TB_SMSCode model = new TB_SMSCode();

            model.fld_type  = type;
            model.fld_phone = phone;
            #region 产生6位随机代码

            Random rNum = new Random();    //随机生成类
            int    num1 = rNum.Next(0, 9); //返回指定范围内的随机数
            int    num2 = rNum.Next(0, 9);
            int    num3 = rNum.Next(0, 9);
            int    num4 = rNum.Next(0, 9);
            int    num5 = rNum.Next(0, 9);
            int    num6 = rNum.Next(0, 9);
            vcode = num1.ToString() + num2.ToString() + num3.ToString() + num4.ToString() + num5.ToString() + num6.ToString();
            #endregion
            model.fld_code  = vcode;
            model.fld_state = 1;//未使用
            model.fld_time  = DateTime.Now;
            if (Add(model) <= 0)
            {
                error = "错误信息:操作异常,请联系管理员";
                return(false);
            }
            return(true);
        }