Exemplo n.º 1
0
        /// <summary>
        /// 获取短信验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult smscode()
        {
            string       json     = "";
            string       vvcode   = "";
            B_usercenter bu       = new B_usercenter();
            string       mobile   = Utils.CheckSQLHtml(Request["mobile"].ToString().Trim());
            int          userid   = DNTRequest.GetInt("userid", 0);
            int          smstype  = (int)Enum.Parse(typeof(EnumSMSType), EnumSMSType.短信验证码.ToString());
            int          smstype1 = (int)Enum.Parse(typeof(EnumSMSType), EnumSMSType.语音短信验证码.ToString());
            string       sql2     = "SELECT registerid,username,mobile from hx_member_table where  mobile='" + mobile + "'";
            DataTable    dt1      = DbHelperSQL.GET_DataTable_List(sql2);

            if (dt1.Rows.Count > 0)
            {
                if (Request["vcodec"] != null)
                {
                    vvcode = Utils.CheckSQLHtml(Request["vcodec"].ToString().Trim());
                }

                string ipc = Utils.GetRealIP();

                if (vvcode.Length >= 4)
                {
                    string strIdentify = "LoginValidateCode"; //随机字串存储键值,以便存储到Session中
                    if (Session[strIdentify] != null)
                    {
                        if (Session[strIdentify].ToString() == vvcode)
                        {
                        }
                        else
                        {
                            json = @" {""rs"": ""n"", ""info"":  ""验证码不对!""}";
                            return(Content(json));
                        }
                    }
                    else
                    {
                        json = @" {""rs"": ""n"", ""info"":  ""验证码已过期!""}";
                        return(Content(json));
                    }
                }
                else if (vvcode.Length > 0 && vvcode.Length <= 3)
                {
                    json = @" {""rs"": ""n"", ""info"":  ""验证码位数不对!""}";
                    return(Content(json));
                }
                else
                {
                    // json = @" {""rs"": ""n"", ""info"":  ""v""}";
                    // return Content(json);
                }

                if (Session["checkmobileq"] == null)
                {
                    Session["checkmobileq"] = DateTime.Now.ToString();
                }
                else
                {
                    DateTime dte = DateTime.Parse(Session["checkmobileq"].ToString());

                    long sec = Utils.DateDiff("Second", dte, DateTime.Now);

                    if (sec > 60)
                    {
                        Session["checkmobileq"] = null;
                    }
                    else
                    {
                        json = @" {""rs"": ""n"", ""info"":  ""短信发送太频繁!请稍后再试""}";
                        return(Content(json));
                    }
                }

                if (bu.checkipsess(Utils.GetRealIP(), smstype, smstype1) == false)
                {
                    json = @" {""rs"": ""n"", ""info"":  ""短信发送太频繁!发送异常""}";
                    return(Content(json));
                }

                if (bu.checkipnum(Utils.GetRealIP(), smstype, smstype1) >= 8)
                {
                    json = @" {""rs"": ""n"", ""info"":  ""短信发送太频繁!请与客服联系""}";
                    return(Content(json));
                }
                else
                {
                    /*
                     * hx_td_SMS_record记录短信,验证码类型应是1
                     *
                     */
                    string contxt = Utils.GetMSMEmailContext(1, 0); // 获取注册成功邮件内容

                    M_td_SMS_record p   = new M_td_SMS_record();
                    B_td_SMS_record o   = new B_td_SMS_record();
                    string          sql = "select sms_record_id,smscontext,phone_number,hits from hx_td_SMS_record where ( smstype=" + smstype + "  or  smstype=" + smstype1 + " ) and phone_number='" + mobile + "' and  DATEDIFF(MINUTE,sendtime,getDate())<3 order by sms_record_id desc";

                    DataTable dt = DbHelperSQL.GET_DataTable_List(sql);
                    if (dt.Rows.Count > 0)
                    {
                        if (int.Parse(dt.Rows[0]["hits"].ToString()) < 3)
                        {
                            //以前存在,直接发送验证码
                            decimal dd = SendSMS.Send_SMS(dt.Rows[0]["phone_number"].ToString(), dt.Rows[0]["smscontext"].ToString());
                            if (dd != 0)
                            {
                                json = @" {""rs"": ""n"", ""info"":  ""短信发送异常,请与客报联系""}";
                                return(Content(json));
                            }
                            //if (dd > 0)
                            // {
                            sql = "update hx_td_SMS_record set orderid=" + dd.ToString() + ",hits=hits+1  where sms_record_id=" + dt.Rows[0]["sms_record_id"].ToString();
                            DbHelperSQL.RunSql(sql);
                            //}
                        }
                        else
                        {
                            json = @" {""rs"": ""n"", ""info"":  ""短信发送异常,请与客报联系""}";
                            return(Content(json));
                        }
                    }
                    else
                    {
                        //不存在生成新的验证码
                        string vcode = Utils.RndNum(6);

                        string smscontxt = Utils.GetMSMEmailContext(16, 1); // 获取注册成功邮件内容

                        StringBuilder sbsms = new StringBuilder(smscontxt);

                        sbsms = sbsms.Replace("#CODE#", vcode);
                        decimal dd = SendSMS.Send_SMS(mobile, sbsms.ToString());
                        if (dd != 0)
                        {
                            json = @" {""rs"": ""n"", ""info"":  ""短信发送异常,请与客报联系""}";
                            return(Content(json));
                        }
                        p.phone_number = mobile;
                        p.sendtime     = DateTime.Now;
                        p.senduserid   = userid;
                        p.smstype      = smstype;
                        p.smscontext   = sbsms.ToString();
                        p.orderid      = dd;
                        p.vcode        = vcode;
                        p.ip           = Utils.GetRealIP();
                        o.Add(p);
                    }
                    json = @" {""rs"": ""y"", ""info"":  ""短信发送成功! ""}";
                    return(Content(json));
                }
            }
            return(Content(json));
        }