Пример #1
0
        public override DResult <UserResult> User()
        {
            var code = "code".Query(string.Empty);

            var accessToken = AccessToken(code, Callback);

            if (accessToken.IsNullOrEmpty())
            {
                return(new DResult <UserResult>("授权失败!"));
            }

            var val = PlatformUtility.GetContext(accessToken);

            if (!string.IsNullOrWhiteSpace(val["error"]))
            {
                return(new DResult <UserResult>(val["error"]));
            }
            var info = new UserResult();

            info.Id = val["uid"];
            var token = val["access_token"];
            var json  = Config.UserUrl.FormatWith(info.Id, token).As <IHtml>().GetHtml(Encoding.UTF8);

            val          = PlatformUtility.GetContext(json);
            info.Gender  = (val["gender"] == "m" ? "男" : "女");
            info.Nick    = val["name"];
            info.Profile = val["profile_image_url"];
            return(new DResult <UserResult>(true, info));
        }
Пример #2
0
        public override DResult <UserResult> User()
        {
            var code = "code".Query(string.Empty);
            var col  = AccessToken(code);

            if (string.IsNullOrWhiteSpace(col["access_token"]))
            {
                return(new DResult <UserResult>("授权失败!"));
            }
            var result = new UserResult
            {
                Id          = col["openid"],
                AccessToken = col["access_token"]
            };
            var url         = string.Format(Config.UserUrl, result.AccessToken, result.Id);
            var html        = url.As <IHtml>().GetHtml(Encoding.UTF8);
            var userCollect = PlatformUtility.GetContext(html);

            if (!string.IsNullOrWhiteSpace(userCollect["errcode"]))
            {
                return(new DResult <UserResult>(userCollect["errmsg"]));
            }
            result.Nick    = userCollect["nickname"];
            result.Gender  = (userCollect["sex"] == "1" ? "男" : "女");
            result.Profile = userCollect["headimgurl"];
            return(new DResult <UserResult>(true, result));
        }
Пример #3
0
        private NameValueCollection AccessToken(string code)
        {
            var    url     = Config.TokenUrl.FormatWith(Config.Partner, Config.Key, code);
            string content = url.As <IHtml>().GetHtml(Encoding.UTF8);

            return(PlatformUtility.GetContext(content));
        }
Пример #4
0
        private string GetAccessToken(string code, string callBackUrl)
        {
            var    url     = Config.TokenUrl.FormatWith(Config.Partner, Config.Key, code, callBackUrl);
            string content = url.As <IHtml>().GetHtml(Encoding.UTF8);
            var    val     = PlatformUtility.GetContext(content);

            if (val["access_token"].IsNotNullOrEmpty())
            {
                return(val["access_token"]);
            }
            return(string.Empty);
        }
Пример #5
0
        public override DResult <UserResult> User()
        {
            var    code    = "code".Query(string.Empty);
            string context = GetAccessToken(code, Callback);

            var info = PlatformUtility.GetContext(context);

            if (info["errorCode"] == "0")
            {
                return(new DResult <UserResult>(true, new UserResult
                {
                    Id = info["openid"],
                    Nick = info["nick"]
                }));
            }
            return(new DResult <UserResult>(info["errorMsg"]));
        }