Пример #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);                  // 调用接口发送消息
        }
Пример #2
0
        /**
         * <p>
         * processDiscuzMsg.
         * </p>
         *
         * @param pollData
         *            a {@link org.json.JSONObject} object.
         * @throws org.json.JSONException
         *             if any.
         * @throws iqq.im.QQException
         *             if any.
         * @return a {@link iqq.im.event.QQNotifyEvent} object.
         */
        public QQNotifyEvent processDiscuzMsg(JSONObject pollData)
        {
            QQStore store = getContext().getStore();

            QQMsg msg     = new QQMsg();
            long  fromUin = pollData.getLong("send_uin");
            long  did     = pollData.getLong("did");

            msg.parseContentList(pollData.getJSONArray("content").ToString());
            msg.setType(QQMsg.Type.DISCUZ_MSG);
            msg.setDiscuz(store.getDiscuzByDid(did));
            msg.setTo(getContext().getAccount());
            msg.setDate(new DateTime(pollData.getLong("time") * 1000));

            if (msg.getDiscuz() != null)
            {
                msg.setFrom(msg.getDiscuz().getMemberByUin(fromUin));
            }

            if (msg.getFrom() == null)
            {
                QQDiscuzMember member = new QQDiscuzMember();
                member.setUin(fromUin);
                msg.setFrom(member);
                if (msg.getDiscuz() != null)
                {
                    msg.getDiscuz().getMembers().Add(member);
                }
            }
            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }
Пример #3
0
        /**
         * <p>
         * processBuddyMsg.
         * </p>
         *
         * @param pollData
         *            a {@link org.json.JSONObject} object.
         * @throws org.json.JSONException
         *             if any.
         * @throws iqq.im.QQException
         *             if any.
         * @return a {@link iqq.im.event.QQNotifyEvent} object.
         */
        public QQNotifyEvent processBuddyMsg(JSONObject pollData)
        {
            QQStore store = getContext().getStore();

            long  fromUin = pollData.getLong("from_uin");
            QQMsg msg     = new QQMsg();

            msg.setId(pollData.getLong("msg_id"));
            msg.setId2(pollData.getLong("msg_id2"));
            msg.parseContentList(pollData.getJSONArray("content").ToString());
            msg.setType(QQMsg.Type.BUDDY_MSG);
            msg.setTo(getContext().getAccount());
            msg.setFrom(store.getBuddyByUin(fromUin));
            msg.setDate(new DateTime(pollData.getLong("time") * 1000));
            if (msg.getFrom() == null)
            {
                QQUser member = store.getStrangerByUin(fromUin);         // 搜索陌生人列表
                if (member == null)
                {
                    member = new QQHalfStranger();
                    member.setUin(fromUin);
                    store.addStranger((QQStranger)member);
                }
                msg.setFrom(member);
            }
            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }
