private void WxLogin(string code, string state) { HttpContext context = HttpContext.Current; WxLogin test = new WxLogin(); string res = test.CheckAndGetUserInfo(context, code, state); if (res == "success") { Response.Redirect("index.aspx", false); } else { Response.Write("<script> $.messager.alert('登录错误', res, 'error');<script/>"); } }
protected void Page_Load(object sender, EventArgs e) { string url = Request.Url.ToString(); if (url.Contains("code") && url.Contains("state")) { string code = Request.QueryString["code"]; string state = Request.QueryString["state"]; WxLogin(code, state); } else if (url.Contains("act=wxlogin")) { WxLogin act = new WxLogin(); HttpContext context = HttpContext.Current; act.GotoGetCode(context); } string action = Request.Form["action"]; if (!string.IsNullOrEmpty(action)) { Response.Clear(); if (action == "init") { //Init(); } else if (action == "login") { Login(); } else if (action == "check") { CheckCookie(); } else if (action == "logout") { LogOut(); } else if (action == "getValideCode") { GetValideCode(); } // else if (action == "gotogetcode") // { // string randomString = ValideCodeHelper.GetRandomCode(16); // Session["randomString"] = randomString; // string urlForGettingCode = string.Format("https://www.baidu.com?appid={0}&agentid={1}&redirect_uri={2}&state={3}" //, Corpid, AgentId, HttpUtility.UrlEncode(RedirectUri), randomString); // Response.Redirect("http://www.baidu.com"); // } // else if(action=="wxlogin") // { // WxLogin(); // } Response.End(); } else { //if (UserInfoManage.IsLogined()) //{ // Response.Redirect("~/index.aspx"); //} } }