Ejemplo n.º 1
0
        public IHttpActionResult UpdatePhoneCode(PhoneCodeModel model)
        {
            var          r   = new ReturnItem <string>();
            PhoneCodeBLL bll = new PhoneCodeBLL();

            bll.UpdatePhoneCode(model.Phone);
            return(InspurJson <string>(r));
        }
Ejemplo n.º 2
0
        public JsonResult PhoneLogin([FromForm] string phone, [FromForm] string code)
        {
            DataResult dr = new DataResult();

            try
            {
                DataResult dataResult = ExaminePhoneAndCode(phone, code);

                if (dataResult.code != "200")
                {
                    return(Json(dataResult));
                }

                UserEntity userEntity = userBLL.GetByPhone(phone);

                if (userEntity == null)
                {
                    int rows = userBLL.CreateToPhone(phone);
                }

                PhoneCodeBLL phoneCodeBLL = new PhoneCodeBLL();
                phoneCodeBLL.Delete(phone);
                UserEntity user = userBLL.GetByPhone(phone);

                UserTokenBLL    userTokenBLL    = new UserTokenBLL();
                UserTokenEntity userTokenEntity = userTokenBLL.GetByUserId(user.userId);
                UserTokenEntity userToken       = new UserTokenEntity();

                if (userTokenEntity == null)
                {
                    userToken = userTokenBLL.Create(user.userId);
                }
                else
                {
                    userToken = userTokenBLL.Update(userTokenEntity);
                }

                LoginResult loginResult = new LoginResult();
                loginResult.token      = userToken.token;
                loginResult.userEntity = user;

                dr.code = "200";
                dr.data = loginResult;
            }
            catch (Exception ex)
            {
                dr.code = "999";
                dr.msg  = ex.Message;
            }

            return(Json(dr));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 检查手机号码
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        private DataResult ExaminePhoneAndCode(string phone, string code)
        {
            DataResult dr = new DataResult();

            try
            {
                if (string.IsNullOrWhiteSpace(phone) || phone.Length != 11)// || Regex.IsMatch(phone, Helper.RegexHelper.PATTERN_PHONE)
                {
                    dr.code = "201";
                    dr.msg  = "手机号码错误";
                    return(dr);
                }

                if (string.IsNullOrWhiteSpace(code) || code.Length != 6)
                {
                    dr.code = "201";
                    dr.msg  = "验证码错误";
                    return(dr);
                }

                PhoneCodeBLL    phoneCodeBLL    = new PhoneCodeBLL();
                PhoneCodeEntity phoneCodeEntity = phoneCodeBLL.GetByPhoneAndCode(phone, code);

                if (phoneCodeEntity == null)
                {
                    dr.code = "201";
                    dr.msg  = "验证码错误";
                    return(dr);
                }

                TimeSpan ts       = DateTime.Now.Subtract(phoneCodeEntity.createDate).Duration();
                double   dateDiff = ts.TotalMinutes;

                if (dateDiff > 15)
                {
                    phoneCodeBLL.Delete(phone);
                    dr.code = "201";
                    dr.msg  = "验证码过期";
                    return(dr);
                }

                dr.code = "200";
            }
            catch (Exception ex)
            {
                dr.code = "999";
                dr.msg  = ex.Message;
            }

            return(dr);
        }
Ejemplo n.º 4
0
        public JsonResult SendCode([FromForm] string phone)
        {
            DataResult dr = new DataResult();

            try
            {
                if (string.IsNullOrWhiteSpace(phone) || phone.Length != 11) //|| !Regex.IsMatch(phone, Helper.RegexHelper.PATTERN_PHONE)
                {
                    dr.code = "201";
                    dr.msg  = "手机号码错误";
                    return(Json(dr));
                }

                Random rd   = new Random();
                string code = rd.Next(100000, 999999).ToString();

                bool rs = Aliyun.MessageHeiper.SendCode(phone, code);

                if (!rs)
                {
                    dr.code = "201";
                    dr.msg  = "验证码发送失败";
                    return(Json(dr));
                }

                PhoneCodeBLL phoneCodeBLL = new PhoneCodeBLL();

                int rows = phoneCodeBLL.Delete(phone);

                if (phoneCodeBLL.Create(phone, code) > 0)
                {
                    dr.code = "200";
                    dr.msg  = "验证码发送成功";
                }
                else
                {
                    dr.code = "201";
                    dr.msg  = "验证码发送成功,但保存失败";
                }
            }
            catch (Exception ex)
            {
                dr.code = "999";
                dr.msg  = ex.Message;
            }
            return(Json(dr));
        }
Ejemplo n.º 5
0
        public IHttpActionResult ValidatePhoneCode(PhoneCodeModel model)
        {
            var          r   = new ReturnItem <string>();
            PhoneCodeBLL bll = new PhoneCodeBLL();

            PhoneCodeModel code = bll.GetPhoneCode(model.Phone, Convert.ToInt32(model.SmsType));

            if (code == null || code.Code != model.Code)
            {
                r.Code = 0;
            }
            else if (code.Code == model.Code)
            {
                r.Code = 1;
            }
            else
            {
                r.Code = -1;
            }
            return(InspurJson <string>(r));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 发送短信,验证,处理
        /// </summary>
        /// <param name="phone">号码</param>
        /// <param name="smstype">短信类型</param>
        /// <param name="clientIp">客户端ip</param>
        /// <returns></returns>
        public ReturnItem <string> SendMessage(string Phone, string clientip, int smstype)
        {
            string msgcontent = GetMsgContent(smstype);

            if (msgcontent == null || msgcontent == "")
            {
                return(new ReturnItem <string>()
                {
                    Code = 0, Msg = "短信模板配置不正确"
                });
            }

            PhoneCodeBLL   bll   = new PhoneCodeBLL();
            PhoneCodeModel model = bll.GetPhoneCode(Phone, smstype);

            //短时间(1分钟)内重复获取
            if (model != null && model.StartTime.AddMinutes(1) > DateTime.Now)
            {
                return(new ReturnItem <string>()
                {
                    Code = 0, Msg = "请耐心等待,勿重复获取"
                });
            }

            //相同IP每天限制可以发送的数量
            if (clientip != "")
            {
                if (bll.GetCountByClientIpEveryDay(clientip) > Convert.ToInt32(GetIpSendNumber()))
                {
                    return(new ReturnItem <string>()
                    {
                        Code = 0, Msg = "Ip发送次数超过限制,请明天再试"
                    });
                }
            }

            //相同号码每天限制可以发送的数量
            if (Phone != "")
            {
                if (bll.GetCountByPhoneEveryDay(Phone) > Convert.ToInt32(GetPhoneSendNumber()))
                {
                    return(new ReturnItem <string>()
                    {
                        Code = 0, Msg = "号码发送次数超过限制,请明天再试"
                    });
                }
            }

            //如果验证码有效,还是发送上次的验证码
            string code = "";

            if (model == null)
            {
                System.Random Random = new System.Random();
                int           Result = Random.Next(0, 999999);
                while (Result.ToString().Length < 6)
                {
                    Result = Random.Next(0, 999999);
                }
                model            = new PhoneCodeModel();
                model.Code       = Result.ToString();
                model.Phone      = Phone;
                model.ClientIp   = clientip;
                model.StartTime  = DateTime.Now;
                model.EndTime    = DateTime.Now.AddMinutes(10);
                model.SmsType    = smstype.ToString();
                model.SmsContent = msgcontent;
                bll.InsertPhoneCode(model);
            }
            code = model.Code;

            if (GetSmsIsDebug() == "1")
            {
                return(new ReturnItem <string>()
                {
                    Code = 1, Msg = "验证码发送成功"
                });
            }
            else
            {
                //发送短信
                QDBeaconFire fire = new QDBeaconFire();
                string       ret  = fire.Send(Phone, msgcontent.Replace("!!!!!!", code));

                var xml = System.Xml.Linq.XElement.Parse(ret);
                if (xml.Elements("returnstatus").FirstOrDefault().Value == "Success")
                {
                    ret = "验证码发送成功";
                }
                else
                {
                    ret = "服务器内部错误,请稍候重试。";
                    log.ErrorFormat("[SMS]发送短信失败:{0}。", xml.Elements("message").FirstOrDefault().Value);
                }


                return(new ReturnItem <string>()
                {
                    Code = 1, Msg = ret
                });
            }
        }