现在的位置: 首页 > 综合 > 正文

SkylineSoft.WebQQ( 1.X)

2017年11月13日 ⁄ 综合 ⁄ 共 3255字 ⁄ 字号 评论关闭

/************************************
版权所有:SkylineSoft版权所有(C)
创建日期:2011-7-10
作  者:天涯居士
电子邮件:Jiangwzh@163.com
 
系统名称:WebQQ演示程序
模块名称:
内容摘要:
***********************************/

using System;
using System.Collections.Generic;
using System.Text;
using SkylineSoft.WebQQ.Model;
using SkylineSoft.WebQQ;
using SkylineSoft.WebQQ.Utils;

namespace SkylineSoft.WebQQ.ConsoleDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "SkylineSoft.WebQQ Demo";

            WebQQClient client = new WebQQClient(0, "");

            client.LoginBegin += new WebQQEventHandler(client_LoginBegin);
            client.LoginCompleted += new LoginCompletedHandler(client_LoginCompleted);
            client.LogoutBegin+=new WebQQEventHandler(client_LogoutBegin);
            client.Logouted += new WebQQEventHandler(client_Logouted);
            client.QQMessageReceived += new QQMessageReceivedHandler(client_QQMessageReceived);

            client.Login();

            Console.ReadKey();

            client.Logout();
        }

        /// <summary>
        /// 开始登录事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void client_LoginBegin(WebQQClient sender, WebQQEventArgs e)
        {
            Console.WriteLine("{0}\t正在登录...", sender.Context.LoginAccount.Account);
        }
       
        /// <summary>
        /// 登录成功事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void client_LoginCompleted(WebQQClient sender, LoginCompletedEventArgs e)
        {
            Console.WriteLine("{0}\t{1}({2})", sender.Context.LoginAccount.Account, e.LoginResult.Message, e.LoginResult.Code);

            if (sender.Context.LoginStatus == LoginStatus.Loginned)
            {
                //加载我的好友
                Console.WriteLine("{0}正在加载好友...", sender.Context.LoginAccount.Account);
                sender.LoadUserFriends();
                //加载所有好友QQ号
                Console.WriteLine("{0}正在加载好友QQ号...", sender.Context.LoginAccount.Account);
                sender.LoadAllFriendsAccount();
                //加载所有好友详细信息
                Console.WriteLine("{0}正在加载好友QQ详细信息...", sender.Context.LoginAccount.Account);
                sender.LoadAllFriendsDetailInfo();

                //打印所有好友信息
                Console.WriteLine(sender.GetAllFriendsSimpleInfo());

                //加载所有群
                Console.WriteLine("{0}正在加载群列表...", sender.Context.LoginAccount.Account);
                sender.LoadGroupList();
                //加载所有群QQ号
                Console.WriteLine("{0}正在加载群帐号...", sender.Context.LoginAccount.Account);
                sender.LoadAllGroupsAccount();
                //加载所有群信息
                Console.WriteLine("{0}正在加载群信息...", sender.Context.LoginAccount.Account);
                sender.LoadAllGroupsInfo();
                //更新所有群的成员信息
                Console.WriteLine("{0}正在加载群成员QQ号与详细信息...", sender.Context.LoginAccount.Account);
                sender.UpdateAllGroupMembersAccountAndDetailInfo(true);

                //打印所有群信息
                Console.WriteLine(sender.GetAllGroupMemberSimpleInfo());


                //发送群消息
                sender.SendGroupMessageByAccount(86276066, "hello any body!");
                sender.SendNormalMessageByAccount(14913978, "hello any body!");
            }
        }


        /// <summary>
        /// 开始退出事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void client_LogoutBegin(WebQQClient sender, WebQQEventArgs e)
        {
            Console.WriteLine("{0}\t准备退出...", sender.Context.LoginAccount.Account);
        }

        /// <summary>
        /// 已经退出事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void client_Logouted(WebQQClient sender, WebQQEventArgs e)
        {
            Console.WriteLine("{0}\t准备退出...", sender.Context.LoginAccount.Account);
        }

        /// <summary>
        /// 处理收到QQ消息事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void client_QQMessageReceived(WebQQClient sender, QQMessageReceivedEventArgs e)
        {
            foreach (var messge in e.Messages)
            {
                Console.WriteLine(string.Format("{0}({1})\t{2}",messge.SenderName,messge.SenderId,messge.SendTime));
                Console.WriteLine(messge.MsgContent);
            }
        }

    }
}

抱歉!评论已关闭.