private string ReGetOpenId(string APPID, string AAPPSECRET) { string UserOpenId = ""; try { WXVariousApi VariousApi = new WXVariousApi(); string url = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;//获取当前url if (Session["openid"] == null || Session["openid"].ToString() == "") { //先要判断是否是获取code后跳转过来的 if (System.Web.HttpContext.Current.Request.QueryString["code"] == "" || System.Web.HttpContext.Current.Request.QueryString["code"] == null) { // Code为空时,先获取Code string GetCodeUrls = VariousApi.GetCodeUrl(url, APPID); System.Web.HttpContext.Current.Response.Redirect(GetCodeUrls); // 先跳转到微信的服务器,取得code后会跳回来这页面的 } else { // Code非空,已经获取了code后跳回来啦,现在重新获取openid string openid = ""; openid = VariousApi.GetOauthAccessOpenId(System.Web.HttpContext.Current.Request.QueryString["Code"], APPID, AAPPSECRET);// 重新取得用户的openid Session["openid"] = openid; UserOpenId = openid; } } } catch (Exception ex) { Log.Instance.Write("Error:" + ex.Message, "微信获取信息错误"); } return(UserOpenId); }