Пример #4
0
        /**
         * <p>
         * processSessionMsg.
         * </p>
         *
         * @param pollData
         *            a {@link org.json.JSONObject} object.
         * @throws org.json.JSONException
         *             if any.
         * @throws iqq.im.QQException
         *             if any.
         * @return a {@link iqq.im.event.QQNotifyEvent} object.
         */
        public QQNotifyEvent processSessionMsg(JSONObject pollData)
        {
            // {"retcode"in0,"result"in[{"poll_type"in"sess_message",
            // "value"in{"msg_id"in25144,"from_uin"in167017143,"to_uin"in1070772010,"msg_id2"in139233,"msg_type"in140,"reply_ip"in176752037,"time"in1365931836,"id"in2581801127,"ruin"in444674479,"service_type"in1,
            // "flags"in{"text"in1,"pic"in1,"file"in1,"audio"in1,"video"in1},"content"in[["font",{"size"in9,"color"in"000000","style"in[0,0,0],"name"in"Tahoma"}],"2\u8F7D3 ",["face",1]," "]}}]}
            QQStore store = getContext().getStore();

            QQMsg msg         = new QQMsg();
            long  fromUin     = pollData.getLong("from_uin");
            long  fromQQ      = pollData.getLong("ruin");        // 真实QQ
            int   serviceType = pollData.getInt("service_type"); // Groupin0,Discussin1
            long  typeId      = pollData.getLong("id");          // Group ID or Discuss ID

            msg.parseContentList(pollData.getJSONArray("content").ToString());
            msg.setType(QQMsg.Type.SESSION_MSG);
            msg.setTo(getContext().getAccount());
            msg.setDate(new DateTime(pollData.getLong("time") * 1000));

            QQUser user = store.getBuddyByUin(fromUin);     // 首先看看是不是自己的好友

            if (user != null)
            {
                msg.setType(QQMsg.Type.BUDDY_MSG);         // 是自己的好友
            }
            else
            {
                if (serviceType == 0)           // 是群成员
                {
                    QQGroup group = store.getGroupByCode(typeId);
                    foreach (QQUser u in group.getMembers())
                    {
                        if (u.getUin() == fromUin)
                        {
                            user = u;
                            break;
                        }
                    }
                }
                else if (serviceType == 1)             // 是讨论组成员
                {
                    QQDiscuz discuz = store.getDiscuzByDid(typeId);
                    foreach (QQUser u in discuz.getMembers())
                    {
                        if (u.getUin() == fromUin)
                        {
                            user = u;
                            break;
                        }
                    }
                }
                else
                {
                    user = store.getStrangerByUin(fromUin); // 看看陌生人列表中有木有
                }
                if (user == null)                           // 还没有就新建一个陌生人,原理来说不应该这样。后面我就不知道怎么回复这消息了,但是消息是不能丢失的
                {
                    user = new QQStranger();
                    user.setQQ(pollData.getLong("ruin"));
                    user.setUin(fromUin);
                    user.setNickname(pollData.getLong("ruin") + "");
                    store.addStranger((QQStranger)user);
                }
            }
            user.setQQ(fromQQ);     // 带上QQ号码
            msg.setFrom(user);
            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }
Пример #5
0
        /**
         * <p>
         * processGroupMsg.
         * </p>
         *
         * @param pollData
         *            a {@link org.json.JSONObject} object.
         * @throws org.json.JSONException
         *             if any.
         * @throws iqq.im.QQException
         *             if any.
         * @return a {@link iqq.im.event.QQNotifyEvent} object.
         */
        public QQNotifyEvent processGroupMsg(JSONObject pollData)
        {
            // {"retcode"in0,"result"in[{"poll_type"in"group_message",
            // "value"in{"msg_id"in6175,"from_uin"in3924684389,"to_uin"in1070772010,"msg_id2"in992858,"msg_type"in43,"reply_ip"in176621921,
            // "group_code"in3439321257,"send_uin"in1843694270,"seq"in875,"time"in1365934781,"info_seq"in170125666,"content"in[["font",{"size"in10,"color"in"3b3b3b","style"in[0,0,0],"name"in"\u5FAE\u8F6F\u96C5\u9ED1"}],"eeeeeeeee "]}}]}
            QQStore store = getContext().getStore();
            QQMsg   msg   = new QQMsg();

            msg.setId(pollData.getLong("msg_id"));
            msg.setId2(pollData.getLong("msg_id2"));
            int     msgType   = pollData.getInt("msg_type");
            long    gin       = pollData.getLong("from_uin");
            long    fromUin   = pollData.getLong("send_uin");
            long    groupCode = pollData.getLong("group_code");
            QQGroup group     = store.getGroupByCode(groupCode);
            long    groupID   = -1;

            if (group == null)
            {
                group = new QQGroup();
                group.setGin(gin);
                group.setCode(groupCode);
                // put to store
                store.addGroup(group);
            }
            switch (msgType)
            {
            case 32: {
                // 魔法、超级、涂鸦表情
                groupID = pollData.getLong("t_gcode");         // 真实群号码
                break;
            }

            case 43:
                // 一般消息
                groupID = pollData.getLong("info_seq");         // 真实群号码


                msg.parseContentList(pollData.getJSONArray("content").ToString());
                msg.setType(QQMsg.Type.GROUP_MSG);
                msg.setDate(new DateTime(pollData.getLong("time") * 1000));
                break;

            default:
                break;
            }
            if (group.getGid() <= 0)
            {
                group.setGid(groupID);
            }
            msg.setGroup(group);
            if (group != null)
            {
                msg.setFrom(group.getMemberByUin(fromUin));
            }
            msg.setTo(getContext().getAccount());
            if (msg.getFrom() == null)
            {
                QQGroupMember member = new QQGroupMember();
                member.setUin(fromUin);
                msg.setFrom(member);
                if (group != null)
                {
                    group.getMembers().Add(member);
                }
            }

            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }