Exemplo n.º 1
0
        private void BindingDataGridView(DataGridView dgv, Dictionary <string, WeiboUserInfo> data)
        {
            dgv_output.Rows.Clear();
            if (data.Any())
            {
                foreach (var item in data)
                {
                    string        origin   = item.Key;
                    WeiboUserInfo userInfo = item.Value;
                    int           index    = dgv.Rows.Add();
                    dgv.Rows[index].Cells["UID"].Value         = userInfo.UID;
                    dgv.Rows[index].Cells["FansNum"].Value     = userInfo.FansNum;
                    dgv.Rows[index].Cells["NickName"].Value    = userInfo.NickName;
                    dgv.Rows[index].Cells["Sex"].Value         = userInfo.Sex;
                    dgv.Rows[index].Cells["IsV"].Value         = userInfo.IsV ? "是" : "否";
                    dgv.Rows[index].Cells["OriginParma"].Value = origin;
                    dgv.Rows[index].Cells["IsTruly"].Value     = userInfo.IsTruly;

                    //头像和是短连接需要单独的处理
                    if (userInfo.IsTruly || !cb_isForceMate.Checked)
                    {
                        //完全匹配了之后就准备短连接了
                        dgv.Rows[index].Cells["ShortLink"].Value = (userInfo.UID == "-1") ? "未匹配到" : ((cb_https.Checked ? "https" : "http") + "://m.weibo.cn/u/" + userInfo.UID);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task <WeiboUserInfo> GetUserInfoAsync(string code)
        {
            var userInfo = new WeiboUserInfo();
            var pair     = GetAccessTokenAndUId(code);

            userInfo.UnionId = pair.Value;
            var url    = $"https://api.weibo.com/2/users/show.json?access_token={pair.Key}&uid={pair.Value}";
            var result = await LoginManager.GetStringAsync(url);

            var data = JObject.Parse(result);

            userInfo.Name        = data["name"].Value <string>();
            userInfo.ScreenName  = data["screen_name"].Value <string>();
            userInfo.AvatarLarge = data["avatar_large"].Value <string>();

            return(userInfo);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 根据微博的昵称获取相关信息
 /// </summary>
 /// <param name="nickName"></param>
 /// <param name="IsMohu">是否模糊匹配,模糊的话,会返回匹配列表的第一个</param>
 /// <returns></returns>
 private static WeiboUserInfo SearchWeibo(string nickName)
 {
     try
     {
         string url  = "http://s.weibo.com/ajax/topsuggest.php?key=" + nickName;
         string html = GetHtmlByUrl(url);
         var    test = HttpHelper.GetBetweenHtml(html, "try{window.&(", ");}catch");
         test = test.Remove(0, 1);
         test = test.Remove(test.Length - 1, 1);//掐头去尾两个()
         QuickSearchReturnModel model = Newtonsoft.Json.JsonConvert.DeserializeObject <QuickSearchReturnModel>(test);
         if (model != null)
         {
             if (model.UserData != null && model.UserData.UserList.Any())
             {
                 //说明有数据,那就开始匹配
                 WeiboUserInfo userInfo = model.UserData.UserList.First();
                 userInfo.IsTruly = false;
                 foreach (var item in model.UserData.UserList)
                 {
                     if (item.NickName == nickName)
                     {
                         userInfo = item;
                         //100%匹配
                         userInfo.IsTruly = true;
                         break;
                     }
                 }
                 return(userInfo);
             }
         }
     }
     catch (Exception ex)
     { }
     return(new WeiboUserInfo()
     {
         IsTruly = false, UID = "-1"
     });                                                        //这个代表了没有返回值,匹配度为0
 }