示例#1
0
        /// <summary>
        /// 保存BD用户数据
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public bool BD_SaveUser(BD_Token token)
        {
            //先根据绑定的QQ取到用户名
            string sql = "select username from BD_User where bindQQ='" + token.User.BindQQ + "'";

            token.User.Username = SqlHelper.ExecuteScalar(sql).ToString();
            //通过用户名取详细信息
            string url   = "https://bestdori.com/api/user?username="******"https://bestdori.com/community/user/" + token.User.Username;
            //发送请求
            string  result  = Tools.CreateGetHttpResponse(url, refer, "token=" + token.Token);
            JObject JResult = JObject.Parse(result);

            if (JResult["result"].ToString().Equals("True"))
            {
                token.User.FollowingCount  = int.Parse(JResult["followingCount"].ToString());
                token.User.FollowedByCount = int.Parse(JResult["followedByCount"].ToString());
                token.User.Nickname        = JResult["nickname"].ToString();
                token.User.SelfIntro       = JResult["selfIntro"].ToString();
                token.User.SocialMedia     = JResult["socialMedia"].ToString();
                token.User.FavCharacters   = JResult["favCharacters"].ToString();
                token.User.FavCards        = JResult["favCards"].ToString();
                token.User.FavBands        = JResult["favBands"].ToString();
                token.User.FavSongs        = JResult["favSongs"].ToString();
                token.User.FavCostumes     = JResult["favCostumes"].ToString();
            }
            sql = "update BD_User set followingcount={0},followedbycount={1},nickname='{2}',selfIntro='{3}',socialMedia='{4}',favCharacters='{5}',favCards='{6}',favBands='{7}',favSongs='{8}',favCostumes='{9}' where username = '******'";
            sql = String.Format(sql, token.User.FollowingCount, token.User.FollowedByCount, token.User.Nickname, token.User.SelfIntro, token.User.SocialMedia, token.User.FavCharacters, token.User.FavCards, token.User.FavBands, token.User.FavSongs, token.User.FavCostumes, token.User.Username);
            if (SqlHelper.ExecuteNonQuery(sql) > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// 同步游戏账号数据(公开数据)
        /// </summary>
        /// <param name="cookie"></param>
        /// <returns></returns>
        public string GBP_SyncUser(BD_Token cookie)
        {
            try
            {
                //请求位置
                string url   = "https://bestdori.com/api/sync/account";
                string refer = "https://bestdori.com/leaderboard/participate";
                //请求到的数据
                JObject result = JObject.Parse(Tools.CreateGetHttpResponse(url, refer, "token=" + cookie.Token));
                //定义一个全局,后面方便取数据
                JArray account_list = null;
                int    succ = 0, fail = 0, upd = 0;
                if (result["result"].ToString().Equals("True"))
                {
                    //账号列表
                    account_list = JArray.Parse(result["accounts"].ToString());
                    //遍历数据
                    for (int i = 0; i < account_list.Count; i++)
                    {
                        //解析账号数据
                        JObject account_ = JObject.Parse(account_list[i].ToString());
                        //创建一个用户对象
                        GBP_User user = new GBP_User();
                        //创建一个伺服器对象
                        GBP_Server server = new GBP_Server();
                        //伺服器对象赋值
                        server.Server = int.Parse(account_["server"].ToString());
                        user.Server   = server;
                        //获取区服详细数据
                        url = "https://bestdori.com/api/sync/account?server=" + server.Server;
                        JObject temp_serverdata = JObject.Parse(JObject.Parse(Tools.CreateGetHttpResponse(url, refer, "token=" + cookie.Token))["account"].ToString());
                        //加好友的id
                        user.Userid = temp_serverdata["uid"].ToString();
                        //玩家等级
                        if (temp_serverdata["rank"] == null)
                        {
                            user.Userrank = 0;
                        }
                        else
                        {
                            user.Userrank = int.Parse(temp_serverdata["rank"].ToString());
                        }
                        //完成的歌曲数量(ex+sp)
                        if (temp_serverdata["clearCount"] == null)
                        {
                            user.Complete = 0;
                        }
                        else
                        {
                            user.Complete = int.Parse(temp_serverdata["clearCount"].ToString());
                        }
                        //FC的数量(ex+sp)
                        if (temp_serverdata["fullComboCount"] == null)
                        {
                            user.Fullcombo = 0;
                        }
                        else
                        {
                            user.Fullcombo = int.Parse(temp_serverdata["fullComboCount"].ToString());
                        }
                        //玩家最高分
                        if (temp_serverdata["hsr"] == null)
                        {
                            user.Highscore = 0;
                        }
                        else
                        {
                            user.Highscore = int.Parse(temp_serverdata["hsr"].ToString());
                        }

                        string sql = "select * from GBP_User where userid='" + user.Userid + "'";
                        if (SqlHelper.ExecuteScalar(sql) == null)
                        {
                            sql = String.Format("insert into GBP_User(userid,userrank,server,complete,fullcombo,highscore,account) values('{0}',{1},{2},{3},{4},{5},'{6}')", user.Userid, user.Userrank, user.Server.Server, user.Complete, user.Fullcombo, user.Highscore, cookie.User.Username);
                            if (SqlHelper.ExecuteNonQuery(sql) > 0)
                            {
                                succ++;
                            }
                            else
                            {
                                fail++;
                            }
                        }
                        else
                        {
                            sql = String.Format("update GBP_User set userrank={0},complete={1},fullcombo={2},highscore={3} where userid='{4}' and server={5} and account='{6}'", user.Userrank, user.Complete, user.Fullcombo, user.Highscore, user.Userid, user.Server.Server, cookie.User.Username);
                            if (SqlHelper.ExecuteNonQuery(sql) > 0)
                            {
                                upd++;
                            }
                            else
                            {
                                fail++;
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception();
                }
                return(String.Format("同步数据成功,您在Bestdori上面绑定了{0}个游戏数据,已新增了{1}个档案,更新了{2}个档案,失败了{3}个档案!", account_list.Count, succ, upd, fail));
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }