Esempio n. 1
0
        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="mobile">手机号</param>
        /// <returns>-1发送错误,0发送限制,1发送成功</returns>
        public static int Vcode(string mobile)
        {
            int      i        = 0;
            string   code     = "";
            string   content  = "您的验证码:" + code + "【领先办公】";
            string   dtime    = DateTime.Today.ToString();
            string   time     = "";
            int      number   = 1;
            int      Id       = 0;
            Smsstore smsstore = new Smsstore();
            DataSet  ds       = smsstore.Model(mobile);

            if (ds != null)
            {
                Id     = Convert.ToInt32(ds.Tables[0].Rows[0]["Id"].ToString());
                time   = ds.Tables[0].Rows[0]["SendTime"].ToString();
                number = Convert.ToInt32(ds.Tables[0].Rows[0]["SMSNumber"].ToString());
                code   = ds.Tables[0].Rows[0]["SMSCode"].ToString();
                if (dtime == time)
                {
                    if (number < 3)
                    {
                        number = number + 1;
                        i      = 1;
                    }
                }
                else
                {
                    Random rd = new Random();
                    code = rd.Next(100000, 999999).ToString();
                    i    = 1;
                }
            }
            else
            {
                i = 0;
            }
            if (i == 1)
            {
                int message = SMSsend(content, mobile);
                if (message == 9)
                {
                    smsstore.Id        = Id;
                    smsstore.SendTime  = Convert.ToDateTime(dtime);
                    smsstore.SMSNumber = number;
                    smsstore.SMSCode   = code;
                    smsstore.Save();
                    return(1);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                return(0);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 发送手机动态验证码
        /// cml:20170614
        /// </summary>
        /// <param name="phoneNumber">手机号</param>
        /// <param name="sendStrStart">发送文字前面部分</param>
        /// <param name="sendStrEnd">发送文字后面部分</param>
        /// <returns></returns>
        public static SendMobileCodeState SendPhoneVerifyCode(string phoneNumber, string sendStrStart, string sendStrEnd)
        {
            SendMobileCodeState smcState = new SendMobileCodeState();

            smcState.State = 0;
            smcState.msg   = "";

            //01生成随机码
            long   tick = DateTime.Now.Ticks;
            Random ran  = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
            int    iResult;
            int    iUp   = 99999;
            int    iDown = 10000;

            iResult = ran.Next(iDown, iUp);
            string code = "8" + iResult.ToString();

            //02判断数据库是否已存在该手机号,进而判断单日已发送数量
            Smsstore smsStore = new Smsstore();
            DataSet  smsDs    = smsStore.Model(phoneNumber);

            if (smsDs != null && smsDs.Tables[0] != null && smsDs.Tables[0].Rows.Count > 0)
            {
                int    sendnumber = Convert.ToInt32(smsDs.Tables[0].Rows[0]["SMSNumber"]);
                string sendtime   = Convert.ToDateTime(smsDs.Tables[0].Rows[0]["SendTime"]).ToString("yyyy-MM-dd");
                if (sendtime == DateTime.Now.ToString("yyyy-MM-dd"))
                {
                    if (sendnumber > 3)
                    {
                        smcState.msg = "您今天的验证码发送次数已经用完。每个手机号一天最多发送3条短信。";
                    }
                    else
                    {
                        //发送验证码
                        int result = SMSsend(sendStrStart + code + sendStrEnd, phoneNumber);
                        if (result == 9)
                        {
                            smcState.State = 1;
                            smcState.msg   = "手机验证码发送成功。";
                            //更新Smsstore
                            int id = Convert.ToInt32(smsDs.Tables[0].Rows[0]["Id"]);
                            smsStore.Id = id;
                            smsStore.Load();
                            smsStore.SMSCode   = code;
                            smsStore.SMSNumber = sendnumber + 1;
                            smsStore.SendTime  = DateTime.Now;
                            smsStore.Save();
                        }
                    }
                }
                else
                {
                    //发送验证码
                    int result = SMSsend(sendStrStart + code + sendStrEnd, phoneNumber);
                    if (result == 9)
                    {
                        smcState.State = 1;
                        smcState.msg   = "手机验证码发送成功。";
                        //更新Smsstore
                        int id = Convert.ToInt32(smsDs.Tables[0].Rows[0]["Id"]);
                        smsStore.Id = id;
                        smsStore.Load();
                        smsStore.SMSCode   = code;
                        smsStore.SMSNumber = 1;
                        smsStore.SendTime  = DateTime.Now;
                        smsStore.Save();
                    }
                }
            }
            else
            {
                //发送验证码
                int result = SMSsend(sendStrStart + code + sendStrEnd, phoneNumber);
                if (result == 9)
                {
                    smcState.State = 1;
                    smcState.msg   = "手机验证码发送成功。";
                    //添加一条数据到Smsstore
                    smsStore.Mobile    = phoneNumber;
                    smsStore.SMSCode   = code;
                    smsStore.SMSNumber = 1;
                    smsStore.SendTime  = DateTime.Now;
                    smsStore.Save();
                }
            }
            return(smcState);
        }
Esempio n. 3
0
        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="mobile">手机号</param>
        /// <returns>-1发送错误,0发送限制,1发送成功</returns>
        public static MobileCode Vcode(string mobile)
        {
            int        i        = 0;
            Random     rd       = new Random();
            string     code     = rd.Next(100000, 999999).ToString();
            string     content  = "";
            string     dtime    = DateTime.Today.ToString();
            string     time     = "";
            int        number   = 1;
            int        Id       = 0;
            MobileCode mc       = new MobileCode();
            Smsstore   smsstore = new Smsstore();
            DataSet    ds       = smsstore.Model(mobile);

            if (ds != null)
            {
                Id     = Convert.ToInt32(ds.Tables[0].Rows[0]["Id"].ToString());
                time   = ds.Tables[0].Rows[0]["SendTime"].ToString();
                number = Convert.ToInt32(ds.Tables[0].Rows[0]["SMSNumber"].ToString());
                if (dtime == time)
                {
                    if (number < 3 || mobile == "15101587969")
                    {
                        code   = ds.Tables[0].Rows[0]["SMSCode"].ToString();
                        number = number + 1;
                        i      = 1;
                    }
                    else
                    {
                        i    = 0;
                        code = "";
                    }
                }
                else
                {
                    i = 1;
                }
            }
            else
            {
                i = 1;
            }

            int j = -1;

            if (i == 1)
            {
                content = "您的验证码:" + code + "【领先办公】";
                int message = SMSsend(content, mobile);
                if (message == 9)
                {
                    smsstore.Id        = Id;
                    smsstore.SendTime  = Convert.ToDateTime(dtime);
                    smsstore.SMSNumber = number;
                    smsstore.SMSCode   = code;
                    smsstore.Mobile    = mobile;
                    smsstore.Save();
                    j = 1;
                }
                else
                {
                    j = -1;
                }
            }
            else
            {
                j = 0;
            }
            mc.Message = j;
            mc.Mobile  = mobile;
            return(mc);
        }