Пример #1
0
        private Userinfo getWechatUserInfo(Authorize authorizeInfo)
        {
            var res = AuthorizeBiz.getUserinfo(authorizeInfo.access_token, authorizeInfo.openid);

            //_Apilog.WriteLog(JsonConvert.SerializeObject(res));
            return(res);
        }
Пример #2
0
 private Authorize getAuthorizeInfo(string code)
 {
     try
     {
         return(AuthorizeBiz.getUserInfo(code));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #3
0
        /// <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));
            }
        }
Пример #4
0
        /// <summary>
        /// 返回关注授权地址
        /// </summary>
        /// <returns></returns>
        private string getSnsapi_userinfo_Link()
        {
            string url = Request.Url.ToString();

            if (url.IndexOf("www.") < 0)
            {
                url = url.Replace("http://", "http://www.");
            }

            //请求微信接口获取code
            string Snsapi_userinfo_Link = AuthorizeBiz.getSnsapi_userinfo_Link(url);

            return(Snsapi_userinfo_Link);
        }
Пример #5
0
 private Userinfo getUserWechatInfo(Authorize authorInfo)
 {
     return(AuthorizeBiz.getUserinfo(authorInfo.access_token, authorInfo.openid));
 }