Ejemplo n.º 1
0
        public override string GetOpenId()
        {
            var userInfoRawJson = GetRawUserInfo();

            if (string.IsNullOrWhiteSpace(userInfoRawJson))
            {
                throw new Exception("获取百度用户信息失败");
            }

            BaiduUserinfoEntity baidu_Userinfo = JsonConvert.DeserializeObject <BaiduUserinfoEntity>(userInfoRawJson);

            return(baidu_Userinfo.openid);
        }
Ejemplo n.º 2
0
        public override string GetRawUserInfo()
        {
            var accessToken = GetAccessToken();
            var url         = $"{UserInfo_Url}?access_token={accessToken.access_token}";
            var result      = HttpUtil.Get(url);

            BaiduUserinfoEntity baidu_Userinfo = JsonConvert.DeserializeObject <BaiduUserinfoEntity>(result);

            if (baidu_Userinfo == null)
            {
                return("");
            }
            else
            {
                return(JsonConvert.SerializeObject(baidu_Userinfo));
            }
        }
Ejemplo n.º 3
0
        public override FormatedUserInfo GetUserInfo()
        {
            var userInfoRawJson = GetRawUserInfo();

            if (string.IsNullOrWhiteSpace(userInfoRawJson))
            {
                throw new Exception("获取百度用户信息失败");
            }

            BaiduUserinfoEntity baidu_Userinfo = JsonConvert.DeserializeObject <BaiduUserinfoEntity>(userInfoRawJson);

            return(new FormatedUserInfo()
            {
                OpenId = baidu_Userinfo.openid,
                Channel = "baidu",
                NickName = string.IsNullOrWhiteSpace(baidu_Userinfo.username) ? baidu_Userinfo.realname : baidu_Userinfo.username,
                Gender = "1".Equals(baidu_Userinfo.sex) ? "m" : ("0".Equals(baidu_Userinfo.sex) ? "f" : "n"),
                Avatar = $"https://himg.bdimg.com/sys/portraitn/item/{baidu_Userinfo.portrait}",
            });
        }