Esempio n. 1
0
        /// <summary>
        /// 通过OpenId获取用户信息(snsapi_base)
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public static SnsapiUserInfo GetSnsapiBase(string openid)
        {
            //string access_token = GetAccessToken(AppID, AppSecret);
            if (string.IsNullOrEmpty(access_token))
            {
                return(null);
            }
            string getUrl = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}";

            getUrl = string.Format(getUrl, access_token, openid);
            try
            {
                string returnJason = HttpUtility.GetData(getUrl);
                Utils.StringToTxt("GetSnsapiBase————cgi-bin/user/info:" + returnJason);
                SnsapiUserInfo model = (SnsapiUserInfo)JsonConvert.DeserializeObject(returnJason, typeof(SnsapiUserInfo));
                if (string.IsNullOrEmpty(model.openid))
                {
                    return(null);
                }
                return(model);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 通过OpenId获取用户信息(snsapi_userinfo )
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public static SnsapiUserInfo GetSnsapiUserInfo(string access_token, string openid)
        {
            string getUrl = "https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN";

            getUrl = string.Format(getUrl, access_token, openid);
            try
            {
                string returnJason = HttpUtility.GetData(getUrl);
                Utils.StringToTxt("GetSnsapiUserInfo————sns/userinfo:" + returnJason);
                SnsapiUserInfo model = (SnsapiUserInfo)JsonConvert.DeserializeObject(returnJason, typeof(SnsapiUserInfo));
                if (string.IsNullOrEmpty(model.openid))
                {
                    return(null);
                }
                return(model);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }