Exemplo n.º 1
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));
        }
Exemplo n.º 2
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
                });
            }
        }