private Authorize getAuthorizeInfo(string code) { try { return(AuthorizeBiz.getUserInfo(code)); } catch (Exception e) { throw e; } }
/// <summary> /// 微信静默授权 /// </summary> /// <param name="code"></param> /// <returns></returns> public Tuple <string, string> getUserOpenId(string code) { string userOpenId = string.Empty; if (isWechatTest == "false") { userOpenId = CookieHelper.GetCookieValue("userOpenId"); //缓存为空 if (string.IsNullOrEmpty(userOpenId)) { try { if (string.IsNullOrEmpty(code)) { string url = Request.Url.ToString(); if (url.IndexOf("www.") < 0) { url = url.Replace("http://", "http://www."); } //请求微信接口获取code string snsapi_Base_Link = AuthorizeBiz.getSnsapi_Base_Link(url); return(new Tuple <string, string>(null, snsapi_Base_Link)); } else { Authorize userInfo = AuthorizeBiz.getUserInfo(code); if (userInfo != null) { userOpenId = userInfo.openid; } //请求微信接口获取openid } } catch (Exception e) { _Apilog.WriteLog("获取微信公众号静默授权 异常: " + e.Message); } if (!string.IsNullOrEmpty(userOpenId)) { CookieHelper.SetCookie("userOpenId", userOpenId); } } return(new Tuple <string, string>(userOpenId, null)); } else { return(new Tuple <string, string>("test", null)); } }