コード例 #1
0
ファイル: QrCode.cs プロジェクト: IllyaTheHath/QQRobot
        public static Int32 Login(DumbQQClient client)
        {
            while (true)
            {
                switch (client.Start(array =>
                {
                    File.WriteAllBytes(SharedInfo.QrCodeFile, array);
                    logger.Info($"二维码已获取,请打开文件 {SharedInfo.QrCodeFile} 扫描二维码");
                }))
                {
                case DumbQQClient.LoginResult.Succeeded:
                    return(0);

                case DumbQQClient.LoginResult.QrCodeExpired:
                    logger.Warn("二维码失效,请重新扫码");
                    continue;

                default:
                    logger.Warn("登录失败,需要重试吗?(y / n)");
                    var response = Console.ReadLine();
                    if (response.Contains("y"))
                    {
                        continue;
                    }
                    return(1);
                }
            }
        }
コード例 #2
0
        internal static List <FriendCategory> GetList(DumbQQClient client)
        {
            DumbQQClient.Logger.Debug("开始获取好友列表");
            var response = client.Client.Post(ApiUrl.GetFriendList,
                                              new JObject {
                { "vfwebqq", client.Vfwebqq }, { "hash", client.Hash }
            });
            var result = (JObject)client.GetResponseJson(response)["result"];
            //获得分组
            var categories         = result["categories"] as JArray;
            var categoryDictionary = new Dictionary <int, FriendCategory> {
                { 0, DefaultCategory() }
            };

            for (var i = 0; categories != null && i < categories.Count; i++)
            {
                var category = categories[i].ToObject <FriendCategory>();
                categoryDictionary.Add(category.Index, category);
            }
            foreach (var category in categoryDictionary.Values)
            {
                category.Client = client;
            }
            return(categoryDictionary.Select(_ => _.Value).ToList());
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            ((string, string, ulong, string), CookieContainer) ReadSession()
            {
                using (var stream = new FileStream(@"session.tmp", FileMode.Open))
                {
                    return((((string, string, ulong, string), CookieContainer)) new BinaryFormatter().Deserialize(
                               stream));
                }
            }

            ((string, string, ulong, string), CookieContainer) Authenticate()
            {
                var session = DumbQQClient.QrAuthenticate(x =>
                {
                    File.WriteAllBytes(@"qrcode.png", x);
                    Process.Start(@"qrcode.png");
                    Console.WriteLine("Waiting for authentication...");
                });

                using (var stream = new FileStream(@"session.tmp", FileMode.OpenOrCreate))
                {
                    new BinaryFormatter().Serialize(stream, session);
                }

                return(session);
            }

            var client = new DumbQQClient();

            try
            {
                client.Session = File.Exists(@"session.tmp") ? ReadSession() : Authenticate();
            }
            catch
            {
                client.Session = Authenticate();
            }

            Console.WriteLine(@"Logged in!");

            client.FriendCategories.Values.ForEach(x => Console.WriteLine(x.Name));
            client.Friends.Values.ForEach(x => Console.WriteLine(x.Name));
            client.Groups.Values.ForEach(x => Console.WriteLine(x.Name));
            client.Groups.Values.FirstOrDefault()?.Members.ForEach(x => Console.WriteLine(x.Value.NameAlias ?? x.Value.Name));
            client.Discussions.Values.ForEach(x => Console.WriteLine(x.Name));
            while (true)
            {
                try
                {
                    Console.Write(".");
                    client.Poll().ForEach(x => Console.WriteLine(x.Content));
                }
                catch (ApiException ex) when(ex.Code == 100100)
                {
                    Console.Write("*");
                }
            }
        }
コード例 #4
0
        internal static List <FriendStatus> GetList(DumbQQClient client)
        {
            DumbQQClient.Logger.Debug("开始获取好友状态列表");
            var response = client.Client.Get(ApiUrl.GetFriendStatus, client.Vfwebqq, client.Psessionid);

            return
                (((JArray)client.GetResponseJson(response)["result"])
                 .ToObject <List <FriendStatus> >());
        }
