⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sms_reg.aspx.cs

📁 java做的短信平台
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBLibrary;
using System.Text.RegularExpressions;
public partial class SMS_SMS_Reg : System.Web.UI.Page
{
    private DBLibrary.DBClass db = new DBClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        string flag = Request["ac"] == null ? "0" : Request["ac"].ToString().Trim();
        switch (flag)
        {
            case "1":
                SMS_Login();
                break;
            case "2":
                SMS_Reg();
                break;
            case "3":
                SMS_GetPassword();
                break;
            case "4":
                ExitLog();
                break;
        }
    }

    private void ExitLog()
    {
        Session["SMS_ID"] = null;
        Session["SMS_NO"] = null;
        Session["SMS_NAME"] = null;
        Session["SMS_Grade"] = null;
        Response.Write("<script>alert('退出成功!');window.close();window.parent.location='SMS_Reg.aspx';</script>");
    }
    private void SMS_Login()
    {
        string js = "";
        string mobile = Request["mob"] == null ? "" : Request["mob"].ToString().Trim();
        string password = Request["pwd"] == null ? "" : Request["pwd"].ToString().Trim();
        string code = Request["scode1"] == null ? "" : Request["scode1"].ToString().Trim();
        try
        {
            if (Session["RandCode"].ToString().Trim() != code)
            {
                Response.Write("<script>alert('验证码错误!请重新输入.');window.history.back();</script>");
                return;
            }
            if (mobile.ToString().Trim() == "" || (!isMobileNo(mobile.ToString().Trim())))
            {
                Response.Write("<script>alert('号码为空或者格式有误!请重新输入.');window.history.back();</script>");
                return;
            }
        }
        catch
        {
            Response.Redirect("SMS_Reg.aspx");
        }
        System.Data.SqlClient.SqlParameter[] para =
            {
                db.MakeInputParameter("@MobileNo",SqlDbType.NVarChar,50,mobile),
                db.MakeInputParameter("@PassWord",SqlDbType.NVarChar,50,password),
            };
        int nRet = 0;
        DataTable dt =null;
        try
        {
            dt = db.RunProcedureForDataSet("SMS_Web_Login", para).Tables[0];
            if (dt == null || dt.Rows.Count<=0)
            {
                js = "<script>alert('登陆失败,手机号或者密码输入错误!');window.history.back();</script>";
                Response.Write(js);
                return;
            }

        }
        catch(Exception ex)
        {
            js = "<script>alert('登陆失败,系统出现异常!原因:"+ex.Message.ToString().Replace("'","\\'")+"');window.history.back();</script>";
            Response.Write(js);
            return;
        }
        //登陆成功
        Session["SMS_ID"] = dt.Rows[0]["id"].ToString().Trim();
        Session["SMS_NO"] = dt.Rows[0]["MobileNo"].ToString().Trim();
        Session["SMS_NAME"] = dt.Rows[0]["RealName"].ToString().Trim();
        Session["SMS_Grade"] = dt.Rows[0]["Grade"].ToString().Trim();
        Response.Redirect("wel.html");

        
    }
    private void SMS_GetPassword()
    {
        string js = "";
        string mobile = Request["mob3"] == null ? "" : Request["mob3"].ToString().Trim();
        string code = Request["scode3"] == null ? "" : Request["scode3"].ToString().Trim();
        try
        {
            if (Session["RandCode2"].ToString().Trim() != code)
            {
                Response.Write("<script>alert('验证码错误!请重新输入.');window.history.back();</script>");
                return;
            }
            if (mobile.ToString().Trim() == "" || (!isMobileNo(mobile.ToString().Trim())))
            {
                Response.Write("<script>alert('号码为空或者格式有误!请重新输入.');window.history.back();</script>");
                return;
            }
        }
        catch
        {
            Response.Redirect("SMS_Reg.aspx");
        }
        
        System.Data.SqlClient.SqlParameter[] para =
            {
                db.MakeInputParameter("@MobileNo",SqlDbType.NVarChar,50,mobile)
            };
        try
        {
            int ret = db.RunProcedureForInt("SMS_Web_GetPassWord", para);
            if (ret == 0)  //失败
            {
                js = "<script>alert('没有找到此号码,操作失败!');window.history.back();</script>";
            }
            else
            {
                js = "<script>alert('操作成功.密码已发送,请耐心等待!');window.location='SMS_Reg.aspx';</script>";
            }
        }
        catch (Exception ex)
        {
            js = "<script>alert('发送密码失败,出现异常!');window.location='SMS_Reg.aspx';</script>";
        }
        Response.Write(js);

    }
    private bool isMobileNo(string no)
    {
         if (no.Trim() == "10086")
        {
            return true;
        }
        if (no.ToString().Trim().StartsWith("1"))
        {
            if (!IsRegEx("(^15[3|8|9]{1}[0-9]{8}$)|(^13[0-9]{9}$)", no))
            {
                return false;
            }
        }
        else if (no.ToString().Trim().StartsWith("0")) //小灵通
        {
            if (!IsRegEx("^0[0-9]{10,11}$", no))
            {
                return false;
            }

        }
        else
        {
            return false;
        }
        return true;
    }
    private bool IsRegEx(string regExValue, string itemValue)
    {

        try
        {
            Regex regex = new System.Text.RegularExpressions.Regex(regExValue);
            if (regex.IsMatch(itemValue))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch (Exception)
        {
            return false;
        }
        finally
        {
        }
    } 
    private void SMS_Reg()
    {
        string js="";
        string mobile = Request["mob2"] == null ? "" : Request["mob2"].ToString().Trim();
        string rname = Request["realname"] == null ? "" : Request["realname"].ToString().Trim();
        string code = Request["scode2"] == null ? "" : Request["scode2"].ToString().Trim();
        try
        {
            if (Session["RandCode1"].ToString().Trim() != code)
            {
                Response.Write("<script>alert('验证码错误!请重新输入.');window.history.back();</script>");
                return;
            }
            if (mobile.ToString().Trim() == "" || (!isMobileNo(mobile.ToString().Trim())))
            {
                Response.Write("<script>alert('号码为空或者格式有误!请重新输入.');window.history.back();</script>");
                return;
            }
            if (rname.Trim() == "")
            {
                Response.Write("<script>alert('姓名不能为空!请重新输入.');window.history.back();</script>");
                return;
            }
        }
        catch
        {
            Response.Redirect("SMS_Reg.aspx");
        }
        System.Data.SqlClient.SqlParameter[] para =
            {
                db.MakeInputParameter("@MobileNo",SqlDbType.NVarChar,50,mobile),
                db.MakeInputParameter("@RealName",SqlDbType.NVarChar,50,rname),
                db.MakeInputParameter("@Reg_Ip",SqlDbType.NVarChar,50,Request.ServerVariables["REMOTE_ADDR"].ToString().Trim())
            };
        try
        {
            int ret = db.RunProcedureForInt("SMS_Web_Register", para);
            if (ret == 0)  //失败
            {
                js = "<script>alert('注册失败,真实姓名或者手机号已存在,请重新输入!');window.history.back();</script>";
            }
            else
            {
                js = "<script>alert('注册成功,密码以短信方式发送给您!');window.location='SMS_Reg.aspx';</script>";
            }
        }
        catch(Exception ex)
        {
            js = "<script>alert('注册失败,出现异常!');window.location='SMS_Reg.aspx';</script>";
        }
        Response.Write(js);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -