예제 #1
0
        private UserInfo_JsonModel GetWxUserInfo()
        {
            string code           = CacheManager.GetCache("code").ToString();
            string responseString = string.Empty;

            string url = string.Format(@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx3fab45769c82a189&secret=1b4feb651f6bbae81776068c241f8603&code={0}&grant_type=authorization_code", code);

            responseString = HttpManager.AccessURL_GET(url);
            Access_Token_JsonModel model = new Access_Token_JsonModel();
            UserInfo_JsonModel     user  = new UserInfo_JsonModel();

            try
            {
                model = JsonConvert.DeserializeObject <Access_Token_JsonModel>(responseString);

                LogHelper.Log.Write("access_token:" + model.access_token);

                user = GetUserInfo(model);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Write(ex.Message);
                LogHelper.Log.Write(ex.StackTrace);
                throw;
            }

            return(user);
        }
예제 #2
0
        /// <summary>
        /// 通过access_token获取用户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private UserInfo_JsonModel GetUserInfo(Access_Token_JsonModel model)
        {
            string responseString = string.Empty;
            string url            = string.Format(@"https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}", model.access_token, model.openid);

            responseString = HttpManager.AccessURL_GET(url);
            LogHelper.Log.Write("打印微信返回的xml");
            LogHelper.Log.Write(responseString);
            UserInfo_JsonModel user = new UserInfo_JsonModel();

            try
            {
                user = JsonConvert.DeserializeObject <UserInfo_JsonModel>(responseString);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Write(ex.Message);
                LogHelper.Log.Write(ex.StackTrace);
                throw;
            }

            return(user);
        }