示例#1
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);
 }
示例#2
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);
        }