Exemplo n.º 1
0
        /**
         * 程序入口
         *
         */
//    public void loginWb(){
//      client.preloginWb(new QQActionListener() {
//
//			@Override
//			public void onActionEvent(QQActionEvent evt) {
//				// TODO Auto-generated method stub
//				if (evt.getType() == Type.EVT_OK) {
//					//到这里就算是登录成功了
//					ArrayList<String> list = (ArrayList<String>) evt.getTarget();
//					foreach (String string : list) {
//						Console.WriteLine(string);
//					}
//					Console.WriteLine("就算是登录成功微博了");
//
//					new Thread(new Runnable() {
//
//						@Override
//						public void run() {
//							// TODO Auto-generated method stub
//							while(true){
//								try {
//									String sendMsg = new BufferedReader(new InputStreamReader(System.in)).readLine();
//									if(sendMsg.contains("#")){
//										client.pollWbMsg("5175429989", new QQActionListener() {
//
//											@Override
//											public void onActionEvent(QQActionEvent evt) {
//												// TODO Auto-generated method stub
//												if (evt.getType() == Type.EVT_OK) {
//													Console.WriteLine("pllmsg:   "+evt.getTarget());
//												}
//											}
//										});
//									}else{
//										client.sendWbMsg(sendMsg, "5175429989", new QQActionListener() {
//
//											@Override
//											public void onActionEvent(QQActionEvent evt) {
//												// TODO Auto-generated method stub
//												if (evt.getType() == Type.EVT_OK) {
//													Console.WriteLine("发送成功");
//												}
//											}
//										});
//									}
//
//								} catch (IOException e) {
//									// TODO Auto-generated catch block
//									e.printStackTrace();
//								}
//							}
//
//						}
//					}).start();
//
//				}else{
//					Console.WriteLine(evt.getTarget());
//				}
//			}
//		});
//    }

        /**
         * 聊天消息通知,使用这个注解可以收到QQ消息
         *
         * 接收到消息然后组装消息发送回去
         *
         * @throws QQException
         */
        public void processBuddyMsg(QQNotifyEvent evt)
        {
            QQMsg msg = (QQMsg)evt.getTarget();

            List <ContentItem> items = msg.getContentList();

            foreach (ContentItem item in items)
            {
                if (item.getType() == ContentItem.Type.FACE)
                {
                }
                else if (item.getType() == ContentItem.Type.OFFPIC)
                {
                }
                else if (item.getType() == ContentItem.Type.TEXT)
                {
                    Console.WriteLine(" Text:" + ((TextItem)item).getContent());
                }
            }

            // 组装QQ消息发送回去
            QQMsg sendMsg = new QQMsg();

            sendMsg.setTo(msg.getFrom());                   // QQ好友UIN
            sendMsg.setType(QQMsg.Type.BUDDY_MSG);          // 发送类型为好友
            // QQ内容
            sendMsg.addContentItem(new TextItem("hello"));  // 添加文本内容
            sendMsg.addContentItem(new FaceItem(0));        // QQ id为0的表情
            sendMsg.addContentItem(new FontItem());         // 使用默认字体
            client.sendMsg(sendMsg, null);                  // 调用接口发送消息
        }