protected void Page_Load(object sender, EventArgs e)
    {
        UserAuthorizationModel userInfo = UserAuthorization.userLogin(this.Page);

        if (userInfo.openId == null || userInfo.openId == "")
        {
            openid = userInfo.mobile;
        }
        else
        {
            openid = userInfo.openId;
        }
        Session["openid"] = openid;

        if (IsPostBack)
        {
            string mobile = Request.Form["tel"];
            string code   = Request.Form["code"];

            object codeCache = HttpContext.Current.Cache.Get("code" + mobile);
            if (codeCache == null)
            {
                Jscript.NorefLocation(this.Page, "验证码失效请重新获取!手机号为:" + mobile + "code is:" + code, "CouponForOneThousand.aspx");
            }
            else
            {
                if (code != codeCache.ToString())
                {
                    Jscript.NorefLocation(this.Page, "验证码不正确!", "CouponForOneThousand.aspx");
                }
                else
                {
                    var member = new LVWEIBA.BLL.MemberInfo().GetModel(openid);
                    if (member != null)
                    {
                        if (member.Tel == "" || member.Tel == null)
                        {
                            //更新用户信息
                            var bll = new LVWEIBA.BLL.MemberInfo();
                            member.Tel = mobile.Trim();
                            bll.Update(member);
                            //发放礼券(500一张,300元一张,50元2张,20元5张)
                            LVWEIBA.BLL.MemberCoupon bllCoupon = new LVWEIBA.BLL.MemberCoupon();
                            //20元
                            for (int i = 0; i < 5; i++)
                            {
                                List <LVWEIBA.Model.MemberCoupon> list = new List <LVWEIBA.Model.MemberCoupon>();
                                LVWEIBA.Model.MemberCoupon        mdl  = new LVWEIBA.Model.MemberCoupon();
                                mdl.CouponID = "0020160604000001KBW1";
                                mdl.Userid   = openid;
                                mdl.ZT       = "0";
                                mdl.Count    = 5;
                                mdl.Sj       = DateTime.Now;
                                mdl.Order_Id = "";
                                list.Add(mdl);
                                bllCoupon.SendCouton(list, "0020160604000001KBW1", 1);
                            }
                            //50元
                            for (int i = 0; i < 2; i++)
                            {
                                List <LVWEIBA.Model.MemberCoupon> listForFifty = new List <LVWEIBA.Model.MemberCoupon>();
                                LVWEIBA.Model.MemberCoupon        mdlForFifty  = new LVWEIBA.Model.MemberCoupon();
                                mdlForFifty.CouponID = "0020160604000001L511";
                                mdlForFifty.Userid   = openid;
                                mdlForFifty.ZT       = "0";
                                mdlForFifty.Count    = 2;
                                mdlForFifty.Sj       = DateTime.Now;
                                mdlForFifty.Order_Id = "";
                                listForFifty.Add(mdlForFifty);
                                bllCoupon.SendCouton(listForFifty, "0020160604000001L511", 1);
                            }
                            //300元
                            List <LVWEIBA.Model.MemberCoupon> listForThreeHundred = new List <LVWEIBA.Model.MemberCoupon>();
                            LVWEIBA.Model.MemberCoupon        mdlForThreeHundred  = new LVWEIBA.Model.MemberCoupon();
                            mdlForThreeHundred.CouponID = "002016060400000164Q5";
                            mdlForThreeHundred.Userid   = openid;
                            mdlForThreeHundred.ZT       = "0";
                            mdlForThreeHundred.Count    = 1;
                            mdlForThreeHundred.Sj       = DateTime.Now;
                            mdlForThreeHundred.Order_Id = "";
                            listForThreeHundred.Add(mdlForThreeHundred);
                            bllCoupon.SendCouton(listForThreeHundred, "002016060400000164Q5", 1);
                            //500元
                            List <LVWEIBA.Model.MemberCoupon> listForFiveHundred = new List <LVWEIBA.Model.MemberCoupon>();
                            LVWEIBA.Model.MemberCoupon        mdlForFiveHundred  = new LVWEIBA.Model.MemberCoupon();
                            mdlForFiveHundred.CouponID = "00201606200000011KA9";
                            mdlForFiveHundred.Userid   = openid;
                            mdlForFiveHundred.ZT       = "0";
                            mdlForFiveHundred.Count    = 1;
                            mdlForFiveHundred.Sj       = DateTime.Now;
                            mdlForFiveHundred.Order_Id = "";
                            listForFiveHundred.Add(mdlForFiveHundred);
                            bllCoupon.SendCouton(listForFiveHundred, "00201606200000011KA9", 1);

                            //删除缓存
                            HttpContext.Current.Cache.Remove("code" + mobile);
                            Jscript.NorefLocation(this.Page, "领取成功!", "Coupon.aspx");
                        }
                        else
                        {
                            //删除缓存
                            HttpContext.Current.Cache.Remove("code" + mobile);
                            Jscript.NorefLocation(this.Page, "请先验证手机!", "bindPhone.aspx");
                        }
                    }
                }
            }
        }
    }
Beispiel #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["openid"] == null)
        {
            if (string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + GetWeiXinInf.appid + "&redirect_uri=http://wx.lvwei8.com/index/bindPhone.aspx&response_type=code&scope=snsapi_base&state=123#wechat_redirect");
            }

            else
            {
                string code = Request.QueryString["code"];
                openid = new WEIxinUserApi().GetUserOpenid(code);

                if (openid.Length < 10)
                {
                    Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + GetWeiXinInf.appid + "&redirect_uri=http://wx.lvwei8.com/index/bindPhone.aspx&response_type=code&scope=snsapi_base&state=123#wechat_redirect");
                }
            }
            Session["openid"] = openid;
        }
        else
        {
            openid = Session["openid"].ToString();
        }

        if (IsPostBack)
        {
            string mobile = Request.Form["tel"];
            string code   = Request.Form["code"];

            object codeCache = HttpContext.Current.Cache.Get("code" + mobile);
            if (codeCache == null)
            {
                Jscript.NorefLocation(this.Page, "验证码失效请重新获取!手机号为:" + mobile + "code is:" + code, "bindPhone.aspx");
            }
            else
            {
                if (code != codeCache.ToString())
                {
                    Jscript.NorefLocation(this.Page, "验证码不正确!", "bindPhone.aspx");
                }
                else
                {
                    var member = new LVWEIBA.BLL.MemberInfo().GetModel(openid);
                    if (member != null)
                    {
                        if (member.Tel == "" || member.Tel == null)
                        {
                            //更新用户信息
                            var bll = new LVWEIBA.BLL.MemberInfo();
                            member.Tel = mobile.Trim();
                            bll.Update(member);

                            //发放礼券
                            //0020160508000001D5KI
                            List <LVWEIBA.Model.MemberCoupon> list      = new List <LVWEIBA.Model.MemberCoupon>();
                            LVWEIBA.BLL.MemberCoupon          bllCoupon = new LVWEIBA.BLL.MemberCoupon();
                            LVWEIBA.BLL.Coupon_Info           bllCou    = new LVWEIBA.BLL.Coupon_Info();
                            LVWEIBA.Model.Coupon_Info         cou       = bllCou.GetModel("0020160604000001KBW1");
                            LVWEIBA.Model.MemberCoupon        mdl       = new LVWEIBA.Model.MemberCoupon();
                            mdl.CouponID = "0020160604000001KBW1";
                            mdl.Userid   = openid;
                            mdl.ZT       = "0";
                            mdl.Count    = 1;
                            mdl.Sj       = DateTime.Now;
                            mdl.Order_Id = "";
                            list.Add(mdl);
                            //删除缓存
                            HttpContext.Current.Cache.Remove("code" + mobile);
                            if (bllCoupon.SendCouton(list, "0020160604000001KBW1", 1))
                            {
                                Jscript.NorefLocation(this.Page, "手机验证成功!", "Coupon.aspx");
                            }
                            else
                            {
                                Jscript.NorefLocation(this.Page, "手机验证失败!", "Coupon.aspx");
                            }
                        }
                        else
                        {
                            //删除缓存
                            HttpContext.Current.Cache.Remove("code" + mobile);
                            Jscript.NorefLocation(this.Page, "该手机已经验证过!", "bindPhone.aspx");
                        }
                    }
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        UserAuthorizationModel userInfo = UserAuthorization.userLogin(this.Page);

        if (userInfo.openId == null || userInfo.openId == "")
        {
            openid_db = userInfo.mobile;
        }
        else
        {
            openid_db = userInfo.openId;
        }
        //Session["openid"] = openid;

        if (string.IsNullOrEmpty(Request.QueryString["code"]))
        {
            Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + GetWeiXinInf.appid + "&redirect_uri=http://wx.lvwei8.com/index/CouponForNinety.aspx&response_type=code&scope=snsapi_base&state=123#wechat_redirect");
        }

        else
        {
            string code = Request.QueryString["code"];
            openid_wx = new WEIxinUserApi().GetUserOpenid(code);
            //Session["openid"] = openid;

            if (openid_wx.Length < 10)
            {
                Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + GetWeiXinInf.appid + "&redirect_uri=http://wx.lvwei8.com/index/CouponForNinety.aspx&response_type=code&scope=snsapi_base&state=123#wechat_redirect");
            }
            else
            {
            }
        }

        if (IsPostBack)
        {
            string mobile = Request.Form["tel"];
            string code   = Request.Form["code"];

            object codeCache = HttpContext.Current.Cache.Get("code" + mobile);
            if (codeCache == null)
            {
                Jscript.NorefLocation(this.Page, "验证码失效请重新获取!手机号为:" + mobile + "code is:" + code, "CouponForNinety.aspx");
            }
            else
            {
                if (code != codeCache.ToString())
                {
                    Jscript.NorefLocation(this.Page, "验证码不正确!", "CouponForNinety.aspx");
                }
                else
                {
                    var member = new LVWEIBA.BLL.MemberInfo().GetModel(openid_db);
                    if (member != null)
                    {
                        if (member.Tel == "" || member.Tel == null || openid_db != openid_wx)
                        {
                            //更新用户信息
                            var bll = new LVWEIBA.BLL.MemberInfo();
                            member.Tel    = mobile.Trim();
                            member.openid = openid_wx;
                            bll.Update(member);
                            //发放礼券(50元一张,20元俩张)
                            LVWEIBA.BLL.MemberCoupon bllCoupon = new LVWEIBA.BLL.MemberCoupon();
                            for (int i = 0; i < 2; i++)
                            {
                                List <LVWEIBA.Model.MemberCoupon> list = new List <LVWEIBA.Model.MemberCoupon>();
                                LVWEIBA.Model.MemberCoupon        mdl  = new LVWEIBA.Model.MemberCoupon();
                                mdl.CouponID = "0020160604000001KBW1";
                                mdl.Userid   = openid_wx;
                                mdl.ZT       = "0";
                                mdl.Count    = 2;
                                mdl.Sj       = DateTime.Now;
                                mdl.Order_Id = "";
                                list.Add(mdl);
                                bllCoupon.SendCouton(list, "0020160604000001KBW1", 1);
                            }
                            //50元
                            List <LVWEIBA.Model.MemberCoupon> listForFifty = new List <LVWEIBA.Model.MemberCoupon>();
                            LVWEIBA.Model.MemberCoupon        mdlForFifty  = new LVWEIBA.Model.MemberCoupon();
                            mdlForFifty.CouponID = "0020160604000001L511";
                            mdlForFifty.Userid   = openid_wx;
                            mdlForFifty.ZT       = "0";
                            mdlForFifty.Count    = 1;
                            mdlForFifty.Sj       = DateTime.Now;
                            mdlForFifty.Order_Id = "";
                            listForFifty.Add(mdlForFifty);
                            bllCoupon.SendCouton(listForFifty, "0020160604000001L511", 1);
                            //删除缓存
                            HttpContext.Current.Cache.Remove("code" + mobile);
                            Jscript.NorefLocation(this.Page, "领取成功!", "Coupon.aspx");
                        }
                        else
                        {
                            //删除缓存
                            HttpContext.Current.Cache.Remove("code" + mobile);
                            Jscript.NorefLocation(this.Page, "该手机号已经验证过!", "CouponForNinety.aspx");
                        }
                    }
                }
            }
        }
    }