/// <summary>
        /// 拉取用户信息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public Model.WeiXinUserInfoResult GetWeiXinUserInfo(string accessToken, string openId)
        {
            string url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + accessToken + "&openid=" + openId + "&lang=zh_CN";

            string jsonStr = Common.Get(url);
            Model.WeiXinUserInfoResult result = new Model.WeiXinUserInfoResult();
            if (jsonStr.Contains("errcode"))
            {
                Model.WeiXinErrorMsg errorResult = new Model.WeiXinErrorMsg();
                errorResult = JsonHelper.ParseFromJson<Model.WeiXinErrorMsg>(jsonStr);
                result.ErrorMsg = errorResult;
                result.Result = false;
            }
            else
            {
                Model.WeiXinUserInfo userInfo = new Model.WeiXinUserInfo();
                userInfo = JsonHelper.ParseFromJson<Model.WeiXinUserInfo>(jsonStr);
                result.UserInfo = userInfo;
                result.Result = true;
            }
            return result;
        }
Exemple #2
0
        /// <summary>
        /// 拉取用户信息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public Model.WeiXinUserInfoResult GetWeiXinUserInfo(string accessToken, string openId)
        {
            string url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + accessToken + "&openid=" + openId + "&lang=zh_CN";

            string jsonStr = Tools.GetHttpRequest(url);

            Model.WeiXinUserInfoResult result = new Model.WeiXinUserInfoResult();
            if (jsonStr.Contains("errcode"))
            {
                Model.WeiXinErrorMsg errorResult = new Model.WeiXinErrorMsg();
                errorResult     = JsonHelper.ParseFromJson <Model.WeiXinErrorMsg>(jsonStr);
                result.ErrorMsg = errorResult;
                result.Result   = false;
            }
            else
            {
                Model.WeiXinUserInfo userInfo = new Model.WeiXinUserInfo();
                userInfo        = JsonHelper.ParseFromJson <Model.WeiXinUserInfo>(jsonStr);
                result.UserInfo = userInfo;
                result.Result   = true;
            }
            return(result);
        }