public LoginResult Start(Action <string> qrCodeDownloadedCallback) => Start(_ =>
 {
     var filePath = Path.GetFullPath("qrcode" + RandomHelper.GetRandomInt() + ".png");
     File.WriteAllBytes(filePath, _);
     SmartQQClient.ConsoleWriteImage(filePath);
     qrCodeDownloadedCallback(filePath);
 });
Beispiel #2
0
        internal static List <FriendCategory> GetList(SmartQQClient client)
        {
            SmartQQClient.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() } };
            var categoryDictionary = new Dictionary <int, FriendCategory> {
            };

            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());
        }
Beispiel #3
0
        internal static List <FriendStatus> GetList(SmartQQClient client)
        {
            SmartQQClient.Logger.Debug("开始获取好友状态列表");
            var response = client.Client.Get(ApiUrl.GetFriendStatus, client.Vfwebqq, client.Psessionid);

            return
                (((JArray)client.GetResponseJson(response)["result"])
                 .ToObject <List <FriendStatus> >());
        }
Beispiel #4
0
        internal static List <Discussion> GetList(SmartQQClient client)
        {
            SmartQQClient.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);
        }
Beispiel #5
0
        internal static List <ChatHistory> GetList(SmartQQClient client)
        {
            SmartQQClient.Logger.Debug("开始获取最近聊天记录列表");
            var response = client.Client.Post(ApiUrl.GetChatHistoryList,
                                              new JObject {
                { "vfwebqq", client.Vfwebqq }, { "clientid", SmartQQClient.ClientId }, { "psessionid", "" }
            });

            return
                (((JArray)client.GetResponseJson(response)["result"])
                 .ToObject <List <ChatHistory> >());
        }
Beispiel #6
0
        internal static List <Group> GetList(SmartQQClient client)
        {
            SmartQQClient.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);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            SmartQQClient
            // 登录
            .Login((bytes) =>
            {
                using (var ms = new MemoryStream(bytes))
                {
                    SmartQQClient.ConsoleWriteImage(new Bitmap(Image.FromStream(ms)));
                    Logger.Instance.Info("二维码已打印在屏幕,请使用手机QQ扫描。");
                }
            })
            // 好友消息回调
            .ReceivedFriendMessage((message) => {
                //message.Reply("test");
                Logger.Instance.Info($"{message.Sender.Alias ?? message.Sender.Nickname}:{message.Content}");
            })
            // 群消息回调
            .ReceivedGroupMessage((message) => {
                Logger.Instance.Info(
                    $"[{message.Group.Name}]{message.Sender.Alias ?? message.Sender.Nickname}:{message.Content}");
                if (message.Content.IsMatch(@"^\s*Knock knock\s*$"))
                {
                    message.Reply("Who's there?");
                }
                else if (message.StrictlyMentionedMe)
                {
                    message.Reply("什么事?");
                }
            })
            // 讨论组消息回调
            .ReceivedDiscussionMessage((message) =>
            {
                Logger.Instance.Info($"[{message.Discussion.Name}]{message.Sender.Nickname}:{message.Content}");
            })
            // 消息回显
            .ReceivedMessageEchoEventArgs((e) => {
                Logger.Instance.Info($"{e.Target.Name}>{e.Content}");
            })
            //开始服务
            .Start((client) => {
                Logger.Instance.Info($"欢迎,{client.Nickname}!");
            });

            Console.ReadLine();
        }
Beispiel #8
0
        internal static List <Friend> GetList(SmartQQClient client)
        {
            SmartQQClient.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 = SmartQQClient.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);
        }
Beispiel #9
0
 public ClientManager(QQState user, SmartQQClient client)
 {
     _user   = user;
     _client = client;
 }