public tb_App_UserExtEntity() { user = new tb_App_UserEntity(); ext = new tb_OpenID_UserEntity(); }
protected override void OnInit(EventArgs e) { shopid = int.Parse(Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("shopid")); appid = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("appid"); secret = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("secret"); weixincode = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("weixincode"); sitepath = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("sitepath"); tb_UsersEntity user = null; Jnwf.Model.tb_App_UserEntity app_user = null; //检查cookie string ticket = ""; string disney = CookieHelper.GetCookieValue("disney"); if (!string.IsNullOrEmpty(disney)) { jinru = "cookie"; Jnwf.Utils.Log.Logger.Log4Net.Error("BasePage,jinru:" + jinru); ticket = Jnwf.Utils.Helper.DESEncrypt.Decrypt(disney); //Jnwf.Utils.Log.Logger.Log4Net.Error("basepage,cookie:" + ticket); user = AutoRepair.BLL.tb_UsersBLL.GetInstance().GetModelByOpenId(ticket); app_user = Jnwf.BLL.tb_App_UserBLL.GetInstance().GetModelByOpenId(ticket); if (app_user == null) { try { Response.Redirect("http://mp.weixin.qq.com/s?__biz=MzI4MzE0ODM1Nw==&mid=402172802&idx=1&sn=c66fe86ffd6b8c8cb73bd3033c1d2903#rd"); } catch (System.Threading.ThreadAbortException ex) { } } else if (user == null) { try { Response.Redirect(sitepath + "Registered.aspx"); } catch (System.Threading.ThreadAbortException ex) { } } else { this.OnBasePageLoad(user); } } else if (!string.IsNullOrEmpty(Code)) { jinru = "code"; Jnwf.Utils.Log.Logger.Log4Net.Error("BasePage,jinru:" + jinru); string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + Code + "&grant_type=authorization_code"; string json = Jnwf.Utils.Helper.HttpHelper.LoadPageContent(url); if (json.IndexOf("errcode") >= 0) { Jnwf.Utils.Log.Logger.Log4Net.Error("Results.aspx:" + json); } else { wx_OpenInfoEntity info = Jnwf.Utils.Json.JsonHelper.DeserializeJson <wx_OpenInfoEntity>(json); string str = info.openid; //Jnwf.Utils.Log.Logger.Log4Net.Error("basepage,code:" + str); CookieHelper.SetCookie("disney", Jnwf.Utils.Helper.DESEncrypt.Encrypt(str)); user = AutoRepair.BLL.tb_UsersBLL.GetInstance().GetModelByOpenId(info.openid); app_user = Jnwf.BLL.tb_App_UserBLL.GetInstance().GetModelByOpenId(info.openid); if (app_user == null) { try { Response.Redirect("http://mp.weixin.qq.com/s?__biz=MzI4MzE0ODM1Nw==&mid=402172802&idx=1&sn=c66fe86ffd6b8c8cb73bd3033c1d2903#rd"); } catch (System.Threading.ThreadAbortException ex) { } } else if (user == null) { try { Response.Redirect(sitepath + "Registered.aspx"); } catch (System.Threading.ThreadAbortException ex) { } } else { this.OnBasePageLoad(user); } } } else { jinru = "url"; Jnwf.Utils.Log.Logger.Log4Net.Error("BasePage,jinru:" + jinru); //string host = this.Request.Url.Host; //string path = this.Request.Path; //string redirect_uri = HttpUtility.UrlEncode("http://" + host + path); string redirect_uri = HttpUtility.UrlEncode(this.Request.Url.ToString()); Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("appid", appid); data.Add("redirect_uri", redirect_uri); data.Add("response_type", "code"); data.Add("scope", "snsapi_base"); string temp_url = "https://open.weixin.qq.com/connect/oauth2/authorize?"; foreach (var dic in data) { temp_url += dic.Key + "=" + dic.Value + "&"; } //Jnwf.Utils.Log.Logger.Log4Net.Error("detail:" + temp_url); try { //触发微信返回code码 this.Response.Redirect(temp_url.TrimEnd('&'));//Redirect函数会抛出ThreadAbortException异常,不用处理这个异常 } catch (System.Threading.ThreadAbortException ex) { } } base.OnInit(e); }