コード例 #5
0
ファイル: ChatHistory.cs プロジェクト: weikety/DumbQQ
        internal static List <ChatHistory> GetList(DumbQQClient client)
        {
            DumbQQClient.Logger.Debug("开始获取最近聊天记录列表");
            var response = client.Client.Post(ApiUrl.GetChatHistoryList,
                                              new JObject {
                { "vfwebqq", client.Vfwebqq }, { "clientid", DumbQQClient.ClientId }, { "psessionid", "" }
            });

            return
                (((JArray)client.GetResponseJson(response)["result"])
                 .ToObject <List <ChatHistory> >());
        }
コード例 #6
0
        internal static List <Discussion> GetList(DumbQQClient client)
        {
            DumbQQClient.Logger.Debug("开始获取讨论组列表");
            var response = client.Client.Get(ApiUrl.GetDiscussionList, client.Psessionid, client.Vfwebqq,
                                             RandomHelper.GetRandomDouble());
            var result =
                ((JArray)((JObject)client.GetResponseJson(response)["result"])["dnamelist"])
                .ToObject <List <Discussion> >();

            result.ForEach(_ => _.Client = client);
            return(result);
        }
コード例 #7
0
        internal static List <Group> GetList(DumbQQClient client)
        {
            DumbQQClient.Logger.Debug("开始获取群列表");
            var response = client.Client.Post(ApiUrl.GetGroupList,
                                              new JObject {
                { "vfwebqq", client.Vfwebqq }, { "hash", client.Hash }
            });
            var result =
                ((JArray)((JObject)client.GetResponseJson(response)["result"])["gnamelist"])
                .ToObject <List <Group> >();

            result.ForEach(_ => _.Client = client);
            return(result);
        }
コード例 #8
0
ファイル: QQService.cs プロジェクト: IllyaTheHath/QQRobot
        public void StartQQBot()
        {
            // 初始化QQ机器人
            logger.Info("初始化QQ机器人");
            logger.Info($"机器人类型为:{botType.Type}");
            client     = new DumbQQClient();
            botService = BotService.GetServiceInstance(botType.Name);

            // 好友消息回调
            client.FriendMessageReceived += OnFriendMessage;
            // 群消息回调
            client.GroupMessageReceived += OnGroupMessage;

            // 二维码登录
            var result = QrCode.Login(client);

            switch (result)
            {
            case 0:
                logger.Info($"登录成功,{client.Nickname}!");
                break;

            case 1:
                logger.Info($"登录失败,正在退出,{client.Nickname}!");
                CloseQQClient();
                Environment.Exit(1);
                return;
            }

            // 上线提醒
            String hello = $"机器人{botName}开始工作,当前工作模式:{botService.Introduction}";

            foreach (var group in client.Groups)
            {
                if (workGroups.Contains(group.Name))
                {
                    logger.Debug($"{group.Name}>>上线提醒:{hello}");
                    SendMessageToGroup(group.Id, hello);
                }
            }
        }
コード例 #9
0
ファイル: Friend.cs プロジェクト: zhilong0606/DumbQQ-Core
        internal static List <Friend> GetList(DumbQQClient client)
        {
            DumbQQClient.Logger.Debug("开始获取好友列表");
            var response = client.Client.Post(ApiUrl.GetFriendList,
                                              new JObject {
                { "vfwebqq", client.Vfwebqq }, { "hash", client.Hash }
            });
            var result = (JObject)client.GetResponseJson(response)["result"];
            //获得好友信息
            var friendDictionary = DumbQQClient.ParseFriendDictionary(result);
            var friends          = result["friends"] as JArray;

            for (var i = 0; friends != null && i < friends.Count; i++)
            {
                var item = (JObject)friends[i];
                friendDictionary[item["uin"].Value <long>()].CategoryIndex = item["categories"].Value <int>();
            }
            var value = friendDictionary.Select(_ => _.Value).ToList();

            value.ForEach(_ => _.Client = client);
            return(value);
        }