protected void Page_Load(object sender, EventArgs e) { string RequestUrl = Request.ServerVariables["SERVER_NAME"].ToLower(); //根据域名读取商户ID,如果没有绑定域名直接跳转后台 comid = GeneralFunc.GetComid(RequestUrl); }
protected void Page_Load(object sender, EventArgs e) { Email = Request["Email"].ConvertTo <string>(""); //获得comid:为0则进入登录页面;非0则进入下面流程 string RequestUrl = Request.ServerVariables["SERVER_NAME"].ToLower(); comid = GeneralFunc.GetComid(RequestUrl); if (comid == 0) { return; } //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "RequestUrl:" + RequestUrl); //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "comid:" + comid); //以下3个参数用于获取微信号,并且通过判断实现手机分销系统免登陆 string code = Request["code"].ConvertTo <string>(""); //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "code:" + code); string openid = Request["openid"].ConvertTo <string>(""); string weixinpass = Request["weixinpass"].ConvertTo <string>(""); //如果3个参数都为空,则进入登录页面 if (code == "" && openid == "" && weixinpass == "") { return; } //如果以上3个参数中有参数传递过来,则进入手机分销系统免登陆判断 if (code != "")//根据微信端code获取微信号 { openid = GetOpenId(code, comid); //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "openid:" + openid); } else//根据微信一次性密码获取微信号 { if (openid != "" && weixinpass != "")//微信端发送来的请求 { bool isavailable = VerifyOneOffPass(openid, weixinpass); if (isavailable == false) { //微信一次性密码失效,判断传递过来的openid 和 客户端cookie中openid 是否相同(防止转发):相同直接免登陆进入手机分销后台;否则进入登录手机分销页面 HttpCookie cookie = Request.Cookies["openid"]; if (cookie != null) { string cookieValue = cookie.Value; if (cookieValue != openid) { openid = ""; } } //else { openid = openid; } //微信一次性密,可以不操作 } //else { openid = openid; } //传递过来的openid 和 客户端cookie中openid相符,可以不操作 } else//非微信端发送来的请求,需要进入登录页面 { openid = ""; } } if (openid != "")//如果微信号 获取成功,则获取当前微信号 微信免登陆 对应的分销商:有则免登陆;没有则需要登录 { Agent_company freelandingagentuser = new AgentCompanyData().GetFreeLandingAgentUserByOpenId(openid); if (freelandingagentuser != null) { Session["Agentid"] = freelandingagentuser.Id;//分销公司id,并不是分销员工id Session["Account"] = freelandingagentuser.Account; //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "agentid:" + freelandingagentuser.Id + ",account:" + freelandingagentuser.Account); HttpCookie cookie = new HttpCookie("Agentid"); //实例化HttpCookie类并添加值 cookie.Value = freelandingagentuser.Id.ToString(); //分销公司id,并不是分销员工id cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); var returnmd5 = EncryptionHelper.ToMD5(freelandingagentuser.Account + "lixh1210" + freelandingagentuser.Id.ToString(), "UTF-8"); cookie = new HttpCookie("AgentKey"); //实例化HttpCookie类并添加值 cookie.Value = returnmd5; cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); cookie = new HttpCookie("Account"); //分销账户 cookie.Value = freelandingagentuser.Account; cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); Response.Redirect("default.aspx"); } } }